File Coverage

findrule
Criterion Covered Total %
statement 47 49 95.9
branch 15 16 93.7
condition 2 3 66.6
subroutine 4 5 80.0
pod n/a
total 68 73 93.1


line stmt bran cond sub pod time code
1             #!perl -w
2 6     6   41713 use strict;
  6         14  
  6         300  
3 6     6   3596 use File::Find::Rule;
  6         32  
  6         64  
4 6     6   3917 use File::Spec::Functions qw(catdir);
  6         6624  
  6         14598  
5              
6             # bootstrap extensions
7 6         1130285 for (@INC) {
8 60         393 my $dir = catdir($_, qw( File Find Rule ) );
9 60 100       1123 next unless -d $dir;
10             my @pm = find( name => '*.pm', maxdepth => 1,
11 0     0   0 exec => sub { (my $name = $_) =~ s/\.pm$//;
12 0         0 eval "require File::Find::Rule::$name"; },
13 24         215 in => $dir );
14             }
15              
16             # what directories are we searching in?
17 6         13 my @where;
18 6         33 while (@ARGV) {
19 12         23 local $_ = shift @ARGV;
20 12 100       40 if (/^-/) {
21 6         16 unshift @ARGV, $_;
22 6         33 last;
23             }
24 6         22 push @where, $_;
25             }
26              
27             # parse arguments, build a rule object
28 6         49 my $rule = new File::Find::Rule;
29 6         22 while (@ARGV) {
30 13         24 my $clause = shift @ARGV;
31              
32 13 100 66     142 unless ( $clause =~ s/^-// && $rule->can( $clause ) ) {
33             # not a known rule - complain about this
34 1         0 die "unknown option '$clause'\n"
35             }
36              
37             # it was the last switch
38 12 100       43 unless (@ARGV) {
39 2         66 $rule->$clause();
40 2         6 next;
41             }
42              
43             # consume the parameters
44 10         40 my $param = shift @ARGV;
45              
46 10 100       30 if ($param =~ /^-/) {
47             # it's the next switch - put it back, and add one with no params
48 4         11 unshift @ARGV, $param;
49 4         143 $rule->$clause();
50 4         12 next;
51             }
52              
53 6 100       22 if ($param eq '(') {
54             # multiple values - just look for the closing parenthesis
55 2         3 my @p;
56 2         6 while (@ARGV) {
57 6         8 my $val = shift @ARGV;
58 6 100       12 last if $val eq ')';
59 4         9 push @p, $val;
60             }
61 2         7 $rule->$clause( @p );
62 2         8 next;
63             }
64              
65             # a single argument
66 4         15 $rule->$clause( $param );
67             }
68              
69             # add a print rule so things happen faster
70 5     6   36 $rule->exec( sub { print "$_[2]\n"; return; } );
  6         69  
  6         330  
71              
72             # profit
73 5 50       25 $rule->in( @where ? @where : '.' );
74 5         0 exit 0;
75              
76             __END__