File Coverage

blib/lib/Perl/Lint/Policy/ValuesAndExpressions/RequireUpperCaseHeredocTerminator.pm
Criterion Covered Total %
statement 28 28 100.0
branch 6 6 100.0
condition 8 9 88.8
subroutine 6 6 100.0
pod 0 1 0.0
total 48 50 96.0


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::ValuesAndExpressions::RequireUpperCaseHeredocTerminator;
2 134     134   96456 use strict;
  134         263  
  134         5074  
3 134     134   648 use warnings;
  134         204  
  134         3433  
4 134     134   1453 use Perl::Lint::Constants::Type;
  134         220  
  134         85662  
5 134     134   850 use parent "Perl::Lint::Policy";
  134         263  
  134         799  
6              
7             use constant {
8 134         34801 DESC => 'Heredoc terminator must be quoted',
9             EXPL => [64],
10 134     134   9411 };
  134         271  
11              
12             sub evaluate {
13 10     10 0 22 my ($class, $file, $tokens, $args) = @_;
14              
15 10         14 my @violations;
16 10         42 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
17 104         103 my $token_type = $token->{type};
18              
19             # XXX workaround
20             # Compiler::Lexer cannot recognize heredoc tag as bare word and lowercase
21             # https://github.com/goccy/p5-Compiler-Lexer/issues/37
22             #
23             # e.g.
24             # <
25 104         73 my $is_before_left_shift = 0;
26 104 100       153 if ($token_type == LEFT_SHIFT) {
27 8         13 $token = $tokens->[++$i];
28 8         10 $token_type = $token->{type};
29 8         11 $is_before_left_shift = 1;
30             }
31              
32 104 100 100     516 if (
      100        
      66        
33             $token_type == HERE_DOCUMENT_TAG ||
34             $token_type == HERE_DOCUMENT_RAW_TAG ||
35             ($is_before_left_shift && $token_type == KEY)
36             ) {
37 7 100       34 if ($token->{data} =~ /[a-z]/) {
38 4         33 push @violations, {
39             filename => $file,
40             line => $token->{line},
41             description => DESC,
42             explanation => EXPL,
43             policy => __PACKAGE__,
44             };
45             }
46             }
47             }
48              
49 10         50 return \@violations;
50             }
51              
52             1;
53