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   93664 use strict;
  133         269  
  133         4937  
3 133     133   620 use warnings;
  133         224  
  133         3420  
4 133     133   1599 use Perl::Lint::Constants::Type;
  133         207  
  133         83938  
5 133     133   1191 use parent "Perl::Lint::Policy";
  133         240  
  133         800  
6              
7             use constant {
8 133         26802 DESC => 'Multiple "package" declarations',
9             EXPL => 'Limit to one per file',
10 133     133   8683 };
  133         243  
11              
12             sub evaluate {
13 4     4 0 11 my ($class, $file, $tokens, $args) = @_;
14              
15 4         5 my @violations;
16 4         6 my $had_declared_package = 0;
17 4         20 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
18 37         34 my $token_type = $token->{type};
19 37 100       82 if ($token_type == PACKAGE) {
20 7 100       14 unless ($had_declared_package) {
21 3         21 $had_declared_package = 1;
22 3         13 next;
23             }
24              
25 4         30 push @violations, {
26             filename => $file,
27             line => $token->{line},
28             description => DESC,
29             explanation => EXPL,
30             policy => __PACKAGE__,
31             };
32             }
33             }
34              
35 4         21 return \@violations;
36             }
37              
38             1;
39