findrule

filter: Statementstmt 95.9% 47 / 49 Branchbran 86.3% 19 / 22 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 80.0% 4 / 5 Podpod n/a totaltotal 90.1% 73 / 81 CC 1 SCAR 1.8
CC
1
Cov
92%
__ANON__
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« testdir/lib/File/Find/Rule/Test/ATeam.pm ↑ Summary
1 #!perl -w
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use File::Find::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use File::Spec::Functions qw(catdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # bootstrap extensions
7 6 for (@INC) {
8 60 my $dir = catdir($_, qw( File Find Rule ) );
9 60 ▶ next unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 36 24 60
10 my @pm = find( name => '*.pm', maxdepth => 1,
11 0 ▶ exec => sub { (my $name = $_) =~ s/\.pm$//;
Subroutine __ANON__: not called CC=1 SCAR=6.9
12 0 eval "require File::Find::Rule::$name"; },
13 24 in => $dir );
14 }
15  
16 # what directories are we searching in?
17 6 my @where;
18 6 ▶while (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV) 12 0 12
19 12 local $_ = shift @ARGV;
20 12 ▶ if (/^-/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^-/) 6 6 12
21 6 unshift @ARGV, $_;
22 6 last;
23 }
24 6 push @where, $_;
25 }
26  
27 # parse arguments, build a rule object
28 6 my $rule = new File::Find::Rule;
29 6 ▶while (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV) 13 5 18
30 13 my $clause = shift @ARGV;
31  
32 13 ▶ unless ( $clause =~ s/^-// && $rule->can( $clause ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($clause =~ s/^-// and $rule->can($clause)) 1 12 13
Condition66%2/3
$clause =~ s/^-// and $rule->can($clause)
!ll&&!rl&&r
1012
MC/DC50%1/2
$clause =~ s/^-// and $rule->can($clause)
$clause =~ s/^-// $rule->can($clause)
Truth table66%2/3
A and B
A= $clause =~ s/^-//B= $rule->can($clause)
ABresult
0X0
100
111
33 # not a known rule - complain about this
34 1 die "unknown option '$clause'\n"
35 }
36  
37 # it was the last switch
38 12 ▶ unless (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@ARGV) 2 10 12
39 2 $rule->$clause();
40 2 next;
41 }
42  
43 # consume the parameters
44 10 my $param = shift @ARGV;
45  
46 10 ▶ if ($param =~ /^-/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param =~ /^-/) 4 6 10
47 # it's the next switch - put it back, and add one with no params
48 4 unshift @ARGV, $param;
49 4 $rule->$clause();
50 4 next;
51 }
52  
53 6 ▶ if ($param eq '(') {
Branch: 1 branch
BranchTrueFalseTotal
if ($param eq "(") 2 4 6
54 # multiple values - just look for the closing parenthesis
55 2 my @p;
56 2 ▶ while (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV) 6 0 6
57 6 my $val = shift @ARGV;
58 6 ▶ last if $val eq ')';
Branch: 1 branch
BranchTrueFalseTotal
if $val eq ")" 2 4 6
59 4 push @p, $val;
60 }
61 2 $rule->$clause( @p );
62 2 next;
63 }
64  
65 # a single argument
66 4 $rule->$clause( $param );
67 }
68  
69 # add a print rule so things happen faster
70 5 ▶$rule->exec( sub { print "$_[2]\n"; return; } );
Subroutine __ANON__: called CC=1 SCAR=0.0
71  
72 # profit
73 5 ▶$rule->in( @where ? @where : '.' );
Branch: 1 branch
BranchTrueFalseTotal
@where ? : 5 0 5
74 5 exit 0;
75  
76 __END__
« testdir/lib/File/Find/Rule/Test/ATeam.pm ↑ Summary