File Coverage

blib/lib/Perl/Lint/Policy/InputOutput/RequireEncodingWithUTF8Layer.pm
Criterion Covered Total %
statement 35 35 100.0
branch 8 8 100.0
condition 24 30 80.0
subroutine 7 7 100.0
pod 0 1 0.0
total 74 81 91.3


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::InputOutput::RequireEncodingWithUTF8Layer;
2 133     133   69229 use strict;
  133         201  
  133         3251  
3 133     133   491 use warnings;
  133         172  
  133         2578  
4 133     133   753 use Perl::Lint::Constants::Kind;
  133         171  
  133         6651  
5 133     133   880 use Perl::Lint::Constants::Type;
  133         193  
  133         62279  
6 133     133   596 use parent "Perl::Lint::Policy";
  133         168  
  133         617  
7              
8             use constant {
9 133         32973 DESC => 'I/O layer ":utf8" used',
10             EXPL => 'Use ":encoding(UTF-8)" to get strict validation',
11 133     133   10439 };
  133         194  
12              
13             sub evaluate {
14 3     3 0 4 my ($class, $file, $tokens, $src, $args) = @_;
15              
16 3         3 my @violations;
17 3         12 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
18 223         145 my $token_type = $token->{type};
19 223         154 my $token_data = $token->{data};
20              
21 223 100 100     539 if ($token_type == BUILTIN_FUNC && ($token_data eq 'open' || $token_data eq 'binmode')) {
      66        
22 90         58 my @args;
23 90         114 for ($i++; my $token = $tokens->[$i]; $i++) {
24 498         324 my $token_type = $token->{type};
25 498         282 my $token_kind = $token->{kind};
26 498 100 100     3526 if ($token_type == RIGHT_PAREN || $token_kind == KIND_STMT_END || $token_kind == KIND_OP) {
    100 100        
      66        
      66        
      33        
      66        
      100        
27 90         64 last;
28             }
29             elsif (
30             $token_type != COMMA &&
31             $token_type != REG_DOUBLE_QUOTE &&
32             $token_type != REG_QUOTE &&
33             $token_type != REG_DELIM &&
34             $token_type != LEFT_PAREN &&
35             $token_kind != KIND_DECL
36             ) {
37 218         389 push @args, $token->{data};
38             }
39             }
40 90         59 my $second_arg = $args[1];
41 90 100 100     293 if ($second_arg && $second_arg =~ /utf8\Z/) {
42             push @violations, {
43             filename => $file,
44             line => $token->{line},
45 38         132 description => DESC,
46             explanation => EXPL,
47             policy => __PACKAGE__,
48             };
49             }
50             }
51              
52             }
53              
54 3         14 return \@violations;
55             }
56              
57             1;
58