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   92960 use strict;
  134         273  
  134         4847  
3 134     134   662 use warnings;
  134         219  
  134         3427  
4 134     134   940 use Perl::Lint::Constants::Type;
  134         267  
  134         82397  
5 134     134   802 use parent "Perl::Lint::Policy";
  134         238  
  134         745  
6              
7             use constant {
8 134         40409 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   8974 };
  134         252  
11              
12             sub evaluate {
13 20     20 0 76 my ($class, $file, $tokens, $src, $args) = @_;
14              
15 20         33 my @violations;
16 20         106 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         1157 $token_type = $token->{type};
22              
23 916 100       2115 if ($token_type == NAMESPACE_RESOLVER) {
    100          
    100          
24 153 100       319 my $is_perl4_package_name = $token->{data} eq q{'} ? 1 : 0;
25              
26 153         366 for ($i++; $token = $tokens->[$i]; $i++) {
27 436         486 $token_type = $token->{type};
28              
29 436 100       1118 if ($token_type == NAMESPACE_RESOLVER) {
    100          
30 65 100       207 if ($token->{data} eq q{'}) {
31 23         55 $is_perl4_package_name = 1;
32             }
33             }
34             elsif ($token_type != NAMESPACE) {
35 153         182 last;
36             }
37             }
38              
39 153 100       260 if ($is_perl4_package_name) {
40 77 100       142 if ($is_just_before_left_brace) { # XXX workaround, for example `$foo{ bar'baz }`
41 2         8 next;
42             }
43              
44 75 50 33     354 if ($token && $token->{type} == ARROW) { # XXX workaround, for example `$foo = { bar'baz => 0 }`
45 0         0 next;
46             }
47              
48 75         439 push @violations, {
49             filename => $file,
50             line => $token->{line},
51             description => DESC,
52             explanation => EXPL,
53             policy => __PACKAGE__,
54             };
55             }
56              
57 151         406 $is_just_before_left_brace = 0;
58             }
59             elsif ($token_type == LEFT_BRACE) {
60 3         12 $is_just_before_left_brace = 1;
61             }
62             elsif ($token_type != NAMESPACE) {
63 646         1401 $is_just_before_left_brace = 0;
64             }
65             }
66              
67 20         151 return \@violations;
68             }
69              
70             1;
71