blib/lib/Perl/Lint/Policy/ValuesAndExpressions/RequireUpperCaseHeredocTerminator.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 SCAR 0.1
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Perl/Lint/Policy/ValuesAndExpressions/RequireQuotedHeredocTerminator.pm ↑ Summary blib/lib/Perl/Lint/Policy/Variables/ProhibitLocalVars.pm »
1 package Perl::Lint::Policy::ValuesAndExpressions::RequireUpperCaseHeredocTerminator;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=2.6
5 use parent "Perl::Lint::Policy";
6  
7 use constant {
8 DESC => 'Heredoc terminator must be quoted',
9 EXPL => [64],
10 };
11  
12 sub evaluate {
13 my ($class, $file, $tokens, $args) = @_;
14  
15 my @violations;
16 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
17 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 # <<endquote
25 my $is_before_left_shift = 0;
26 if ($token_type == LEFT_SHIFT) {
27 $token = $tokens->[++$i];
28 $token_type = $token->{type};
29 $is_before_left_shift = 1;
30 }
31  
32 if (
33 $token_type == HERE_DOCUMENT_TAG ||
34 $token_type == HERE_DOCUMENT_RAW_TAG ||
35 ($is_before_left_shift && $token_type == KEY)
36 ) {
37 if ($token->{data} =~ /[a-z]/) {
38 push @violations, {
39 filename => $file,
40 line => $token->{line},
41 description => DESC,
42 explanation => EXPL,
43 policy => __PACKAGE__,
44 };
45 }
46 }
47 }
48  
49 return \@violations;
50 }
51  
52 1;
53  
« blib/lib/Perl/Lint/Policy/ValuesAndExpressions/RequireQuotedHeredocTerminator.pm ↑ Summary blib/lib/Perl/Lint/Policy/Variables/ProhibitLocalVars.pm »