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   68792 use strict;
  134         190  
  134         3034  
3 134     134   410 use warnings;
  134         149  
  134         2367  
4 134     134   804 use Perl::Lint::Constants::Type;
  134         159  
  134         59003  
5 134     134   545 use parent "Perl::Lint::Policy";
  134         207  
  134         551  
6              
7             use constant {
8 134         31280 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   6859 };
  134         167  
11              
12             sub evaluate {
13 20     20 0 33 my ($class, $file, $tokens, $src, $args) = @_;
14              
15 20         14 my @violations;
16 20         62 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         601 $token_type = $token->{type};
22              
23 916 100       1493 if ($token_type == NAMESPACE_RESOLVER) {
    100          
    100          
24 153 100       158 my $is_perl4_package_name = $token->{data} eq q{'} ? 1 : 0;
25              
26 153         196 for ($i++; $token = $tokens->[$i]; $i++) {
27 436         313 $token_type = $token->{type};
28              
29 436 100       763 if ($token_type == NAMESPACE_RESOLVER) {
    100          
30 65 100       117 if ($token->{data} eq q{'}) {
31 23         44 $is_perl4_package_name = 1;
32             }
33             }
34             elsif ($token_type != NAMESPACE) {
35 153         113 last;
36             }
37             }
38              
39 153 100       171 if ($is_perl4_package_name) {
40 77 100       87 if ($is_just_before_left_brace) { # XXX workaround, for example `$foo{ bar'baz }`
41 2         5 next;
42             }
43              
44 75 50 33     197 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         186 description => DESC,
52             explanation => EXPL,
53             policy => __PACKAGE__,
54             };
55             }
56              
57 151         223 $is_just_before_left_brace = 0;
58             }
59             elsif ($token_type == LEFT_BRACE) {
60 3         5 $is_just_before_left_brace = 1;
61             }
62             elsif ($token_type != NAMESPACE) {
63 646         808 $is_just_before_left_brace = 0;
64             }
65             }
66              
67 20         67 return \@violations;
68             }
69              
70             1;
71