line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::Subroutines::ProhibitAmpersandSigils; |
2
|
134
|
|
|
134
|
|
69451
|
use strict; |
|
134
|
|
|
|
|
202
|
|
|
134
|
|
|
|
|
3440
|
|
3
|
134
|
|
|
134
|
|
449
|
use warnings; |
|
134
|
|
|
|
|
191
|
|
|
134
|
|
|
|
|
2586
|
|
4
|
134
|
|
|
134
|
|
808
|
use Perl::Lint::Constants::Type; |
|
134
|
|
|
|
|
152
|
|
|
134
|
|
|
|
|
60204
|
|
5
|
134
|
|
|
134
|
|
584
|
use parent "Perl::Lint::Policy"; |
|
134
|
|
|
|
|
189
|
|
|
134
|
|
|
|
|
597
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
134
|
|
|
|
|
29635
|
DESC => 'Subroutine called with "&" sigil', |
9
|
|
|
|
|
|
|
EXPL => [175], |
10
|
134
|
|
|
134
|
|
6947
|
}; |
|
134
|
|
|
|
|
185
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
13
|
9
|
|
|
9
|
0
|
11
|
my ($class, $file, $tokens, $args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
9
|
|
|
|
|
9
|
my @violations; |
16
|
9
|
|
|
|
|
8
|
my $is_before_token_function = 0; |
17
|
9
|
|
|
|
|
9
|
my $is_in_ref = 0; |
18
|
9
|
|
|
|
|
7
|
my $left_paren_num = 0; |
19
|
9
|
|
|
|
|
23
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
20
|
229
|
|
|
|
|
167
|
my $token_type = $token->{type}; |
21
|
|
|
|
|
|
|
|
22
|
229
|
100
|
100
|
|
|
913
|
if ($token_type == BIT_AND) { |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
23
|
24
|
|
|
|
|
19
|
my $next_token_type = $tokens->[++$i]->{type}; |
24
|
24
|
50
|
100
|
|
|
54
|
if ( |
|
|
|
66
|
|
|
|
|
25
|
|
|
|
|
|
|
$next_token_type == KEY || |
26
|
|
|
|
|
|
|
$next_token_type == NAMESPACE || |
27
|
|
|
|
|
|
|
$next_token_type == NAMESPACE_RESOLVER |
28
|
|
|
|
|
|
|
) { |
29
|
24
|
100
|
66
|
|
|
52
|
if (!$is_before_token_function && !$is_in_ref) { |
30
|
|
|
|
|
|
|
push @violations, { |
31
|
|
|
|
|
|
|
filename => $file, |
32
|
|
|
|
|
|
|
line => $token->{line}, |
33
|
14
|
|
|
|
|
33
|
description => DESC, |
34
|
|
|
|
|
|
|
explanation => EXPL, |
35
|
|
|
|
|
|
|
policy => __PACKAGE__, |
36
|
|
|
|
|
|
|
}; |
37
|
14
|
|
|
|
|
22
|
next; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif ($token_type == KEY || $token_type == BUILTIN_FUNC || $token_type == GOTO) { |
42
|
15
|
|
|
|
|
22
|
$is_before_token_function = 1; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
elsif ($token_type == REF) { |
45
|
8
|
|
|
|
|
12
|
$is_in_ref = 1; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
elsif ($token_type == LEFT_PAREN) { |
48
|
25
|
|
|
|
|
38
|
$left_paren_num++; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_PAREN) { |
51
|
25
|
|
|
|
|
15
|
$left_paren_num--; |
52
|
25
|
100
|
|
|
|
38
|
if ($left_paren_num <= 0) { |
53
|
22
|
|
|
|
|
31
|
$is_in_ref = 0; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else { |
57
|
132
|
100
|
|
|
|
141
|
if ($left_paren_num <= 0) { |
58
|
104
|
|
|
|
|
75
|
$is_in_ref = 0; |
59
|
|
|
|
|
|
|
} |
60
|
132
|
|
|
|
|
161
|
$is_before_token_function = 0; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
9
|
|
|
|
|
29
|
return \@violations; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|