File Coverage

blib/lib/Perl/Lint/Policy/ValuesAndExpressions/ProhibitSpecialHeredocTerminator.pm
Criterion Covered Total %
statement 24 24 100.0
branch 4 4 100.0
condition 18 18 100.0
subroutine 6 6 100.0
pod 0 1 0.0
total 52 53 98.1


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::ValuesAndExpressions::ProhibitSpecialHeredocTerminator;
2 134     134   94969 use strict;
  134         259  
  134         4912  
3 134     134   627 use warnings;
  134         214  
  134         3360  
4 134     134   960 use Perl::Lint::Constants::Type;
  134         199  
  134         84948  
5 134     134   784 use parent "Perl::Lint::Policy";
  134         238  
  134         796  
6              
7             use constant {
8 134         30746 DESC => 'Heredoc terminator must not be a special literal',
9             EXPL => 'Used "%s" as heredoc terminator',
10 134     134   8775 };
  134         284  
11              
12             sub evaluate {
13 6     6 0 18 my ($class, $file, $tokens, $args) = @_;
14              
15 6         7 my @violations;
16 6         23 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
17 194         164 my $token_type = $token->{type};
18 194 100 100     904 if ($token_type == HERE_DOCUMENT_TAG || $token_type == HERE_DOCUMENT_RAW_TAG || $token_type == HERE_DOCUMENT_BARE_TAG) {
      100        
19 13         15 my $token_data = $token->{data};
20 13 100 100     81 if (
      100        
      100        
      100        
21             $token_data eq '__FILE__' ||
22             $token_data eq '__LINE__' ||
23             $token_data eq '__PACKAGE__' ||
24             $token_data eq '__END__' ||
25             $token_data eq '__DATA__'
26             ) {
27 12         82 push @violations, {
28             filename => $file,
29             line => $token->{line},
30             description => DESC,
31             explanation => sprintf(EXPL, $token_data),
32             policy => __PACKAGE__,
33             };
34             }
35             }
36             }
37              
38 6         25 return \@violations;
39             }
40              
41             1;
42