Changeset 12 in mp3-find for trunk/lib/MP3/Find/Filesystem.pm


Ignore:
Timestamp:
02/14/06 20:19:23 (18 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)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.