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   68738 use strict;
  134         175  
  134         2972  
3 134     134   426 use warnings;
  134         146  
  134         2340  
4 134     134   804 use Perl::Lint::Constants::Type;
  134         141  
  134         60066  
5 134     134   544 use parent "Perl::Lint::Policy";
  134         165  
  134         529  
6              
7             use constant {
8 134         26286 DESC => 'Numeric escapes in interpolated string',
9             EXPL => [54, 55],
10 134     134   7066 };
  134         172  
11              
12             sub evaluate {
13 5     5 0 9 my ($class, $file, $tokens, $args) = @_;
14              
15 5         6 my @violations;
16 5         5 my $is_reg_quote = 0;
17 5         16 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
18 82         51 my $token_type = $token->{type};
19 82 100 100     277 if ($token_type == REG_QUOTE) {
    100          
20 1         2 $is_reg_quote = 1;
21             }
22             elsif ($token_type == STRING || $token_type == REG_EXP) {
23 12 100       18 if ($is_reg_quote) {
24 1         1 $is_reg_quote = 0;
25 1         3 next;
26             }
27              
28 11         11 my $string = $token->{data};
29 11 100       36 if ($string =~ /\\x?[0-9a-fA-F]{2,}/) {
30             push @violations, {
31             filename => $file,
32             line => $token->{line},
33 6         42 description => DESC,
34             explanation => EXPL,
35             policy => __PACKAGE__,
36             };
37             }
38             }
39             }
40              
41 5         15 return \@violations;
42             }
43              
44             1;
45