BoolFindGrep/Grep.pm

filter: Statementstmt 81.8% 72 / 88 Branchbran 45.4% 20 / 44 Conditioncond 65.0% 13 / 20 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 95.0% 19 / 20 Podpod 100% 1 / 1 totaltotal 67.2% 125 / 186 CC 32 SCAR 29.5
CC
32
Cov
69%
process
90.0
_process_patterns
9.0
_search
4.0
CRAP 19.2
« BoolFindGrep/CLI.pm ↑ Summary BoolFindGrep/Find.pm »
1 package App::BoolFindGrep::Grep;
2  
3 5 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use charnames q(:full);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use English qw[-no_match_vars];
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Text::Glob qw[glob_to_regex_string];
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 our $VERSION = '0.06'; # VERSION
12  
13 has match_expr => (
14 is => q(rw),
15 17 ▶ isa => sub { die if @_ > 1; die if ref $_[0]; },
Subroutine __ANON__: called CC=3 SCAR=12.0
Branch: 2 branches
BranchTrueFalseTotal
if @_ > 1 0 17 17
if ref $_[0] 0 17 17
16 5 default => undef,
17 );
18 17 ▶has patterns => ( is => q(rw), default => sub { {}; }, );
Subroutine __ANON__: called CC=1 SCAR=0.0
19 17 ▶has greped => ( is => q(rw), default => sub { {}; }, );
Subroutine __ANON__: called CC=1 SCAR=0.0
20 has fixed_strings => (
21 is => q(rw),
22 18 ▶ isa => sub { ( $_[0] == 1 || $_[0] == 0 ) or die; },
Subroutine __ANON__: called CC=3 SCAR=12.0
Branch: 1 branch
BranchTrueFalseTotal
$_[0] == 1 or $_[0] == 0 or die 18 0 18
Condition66%2/3
$_[0] == 1 or $_[0] == 0
l!l&&r!l&&!r
1170
MC/DC0%0/2
$_[0] == 1 or $_[0] == 0
$_[0] == 1 $_[0] == 0
Truth table66%2/3
A or B
A= $_[0] == 1B= $_[0] == 0
ABresult
1X1
011
000
23 5 default => 0,
24 );
25 has ignore_case => (
26 is => q(rw),
27 18 ▶ isa => sub { ( $_[0] == 1 || $_[0] == 0 ) or die; },
Subroutine __ANON__: called CC=3 SCAR=12.0
Branch: 1 branch
BranchTrueFalseTotal
$_[0] == 1 or $_[0] == 0 or die 18 0 18
Condition66%2/3
$_[0] == 1 or $_[0] == 0
l!l&&r!l&&!r
1170
MC/DC0%0/2
$_[0] == 1 or $_[0] == 0
$_[0] == 1 $_[0] == 0
Truth table66%2/3
A or B
A= $_[0] == 1B= $_[0] == 0
ABresult
1X1
011
000
28 5 default => 0,
29 );
30 has line_regexp => (
31 is => q(rw),
32 18 ▶ isa => sub { ( $_[0] == 1 || $_[0] == 0 ) or die; },
Subroutine __ANON__: called CC=3 SCAR=12.0
Branch: 1 branch
BranchTrueFalseTotal
$_[0] == 1 or $_[0] == 0 or die 18 0 18
Condition66%2/3
$_[0] == 1 or $_[0] == 0
l!l&&r!l&&!r
1170
MC/DC0%0/2
$_[0] == 1 or $_[0] == 0
$_[0] == 1 $_[0] == 0
Truth table66%2/3
A or B
A= $_[0] == 1B= $_[0] == 0
ABresult
1X1
011
000
33 5 default => 0,
34 );
35 has word_regexp => (
36 is => q(rw),
37 18 ▶ isa => sub { ( $_[0] == 1 || $_[0] == 0 ) or die; },
Subroutine __ANON__: called CC=3 SCAR=12.0
Branch: 1 branch
BranchTrueFalseTotal
$_[0] == 1 or $_[0] == 0 or die 18 0 18
Condition66%2/3
$_[0] == 1 or $_[0] == 0
l!l&&r!l&&!r
1170
MC/DC0%0/2
$_[0] == 1 or $_[0] == 0
$_[0] == 1 $_[0] == 0
Truth table66%2/3
A or B
A= $_[0] == 1B= $_[0] == 0
ABresult
1X1
011
000
38 5 default => 0,
39 );
40 has glob_regexp => (
41 is => q(rw),
42 18 ▶ isa => sub { ( $_[0] == 1 || $_[0] == 0 ) or die; },
Subroutine __ANON__: called CC=3 SCAR=12.0
Branch: 1 branch
BranchTrueFalseTotal
$_[0] == 1 or $_[0] == 0 or die 18 0 18
Condition66%2/3
$_[0] == 1 or $_[0] == 0
l!l&&r!l&&!r
1170
MC/DC0%0/2
$_[0] == 1 or $_[0] == 0
$_[0] == 1 $_[0] == 0
Truth table66%2/3
A or B
A= $_[0] == 1B= $_[0] == 0
ABresult
1X1
011
000
43 5 default => 0,
44 );
45 has content_found => (
46 is => q(rw),
47 17 ▶ default => sub { {}; },
Subroutine __ANON__: called CC=1 SCAR=0.0
48 5 );
49  
50 0 ▶sub process {
Subroutine process: not called CC=9 SCAR=45.0
Pod documented
51 0 my $self = shift;
52 0 my @file = splice @_;
53  
54 0 ▶ return unless defined $self->match_expr();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->match_expr 0 0 0
55 0 ▶ return unless %{ $self->patterns() };
Branch: 1 branch
BranchTrueFalseTotal
unless %{$self->patterns;} 0 0 0
56  
57 0 $self->_process_patterns();
58  
59 0 ▶ while ( my $file = shift @file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = shift @file) 0 0 0
60 0 ▶ croak sprintf q('%s': nonexistent file.), $file if !-e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 0 0 0
61 0 ▶ croak sprintf q('%s': irregular file.), $file if !-f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
62 0 ▶ croak sprintf q('%s': unreadable file.), $file if !-r $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $file 0 0 0
63 0 ▶ if ( my $fh = IO::File->new( $file, q(r) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fh = 'IO::File'->new($file, 'r')) { } 0 0 0
64 0 ▶ while ( my $line = readline $fh ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
65 0 chomp $line;
66 0 $self->_search( $line, $file, $fh->input_line_number(), );
67 }
68 }
69 0 else { croak $OS_ERROR; }
70 }
71  
72 0 return 1;
73 } ## end sub process
74  
75 1 ▶sub _search {
Subroutine _search: called CC=4 SCAR=13.9
76 1 my $self = shift;
77 1 my $string = shift;
78 1 my $file = shift;
79 1 my $line_number = shift;
80  
81 1 foreach my $pattern ( keys %{ $self->patterns } ) {
82 6 my $re = $self->patterns->{$pattern};
83 6 ▶ $self->greped->{$file}{$pattern} //= 0;
Condition50%1/2
$self->greped->{$file}{$pattern} //= 0
l!l
06
MC/DC0%0/1
$self->greped->{$file}{$pattern} //= 0
$self->greped->{$file}{$pattern}
Truth table50%1/2
A
A= $self->greped->{$file}{$pattern}
Aresult
11
00
84  
85 6 ▶ if ( $string =~ m{$re} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$re/u) 5 1 6
86 5 $self->greped->{$file}{$pattern}++;
87 5 $self->content_found->{$file}{$line_number} = $string;
88 }
89 }
90  
91 1 return 1;
92 } ## end sub _search
93  
94 5 ▶sub _process_patterns {
Subroutine _process_patterns: called CC=9 SCAR=22.0
95 5 my $self = shift;
96  
97 5 ▶ die if $self->line_regexp() && $self->word_regexp();
Branch: 1 branch
BranchTrueFalseTotal
if $self->line_regexp and $self->word_regexp 0 5 5
Condition66%2/3
$self->line_regexp and $self->word_regexp
!ll&&!rl&&r
410
MC/DC0%0/2
$self->line_regexp and $self->word_regexp
$self->line_regexp $self->word_regexp
Truth table66%2/3
A and B
A= $self->line_regexpB= $self->word_regexp
ABresult
0X0
100
111
98  
99 5 foreach my $pattern ( keys %{ $self->patterns() } ) {
100 5 my $value = $pattern;
101 5 ▶ if ( $self->glob_regexp() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->glob_regexp) { } 1 4 5
102 1 $value = glob_to_regex_string($value);
103 }
104 else {
105 4 ▶ $value = quotemeta $value if $self->fixed_strings();
Branch: 1 branch
BranchTrueFalseTotal
if $self->fixed_strings 1 3 4
106  
107 4 ▶ if ( $self->line_regexp() ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->line_regexp) { } 1 3 4
elsif ($self->word_regexp) { } 1 2 3
108 1 $value = sprintf q(\A%s\z), $value;
109 }
110 elsif ( $self->word_regexp() ) {
111 1 $value = sprintf q(\b%s\b), $value;
112 }
113 }
114  
115 5 ▶ $value = $self->ignore_case() ? qr{$value}i : qr{$value};
Branch: 1 branch
BranchTrueFalseTotal
$self->ignore_case ? : 1 4 5
116  
117 5 $self->patterns->{$pattern} = $value;
118 } ## end foreach my $pattern ( keys ...)
119  
120 5 return 1;
121 } ## end sub _process_patterns
122  
123 5 ▶no Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
124 5 __PACKAGE__->meta->make_immutable;
125  
126 5 1;
127  
128 __END__
« BoolFindGrep/CLI.pm ↑ Summary BoolFindGrep/Find.pm »