File Coverage

blib/lib/Perl/PrereqScanner/Scanner/Superclass.pm
Criterion Covered Total %
statement 21 21 100.0
branch 6 6 100.0
condition 8 8 100.0
subroutine 4 4 100.0
pod 0 1 0.0
total 39 40 97.5


line stmt bran cond sub pod time code
1 2     2   13 use strict;
  2         5  
  2         57  
2 2     2   12 use warnings;
  2         4  
  2         71  
3              
4             package Perl::PrereqScanner::Scanner::Superclass 1.100;
5             # ABSTRACT: scan for modules loaded with superclass.pm
6              
7 2     2   10 use Moo;
  2         4  
  2         10  
8             with 'Perl::PrereqScanner::Scanner';
9              
10             #pod =head1 DESCRIPTION
11             #pod
12             #pod This scanner will look for dependencies from the L module:
13             #pod
14             #pod use superclass 'Foo', Bar => 1.23;
15             #pod
16             #pod =cut
17              
18             my $mod_re = qr/^[A-Z_a-z][0-9A-Z_a-z]*(?:(?:::|')[0-9A-Z_a-z]+)*$/;
19              
20             sub scan_for_prereqs {
21 265     265 0 615 my ( $self, $ppi_doc, $req ) = @_;
22              
23             # regular use, require, and no
24 265   100     700 my $includes = $ppi_doc->find('Statement::Include') || [];
25 265         167461 for my $node (@$includes) {
26             # inheritance
27 173 100       2026 if ( $node->module eq 'superclass' ) {
28             # rt#55713: skip arguments like '-norequires', focus only on inheritance
29             my @meat = grep {
30 27 100 100     754 $_->isa('PPI::Token::QuoteLike::Words')
  69         1442  
31             || $_->isa('PPI::Token::Quote')
32             || $_->isa('PPI::Token::Number')
33             } $node->arguments;
34              
35 27         61 my @args = map { $self->_q_contents($_) } @meat;
  42         120  
36              
37 27         70 while (@args) {
38 33         454 my $module = shift @args;
39 33 100 100     232 my $version = ( @args && $args[0] !~ $mod_re ) ? shift(@args) : 0;
40 33         110 $req->add_minimum( $module => $version );
41             }
42             }
43             }
44             }
45              
46             1;
47              
48             __END__