File Coverage

blib/lib/Perl/Lint/Policy/InputOutput/ProhibitBarewordFileHandles.pm
Criterion Covered Total %
statement 32 32 100.0
branch 6 6 100.0
condition 3 3 100.0
subroutine 7 7 100.0
pod 0 1 0.0
total 48 49 97.9


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::InputOutput::ProhibitBarewordFileHandles;
2 133     133   68458 use strict;
  133         228  
  133         3209  
3 133     133   424 use warnings;
  133         159  
  133         2458  
4 133     133   797 use Perl::Lint::Constants::Type;
  133         160  
  133         71249  
5 133     133   1242 use Perl::Lint::Constants::Kind;
  133         175  
  133         6744  
6 133     133   516 use parent "Perl::Lint::Policy";
  133         154  
  133         596  
7              
8             use constant {
9 133         24429 DESC => 'Bareword file handle opened',
10             EXPL => [202, 204],
11 133     133   7145 };
  133         176  
12              
13             sub evaluate {
14 4     4 0 7 my ($class, $file, $tokens, $src, $args) = @_;
15              
16 4         5 my @violations;
17 4         13 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
18 178         108 my $token_type = $token->{type};
19 178         122 my $token_data = $token->{data};
20              
21 178 100 100     373 if ($token_type == BUILTIN_FUNC && $token_data eq 'open') {
22 21         16 $token = $tokens->[++$i];
23 21         17 $token_type = $token->{type};
24              
25 21 100       27 if ($token_type == LEFT_PAREN) {
26 13         9 $token = $tokens->[++$i];
27 13         11 $token_type = $token->{type};
28             }
29              
30 21 100       32 if ($token_type == KEY) {
31             push @violations, {
32             filename => $file,
33             line => $token->{line},
34 10         34 description => DESC,
35             explanation => EXPL,
36             policy => __PACKAGE__,
37             };
38             }
39             }
40             }
41              
42 4         14 return \@violations;
43             }
44              
45             1;
46