File Coverage

blib/lib/Perl/Lint/Policy/Variables/ProhibitPerl4PackageNames.pm
Criterion Covered Total %
statement 36 37 97.3
branch 19 20 95.0
condition 1 3 33.3
subroutine 6 6 100.0
pod 0 1 0.0
total 62 67 92.5


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::Variables::ProhibitPerl4PackageNames;
2 134     134   68534 use strict;
  134         182  
  134         3210  
3 134     134   431 use warnings;
  134         155  
  134         2510  
4 134     134   1074 use Perl::Lint::Constants::Type;
  134         150  
  134         60939  
5 134     134   567 use parent "Perl::Lint::Policy";
  134         173  
  134         572  
6              
7             use constant {
8 134         31407 DESC => 'Using the obsolete single quote as package separator',
9             EXPL => q{Use double colon (::) to separate package name components instead of single quotes (')},
10 134     134   6816 };
  134         167  
11              
12             sub evaluate {
13 20     20 0 29 my ($class, $file, $tokens, $src, $args) = @_;
14              
15 20         17 my @violations;
16 20         54 for (
17             my $i = 0, my $token_type, my $token_data, my $is_just_before_left_brace = 0;
18             my $token = $tokens->[$i];
19             $i++
20             ) {
21 916         577 $token_type = $token->{type};
22              
23 916 100       1492 if ($token_type == NAMESPACE_RESOLVER) {
    100          
    100          
24 153 100       153 my $is_perl4_package_name = $token->{data} eq q{'} ? 1 : 0;
25              
26 153         195 for ($i++; $token = $tokens->[$i]; $i++) {
27 436         272 $token_type = $token->{type};
28              
29 436 100       704 if ($token_type == NAMESPACE_RESOLVER) {
    100          
30 65 100       106 if ($token->{data} eq q{'}) {
31 23         29 $is_perl4_package_name = 1;
32             }
33             }
34             elsif ($token_type != NAMESPACE) {
35 153         89 last;
36             }
37             }
38              
39 153 100       166 if ($is_perl4_package_name) {
40 77 100       81 if ($is_just_before_left_brace) { # XXX workaround, for example `$foo{ bar'baz }`
41 2         5 next;
42             }
43              
44 75 50 33     190 if ($token && $token->{type} == ARROW) { # XXX workaround, for example `$foo = { bar'baz => 0 }`
45 0         0 next;
46             }
47              
48             push @violations, {
49             filename => $file,
50             line => $token->{line},
51 75         158 description => DESC,
52             explanation => EXPL,
53             policy => __PACKAGE__,
54             };
55             }
56              
57 151         206 $is_just_before_left_brace = 0;
58             }
59             elsif ($token_type == LEFT_BRACE) {
60 3         7 $is_just_before_left_brace = 1;
61             }
62             elsif ($token_type != NAMESPACE) {
63 646         832 $is_just_before_left_brace = 0;
64             }
65             }
66              
67 20         58 return \@violations;
68             }
69              
70             1;
71