File Coverage

blib/lib/Perl/Lint/Policy/Modules/RequireBarewordIncludes.pm
Criterion Covered Total %
statement 25 25 100.0
branch 2 2 100.0
condition 9 12 75.0
subroutine 6 6 100.0
pod 0 1 0.0
total 42 46 91.3


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::Modules::RequireBarewordIncludes;
2 133     133   92701 use strict;
  133         272  
  133         4891  
3 133     133   628 use warnings;
  133         222  
  133         3720  
4 133     133   1131 use Perl::Lint::Constants::Type;
  133         211  
  133         83193  
5 133     133   827 use parent "Perl::Lint::Policy";
  133         237  
  133         775  
6              
7             use constant {
8 133         33325 DESC => '"%s" statement with library name as string',
9             EXPL => 'Use a bareword instead',
10 133     133   9076 };
  133         244  
11              
12             sub evaluate {
13 4     4 0 6 my ($class, $file, $tokens, $args) = @_;
14              
15 4         5 my @violations;
16             my $next_token;
17 4         19 for (my $i = 0, my $next_token, my $next_token_type; my $token = $tokens->[$i]; $i++) {
18 93         67 my $token_type = $token->{type};
19 93         75 my $token_data = $token->{data};
20              
21 93         77 $next_token = $tokens->[$i+1];
22 93         71 $next_token_type = $next_token->{type};
23 93 100 66     532 if (
      66        
      100        
      66        
24             $next_token_type &&
25             (
26             $token_type == USE_DECL ||
27             $token_type == REQUIRE_DECL ||
28             ($token_type == BUILTIN_FUNC && $token_data eq 'no')
29             ) &&
30             (
31             $next_token_type == STRING ||
32             $next_token_type == RAW_STRING ||
33             $next_token_type == REG_QUOTE ||
34             $next_token_type == REG_DOUBLE_QUOTE
35             )
36             ) {
37 12         59 push @violations, {
38             filename => $file,
39             line => $token->{line},
40             description => sprintf(DESC, $token_data),
41             explanation => EXPL,
42             policy => __PACKAGE__,
43             };
44             }
45             }
46              
47 4         21 return \@violations;
48             }
49              
50             1;
51