File Coverage

blib/lib/Perl/Lint/Policy/ValuesAndExpressions/ProhibitEscapedCharacters.pm
Criterion Covered Total %
statement 29 29 100.0
branch 8 8 100.0
condition 3 3 100.0
subroutine 6 6 100.0
pod 0 1 0.0
total 46 47 97.8


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::ValuesAndExpressions::ProhibitEscapedCharacters;
2 134     134   93098 use strict;
  134         272  
  134         4631  
3 134     134   688 use warnings;
  134         205  
  134         3428  
4 134     134   1017 use Perl::Lint::Constants::Type;
  134         190  
  134         90224  
5 134     134   783 use parent "Perl::Lint::Policy";
  134         212  
  134         752  
6              
7             use constant {
8 134         35269 DESC => 'Numeric escapes in interpolated string',
9             EXPL => [54, 55],
10 134     134   9268 };
  134         237  
11              
12             sub evaluate {
13 5     5 0 15 my ($class, $file, $tokens, $args) = @_;
14              
15 5         10 my @violations;
16 5         9 my $is_reg_quote = 0;
17 5         31 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
18 82         75 my $token_type = $token->{type};
19 82 100 100     347 if ($token_type == REG_QUOTE) {
    100          
20 1         7 $is_reg_quote = 1;
21             }
22             elsif ($token_type == STRING || $token_type == REG_EXP) {
23 12 100       29 if ($is_reg_quote) {
24 1         3 $is_reg_quote = 0;
25 1         5 next;
26             }
27              
28 11         20 my $string = $token->{data};
29 11 100       61 if ($string =~ /\\x?[0-9a-fA-F]{2,}/) {
30 6         46 push @violations, {
31             filename => $file,
32             line => $token->{line},
33             description => DESC,
34             explanation => EXPL,
35             policy => __PACKAGE__,
36             };
37             }
38             }
39             }
40              
41 5         28 return \@violations;
42             }
43              
44             1;
45