File Coverage

blib/lib/Perl/Lint/Policy/Subroutines/ProhibitAmpersandSigils.pm
Criterion Covered Total %
statement 38 38 100.0
branch 17 18 94.4
condition 13 15 86.6
subroutine 6 6 100.0
pod 0 1 0.0
total 74 78 94.8


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::Subroutines::ProhibitAmpersandSigils;
2 134     134   98154 use strict;
  134         291  
  134         5304  
3 134     134   741 use warnings;
  134         217  
  134         3610  
4 134     134   1098 use Perl::Lint::Constants::Type;
  134         261  
  134         84221  
5 134     134   953 use parent "Perl::Lint::Policy";
  134         275  
  134         873  
6              
7             use constant {
8 134         40115 DESC => 'Subroutine called with "&" sigil',
9             EXPL => [175],
10 134     134   9137 };
  134         290  
11              
12             sub evaluate {
13 9     9 0 22 my ($class, $file, $tokens, $args) = @_;
14              
15 9         14 my @violations;
16 9         18 my $is_before_token_function = 0;
17 9         21 my $is_in_ref = 0;
18 9         14 my $left_paren_num = 0;
19 9         43 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
20 229         232 my $token_type = $token->{type};
21              
22 229 100 100     1230 if ($token_type == BIT_AND) {
    100 100        
    100          
    100          
    100          
23 24         37 my $next_token_type = $tokens->[++$i]->{type};
24 24 50 100     89 if (
      66        
25             $next_token_type == KEY ||
26             $next_token_type == NAMESPACE ||
27             $next_token_type == NAMESPACE_RESOLVER
28             ) {
29 24 100 66     81 if (!$is_before_token_function && !$is_in_ref) {
30 14         84 push @violations, {
31             filename => $file,
32             line => $token->{line},
33             description => DESC,
34             explanation => EXPL,
35             policy => __PACKAGE__,
36             };
37 14         100 next;
38             }
39             }
40             }
41             elsif ($token_type == KEY || $token_type == BUILTIN_FUNC || $token_type == GOTO) {
42 15         37 $is_before_token_function = 1;
43             }
44             elsif ($token_type == REF) {
45 8         19 $is_in_ref = 1;
46             }
47             elsif ($token_type == LEFT_PAREN) {
48 25         56 $left_paren_num++;
49             }
50             elsif ($token_type == RIGHT_PAREN) {
51 25         26 $left_paren_num--;
52 25 100       58 if ($left_paren_num <= 0) {
53 22         58 $is_in_ref = 0;
54             }
55             }
56             else {
57 132 100       221 if ($left_paren_num <= 0) {
58 104         89 $is_in_ref = 0;
59             }
60 132         342 $is_before_token_function = 0;
61             }
62             }
63              
64 9         77 return \@violations;
65             }
66              
67             1;
68