bin/findorule

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