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

filter: Statementstmt 96.8% 62 / 64 Branchbran 87.5% 28 / 32 Conditioncond 87.5% 28 / 32 MC/DCmcdc 73.6% 14 / 19 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 89.4% 136 / 152 CC 33 SCAR 34.3
CC
33
Cov
92%
scan_for_prereqs
33.7
BEGIN
1.0
BEGIN
1.0
CRAP 31.0
↑ Summary blib/lib/Perl/PrereqScanner/Scanner/Perl5.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::Moose 1.100;
5 # ABSTRACT: scan for Moose sugar 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 * L<Moose> inheritance declared with the C<extends> keyword
17 #pod
18 #pod * L<Moose> roles included with the C<with> keyword
19 #pod
20 #pod =end :list
21 #pod
22 #pod =cut
23  
24 269 ▶sub scan_for_prereqs {
Subroutine scan_for_prereqs: called CC=33 SCAR=35.2
Pod undocumented
25 269 my ($self, $ppi_doc, $req) = @_;
26  
27 # Moose-based roles / inheritance
28 my @chunks =
29 # This is what we get when someone does: with('Foo');
30 # The target to get at is the PPI::Token::Quote::Single.
31 # -- rjbs, 2010-09-05
32 #
33 # PPI::Statement
34 # PPI::Token::Word
35 # PPI::Structure::List
36 # PPI::Statement::Expression
37 # PPI::Token::Quote::Single
38 # PPI::Token::Structure
39  
40 132 map { [ $_->schildren ] }
41 507 grep { $_->child(0)->literal =~ m{\A(?:with|extends)\z} }
42 638 grep { $_->child(0)->isa('PPI::Token::Word') }
43 269 ▶ @{ $ppi_doc->find('PPI::Statement') || [] };
Condition100%2/2
$ppi_doc->find('PPI::Statement') || []
l!l
2663
MC/DC100%1/1
$ppi_doc->find('PPI::Statement') || []
$ppi_doc->find('PPI::Statement')
Truth table100%2/2
A
A= $ppi_doc->find('PPI::Statement')
Aresult
11
00
44  
45 269 foreach my $hunk ( @chunks ) {
46 # roles/inheritance *WITH* version declaration ( added in Moose 1.03 )
47 132 ▶ if ( grep { $_->isa('PPI::Structure::Constructor') || $_->isa('PPI::Structure::List') } @$hunk ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_->isa('PPI::Structure::Constructor') or $_->isa('PPI::Structure::List');} @$hunk) { } 96 36 132
Condition100%3/3
$_->isa('PPI::Structure::Constructor') || $_->isa('PPI::Structure::List')
l!l&&r!l&&!r
4560423
MC/DC100%2/2
$_->isa('PPI::Structure::Constructor') || $_->isa('PPI::Structure::List')
$_->isa('PPI::Structure::Constructor') $_->isa('PPI::Structure::List')
Truth table100%3/3
A || B
A= $_->isa('PPI::Structure::Constructor')B= $_->isa('PPI::Structure::List')
ABresult
1X1
011
000
48 # hack for List
49 96 my @hunkdata = @$hunk;
50 0 ▶ while ( $hunkdata[0]->isa('PPI::Token::Whitespace') ) { shift @hunkdata }
Branch: 1 branch
BranchTrueFalseTotal
if ($hunkdata[0]->isa("PPI::Token::Whitespace")) 0 96 96
51 96 ▶ if ( $hunkdata[1]->isa('PPI::Structure::List') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hunkdata[1]->isa("PPI::Structure::List")) 60 36 96
52 60 @hunkdata = $hunkdata[1]->children;
53 60 ▶ next unless @hunkdata;
Branch: 1 branch
BranchTrueFalseTotal
unless @hunkdata 0 60 60
54 60 ▶ while ( $hunkdata[0]->isa('PPI::Token::Whitespace') ) { shift @hunkdata }
Branch: 1 branch
BranchTrueFalseTotal
if ($hunkdata[0]->isa("PPI::Token::Whitespace")) 42 60 102
55 }
56 96 ▶ if ( $hunkdata[0]->isa('PPI::Statement::Expression') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hunkdata[0]->isa("PPI::Statement::Expression")) 60 36 96
57 60 @hunkdata = $hunkdata[0]->children;
58 60 ▶ next unless @hunkdata;
Branch: 1 branch
BranchTrueFalseTotal
unless @hunkdata 0 60 60
59 }
60  
61 # possibly contains a version declaration!
62 96 my( $pkg, $done );
63 96 foreach my $elem ( @hunkdata ) {
64 # Scan for the first quote-like word, which is the package name
65 672 ▶ if ( $elem->isa('PPI::Token::Quote') || $elem->isa('PPI::Token::QuoteLike') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Token::Quote") or $elem->isa("PPI::Token::QuoteLike")) 180 492 672
Condition66%2/3
$elem->isa("PPI::Token::Quote") or $elem->isa("PPI::Token::QuoteLike")
l!l&&r!l&&!r
1800492
MC/DC50%1/2
$elem->isa("PPI::Token::Quote") or $elem->isa("PPI::Token::QuoteLike")
$elem->isa("PPI::Token::Quote") $elem->isa("PPI::Token::QuoteLike")
Truth table66%2/3
A or B
A= $elem->isa("PPI::Token::Quote")B= $elem->isa("PPI::Token::QuoteLike")
ABresult
1X1
011
000
66 # found a new package and the previous one didn't have a version?
67 180 ▶ if ( defined $pkg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pkg) 36 144 180
68 36 $req->add_minimum( $pkg => 0 );
69 }
70 180 $pkg = ( $self->_q_contents( $elem ) )[0];
71 180 undef $done;
72 180 next;
73 }
74  
75 # skip over the fluff and look for the version block
76 492 ▶ if ( $pkg and $elem->isa('PPI::Structure::Constructor') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg and $elem->isa("PPI::Structure::Constructor")) 87 405 492
Condition100%3/3
$pkg and $elem->isa("PPI::Structure::Constructor")
!ll&&!rl&&r
17722887
MC/DC100%2/2
$pkg and $elem->isa("PPI::Structure::Constructor")
$pkg $elem->isa("PPI::Structure::Constructor")
Truth table100%3/3
A and B
A= $pkgB= $elem->isa("PPI::Structure::Constructor")
ABresult
0X0
100
111
77 87 foreach my $subelem ( $elem->children ) {
78 # skip over the fluff and look for the real version code
79 234 ▶ if ( $subelem->isa('PPI::Statement') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subelem->isa("PPI::Statement")) 87 147 234
80 87 my $found_ver;
81 87 foreach my $code ( $subelem->children ) {
82 # skip over the fluff until we're sure we saw the version declaration
83 468 ▶ if ( $code->isa('PPI::Token::Word') and $code->literal eq '-version' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code->isa("PPI::Token::Word") and $code->literal eq "-version") 81 387 468
Condition100%3/3
$code->isa("PPI::Token::Word") and $code->literal eq "-version"
!ll&&!rl&&r
3721581
MC/DC100%2/2
$code->isa("PPI::Token::Word") and $code->literal eq "-version"
$code->isa("PPI::Token::Word") $code->literal eq "-version"
Truth table100%3/3
A and B
A= $code->isa("PPI::Token::Word")B= $code->literal eq "-version"
ABresult
0X0
100
111
84 81 $found_ver++;
85 81 next;
86 }
87  
88 387 ▶ if ( $found_ver and ( $code->isa('PPI::Token::Quote') || $code->isa('PPI::Token::QuoteLike') || $code->isa('PPI::Token::Number') ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found_ver and $code->isa("PPI::Token::Quote") || $code->isa("PPI::Token::QuoteLike") || $code->isa("PPI::Token::Number")) 81 306 387
Condition88%8/9
$found_ver and $code->isa("PPI::Token::Quote") || $code->isa("PPI::Token::QuoteLike") || $code->isa("PPI::Token::Number")
!ll&&!rl&&r
9321381
$code->isa("PPI::Token::Quote") or $code->isa("PPI::Token::QuoteLike") or $code->isa("PPI::Token::Number")
l!l&&r!l&&!r
5427213
$code->isa("PPI::Token::Quote") or $code->isa("PPI::Token::QuoteLike")
l!l&&r!l&&!r
540240
MC/DC75%3/4
$found_ver and $code->isa("PPI::Token::Quote") || $code->isa("PPI::Token::QuoteLike") || $code->isa("PPI::Token::Number")
$found_ver $code->isa("PPI::Token::Quote") $code->isa("PPI::Token::QuoteLike") $code->isa("PPI::Token::Number")
Truth table80%4/5
A and B or C or D
A= $found_verB= $code->isa("PPI::Token::Quote")C= $code->isa("PPI::Token::QuoteLike")D= $code->isa("PPI::Token::Number")
ABCDresult
0XXX0
10000
11XX1
101X1
10011
89 81 $req->add_minimum( $pkg => ( $self->_q_contents( $code ) )[0] );
90 81 $done++;
91 81 undef $pkg;
92 81 last;
93 }
94 }
95  
96 # Did we fail to find the ver?
97 87 ▶ if ( $found_ver and ! $done ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found_ver and not $done) 0 87 87
Condition66%2/3
$found_ver and not $done
!ll&&!rl&&r
6810
MC/DC0%0/2
$found_ver and not $done
$found_ver not $done
Truth table66%2/3
A and not(B)
A= $found_verB= not $done
ABresult
0X0
100
111
98 0 die "Possible internal error!";
99 }
100 }
101 }
102  
103 # Failed to find version-specific stuff
104 87 ▶ if ( ! $done ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($done) 6 81 87
105 6 $req->add_minimum( $pkg => 0 );
106 6 undef $pkg;
107 6 next;
108 }
109 }
110 }
111  
112 # If we found a pkg but no done, this must be the "last" pkg to be declared and it has no version
113 96 ▶ if ( $pkg and ! $done ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg and not $done) 57 39 96
Condition66%2/3
$pkg and not $done
!ll&&!rl&&r
39057
MC/DC50%1/2
$pkg and not $done
$pkg not $done
Truth table66%2/3
A and not(B)
A= $pkgB= not $done
ABresult
0X0
100
111
114 57 $req->add_minimum( $pkg => 0 );
115 }
116 } else {
117 # no version or funky blocks in code, yay!
118 36 $req->add_minimum( $_ => 0 ) for
119 42 grep { Params::Util::_CLASS($_) }
120 36 map { $self->_q_contents( $_ ) }
121 114 ▶ grep { $_->isa('PPI::Token::Quote') || $_->isa('PPI::Token::QuoteLike') }
Condition100%3/3
$_->isa('PPI::Token::Quote') || $_->isa('PPI::Token::QuoteLike')
l!l&&r!l&&!r
30678
MC/DC100%2/2
$_->isa('PPI::Token::Quote') || $_->isa('PPI::Token::QuoteLike')
$_->isa('PPI::Token::Quote') $_->isa('PPI::Token::QuoteLike')
Truth table100%3/3
A || B
A= $_->isa('PPI::Token::Quote')B= $_->isa('PPI::Token::QuoteLike')
ABresult
1X1
011
000
122 @$hunk;
123 }
124 }
125 }
126  
127 4 1;
128  
129 __END__
↑ Summary blib/lib/Perl/PrereqScanner/Scanner/Perl5.pm »