ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Convert-CD/lib/Convert/CD.pm
Revision: 1.4
Committed: Tue Jun 10 12:47:49 2003 UTC (23 years, 3 months ago) by root
Branch: MAIN
Changes since 1.3: +71 -12 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3 root 1.2 Convert::CD - import/export/represent various cd image file formats
4 root 1.1
5     =head1 SYNOPSIS
6    
7     use Convert::CD;
8    
9     # to be done
10    
11     =head1 DESCRIPTION
12    
13     Kidding?
14    
15 root 1.3 =head2 Convert:CD METHODS
16    
17 root 1.4 This class represents a full CD image, which can consist of one or more
18     files. While track layout and TOC data is stored in this class, to
19     read/write TOC files you need a Convert::CD::TOCFile.
20 root 1.1
21     =over 4
22    
23     =cut
24    
25     package Convert::CD;
26    
27     $VERSION = 0.01;
28    
29 root 1.4 use base Exporter;
30    
31 root 1.1 =item new param => value...
32    
33     Create a new Convert::CD object.
34    
35 root 1.3 my $cd = new path => "/tmp/mycd.bin";
36 root 1.1
37     =cut
38    
39     sub new {
40     my $class = shift;
41 root 1.4 my $self = bless {
42     track => [], # an array of tracks, track #1 is in index 0
43 root 1.2 @_,
44     }, $class;
45 root 1.4
46     $self;
47     }
48    
49     =item $cd->append_track(param => value...)
50    
51     Appends a new track to the image. Same parameters as Convert::CD::Track->new.
52    
53     =cut
54    
55     sub append_track {
56     my ($self, %arg) = @_;
57    
58     push @{$self->{track}}, Convert::CD::Track->new (%arg);
59 root 1.3 }
60    
61 root 1.4 =item $cd->as_string
62    
63     Returns a multi-line, textual description of the CD Image.
64    
65     =cut
66    
67     sub as_string {
68     my ($self) = @_;
69     my $r;
70    
71     $r .= "Image Path: $self->{path}\n";
72    
73     for my $idx (1 .. @{$self->{track}}) {
74     $r .= sprintf "Track %02d: %s\n", $idx, $self->{track}[$idx - 1]->as_string;
75     }
76    
77     $r;
78     }
79    
80     package Convert::CD::Track;
81    
82 root 1.3 =back
83    
84     =head2 Convert::CD::Track METHODS
85    
86     This class is used to repesent single track objects.
87    
88     =over 4
89    
90     =item new param => value...
91    
92     Create a new track object.
93    
94     Parameters:
95    
96 root 1.4 path the file that contains the track
97     offset the offste within the file that contains the first sector
98     (may be negative)
99     size the raw size (in bytes) of the track. (guessed if missing)
100     mode a mode string (MODE1, MODE2, AUDIO, CDI, CDG....)
101     datasize size of the data part of the sector (e.g. 2048). (def. secsize)
102     secsize size of a sector in disk image
103     index an array of index times (0 is pregap start, 1 is track start)
104 root 1.3
105     =cut
106    
107     sub new {
108     my $class = shift;
109 root 1.4 my $self = bless {
110 root 1.3 @_,
111     }, $class;
112 root 1.4
113     $self->{size} ||= (-s $self->{path}) - $self->{offset};
114     $self->{datasize} ||= $self->{secsize};
115    
116     $self;
117     }
118    
119     =item $cd->as_string
120    
121     Returns a single-line, textual description of the track.
122    
123     =cut
124    
125     sub as_string {
126     my ($self) = @_;
127     my $r;
128    
129     sprintf "%s %08x+%08x %s/%d", $self->{path},
130     $self->{offset}, $self->{size},
131     $self->{mode}, $self->{secsize};
132 root 1.1 }
133    
134     1;
135    
136     =back
137    
138     =head1 AUTHOR
139    
140     Marc Lehmann <pcg@goof.com>
141    
142     =cut
143