Midgen/Role/Eval.pm

filter: Statementstmt 15.3% 22 / 143 Branchbran 0.0% 0 / 82 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 33.3% 6 / 18 Podpod 100% 1 / 1 totaltotal 10.7% 29 / 271 CC 60 SCAR 47.3
CC
60
Cov
9%
_eval_info
210.0
__ANON__
182.0
__ANON__
156.0
CRAP 112.9
« Midgen/Role/Output/Dist.pm ↑ Summary Midgen/Role/UseModule.pm »
1 package App::Midgen::Role::Eval;
2  
3 2 ▶use constant {NONE => q{}, TWO => 2,};
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 requires
6 qw( ppi_document debug verbose format xtest _process_found_modules develop meta2 );
7  
8 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Data::Printer {caller_info => 1,};
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use List::MoreUtils qw(any firstidx);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # Load time and dependencies negate execution time
13 # use namespace::clean -except => 'meta';
14  
15 2 our $VERSION = '0.34';
16 2 $VERSION = eval $VERSION; ## no critic
17  
18 #######
19 # composed method - xtests_eval
20 #######
21 0 ▶sub xtests_eval {
Subroutine xtests_eval: not called CC=7 SCAR=40.3
Pod documented
22 0 my $self = shift;
23 0 ▶ my $phase_relationship = shift || NONE;
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
24  
25 0 my @modules;
26 my @version_strings;
27  
28 #PPI::Document
29 # PPI::Statement::Sub
30 # PPI::Token::Word 'sub'
31 # PPI::Token::Whitespace ' '
32 # PPI::Token::Word '_assert_ssl'
33 # PPI::Token::Whitespace ' '
34 # PPI::Structure::Block { ... }
35 # PPI::Token::Whitespace '\n'
36 # PPI::Token::Whitespace '\t\t'
37 # PPI::Statement
38 # PPI::Token::Word 'eval'
39 # PPI::Token::Whitespace ' '
40 # PPI::Structure::Block { ... }
41 # PPI::Token::Whitespace ' '
42 # PPI::Statement::Include
43 # PPI::Token::Word 'require'
44 # PPI::Token::Whitespace ' '
45 # PPI::Token::Word 'IO::Socket::SSL'
46 # PPI::Token::Structure ';'
47 # PPI::Token::Whitespace ' '
48 # PPI::Statement
49 # PPI::Token::Word 'IO::Socket::SSL'
50 # PPI::Token::Operator '->'
51 # PPI::Token::Word 'VERSION'
52 # PPI::Structure::List ( ... )
53 # PPI::Statement::Expression
54 # PPI::Token::Number::Float '1.44'
55 # PPI::Token::Whitespace ' '
56 # PPI::Token::Structure ';'
57 # PPI::Token::Whitespace '\n'
58  
59 0 ▶ try {
Subroutine __ANON__: not called CC=13 SCAR=52.0
60  
61 0 my @chunks3 = @{$self->ppi_document->find('PPI::Statement::Sub')};
62  
63 0 foreach my $chunk (@chunks3) {
64 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk->find(sub { $_[1]->isa("PPI::Token::Word") and $_[1]->content =~ /\A(?:sub)\z/; } )) 0 0 0
65 $chunk->find(
66 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
67 0 ▶ $_[1]->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Token::Word") and $_[1]->content =~ /\A(?:sub)\z/ 0 0 0
68 and $_[1]->content =~ m{\A(?:sub)\z};
69 }
70 )
71 )
72 {
73 0 my $module_name;
74 my $version_string;
75 0 for (0 .. $#{$chunk->{children}}) {
76 0 ▶ if ($chunk->{children}[$_]->isa('PPI::Structure::Block')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk->{"children"}[$_]->isa("PPI::Structure::Block")) 0 0 0
77 my $ppi_sb = $chunk->{children}[$_]
78 0 ▶ if $chunk->{children}[$_]->isa('PPI::Structure::Block');
Branch: 1 branch
BranchTrueFalseTotal
if $chunk->{"children"}[$_]->isa("PPI::Structure::Block") 0 0 0
79 0 for (0 .. $#{$ppi_sb->{children}}) {
80 0 ▶ if ($ppi_sb->{children}[$_]->isa('PPI::Statement')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ppi_sb->{"children"}[$_]->isa("PPI::Statement")) 0 0 0
81 my $ppi_s = $ppi_sb->{children}[$_]
82 0 ▶ if $ppi_sb->{children}[$_]->isa('PPI::Statement');
Branch: 1 branch
BranchTrueFalseTotal
if $ppi_sb->{"children"}[$_]->isa("PPI::Statement") 0 0 0
83 0 my @chunks3 = @{$ppi_s->{children}};
84 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $_->isa("PPI::Token::Word") and $_->content =~ /\A(?:eval|try)\z/; } , @{$$ppi_s{"children"};})) 0 0 0
85 0 ▶ any {
Subroutine __ANON__: not called CC=2 SCAR=17.9
86 0 ▶ $_->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
$_->isa("PPI::Token::Word") and $_->content =~ /\A(?:eval|try)\z/ 0 0 0
87 and $_->content =~ m{\A(?:eval|try)\z};
88 }
89 0 @{$ppi_s->{children}}
90 )
91 {
92 0 ▶ my @ppisb = firstidx {
Subroutine __ANON__: not called CC=1 SCAR=6.9
93 0 $_->isa('PPI::Structure::Block');
94 }
95 0 @{$ppi_s->{children}};
96  
97 # extract first Structure::Block
98 0 my $ppi_sb = $ppisb[0];
99  
100 0 $self->_eval_info($ppi_sb, \$module_name, \$version_string);
101  
102 0 ▶ print "Option3 $module_name - $version_string\n"
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
103 if $self->debug;
104  
105  
106 0 ▶ if (version::is_lax($version_string)) {
Branch: 1 branch
BranchTrueFalseTotal
if (version::is_lax($version_string)) 0 0 0
107  
108 0 push @modules, $module_name;
109 0 ▶ $version_string
Branch: 1 branch
BranchTrueFalseTotal
version::is_lax($version_string) ? : 0 0 0
110 = version::is_lax($version_string)
111 ? $version_string
112 : 0;
113 0 push @version_strings, $version_string;
114 0 $self->{found_version}{$module_name} = $version_string;
115 }
116 }
117 }
118 }
119 }
120 }
121 }
122 }
123 0 };
124  
125  
126 #PPI::Document
127 # PPI::Statement
128 # PPI::Token::Word 'eval'
129 # PPI::Token::Whitespace ' '
130 # PPI::Structure::Block { ... }
131 # PPI::Statement::Include
132 # PPI::Token::Word 'require'
133 # PPI::Token::Whitespace ' '
134 # PPI::Token::Word 'PAR::Dist'
135 # PPI::Token::Structure ';'
136 # PPI::Token::Whitespace ' '
137 # PPI::Statement
138 # PPI::Token::Word 'PAR::Dist'
139 # PPI::Token::Operator '->'
140 # PPI::Token::Word 'VERSION'
141 # PPI::Structure::List ( ... )
142 # PPI::Statement::Expression
143 # PPI::Token::Number::Float '0.17'
144  
145 0 ▶ try {
Subroutine __ANON__: not called CC=9 SCAR=45.0
146 0 my @chunks2 = @{$self->ppi_document->find('PPI::Statement')};
147 0 foreach my $chunk (@chunks2) {
148 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk->find(sub { $_[1]->isa("PPI::Token::Word") and $_[1]->content =~ /\A(?:eval|try)\z/; } )) 0 0 0
149 $chunk->find(
150 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
151 0 ▶ $_[1]->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Token::Word") and $_[1]->content =~ /\A(?:eval|try)\z/ 0 0 0
152 and $_[1]->content =~ m{\A(?:eval|try)\z};
153 }
154 )
155 )
156 {
157 0 for (0 .. $#{$chunk->{children}}) {
158  
159 0 my $module_name;
160 my $version_string;
161  
162 0 ▶ if ($chunk->{children}[$_]->isa('PPI::Structure::Block')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk->{"children"}[$_]->isa("PPI::Structure::Block")) 0 0 0
163  
164 my $ppi_sb = $chunk->{children}[$_]
165 0 ▶ if $chunk->{children}[$_]->isa('PPI::Structure::Block');
Branch: 1 branch
BranchTrueFalseTotal
if $chunk->{"children"}[$_]->isa("PPI::Structure::Block") 0 0 0
166  
167 0 $self->_eval_info($ppi_sb, \$module_name, \$version_string);
168 0 ▶ print "Option2 $module_name - $version_string\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
169 }
170 0 ▶ if (version::is_lax($version_string)) {
Branch: 1 branch
BranchTrueFalseTotal
if (version::is_lax($version_string)) 0 0 0
171  
172 0 push @modules, $module_name;
173 0 ▶ $version_string
Branch: 1 branch
BranchTrueFalseTotal
version::is_lax($version_string) ? : 0 0 0
174 = version::is_lax($version_string) ? $version_string : 0;
175 0 push @version_strings, $version_string;
176 0 $self->{found_version}{$module_name} = $version_string;
177 }
178 }
179 }
180 }
181 0 };
182  
183  
184 #PPI::Document
185 # PPI::Statement
186 # PPI::Token::Word 'eval'
187 # PPI::Token::Whitespace ' '
188 # PPI::Token::Quote::Double '"require Test::Kwalitee::Extra $mod_ver"'
189 # PPI::Token::Structure ';'
190 #
191  
192 0 ▶ try {
Subroutine __ANON__: not called CC=12 SCAR=50.5
193 0 my @chunks1 = @{$self->ppi_document->find('PPI::Statement')};
194 0 foreach my $chunk (@chunks1) {
195 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk->find(sub { $_[1]->isa("PPI::Token::Word") and $_[1]->content =~ /\A(?:eval|try)\z/; } )) 0 0 0
196 $chunk->find(
197 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
198 0 ▶ $_[1]->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Token::Word") and $_[1]->content =~ /\A(?:eval|try)\z/ 0 0 0
199 and $_[1]->content =~ m{\A(?:eval|try)\z};
200 }
201 )
202 )
203 {
204 0 for (0 .. $#{$chunk->{children}}) {
205  
206 # ignore sub blocks - false positive
207 0 ▶ last if $chunk->{children}[$_]->content eq 'sub';
Branch: 1 branch
BranchTrueFalseTotal
if $chunk->{"children"}[$_]->content eq "sub" 0 0 0
208  
209 0 ▶ if ( $chunk->{children}[$_]->isa('PPI::Token::Quote::Double')
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk->{"children"}[$_]->isa("PPI::Token::Quote::Double") or $chunk->{"children"}[$_]->isa("PPI::Token::Quote::Single")) 0 0 0
Condition0%0/3
$chunk->{"children"}[$_]->isa("PPI::Token::Quote::Double") or $chunk->{"children"}[$_]->isa("PPI::Token::Quote::Single")
l!l&&r!l&&!r
000
MC/DC0%0/2
$chunk->{"children"}[$_]->isa("PPI::Token::Quote::Double") or $chunk->{"children"}[$_]->isa("PPI::Token::Quote::Single")
$chunk->{"children"}[$_]->isa("PPI::Token::Quote::Double") $chunk->{"children"}[$_]->isa("PPI::Token::Quote::Single")
Truth table0%0/3
A or B
A= $chunk->{"children"}[$_]->isa("PPI::Token::Quote::Double")B= $chunk->{"children"}[$_]->isa("PPI::Token::Quote::Single")
ABresult
1X1
011
000
210 || $chunk->{children}[$_]->isa('PPI::Token::Quote::Single'))
211 {
212 0 my $eval_line = $chunk->{children}[$_]->content;
213  
214 0 $eval_line =~ s/(?:'|"|{|})//g;
215 0 my @eval_includes = split /;/, $eval_line;
216  
217 0 foreach my $eval_include (@eval_includes) {
218  
219 0 $self->_mod_ver(\@modules, \@version_strings, $eval_include);
220 }
221 }
222  
223 0 ▶ if ($chunk->{children}[$_]->isa('PPI::Structure::Block')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk->{"children"}[$_]->isa("PPI::Structure::Block")) 0 0 0
224 0 my @children = $chunk->{children}[$_]->children;
225  
226 0 foreach my $child_element (@children) {
227 0 ▶ if ($child_element->isa('PPI::Statement::Include')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($child_element->isa("PPI::Statement::Include")) 0 0 0
228  
229 0 my $eval_line = $child_element->content;
230 0 my @eval_includes = split /;/, $eval_line;
231 0 foreach my $eval_include (@eval_includes) {
232 0 $self->_mod_ver(\@modules, \@version_strings,
233 $eval_include);
234 }
235 }
236 }
237 }
238 }
239 }
240 }
241 0 };
242  
243 0 ▶ p @modules if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
244 0 ▶ p @version_strings if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
245  
246 0 ▶ if (scalar @modules > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @modules > 0) 0 0 0
247 0 for (0 .. $#modules) {
248 0 ▶ print "Info: Eval -> Sending $modules[$_] - $version_strings[$_]\n"
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose == 2 0 0 0
249 if ($self->verbose == TWO);
250  
251 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
252 0 $self->_process_found_modules(
253 $phase_relationship, $modules[$_], $version_strings[$_],
254 __PACKAGE__, $phase_relationship,
255 );
256 0 };
257 }
258 }
259 0 return;
260 }
261  
262  
263 #######
264 # composed Method
265 #######
266 0 ▶sub _mod_ver {
Subroutine _mod_ver: not called CC=6 SCAR=37.4
267 0 my ($self, $modules, $version_strings, $eval_include) = @_;
268  
269 0 ▶ if ($eval_include =~ /^\s*(?:use|require|no)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eval_include =~ /^\s*(?:use|require|no)/) 0 0 0
270  
271 0 $eval_include =~ s/^\s*(?:use|require|no)\s*//;
272  
273 0 my $module_name = $eval_include;
274  
275 0 $module_name =~ s/(?:\s[\s|\w|\n|.|;]+)$//;
276 0 $module_name =~ s/\s+(?:[\$|\w|\n]+)$//;
277 0 $module_name =~ s/\s+$//;
278  
279 0 $module_name =~ m/\A([\w|:]+)\b/;
280 0 $module_name = $1;
281  
282 # exit if already found by this extra scanner
283 0 ▶ return if $self->{found_version}{$module_name};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"found_version"}{$module_name} 0 0 0
284  
285 # check for first char upper in module name
286 0 ▶ push @{$modules}, $module_name if $module_name =~ m{\A(?:[a-zA-Z])};
Branch: 1 branch
BranchTrueFalseTotal
if $module_name =~ /\A(?:[a-zA-Z])/ 0 0 0
287  
288  
289 0 my $version_string = $eval_include;
290 0 $version_string =~ s/$module_name\s*//;
291 0 $version_string =~ s/\s*$//;
292 0 $version_string =~ s/[a-zA-Z]|\s|\$|s|:|;//g;
293  
294 0 ▶ $version_string = version::is_lax($version_string) ? $version_string : 0;
Branch: 1 branch
BranchTrueFalseTotal
version::is_lax($version_string) ? : 0 0 0
295 0 push @{$version_strings}, $version_string;
296 0 $self->{found_version}{$module_name} = $version_string;
297 0 ▶ print "Option1 $module_name - $version_string\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
298 }
299  
300 0 return;
301 }
302  
303  
304 #######
305 # composed Method
306 #######
307 0 ▶sub _eval_info {
Subroutine _eval_info: not called CC=14 SCAR=53.5
308 0 my ($self, $ppi_sb, $mn_ref, $vs_ref) = @_;
309  
310 0 for (0 .. $#{$ppi_sb->{children}}) {
311  
312 # find module name
313 0 ▶ if ($ppi_sb->{children}[$_]->isa('PPI::Statement::Include')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ppi_sb->{"children"}[$_]->isa("PPI::Statement::Include")) 0 0 0
314 my $ppi_si = $ppi_sb->{children}[$_]
315 0 ▶ if $ppi_sb->{children}[$_]->isa('PPI::Statement::Include');
Branch: 1 branch
BranchTrueFalseTotal
if $ppi_sb->{"children"}[$_]->isa("PPI::Statement::Include") 0 0 0
316 0 ▶ if ( $ppi_si->{children}[0]->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
if ($ppi_si->{"children"}[0]->isa("PPI::Token::Word") and $ppi_si->{"children"}[0]->content eq "require") 0 0 0
Condition0%0/3
$ppi_si->{"children"}[0]->isa("PPI::Token::Word") and $ppi_si->{"children"}[0]->content eq "require"
!ll&&!rl&&r
000
MC/DC0%0/2
$ppi_si->{"children"}[0]->isa("PPI::Token::Word") and $ppi_si->{"children"}[0]->content eq "require"
$ppi_si->{"children"}[0]->isa("PPI::Token::Word") $ppi_si->{"children"}[0]->content eq "require"
Truth table0%0/3
A and B
A= $ppi_si->{"children"}[0]->isa("PPI::Token::Word")B= $ppi_si->{"children"}[0]->content eq "require"
ABresult
0X0
100
111
317 && $ppi_si->{children}[0]->content eq 'require')
318 {
319 0 ${$mn_ref} = $ppi_si->{children}[2]->content
320 0 ▶ if $ppi_si->{children}[2]->isa('PPI::Token::Word');
Branch: 1 branch
BranchTrueFalseTotal
if $ppi_si->{"children"}[2]->isa("PPI::Token::Word") 0 0 0
321 }
322 }
323  
324 # find version string if we previously found a name
325 0 ▶ if ($ppi_sb->{children}[$_]->isa('PPI::Statement')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ppi_sb->{"children"}[$_]->isa("PPI::Statement")) 0 0 0
326 my $ppi_s = $ppi_sb->{children}[$_]
327 0 ▶ if $ppi_sb->{children}[$_]->isa('PPI::Statement');
Branch: 1 branch
BranchTrueFalseTotal
if $ppi_sb->{"children"}[$_]->isa("PPI::Statement") 0 0 0
328 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($ppi_s->{"children"}[0]->isa("PPI::Token::Word") and $ppi_s->{"children"}[0]->content eq ${$mn_ref;} and ($ppi_s->{"children"}[2]->isa("PPI::Token::Word") and $ppi_s->{"children"}[2]->content eq "VERSION")) 0 0 0
Condition0%0/6
$ppi_s->{"children"}[0]->isa("PPI::Token::Word") and $ppi_s->{"children"}[0]->content eq ${$mn_ref;} and ($ppi_s->{"children"}[2]->isa("PPI::Token::Word") and $ppi_s->{"children"}[2]->content eq "VERSION")
!ll&&!rl&&r
000
$ppi_s->{"children"}[0]->isa("PPI::Token::Word") and $ppi_s->{"children"}[0]->content eq ${$mn_ref;}
!ll&&!rl&&r
000
MC/DC0%0/3
$ppi_s->{"children"}[0]->isa("PPI::Token::Word") and $ppi_s->{"children"}[0]->content eq ${$mn_ref;} and ($ppi_s->{"children"}[2]->isa("PPI::Token::Word") and $ppi_s->{"children"}[2]->content eq "VERSION")
$ppi_s->{"children"}[0]->isa("PPI::Token::Word") $ppi_s->{"children"}[0]->content eq ${$mn_ref;} ($ppi_s->{"children"}[2]->isa("PPI::Token::Word") and $ppi_s->{"children"}[2]->content eq "VERSION")
Truth table0%0/4
A and B and C
A= $ppi_s->{"children"}[0]->isa("PPI::Token::Word")B= $ppi_s->{"children"}[0]->content eq ${$mn_ref;}C= ($ppi_s->{"children"}[2]->isa("PPI::Token::Word") and $ppi_s->{"children"}[2]->content eq "VERSION")
ABCresult
0XX0
10X0
1100
1111
329 (
330 $ppi_s->{children}[0]->isa('PPI::Token::Word')
331 0 ▶ and $ppi_s->{children}[0]->content eq ${$mn_ref}
Condition0%0/3
$ppi_s->{"children"}[2]->isa("PPI::Token::Word") and $ppi_s->{"children"}[2]->content eq "VERSION"
!ll&&!rl&&r
000
MC/DC0%0/2
$ppi_s->{"children"}[2]->isa("PPI::Token::Word") and $ppi_s->{"children"}[2]->content eq "VERSION"
$ppi_s->{"children"}[2]->isa("PPI::Token::Word") $ppi_s->{"children"}[2]->content eq "VERSION"
Truth table0%0/3
A and B
A= $ppi_s->{"children"}[2]->isa("PPI::Token::Word")B= $ppi_s->{"children"}[2]->content eq "VERSION"
ABresult
0X0
100
111
332 )
333 && ( $ppi_s->{children}[2]->isa('PPI::Token::Word')
334 and $ppi_s->{children}[2]->content eq 'VERSION')
335 )
336 {
337 my $ppi_sl = $ppi_s->{children}[3]
338 0 ▶ if $ppi_s->{children}[3]->isa('PPI::Structure::List');
Branch: 1 branch
BranchTrueFalseTotal
if $ppi_s->{"children"}[3]->isa("PPI::Structure::List") 0 0 0
339 0 ${$vs_ref} = $ppi_sl->{children}[0]->{children}[0]->content;
340 }
341 }
342 }
343  
344 0 return;
345 }
346  
347 2 ▶no Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
348  
349 2 1;
350  
351 __END__
« Midgen/Role/Output/Dist.pm ↑ Summary Midgen/Role/UseModule.pm »