File Coverage

blib/lib/Perl/Lint/Policy/Modules/ProhibitMultiplePackages.pm
Criterion Covered Total %
statement 26 26 100.0
branch 4 4 100.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 36 37 97.3


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::Modules::ProhibitMultiplePackages;
2 133     133   67251 use strict;
  133         179  
  133         3101  
3 133     133   394 use warnings;
  133         736  
  133         2585  
4 133     133   784 use Perl::Lint::Constants::Type;
  133         144  
  133         59579  
5 133     133   1227 use parent "Perl::Lint::Policy";
  133         167  
  133         1163  
6              
7             use constant {
8 133         21417 DESC => 'Multiple "package" declarations',
9             EXPL => 'Limit to one per file',
10 133     133   7401 };
  133         1640  
11              
12             sub evaluate {
13 4     4 0 5 my ($class, $file, $tokens, $args) = @_;
14              
15 4         4 my @violations;
16 4         3 my $had_declared_package = 0;
17 4         12 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
18 37         24 my $token_type = $token->{type};
19 37 100       66 if ($token_type == PACKAGE) {
20 7 100       13 unless ($had_declared_package) {
21 3         3 $had_declared_package = 1;
22 3         7 next;
23             }
24              
25             push @violations, {
26             filename => $file,
27             line => $token->{line},
28 4         14 description => DESC,
29             explanation => EXPL,
30             policy => __PACKAGE__,
31             };
32             }
33             }
34              
35 4         12 return \@violations;
36             }
37              
38             1;
39