BoolFindGrep.pm

filter: Statementstmt 80.9% 68 / 84 Branchbran 50.0% 12 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 17 / 17 Podpod 50.0% 1 / 2 totaltotal 77.1% 98 / 127 CC 19 SCAR 21.2
CC
19
Cov
74%
_grep_files
29.2
_find_files
8.4
BUILD
5.0
CRAP 8.3
« BoolFindGrep/Find.pm ↑ Summary BoolFindGrep/Bool.pm »
1 package App::BoolFindGrep;
2  
3 3 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use charnames q(:full);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use English qw[-no_match_vars];
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use App::BoolFindGrep::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use App::BoolFindGrep::Grep;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use App::BoolFindGrep::Bool;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 our $VERSION = '0.06'; # VERSION
12  
13 has find => (
14 is => q(ro),
15 11 ▶ default => sub { App::BoolFindGrep::Find->new(); }
Subroutine __ANON__: called CC=1 SCAR=0.0
16 3 );
17 has grep => (
18 is => q(ro),
19 11 ▶ default => sub { App::BoolFindGrep::Grep->new(); }
Subroutine __ANON__: called CC=1 SCAR=0.0
20 3 );
21 has bool => (
22 is => q(ro),
23 11 ▶ default => sub { App::BoolFindGrep::Bool->new(); }
Subroutine __ANON__: called CC=1 SCAR=0.0
24 3 );
25 has found_files => (
26 is => q(rw),
27 11 ▶ default => sub { []; },
Subroutine __ANON__: called CC=1 SCAR=0.0
28 3 );
29 has greped_files => (
30 is => q(rw),
31 11 ▶ default => sub { []; },
Subroutine __ANON__: called CC=1 SCAR=0.0
32 3 );
33  
34 11 ▶sub BUILD {
Subroutine BUILD: called CC=5 SCAR=16.1
Pod undocumented
35 11 my $self = shift;
36 11 my $args = shift;
37  
38 11 foreach my $method ( keys %$args ) {
39 33 foreach my $class (qw[bool find grep]) {
40 99 ▶ if ( $self->$class->can($method) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->$class->can($method)) 33 66 99
41 33 my $value = delete $args->{$method};
42 33 $self->$class->$method($value);
43 }
44 }
45 }
46  
47 11 ▶ die if %{$args};
Branch: 1 branch
BranchTrueFalseTotal
if %{$args;} 0 11 11
48  
49 11 return 1;
50 } ## end sub BUILD
51  
52 11 ▶sub process {
Subroutine process: called CC=3 SCAR=12.5
Pod documented
53 11 my $self = shift;
54  
55 11 ▶ return unless $self->_find_files();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_find_files 0 11 11
56 11 ▶ return unless $self->_grep_files();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_grep_files 11 0 11
57  
58 0 return 1;
59 }
60  
61 11 ▶sub _find_files {
Subroutine _find_files: called CC=8 SCAR=21.3
62 11 my $self = shift;
63  
64 11 ▶ if ( defined $self->find->file_expr() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->find->file_expr) 11 0 11
65 11 $self->bool->expression( $self->find->file_expr() );
66 11 ▶ return unless $self->bool->parse_expr();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->bool->parse_expr 0 11 11
67 11 foreach my $operand ( @{ $self->bool->operands() } ) {
68 11 $self->find->patterns->{$operand} = undef;
69 }
70 }
71 11 ▶ return unless $self->find->process();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->find->process 0 11 11
72  
73 11 ▶ if ( defined $self->find->file_expr() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->find->file_expr) { } 11 0 11
74 11 foreach my $file ( keys %{ $self->find->found() } ) {
75 3960 my $operand = $self->find->found->{$file};
76 3960 my $result = $self->bool->lazy_solver(%$operand);
77 3960 ▶ push @{ $self->found_files() }, $file if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 3120 840 3960
78 }
79 }
80 0 else { $self->found_files( $self->find->files() ); }
81  
82 11 return 1;
83 } ## end sub _find_files
84  
85 11 ▶sub _grep_files {
Subroutine _grep_files: called CC=6 SCAR=33.7
86 11 my $self = shift;
87  
88 11 ▶ return unless defined $self->grep->match_expr();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->grep->match_expr 11 0 11
89  
90 0 $self->bool->expression( $self->grep->match_expr() );
91 0 ▶ return unless $self->bool->parse_expr();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->bool->parse_expr 0 0 0
92  
93 0 foreach my $operand ( @{ $self->bool->operands() } ) {
94 0 $self->grep->patterns->{$operand} = undef;
95 }
96 0 $self->grep->process( @{ $self->found_files() } );
97  
98 0 foreach my $file ( keys %{ $self->grep->greped() } ) {
99 0 my $operand = $self->grep->greped->{$file};
100 0 my $result = $self->bool->lazy_solver(%$operand);
101 0 ▶ push @{ $self->greped_files() }, $file if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 0 0 0
102 }
103  
104 0 return 1;
105 } ## end sub _grep_files
106  
107 3 ▶no Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 3 __PACKAGE__->meta->make_immutable;
109  
110 3 1;
111  
112 __END__
« BoolFindGrep/Find.pm ↑ Summary BoolFindGrep/Bool.pm »