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   66377 use strict;
  133         162  
  133         3141  
3 133     133   386 use warnings;
  133         135  
  133         2409  
4 133     133   742 use Perl::Lint::Constants::Type;
  133         135  
  133         58914  
5 133     133   1480 use parent "Perl::Lint::Policy";
  133         977  
  133         521  
6              
7             use constant {
8 133         25646 DESC => '"%s" statement with library name as string',
9             EXPL => 'Use a bareword instead',
10 133     133   6780 };
  133         176  
11              
12             sub evaluate {
13 4     4 0 7 my ($class, $file, $tokens, $args) = @_;
14              
15 4         4 my @violations;
16             my $next_token;
17 4         15 for (my $i = 0, my $next_token, my $next_token_type; my $token = $tokens->[$i]; $i++) {
18 93         60 my $token_type = $token->{type};
19 93         63 my $token_data = $token->{data};
20              
21 93         66 $next_token = $tokens->[$i+1];
22 93         68 $next_token_type = $next_token->{type};
23 93 100 66     470 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             push @violations, {
38             filename => $file,
39             line => $token->{line},
40 12         61 description => sprintf(DESC, $token_data),
41             explanation => EXPL,
42             policy => __PACKAGE__,
43             };
44             }
45             }
46              
47 4         16 return \@violations;
48             }
49              
50             1;
51