Midgen/Role/TestRequires.pm

filter: Statementstmt 27.5% 22 / 80 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 54.5% 6 / 11 Podpod 100% 1 / 1 totaltotal 18.1% 29 / 160 CC 34 SCAR 59.5
CC
34
Cov
16%
__ANON__
650.0
xtests_test_requires
72.0
__ANON__
6.0
CRAP 383.1
« Midgen/Role/UseOk.pm ↑ Summary Midgen/Role/Output/CPANfile.pm »
1 package App::Midgen::Role::TestRequires;
2  
3 2 ▶use constant {BLANK => q{ }, NONE => q{}, TWO => 2, THREE => 3,};
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 requires
7 qw( ppi_document develop debug verbose format xtest _process_found_modules meta2 );
8  
9 2 ▶use PPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Data::Printer {caller_info => 1,};
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # Load time and dependencies negate execution time
14 # use namespace::clean -except => 'meta';
15  
16 2 our $VERSION = '0.34';
17 2 $VERSION = eval $VERSION; ## no critic
18  
19  
20 #######
21 # composed method - xtests_test_requires
22 #######
23 0 ▶sub xtests_test_requires {
Subroutine xtests_test_requires: not called CC=8 SCAR=42.8
Pod documented
24 0 my $self = shift;
25 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
26  
27 0 my @modules;
28 my @version_strings;
29  
30 # PPI::Statement::Include
31 # PPI::Token::Word 'use'
32 # PPI::Token::Whitespace ' '
33 # PPI::Token::Word 'Test::Requires'
34 # PPI::Token::Whitespace ' '
35 # PPI::Structure::Constructor { ... }
36 # PPI::Token::Whitespace ' '
37 # PPI::Statement
38 # PPI::Token::Quote::Single ''Test::Pod''
39 # PPI::Token::Whitespace ' '
40 # PPI::Token::Operator '=>'
41 # PPI::Token::Whitespace ' '
42 # PPI::Token::Number::Float '1.46'
43 # PPI::Token::Whitespace ' '
44 # PPI::Token::Structure ';'
45  
46 0 ▶ try {
Subroutine __ANON__: not called CC=25 SCAR=64.8
47 my @chunks
48 0 ▶ = @{$self->ppi_document->find('PPI::Statement::Include') || []};
Condition0%0/2
$self->ppi_document->find('PPI::Statement::Include') || []
l!l
00
MC/DC0%0/1
$self->ppi_document->find('PPI::Statement::Include') || []
$self->ppi_document->find('PPI::Statement::Include')
Truth table0%0/2
A
A= $self->ppi_document->find('PPI::Statement::Include')
Aresult
11
00
49  
50 0 foreach my $hunk (@chunks) {
51  
52 # test for use
53 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($hunk->find(sub { $_[1]->isa("PPI::Token::Word") and $_[1]->content =~ /\A(?:use)\z/; } )) 0 0 0
54 $hunk->find(
55 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
56 0 ▶ $_[1]->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Token::Word") and $_[1]->content =~ /\A(?:use)\z/ 0 0 0
57 and $_[1]->content =~ m{\A(?:use)\z};
58 }
59 )
60 )
61 {
62  
63 # test for Test::Requires
64 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($hunk->find(sub { $_[1]->isa("PPI::Token::Word") and $_[1]->content =~ /\A(?:Test::Requires)\z/; } )) 0 0 0
65 $hunk->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(?:Test::Requires)\z/ 0 0 0
68 and $_[1]->content =~ m{\A(?:Test::Requires)\z};
69 }
70 )
71 )
72 {
73  
74 0 foreach (0 .. $#{$hunk->{children}}) {
75  
76 # looking for use Test::Requires { 'Test::Pod' => '1.46' };
77 0 ▶ if ($hunk->{children}[$_]->isa('PPI::Structure::Constructor')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hunk->{"children"}[$_]->isa("PPI::Structure::Constructor")) 0 0 0
78  
79 my $ppi_sc = $hunk->{children}[$_]
80 0 ▶ if $hunk->{children}[$_]->isa('PPI::Structure::Constructor');
Branch: 1 branch
BranchTrueFalseTotal
if $hunk->{"children"}[$_]->isa("PPI::Structure::Constructor") 0 0 0
81  
82 0 foreach (0 .. $#{$ppi_sc->{children}}) {
83  
84 0 ▶ if ($ppi_sc->{children}[$_]->isa('PPI::Statement')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ppi_sc->{"children"}[$_]->isa("PPI::Statement")) 0 0 0
85  
86 my $ppi_s = $ppi_sc->{children}[$_]
87 0 ▶ if $ppi_sc->{children}[$_]->isa('PPI::Statement');
Branch: 1 branch
BranchTrueFalseTotal
if $ppi_sc->{"children"}[$_]->isa("PPI::Statement") 0 0 0
88  
89 0 foreach my $element (@{$ppi_s->{children}}) {
90  
91 # extract module name
92 0 ▶ if ( $element->isa('PPI::Token::Quote::Double')
Branch: 1 branch
BranchTrueFalseTotal
if ($element->isa("PPI::Token::Quote::Double") or $element->isa("PPI::Token::Quote::Single") or $element->isa("PPI::Token::Word")) 0 0 0
Condition0%0/6
$element->isa("PPI::Token::Quote::Double") or $element->isa("PPI::Token::Quote::Single") or $element->isa("PPI::Token::Word")
l!l&&r!l&&!r
000
$element->isa("PPI::Token::Quote::Double") or $element->isa("PPI::Token::Quote::Single")
l!l&&r!l&&!r
000
MC/DC0%0/3
$element->isa("PPI::Token::Quote::Double") or $element->isa("PPI::Token::Quote::Single") or $element->isa("PPI::Token::Word")
$element->isa("PPI::Token::Quote::Double") $element->isa("PPI::Token::Quote::Single") $element->isa("PPI::Token::Word")
Truth table0%0/4
A or B or C
A= $element->isa("PPI::Token::Quote::Double")B= $element->isa("PPI::Token::Quote::Single")C= $element->isa("PPI::Token::Word")
ABCresult
1XX1
01X1
0011
0000
93 || $element->isa('PPI::Token::Quote::Single')
94 || $element->isa('PPI::Token::Word'))
95 {
96 0 my $module_name = $element->content;
97 0 $module_name =~ s/(?:'|")//g;
98 0 ▶ if ($module_name =~ m/\A(?:[a-zA-Z])/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_name =~ /\A(?:[a-zA-Z])/) 0 0 0
99 0 ▶ print "found module - $module_name\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
100 0 push @modules, $module_name;
101 0 $version_strings[$#modules] = undef;
102 }
103 }
104  
105 # extract version string
106 0 ▶ if ( $element->isa('PPI::Token::Number::Float')
Branch: 1 branch
BranchTrueFalseTotal
if ($element->isa("PPI::Token::Number::Float") or $element->isa("PPI::Token::Quote::Double") or $element->isa("PPI::Token::Quote::Single")) 0 0 0
Condition0%0/6
$element->isa("PPI::Token::Number::Float") or $element->isa("PPI::Token::Quote::Double") or $element->isa("PPI::Token::Quote::Single")
l!l&&r!l&&!r
000
$element->isa("PPI::Token::Number::Float") or $element->isa("PPI::Token::Quote::Double")
l!l&&r!l&&!r
000
MC/DC0%0/3
$element->isa("PPI::Token::Number::Float") or $element->isa("PPI::Token::Quote::Double") or $element->isa("PPI::Token::Quote::Single")
$element->isa("PPI::Token::Number::Float") $element->isa("PPI::Token::Quote::Double") $element->isa("PPI::Token::Quote::Single")
Truth table0%0/4
A or B or C
A= $element->isa("PPI::Token::Number::Float")B= $element->isa("PPI::Token::Quote::Double")C= $element->isa("PPI::Token::Quote::Single")
ABCresult
1XX1
01X1
0011
0000
107 || $element->isa('PPI::Token::Quote::Double')
108 || $element->isa('PPI::Token::Quote::Single'))
109 {
110 0 my $version_string = $element->content;
111 0 $version_string =~ s/(?:'|")//g;
112 0 ▶ if ($version_string =~ m/\A(?:[0-9])/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version_string =~ /\A(?:[0-9])/) 0 0 0
113  
114 0 ▶ $version_string
Branch: 1 branch
BranchTrueFalseTotal
version::is_lax($version_string) ? : 0 0 0
115 = version::is_lax($version_string)
116 ? $version_string
117 : 0;
118  
119 0 ▶ print "found version string - $version_string\n"
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
120 if $self->debug;
121 0 $self->{found_version}{$modules[$#modules]}
122 = $version_string;
123 0 $version_strings[$#modules] = $version_string;
124 }
125 }
126 }
127 }
128 }
129 }
130  
131 # looking for use Test::Requires qw(MIME::Types);
132 0 ▶ if ($hunk->{children}[$_]->isa('PPI::Token::QuoteLike::Words')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hunk->{"children"}[$_]->isa("PPI::Token::QuoteLike::Words")) 0 0 0
133  
134 my $ppi_tqw = $hunk->{children}[$_]
135 0 ▶ if $hunk->{children}[$_]->isa('PPI::Token::QuoteLike::Words');
Branch: 1 branch
BranchTrueFalseTotal
if $hunk->{"children"}[$_]->isa("PPI::Token::QuoteLike::Words") 0 0 0
136  
137 0 my $operator = $ppi_tqw->{operator};
138 0 my @type = split(//, $ppi_tqw->{sections}->[0]->{type});
139  
140 0 my $module = $ppi_tqw->{content};
141 0 $module =~ s/$operator//;
142 0 my $type_open = '\A\\' . $type[0];
143  
144 0 $module =~ s{$type_open}{};
145 0 my $type_close = '\\' . $type[1] . '\Z';
146  
147 0 $module =~ s{$type_close}{};
148 0 push @modules, split(BLANK, $module);
149 0 $version_strings[$#modules] = undef;
150 }
151 }
152 }
153 }
154 }
155 0 };
156  
157 0 ▶ @version_strings = map { defined $_ ? $_ : 0 } @version_strings;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
158 0 ▶ p @modules if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
159 0 ▶ p @version_strings if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
160  
161 0 ▶ if (scalar @modules > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @modules > 0) 0 0 0
162  
163 0 for (0 .. $#modules) {
164 0 ▶ print
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose == 2 0 0 0
165 "Info: TestRequires -> Sending $modules[$_] - $version_strings[$_]\n"
166 if ($self->verbose == TWO);
167 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
168 0 $self->_process_found_modules(
169 $phase_relationship, $modules[$_], $version_strings[$_],
170 __PACKAGE__, $phase_relationship,
171 );
172 0 };
173 }
174 }
175 0 return;
176 }
177  
178 2 ▶no Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
179  
180 2 1;
181  
182 __END__
« Midgen/Role/UseOk.pm ↑ Summary Midgen/Role/Output/CPANfile.pm »