Changeset 12 in mp3-find


Ignore:
Timestamp:
02/14/06 20:19:23 (19 years ago)
Author:
peter
Message:
  • added "exclude_path" option to Filesystem backend
  • added an excluded directory to the test suite ("t/dont_look_here")
  • fixed dying DB test (still a workaround for a DBD::SQLite problem)
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Changes

    r10 r12  
    11Revision history for Perl extension MP3::Find. 
    22 
    3 0.01  29 Jan 2006 
    4     - first CPAN release 
     30.03 
     4    - added "exclude_path" option to filesystem backend 
    55 
    660.02  1 Feb 2006 
     
    99    - DB management functions are now in the DB backend 
    1010    - rewrote (and documented) mp3db to use the new DB backend functions 
     11 
     120.01  29 Jan 2006 
     13    - first CPAN release 
  • trunk/lib/MP3/Find/DB.pm

    r10 r12  
    123123        warn "Multiple records for $$mp3{FILENAME}\n" if @$records > 1; 
    124124         
     125        #TODO: maybe print status updates somewhere else? 
    125126        if (@$records == 0) { 
    126127            $insert_sth->execute(map { $mp3->{$$_[0]} } @COLUMNS); 
     
    138139    # (see http://rt.cpan.org/Ticket/Display.html?id=9643#txn-120724) 
    139140    foreach ($mtime_sth, $insert_sth, $update_sth) { 
     141        $_->{RaiseError} = 0;  # don't die on error 
    140142        $_->{Active} = 1; 
    141143        $_->finish; 
  • trunk/lib/MP3/Find/Filesystem.pm

    r3 r12  
    3030    } 
    3131     
     32    if ($$options{exclude_path}) { 
     33        my $ref = ref $$options{exclude_path}; 
     34        if ($ref eq 'ARRAY') { 
     35            $$options{exclude_path} = '(' . join('|', @{ $$options{exclude_path} }) . ')'; 
     36        } 
     37        unless ($ref eq 'Regexp') { 
     38            $$options{exclude_path} = qr[$$options{exclude_path}]; 
     39        } 
     40    } 
     41     
    3242    # run the actual find 
    3343    my @results; 
    34     find(sub { match_mp3($File::Find::name, $query, \@results) }, $_) foreach @$dirs; 
     44    find(sub { match_mp3($File::Find::name, $query, \@results, $options) }, $_) foreach @$dirs; 
    3545     
    3646    # sort the results 
     
    5464 
    5565sub match_mp3 { 
    56     my ($filename, $query, $results) = @_; 
     66    my ($filename, $query, $results, $options) = @_; 
    5767     
    5868    return unless $filename =~ m{[^/]\.mp3$}; 
     69    if ($$options{exclude_path}) { 
     70        return if $filename =~ $$options{exclude_path}; 
     71    } 
     72     
    5973    my $mp3 = { 
    6074        FILENAME => $filename, 
     
    103117=head2 Special Options 
    104118 
    105 There are no special options for B<MP3::Find::Filesystem>. See 
    106 L<MP3::Find> for the description of the general options. 
     119=over 
     120 
     121=item C<exclude_path> 
     122 
     123Scalar or arrayref; any file whose name matches any of these paths 
     124will be skipped. 
    107125 
    108126=head1 SEE ALSO 
  • trunk/t/02-filesystem.t

    r8 r12  
    22use strict; 
    33 
    4 use Test::More 'no_plan'; #tests => 4; 
     4use Test::More tests => 6; 
    55BEGIN { use_ok('MP3::Find::Filesystem') }; 
    66 
    77my $SEARCH_DIR = 't/mp3s'; 
    8 my $MP3_COUNT = 0; 
     8my $EXCLUDE_DIR = 't/mp3s/dont_look_here'; 
     9my $MP3_COUNT = 1; 
     10my $EXCLUDED_MP3_COUNT = 1; 
    911 
    1012# exercise the object 
     
    2022is(scalar(@res), $MP3_COUNT, 'dir as ARRAY ref'); 
    2123 
     24# exclude 
     25@res = $finder->find_mp3s(dir => $SEARCH_DIR, exclude_path => $EXCLUDE_DIR); 
     26is(scalar(@res), $MP3_COUNT - $EXCLUDED_MP3_COUNT, 'excluded directory'); 
     27 
     28@res = $finder->find_mp3s(dir => $SEARCH_DIR, exclude_path => [$EXCLUDE_DIR]); 
     29is(scalar(@res), $MP3_COUNT - $EXCLUDED_MP3_COUNT, 'excluded directory as array'); 
     30 
    2231#TODO: get some test mp3s 
  • trunk/t/03-db.t

    r10 r12  
    1919my $SEARCH_DIR = 't/mp3s'; 
    2020my $DB_FILE = 't/mp3.db'; 
    21 my $MP3_COUNT = 0; 
     21my $MP3_COUNT = 1; 
    2222 
    2323# exercise the object 
Note: See TracChangeset for help on using the changeset viewer.