File Coverage

blib/lib/Perl/PrereqScanner/Scanner/Aliased.pm
Criterion Covered Total %
statement 19 19 100.0
branch 5 6 83.3
condition 2 2 100.0
subroutine 4 4 100.0
pod 0 1 0.0
total 30 32 93.7


line stmt bran cond sub pod time code
1 2     2   13 use strict;
  2         4  
  2         60  
2 2     2   10 use warnings;
  2         4  
  2         73  
3              
4             package Perl::PrereqScanner::Scanner::Aliased 1.100;
5             # ABSTRACT: scan for OO module aliases via aliased.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 aliased OO modules:
13             #pod
14             #pod use aliased 'Some::Long::Long::Name' => 'Short::Name';
15             #pod
16             #pod Short::Name->new;
17             #pod ...
18             #pod
19             #pod =cut
20              
21             sub scan_for_prereqs {
22 265     265 0 557 my ($self, $ppi_doc, $req) = @_;
23              
24             # regular use and require
25 265   100     660 my $includes = $ppi_doc->find('Statement::Include') || [];
26 265         166300 for my $node ( @$includes ) {
27             # aliasing
28 173 100       1358 if (grep { $_ eq $node->module } qw{ aliased }) {
  173         497  
29             # We only want the first argument to aliased
30             my @args = grep {
31 12 50       362 $_->isa('PPI::Token::QuoteLike::Words')
  15         389  
32             || $_->isa('PPI::Token::Quote')
33             } $node->arguments;
34              
35 12 100       112 next unless @args;
36 9         34 my ($module) = $self->_q_contents($args[0]);
37 9         32 $req->add_minimum($module => 0);
38             }
39             }
40             }
41              
42             1;
43              
44             __END__