BoolFindGrep/Find.pm

filter: Statementstmt 84.1% 85 / 101 Branchbran 47.6% 20 / 42 Conditioncond 20.0% 7 / 35 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 87.5% 21 / 24 Podpod 100% 1 / 1 totaltotal 60.6% 134 / 221 CC 37 SCAR 25.6
CC
37
Cov
63%
__ANON__
56.0
_get_made_list
20.0
process
18.1
CRAP 12.9
« BoolFindGrep/Grep.pm ↑ Summary BoolFindGrep.pm »
1 package App::BoolFindGrep::Find;
2  
3 4 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use charnames q(:full);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use English qw[-no_match_vars];
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Text::Glob qw[glob_to_regex_string];
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 our $VERSION = '0.06'; # VERSION
13  
14 has files_from => (
15 is => q(rw),
16 0 ▶ isa => sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
17 0 ▶ ( ( -e $_[0] && -r $_[0] && -f $_[0] && -s $_[0] )
Branch: 1 branch
BranchTrueFalseTotal
-e $_[0] and -r $_[0] and -f $_[0] and -s $_[0] or ($_[0] eq "-" or $_[0] =~ /\Astdin\z/iu) or die 0 0 0
Condition0%0/15
-e $_[0] and -r $_[0] and -f $_[0] and -s $_[0] or ($_[0] eq "-" or $_[0] =~ /\Astdin\z/iu)
l!l&&r!l&&!r
000
-e $_[0] and -r $_[0] and -f $_[0] and -s $_[0]
!ll&&!rl&&r
000
-e $_[0] and -r $_[0] and -f $_[0]
!ll&&!rl&&r
000
-e $_[0] and -r $_[0]
!ll&&!rl&&r
000
$_[0] eq "-" or $_[0] =~ /\Astdin\z/iu
l!l&&r!l&&!r
000
MC/DC0%0/6
-e $_[0] and -r $_[0] and -f $_[0] and -s $_[0] or ($_[0] eq "-" or $_[0] =~ /\Astdin\z/iu)
-e $_[0] -r $_[0] -f $_[0] -s $_[0] $_[0] eq "-" $_[0] =~ /\Astdin\z/iu
Truth table0%0/13
A and B and C and D or E or F
A= -e $_[0]B= -r $_[0]C= -f $_[0]D= -s $_[0]E= $_[0] eq "-"F= $_[0] =~ /\Astdin\z/iu
ABCDEFresult
1111XX1
0XXX1X1
0XXX011
10XX1X1
10XX011
110X1X1
110X011
11101X1
1110011
0XXX000
10XX000
110X000
1110000
18 || ( $_[0] eq q(-) || $_[0] =~ /\Astdin\z/i ) )
19 || die;
20 }
21 4 );
22 4 has files_delim => (
23 is => q(rw),
24 default => undef,
25 );
26 has file_expr => (
27 is => q(rw),
28 22 ▶ isa => sub { die if @_ > 1; die if ref $_[0]; },
Subroutine __ANON__: called CC=3 SCAR=12.0
Branch: 2 branches
BranchTrueFalseTotal
if @_ > 1 0 22 22
if ref $_[0] 0 22 22
29 4 default => undef,
30 );
31 has find_type => (
32 is => q(rw),
33 22 ▶ isa => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
34 22 ▶ ( grep { $_[0] eq $_ } qw[glob literal regexp] ) > 0 or die;
Branch: 1 branch
BranchTrueFalseTotal
grep({$_[0] eq $_;} "glob", "literal", "regexp") > 0 or die 22 0 22
35 },
36 4 default => q(regexp),
37 );
38 has find_ignore_case => (
39 is => q(rw),
40 11 ▶ isa => sub { ( $_[0] == 0 || $_[0] == 1 ) or die; },
Subroutine __ANON__: called CC=3 SCAR=14.2
Branch: 1 branch
BranchTrueFalseTotal
$_[0] == 0 or $_[0] == 1 or die 11 0 11
Condition33%1/3
$_[0] == 0 or $_[0] == 1
l!l&&r!l&&!r
1100
MC/DC0%0/2
$_[0] == 0 or $_[0] == 1
$_[0] == 0 $_[0] == 1
Truth table33%1/3
A or B
A= $_[0] == 0B= $_[0] == 1
ABresult
1X1
011
000
41 4 default => 0,
42 );
43 has directory => (
44 is => q(rw),
45 22 ▶ isa => sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
46 22 ▶ @{ $_[0] } == ( grep { -d $_ && -r $_ } @{ $_[0] } ) or die;
Branch: 1 branch
BranchTrueFalseTotal
@{$_[0];} == grep({-d $_ and -r $_;} @{$_[0];}) or die 22 0 22
Condition33%1/3
-d $_ && -r $_
!ll&&!rl&&r
0022
MC/DC0%0/2
-d $_ && -r $_
-d $_ -r $_
Truth table33%1/3
A && B
A= -d $_B= -r $_
ABresult
0X0
100
111
47 },
48 11 ▶ default => sub { [q(.)] },
Subroutine __ANON__: called CC=1 SCAR=0.0
49 4 );
50 11 ▶has patterns => ( is => q(rw), default => sub { {}; }, );
Subroutine __ANON__: called CC=1 SCAR=0.0
51 11 ▶has found => ( is => q(rw), default => sub { {}; }, );
Subroutine __ANON__: called CC=1 SCAR=0.0
52 11 ▶has files => ( is => q(rw), default => sub { []; }, );
Subroutine __ANON__: called CC=1 SCAR=0.0
53  
54 11 ▶sub process {
Subroutine process: called CC=9 SCAR=29.0
Pod documented
55 11 my $self = shift;
56  
57 11 ▶ die if defined $self->files_delim() && !( defined $self->files_from() );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->files_delim and not defined $self->files_from 0 11 11
Condition33%1/3
defined $self->files_delim and not defined $self->files_from
!ll&&!rl&&r
1100
MC/DC0%0/2
defined $self->files_delim and not defined $self->files_from
defined $self->files_delim not defined $self->files_from
Truth table33%1/3
A and not(B)
A= defined $self->files_delimB= not defined $self->files_from
ABresult
0X0
100
111
58 11 ▶ die if defined $self->files_from() && defined $self->file_expr();
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->files_from and defined $self->file_expr 0 11 11
Condition33%1/3
defined $self->files_from and defined $self->file_expr
!ll&&!rl&&r
1100
MC/DC0%0/2
defined $self->files_from and defined $self->file_expr
defined $self->files_from defined $self->file_expr
Truth table33%1/3
A and B
A= defined $self->files_fromB= defined $self->file_expr
ABresult
0X0
100
111
59 die
60 if defined $self->files_from()
61 0 ▶ && @{ $self->directory() } != 1
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->files_from and @{$self->directory;} != 1 and $self->directory->[0] ne "." 0 11 11
Condition33%2/6
defined $self->files_from and @{$self->directory;} != 1 and $self->directory->[0] ne "."
!ll&&!rl&&r
1100
defined $self->files_from and @{$self->directory;} != 1
!ll&&!rl&&r
1100
MC/DC0%0/3
defined $self->files_from and @{$self->directory;} != 1 and $self->directory->[0] ne "."
defined $self->files_from @{$self->directory;} != 1 $self->directory->[0] ne "."
Truth table25%1/4
A and B and C
A= defined $self->files_fromB= @{$self->directory;} != 1C= $self->directory->[0] ne "."
ABCresult
0XX0
10X0
1100
1111
62 && $self->directory->[0] ne q(.);
63  
64 11 ▶ if ( defined $self->files_from() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->files_from) { } 0 11 11
65 0 $self->_get_made_list();
66 }
67 11 else { $self->_finder(); }
68  
69 11 return 1;
70 } ## end sub process
71  
72 0 ▶sub _get_made_list {
Subroutine _get_made_list: not called CC=4 SCAR=30.0
73 0 my $self = shift;
74  
75 0 local $INPUT_RECORD_SEPARATOR = $self->files_delim();
76  
77 0 ▶ my $fh
Branch: 1 branch
BranchTrueFalseTotal
$self->files_from =~ /\A(?:-|stdin)\z/iu ? : 0 0 0
78 = $self->files_from() =~ /\A(?:-|stdin)\z/i
79 ? \*STDIN
80 : IO::File->new( $self->files_from(), q(r) );
81  
82 0 ▶ while ( my $file = readline $fh ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $file = readline $fh)) 0 0 0
83 0 chomp $file;
84 0 ▶ croak sprintf q('%s': irregular file.), $file if !-f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
85 0 push @{ $self->files() }, $file;
86 }
87  
88 0 return 1;
89 } ## end sub _get_made_list
90  
91 11 ▶sub _finder {
Subroutine _finder: called CC=2 SCAR=7.5
92 11 my $self = shift;
93  
94 11 ▶ unless ( defined $self->file_expr() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->file_expr) 0 11 11
95 0 ▶ find sub { push @{ $self->files() }, $File::Find::name if -f },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if -f $_ 0 0 0
96 0 @{ $self->directory() };
97 }
98  
99 11 $self->_process_patterns();
100  
101 3971 ▶ find sub {
Subroutine __ANON__: called CC=6 SCAR=18.0
102 3971 ▶ if ( -f $_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $_) 3960 11 3971
103 3960 ▶ if ( %{ $self->patterns() } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$self->patterns;}) 3960 0 3960
104 3960 foreach my $pattern ( keys %{ $self->patterns() } ) {
105 3960 my $re = $self->patterns->{$pattern};
106 3960 ▶ $self->found->{$File::Find::name}{$pattern} //= 0;
Condition50%1/2
$self->found->{$File::Find::name}{$pattern} //= 0
l!l
03960
MC/DC0%0/1
$self->found->{$File::Find::name}{$pattern} //= 0
$self->found->{$File::Find::name}{$pattern}
Truth table50%1/2
A
A= $self->found->{$File::Find::name}{$pattern}
Aresult
11
00
107 3960 ▶ $self->found->{$File::Find::name}{$pattern}++ if m{$re};
Branch: 1 branch
BranchTrueFalseTotal
if /$re/u 3120 840 3960
108 }
109 }
110 }
111 11 }, @{ $self->directory() };
112  
113 11 return 1;
114 } ## end sub _finder
115  
116 11 ▶sub _process_patterns {
Subroutine _process_patterns: called CC=6 SCAR=17.9
117 11 my $self = shift;
118  
119 11 foreach my $pattern ( keys %{ $self->patterns() } ) {
120 11 my $value = $pattern;
121 11 foreach ( $self->find_type() ) {
122 11 ▶ if ( $_ eq q(literal) ) { $value = quotemeta $value; }
Branch: 2 branches
BranchTrueFalseTotal
if ($_ eq 'literal') { } 3 8 11
elsif ($_ eq 'glob') { } 5 3 8
123 elsif ( $_ eq q(glob) ) {
124 5 $value = glob_to_regex_string($value);
125 5 $value.= q(\z);
126 }
127 }
128 11 ▶ $value = $self->find_ignore_case() == 1 ? qr{$value}i : qr{$value};
Branch: 1 branch
BranchTrueFalseTotal
$self->find_ignore_case == 1 ? : 0 11 11
129 11 $self->patterns->{$pattern} = $value;
130 }
131  
132 11 return 1;
133 } ## end sub _process_patterns
134  
135 4 ▶no Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
136 4 __PACKAGE__->meta->make_immutable;
137  
138 4 1;
139  
140 __END__
« BoolFindGrep/Grep.pm ↑ Summary BoolFindGrep.pm »