=head1 NAME Convert::CD::TOCFile - base class to represent TOC files. =head1 SYNOPSIS use Convert::CD::TOCFile; # to be done =head1 DESCRIPTION A TOCFile object is used to represent file-format-specific information about an image, such as image or track filenames and read/write functionality for toc files. =head2 Convert:CD::TOCFile METHODS =over 4 =cut package Convert::CD::TOCFile; $VERSION = 0.01; use File::Spec; use Carp; use Convert::CD; use base Convert::CD::TOCFile; =item Convert::CD::TOCFile->autodetect (path) Try to autodetect the type of image (or tocfile) identified by C. Returns a list of TOCFile-Classes to try. =cut sub autodetect { my ($self, $path) = @_; my @r; # shouldn't use ending... but Class->autodetect. #push @r, Convert::CD::Toc # if $self->find_tocfile ("toc", "TOC", "Toc"); #push @r, Convert::CD::Ccd # if $self->find_tocfile ("ccd", "CCD", "Ccd"); push @r, Convert::CD::Cue if $self->find_tocfile ("cue", "CUE", "Cue"); #push @r, Convert::CD::Nrg # bad # if $self->find_tocfile ("nrg", "NRG", "Nrg"); push @r, Convert::CD::Analyze; @r; } =item new param => value... Create a new Convert::CD::TOCFile object. Parameters: path the base image filename =cut sub new { my $class = shift; my $self = bless { @_, }, $class; $self; } =item $toc->find_tocfile suffixes.. Try to find a tocfile by probing the given suffixes. =cut sub find_tocfile { my ($self, @ext) = @_; my $stem = $self->{path}; $stem =~ s/\.\S{2,4}$//; for (@ext) { return "$stem.$_" if -f "$stem.$_"; } (); } =item $cd = $toc->read Read the TOC file, returns a new Convert::CD object. =item $toc->write ($cd) Write the TOC File using the information in the given Convert::CD object. =cut sub read { my ($self) = @_; my $cd = new Convert::CD path => $self->{path} or croak "unable to create a new Convert::CD object"; $self->_read ($cd); $cd; } sub write { my ($self, $cd) = @_; $self->_write ($cd); } # abstract methods sub _read { my ($self, $cd) = @_; croak sprintf "reading %s toc files is not supported", ref $self; } sub _write { my ($self, $cd) = @_; croak sprintf "writing %s toc files is not supported", ref $self; } =item $msf = Convert::CD::TOCFile->parse_msf ($string) Parses a time and returns it as a frame number (can be negative if the string contains a leading minus). Returns C on error. =cut sub parse_msf { $_[1] =~ /^(-?\d+):(\d+):(\d+)$/ or return undef; ($1 * 60 + $2) * 75 + $3; } 1; =back =head1 AUTHOR Marc Lehmann =cut