blib/lib/Perl/PrereqScanner/Scanner/Perl5.pm

filter: Statementstmt 97.5% 39 / 40 Branchbran 95.0% 19 / 20 Conditioncond 80.4% 37 / 46 MC/DCmcdc 59.0% 13 / 22 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 84.3% 113 / 134 CC 29 SCAR 27.4
CC
29
Cov
90%
_check_required_version
20.2
scan_for_prereqs
12.0
BEGIN
1.0
CRAP 15.5
« blib/lib/Perl/PrereqScanner/Scanner/Moose.pm ↑ Summary blib/lib/Perl/PrereqScanner/Scanner/Superclass.pm »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Perl::PrereqScanner::Scanner::Perl5 1.100;
5 # ABSTRACT: scan for core Perl 5 language indicators of required modules
6  
7 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 with 'Perl::PrereqScanner::Scanner';
9  
10 #pod =head1 DESCRIPTION
11 #pod
12 #pod This scanner will look for the following indicators:
13 #pod
14 #pod =begin :list
15 #pod
16 #pod * plain lines beginning with C<use>, C<require>, or C<no> in your perl modules and scripts, including minimum perl version
17 #pod
18 #pod * regular inheritance declared with the C<base> and C<parent> pragmata
19 #pod
20 #pod =end :list
21 #pod
22 #pod Since Perl does not allow you to supply a version requirement with a
23 #pod C<require> statement, the scanner will check the statement after the
24 #pod C<require Module> to see if it is C<< Module->VERSION( minimum_version ); >>.
25 #pod
26 #pod In order to provide a minimum version, that method call must meet the
27 #pod following requirements:
28 #pod
29 #pod =begin :list
30 #pod
31 #pod * it must be the very next statement after C<require Module>. Nothing can separate them but whitespace and comments (and one semicolon).
32 #pod
33 #pod * C<Module> must be a bareword, and match the C<require> exactly.
34 #pod
35 #pod * C<minimum_version> must be a literal number, v-string, or single-quoted string. Double quotes are not allowed.
36 #pod
37 #pod =end :list
38 #pod
39 #pod =cut
40  
41 269 ▶sub scan_for_prereqs {
Subroutine scan_for_prereqs: called CC=12 SCAR=24.8
Pod undocumented
42 269 my ($self, $ppi_doc, $req) = @_;
43  
44 # regular use, require, and no
45 269 ▶ my $includes = $ppi_doc->find('Statement::Include') || [];
Condition100%2/2
$ppi_doc->find('Statement::Include') || []
l!l
137132
MC/DC100%1/1
$ppi_doc->find('Statement::Include') || []
$ppi_doc->find('Statement::Include')
Truth table100%2/2
A
A= $ppi_doc->find('Statement::Include')
Aresult
11
00
46 269 for my $node ( @$includes ) {
47 # minimum perl version
48 191 ▶ if ( $node->version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->version) 1 190 191
49 1 $req->add_minimum(perl => $node->version);
50 1 next;
51 }
52  
53 # inheritance
54 190 ▶ if (grep { $_ eq $node->module } qw{ base parent }) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $node->module;} "base", "parent") 33 157 190
55 # rt#55713: skip arguments to base or parent, focus only on inheritance
56 my @meat = grep {
57 33 ▶ $_->isa('PPI::Token::QuoteLike::Words')
Condition100%3/3
$_->isa('PPI::Token::QuoteLike::Words') || $_->isa('PPI::Token::Quote')
l!l&&r!l&&!r
9246
MC/DC100%2/2
$_->isa('PPI::Token::QuoteLike::Words') || $_->isa('PPI::Token::Quote')
$_->isa('PPI::Token::QuoteLike::Words') $_->isa('PPI::Token::Quote')
Truth table100%3/3
A || B
A= $_->isa('PPI::Token::QuoteLike::Words')B= $_->isa('PPI::Token::Quote')
ABresult
1X1
011
000
58 || $_->isa('PPI::Token::Quote')
59 } $node->arguments;
60  
61 33 my @parents = map { $self->_q_contents($_) } @meat;
62 33 $req->add_minimum($_ => 0) for @parents;
63 }
64  
65 # regular modules
66 190 ▶ my $version = $node->module_version ? $node->module_version->content : 0;
Branch: 1 branch
BranchTrueFalseTotal
$node->module_version ? : 62 128 190
67  
68 # rt#55851: 'require $foo;' shouldn't add any prereq
69 190 ▶ next unless $node->module;
Branch: 1 branch
BranchTrueFalseTotal
unless $node->module 3 187 190
70  
71 # See if the next statement after require is Module->VERSION(min):
72 187 ▶ $version = $self->_check_required_version($node) || 0
Branch: 1 branch
BranchTrueFalseTotal
if not $version and $node->type =~ /\A(?:require|use)\z/ 122 65 187
Condition100%5/5
not $version and $node->type =~ /\A(?:require|use)\z/
!ll&&!rl&&r
623122
$self->_check_required_version($node) || 0
l!l
18104
MC/DC100%2/2
not $version and $node->type =~ /\A(?:require|use)\z/
not $version $node->type =~ /\A(?:require|use)\z/
MC/DC100%1/1
$self->_check_required_version($node) || 0
$self->_check_required_version($node)
Truth table100%3/3
not(A) and B
A= not $versionB= $node->type =~ /\A(?:require|use)\z/
ABresult
0X0
100
111
Truth table100%2/2
A
A= $self->_check_required_version($node)
Aresult
11
00
73 if not $version and $node->type =~ /\A(?:require|use)\z/;
74  
75 187 $req->add_minimum($node->module, $version);
76 }
77 }
78  
79 # For "require Module", see if the next statement is Module->VERSION(min):
80 122 ▶sub _check_required_version {
Subroutine _check_required_version: called CC=18 SCAR=30.1
81 122 my ($self, $node) = @_;
82  
83 122 my $next = $node->snext_sibling;
84  
85 122 ▶ return unless $next and $next->class eq 'PPI::Statement';
Branch: 1 branch
BranchTrueFalseTotal
unless $next and $next->class eq "PPI::Statement" 88 34 122
Condition100%3/3
$next and $next->class eq "PPI::Statement"
!ll&&!rl&&r
573134
MC/DC100%2/2
$next and $next->class eq "PPI::Statement"
$next $next->class eq "PPI::Statement"
Truth table100%3/3
A and B
A= $nextB= $next->class eq "PPI::Statement"
ABresult
0X0
100
111
86  
87 34 my ($invocant, $op, $method, $list, $too_much) = $next->schildren;
88  
89 34 ▶ return unless defined $list # need enough children
Branch: 1 branch
BranchTrueFalseTotal
unless defined $list and $op->class eq "PPI::Token::Operator" and $op->content eq "->" and $method->content eq "VERSION" and !defined($too_much) || $too_much->content eq ";" and $invocant->content eq $node->module and $list->class eq "PPI::Structure::List" and $list->braces eq "()" and $list->schildren == 1 13 21 34
Condition77%21/27
defined $list and $op->class eq "PPI::Token::Operator" and $op->content eq "->" and $method->content eq "VERSION" and !defined($too_much) || $too_much->content eq ";" and $invocant->content eq $node->module and $list->class eq "PPI::Structure::List" and $list->braces eq "()" and $list->schildren == 1
!ll&&!rl&&r
13021
defined $list and $op->class eq "PPI::Token::Operator" and $op->content eq "->" and $method->content eq "VERSION" and !defined($too_much) || $too_much->content eq ";" and $invocant->content eq $node->module and $list->class eq "PPI::Structure::List" and $list->braces eq "()"
!ll&&!rl&&r
13021
defined $list and $op->class eq "PPI::Token::Operator" and $op->content eq "->" and $method->content eq "VERSION" and !defined($too_much) || $too_much->content eq ";" and $invocant->content eq $node->module and $list->class eq "PPI::Structure::List"
!ll&&!rl&&r
13021
defined $list and $op->class eq "PPI::Token::Operator" and $op->content eq "->" and $method->content eq "VERSION" and !defined($too_much) || $too_much->content eq ";" and $invocant->content eq $node->module
!ll&&!rl&&r
10321
defined $list and $op->class eq "PPI::Token::Operator" and $op->content eq "->" and $method->content eq "VERSION" and !defined($too_much) || $too_much->content eq ";"
!ll&&!rl&&r
7324
defined $list and $op->class eq "PPI::Token::Operator" and $op->content eq "->" and $method->content eq "VERSION"
!ll&&!rl&&r
7027
defined $list and $op->class eq "PPI::Token::Operator" and $op->content eq "->"
!ll&&!rl&&r
7027
defined $list and $op->class eq "PPI::Token::Operator"
!ll&&!rl&&r
3427
not defined $too_much or $too_much->content eq ";"
l!l&&r!l&&!r
0243
MC/DC40%4/10
defined $list and $op->class eq "PPI::Token::Operator" and $op->content eq "->" and $method->content eq "VERSION" and !defined($too_much) || $too_much->content eq ";" and $invocant->content eq $node->module and $list->class eq "PPI::Structure::List" and $list->braces eq "()" and $list->schildren == 1
defined $list $op->class eq "PPI::Token::Operator" $op->content eq "->" $method->content eq "VERSION" not defined $too_much $too_much->content eq ";" $invocant->content eq $node->module $list->class eq "PPI::Structure::List" $list->braces eq "()" $list->schildren == 1
Truth table33%5/15
A and B and C and D and not(E) or F and G and H and I and J
A= defined $listB= $op->class eq "PPI::Token::Operator"C= $op->content eq "->"D= $method->content eq "VERSION"E= not defined $too_muchF= $too_much->content eq ";"G= $invocant->content eq $node->moduleH= $list->class eq "PPI::Structure::List"I= $list->braces eq "()"J= $list->schildren == 1
ABCDEFGHIJresult
0XXXXXXXXX0
10XXXXXXXX0
110XXXXXXX0
1110XXXXXX0
111100XXXX0
11111X0XXX0
1111010XXX0
11111X10XX0
11110110XX0
11111X110X0
111101110X0
11111X11100
11110111100
11111X11111
11110111111
90 and $op->class eq 'PPI::Token::Operator'
91 and $op->content eq '->'
92 and $method->content eq 'VERSION'
93 and (not defined $too_much # but not too many children
94 or $too_much->content eq ';')
95 and $invocant->content eq $node->module
96 and $list->class eq 'PPI::Structure::List'
97 and $list->braces eq '()'
98 and $list->schildren == 1;
99  
100 21 my $exp = $list->schild(0);
101  
102 21 ▶ return unless $exp->class eq 'PPI::Statement::Expression'
Branch: 1 branch
BranchTrueFalseTotal
unless $exp->class eq "PPI::Statement::Expression" and $exp->schildren == 1 3 18 21
Condition66%2/3
$exp->class eq "PPI::Statement::Expression" and $exp->schildren == 1
!ll&&!rl&&r
0318
MC/DC50%1/2
$exp->class eq "PPI::Statement::Expression" and $exp->schildren == 1
$exp->class eq "PPI::Statement::Expression" $exp->schildren == 1
Truth table66%2/3
A and B
A= $exp->class eq "PPI::Statement::Expression"B= $exp->schildren == 1
ABresult
0X0
100
111
103 and $exp->schildren == 1;
104  
105 18 my $arg = $exp->schild(0);
106  
107 18 ▶ if ($arg->isa('PPI::Token::Number')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($arg->isa('PPI::Token::Number')) { } 12 6 18
elsif ($arg->isa('PPI::Token::Quote') and $arg->can('literal')) { } 6 0 6
108 12 return $arg->content;
109 ▶ } elsif ($arg->isa('PPI::Token::Quote') and $arg->can('literal')) {
Condition33%1/3
$arg->isa("PPI::Token::Quote") and $arg->can("literal")
!ll&&!rl&&r
006
MC/DC0%0/2
$arg->isa("PPI::Token::Quote") and $arg->can("literal")
$arg->isa("PPI::Token::Quote") $arg->can("literal")
Truth table33%1/3
A and B
A= $arg->isa("PPI::Token::Quote")B= $arg->can("literal")
ABresult
0X0
100
111
110 6 return $arg->literal;
111 }
112  
113 0 return; # No minimum version found
114 } # end _check_required_version
115  
116 4 1;
117  
118 __END__
« blib/lib/Perl/PrereqScanner/Scanner/Moose.pm ↑ Summary blib/lib/Perl/PrereqScanner/Scanner/Superclass.pm »