Changeset 19 in mp3-find for trunk/lib/MP3/Find


Ignore:
Timestamp:
03/28/06 19:38:39 (19 years ago)
Author:
peter
Message:
  • added "status_callback" option to the constructor for MP3::Find::DB
  • default status callback just prints the status code and the file name to STDERR as before
  • using an empty status_callback in t/03-db.t (status_callback => sub {}) to keep the test output more legible
  • updated docs in Find.pm
  • mkreadme now prints a blank line between the file header and the DESCRIPION section
  • generated new README file
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/MP3/Find/DB.pm

    r13 r19  
    4343); 
    4444 
     45my $DEFAULT_STATUS_CALLBACK = sub { 
     46    my ($action_code, $filename) = @_; 
     47    print STDERR "$action_code $filename\n"; 
     48}; 
    4549 
    4650sub search { 
     
    8993sub update_db { 
    9094    my $self = shift; 
    91     my $db_file = shift or croak "Need the name of the databse to update"; 
     95    my $db_file = shift or croak "Need the name of the database to update"; 
    9296    my $dirs = shift; 
     97     
     98    my $status_callback = $self->{status_callback} || $DEFAULT_STATUS_CALLBACK; 
    9399     
    94100    my @dirs = ref $dirs eq 'ARRAY' ? @$dirs : ($dirs); 
     
    126132        if (@$records == 0) { 
    127133            $insert_sth->execute(map { $mp3->{$$_[0]} } @COLUMNS); 
    128             print STDERR "A $$mp3{FILENAME}\n"; 
     134            $status_callback->(A => $$mp3{FILENAME}); 
    129135            $count++; 
    130136        } elsif ($mp3->{mtime} > $$records[0][0]) { 
    131137            # the mp3 file is newer than its record 
    132138            $update_sth->execute((map { $mp3->{$$_[0]} } @COLUMNS), $mp3->{FILENAME}); 
    133             print STDERR "U $$mp3{FILENAME}\n"; 
     139            $status_callback->(U => $$mp3{FILENAME}); 
    134140            $count++; 
    135141        } 
     
    140146    foreach ($mtime_sth, $insert_sth, $update_sth) { 
    141147        $_->{RaiseError} = 0;  # don't die on error 
     148        $_->{PrintError} = 0;  # ...and don't even say anything 
    142149        $_->{Active} = 1; 
    143150        $_->finish; 
     
    150157    my $self = shift; 
    151158    my $db_file = shift or croak "Need the name of the databse to sync"; 
    152      
     159 
     160    my $status_callback = $self->{status_callback} || $DEFAULT_STATUS_CALLBACK; 
     161 
    153162    my $dbh = DBI->connect("dbi:SQLite:dbname=$db_file", '', '', {RaiseError => 1}); 
    154163    my $select_sth = $dbh->prepare('SELECT FILENAME FROM mp3'); 
     
    162171        unless (-e $filename) { 
    163172            $delete_sth->execute($filename); 
    164             print STDERR "D $filename\n"; 
     173            $status_callback->(D => $filename); 
    165174            $count++; 
    166175        } 
Note: See TracChangeset for help on using the changeset viewer.