| 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') || []
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')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$_->isa('PPI::Structure::Constructor') || $_->isa('PPI::Structure::List')
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')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # hack for List | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 96 | my @hunkdata = @$hunk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | while ( $hunkdata[0]->isa('PPI::Token::Whitespace') ) { shift @hunkdata } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 96 | ▶ | if ( $hunkdata[1]->isa('PPI::Structure::List') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 60 | @hunkdata = $hunkdata[1]->children; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 60 | ▶ | next unless @hunkdata; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 60 | ▶ | while ( $hunkdata[0]->isa('PPI::Token::Whitespace') ) { shift @hunkdata } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 96 | ▶ | if ( $hunkdata[0]->isa('PPI::Statement::Expression') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 60 | @hunkdata = $hunkdata[0]->children; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 60 | ▶ | next unless @hunkdata; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$elem->isa("PPI::Token::Quote") or $elem->isa("PPI::Token::QuoteLike")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # found a new package and the previous one didn't have a version? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 180 | ▶ | if ( defined $pkg ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$pkg and $elem->isa("PPI::Structure::Constructor")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$code->isa("PPI::Token::Word") and $code->literal eq "-version"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition88%8/9
$found_ver and $code->isa("PPI::Token::Quote") || $code->isa("PPI::Token::QuoteLike") || $code->isa("PPI::Token::Number")
$code->isa("PPI::Token::Quote") or $code->isa("PPI::Token::QuoteLike") or $code->isa("PPI::Token::Number")
$code->isa("PPI::Token::Quote") or $code->isa("PPI::Token::QuoteLike")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$found_ver and not $done
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | die "Possible internal error!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # Failed to find version-specific stuff | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 87 | ▶ | if ( ! $done ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$pkg and not $done
MC/DC50%1/2
$pkg and not $done
$pkg
not $done
Truth table66%2/3
A and not(B)
A= $pkgB= not $done
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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')
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')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | @$hunk; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||