File Coverage

blib/lib/Perl/Lint/Policy/TestingAndDebugging/ProhibitNoStrict.pm
Criterion Covered Total %
statement 46 46 100.0
branch 14 16 87.5
condition 11 15 73.3
subroutine 7 7 100.0
pod 0 1 0.0
total 78 85 91.7


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::TestingAndDebugging::ProhibitNoStrict;
2 133     133   69061 use strict;
  133         167  
  133         3005  
3 133     133   381 use warnings;
  133         146  
  133         2358  
4 133     133   866 use utf8;
  133         153  
  133         509  
5 133     133   2382 use Perl::Lint::Constants::Type;
  133         162  
  133         59519  
6 133     133   541 use parent "Perl::Lint::Policy";
  133         164  
  133         538  
7              
8             use constant {
9 133         44489 DESC => 'Stricture disabled',
10             EXPL => [429],
11 133     133   6742 };
  133         180  
12              
13             sub evaluate {
14 10     10 0 26 my ($class, $file, $tokens, $src, $args) = @_;
15              
16 10         11 my @arg_allows;
17 10 100       50 if (my $this_policies_arg = $args->{prohibit_no_strict}) {
18 6 50       25 if (my $allow = $this_policies_arg->{allow}) {
19 6         32 @arg_allows = map { lc $_ } split(/[\s,]/, $allow);
  12         30  
20             }
21             }
22              
23 10         15 my @violations;
24 10         22 my $token_num = scalar @$tokens;
25 10         38 for (my $i = 0; $i < $token_num; $i++) {
26 40         34 my $token = $tokens->[$i];
27 40         37 my $token_type = $token->{type};
28              
29 40 100 66     121 if ($token_type == BUILTIN_FUNC and $token->{data} eq 'no') {
30 10         18 $token = $tokens->[++$i];
31              
32 10         11 my @allows;
33 10 50 33     50 if ($token->{type} == KEY && $token->{data} eq 'strict') {
34 10         31 for ($i++; $i < $token_num; $i++) {
35 43         33 $token = $tokens->[$i];
36 43         40 $token_type = $token->{type};
37              
38 43 100 100     233 if ($token_type == STRING || $token_type == RAW_STRING) {
    100 66        
    100          
39 13         30 push @allows, $token->{data};
40             }
41             elsif ($token_type == REG_EXP) {
42 3         15 push @allows, split(/ /, $token->{data});
43             }
44             elsif ($token_type == SEMI_COLON || !$tokens->[$i+1]) {
45 10         21 for my $arg_allow (@arg_allows) {
46 12         18 @allows = grep { $_ ne $arg_allow } @allows;
  25         41  
47             }
48 10 100 100     53 if (!@arg_allows || @allows) {
49             push @violations, {
50             filename => $file,
51             line => $token->{line},
52 7         39 description => DESC,
53             explanation => EXPL,
54             policy => __PACKAGE__,
55             };
56 7         21 last;
57             }
58             }
59             }
60             }
61             }
62             }
63              
64 10         38 return \@violations;
65             }
66              
67             1;
68