Changeset 24 in flacrip


Ignore:
Timestamp:
10/08/14 21:47:47 (9 years ago)
Author:
peter
Message:
  • converted Tracks from Class::Std to Moose
  • added a has_tracks() method to Tracks
Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Ripper.pm

    r23 r24  
    1212has tracks => (  
    1313    is => 'rw', 
    14     handles => [qw{read_disc get_tracks get_cuesheet}], 
     14    handles => [qw{read_disc has_tracks get_cuesheet}], 
    1515); 
    1616 
     
    2121    $self->read_disc($self->device); 
    2222 
    23     die "No tracks found; is there a CD in the drive?\n" unless @{ $self->get_tracks }; 
     23    die "No tracks found; is there a CD in the drive?\n" unless $self->has_tracks; 
    2424 
    2525    my $tempdir = tempdir(CLEANUP => 1); 
  • trunk/lib/Tracks.pm

    r22 r24  
    11package Tracks; 
    22 
    3 use strict; 
    4 use warnings; 
    5  
    6 use Class::Std; 
     3use Moose; 
    74use Digest::SHA1; 
    8 use Audio::FLAC::Header; 
    95 
    106use constant SECTOR_OFFSET => 150; 
    117 
    12 my %tracks_for :ATTR( get => 'tracks' ); 
     8has tracks => ( 
     9    is      => 'rw', 
     10    default => sub { [] }, 
     11); 
    1312 
    1413sub _get_tracks_from_cdinfo {     
     
    6665sub read_disc { 
    6766    my ($self, $device) = @_; 
    68     $tracks_for{ident $self} = [ _get_tracks_from_cdparanoia($device) ]; 
     67    $self->tracks([ _get_tracks_from_cdparanoia($device) ]); 
     68} 
     69 
     70sub has_tracks { 
     71    my $self = shift; 
     72    return @{ $self->tracks } > 0; 
    6973} 
    7074 
     
    7276    my ($self) = @_; 
    7377 
    74     my @tracks = @{ $tracks_for{ident $self} }; 
     78    my @tracks = @{ $self->tracks }; 
    7579 
    7680    return unless @tracks; 
     
    9599sub get_cuesheet { 
    96100    my ($self) = @_; 
    97     my @tracks = @{ $tracks_for{ident $self} }; 
     101    my @tracks = @{ $self->tracks }; 
    98102    my @cuesheet; 
    99103    push @cuesheet, qq{FILE "cdda.wav" WAVE}; 
     
    112116    my ($self) = @_; 
    113117    # use a msf start unless track 1 begins at sector 
    114     return $tracks_for{ident $self}[1]{sector} == 0 ? '1-' : '00:00.00-'; 
     118    return $self->tracks->[1]{sector} == 0 ? '1-' : '00:00.00-'; 
    115119} 
    116120 
Note: See TracChangeset for help on using the changeset viewer.