| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::Variables::ProhibitLocalVars; |
|
2
|
134
|
|
|
134
|
|
71666
|
use strict; |
|
|
134
|
|
|
|
|
195
|
|
|
|
134
|
|
|
|
|
3181
|
|
|
3
|
134
|
|
|
134
|
|
450
|
use warnings; |
|
|
134
|
|
|
|
|
152
|
|
|
|
134
|
|
|
|
|
2586
|
|
|
4
|
134
|
|
|
134
|
|
809
|
use Perl::Lint::Constants::Type; |
|
|
134
|
|
|
|
|
156
|
|
|
|
134
|
|
|
|
|
59535
|
|
|
5
|
134
|
|
|
134
|
|
591
|
use parent "Perl::Lint::Policy"; |
|
|
134
|
|
|
|
|
168
|
|
|
|
134
|
|
|
|
|
567
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
|
8
|
134
|
|
|
|
|
42938
|
DESC => 'The names of or patterns for variables to forbid', |
|
9
|
|
|
|
|
|
|
EXPL => 'Find an alternative variable', |
|
10
|
134
|
|
|
134
|
|
6549
|
}; |
|
|
134
|
|
|
|
|
163
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
|
13
|
5
|
|
|
5
|
0
|
9
|
my ($class, $file, $tokens, $src, $args) = @_; |
|
14
|
|
|
|
|
|
|
|
|
15
|
5
|
|
|
|
|
5
|
my @violations; |
|
16
|
5
|
|
|
|
|
17
|
for (my $i = 0, my $token_type; my $token = $tokens->[$i]; $i++) { |
|
17
|
131
|
|
|
|
|
91
|
$token_type = $token->{type}; |
|
18
|
|
|
|
|
|
|
|
|
19
|
131
|
100
|
|
|
|
211
|
if ($token_type == LOCAL_DECL) { |
|
20
|
18
|
|
|
|
|
19
|
$token = $tokens->[++$i]; |
|
21
|
18
|
|
|
|
|
15
|
$token_type = $token->{type}; |
|
22
|
|
|
|
|
|
|
|
|
23
|
18
|
100
|
66
|
|
|
40
|
if ($token_type == LEFT_PAREN) { |
|
|
|
100
|
|
|
|
|
|
|
24
|
9
|
|
|
|
|
5
|
my $violation; |
|
25
|
9
|
|
|
|
|
7
|
my $left_paren_num = 1; |
|
26
|
9
|
|
|
|
|
16
|
for ($i++; my $token = $tokens->[$i]; $i++) { |
|
27
|
36
|
|
|
|
|
31
|
$token_type = $token->{type}; |
|
28
|
36
|
50
|
100
|
|
|
115
|
if ($token_type == LEFT_PAREN) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
$left_paren_num++; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_PAREN) { |
|
32
|
9
|
50
|
|
|
|
15
|
if (--$left_paren_num <= 0) { |
|
33
|
9
|
100
|
|
|
|
13
|
if ($violation) { |
|
34
|
4
|
|
|
|
|
3
|
push @violations, $violation; |
|
35
|
4
|
|
|
|
|
5
|
undef $violation; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
9
|
|
|
|
|
21
|
last; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
elsif ($token_type == GLOBAL_VAR || $token_type == VAR) { |
|
41
|
11
|
100
|
|
|
|
50
|
if ($token->{data} !~ /\A\$[A-Z_]+\Z/) { |
|
42
|
6
|
|
|
|
|
8
|
my $next_token = $tokens->[$i+1]; |
|
43
|
6
|
50
|
|
|
|
9
|
if ($next_token->{type} != NAMESPACE_RESOLVER) { |
|
44
|
|
|
|
|
|
|
$violation ||= +{ |
|
45
|
|
|
|
|
|
|
filename => $file, |
|
46
|
|
|
|
|
|
|
line => $token->{line}, |
|
47
|
6
|
|
100
|
|
|
32
|
description => DESC, |
|
48
|
|
|
|
|
|
|
explanation => EXPL, |
|
49
|
|
|
|
|
|
|
policy => __PACKAGE__, |
|
50
|
|
|
|
|
|
|
}; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
elsif ($token_type == GLOBAL_VAR || $token_type == VAR) { |
|
57
|
7
|
100
|
|
|
|
20
|
if ($token->{data} !~ /\A\$[A-Z_]+\Z/) { |
|
58
|
3
|
|
|
|
|
4
|
my $next_token = $tokens->[$i+1]; |
|
59
|
3
|
100
|
|
|
|
8
|
if ($next_token->{type} != NAMESPACE_RESOLVER) { |
|
60
|
|
|
|
|
|
|
push @violations, { |
|
61
|
|
|
|
|
|
|
filename => $file, |
|
62
|
|
|
|
|
|
|
line => $token->{line}, |
|
63
|
2
|
|
|
|
|
14
|
description => DESC, |
|
64
|
|
|
|
|
|
|
explanation => EXPL, |
|
65
|
|
|
|
|
|
|
policy => __PACKAGE__, |
|
66
|
|
|
|
|
|
|
}; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
5
|
|
|
|
|
20
|
return \@violations; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
|
77
|
|
|
|
|
|
|
|