| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||
| 30 | 10 | local $_ = shift @ARGV; | |||||||||||||||||||||||||||
| 31 | 10 | ▶ | if (/^-/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 10 | my $clause = shift @ARGV; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 10 | ▶ | unless ( $clause =~ s/^-// && $rule->can($clause) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$clause =~ s/^-// and $rule->can($clause)
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)
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||
| 71 | # multiple values - just look for the closing parenthesis | ||||||||||||||||||||||||||||
| 72 | 2 | my @p; | |||||||||||||||||||||||||||
| 73 | 2 | ▶ | while (@ARGV) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||
| 75 | 6 | my $val = shift @ARGV; | |||||||||||||||||||||||||||
| 76 | 6 | ▶ | last if $val eq ')'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 92 | 5 | exit 0; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||||||||||