File Coverage

blib/lib/Perl/Lint/Policy/ValuesAndExpressions/ProhibitConstantPragma.pm
Criterion Covered Total %
statement 24 24 100.0
branch 3 4 75.0
condition 1 3 33.3
subroutine 6 6 100.0
pod 0 1 0.0
total 34 38 89.4


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::ValuesAndExpressions::ProhibitConstantPragma;
2 133     133   93354 use strict;
  133         254  
  133         4771  
3 133     133   579 use warnings;
  133         209  
  133         3333  
4 133     133   927 use Perl::Lint::Constants::Type;
  133         193  
  133         81479  
5 133     133   826 use parent "Perl::Lint::Policy";
  133         299  
  133         795  
6              
7             use constant {
8 133         26413 DESC => 'Pragma "constant" used',
9             EXPL => [55],
10 133     133   9098 };
  133         240  
11              
12             sub evaluate {
13 3     3 0 6 my ($class, $file, $tokens, $args) = @_;
14              
15 3         4 my @violations;
16 3         11 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
17 50         43 my $token_type = $token->{type};
18              
19 50 100       99 if ($token_type == USE_DECL) {
20 7         7 my $next_token = $tokens->[++$i];
21 7 50 33     27 if ($next_token->{type} == USED_NAME && $next_token->{data} eq 'constant') {
22 7         29 push @violations, {
23             filename => $file,
24             line => $token->{line},
25             description => DESC,
26             explanation => EXPL,
27             policy => __PACKAGE__,
28             };
29             }
30             }
31             }
32              
33 3         10 return \@violations;
34             }
35              
36             1;
37