line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::Variables::ProhibitLocalVars; |
2
|
134
|
|
|
134
|
|
69831
|
use strict; |
|
134
|
|
|
|
|
205
|
|
|
134
|
|
|
|
|
3275
|
|
3
|
134
|
|
|
134
|
|
427
|
use warnings; |
|
134
|
|
|
|
|
163
|
|
|
134
|
|
|
|
|
2505
|
|
4
|
134
|
|
|
134
|
|
776
|
use Perl::Lint::Constants::Type; |
|
134
|
|
|
|
|
154
|
|
|
134
|
|
|
|
|
60033
|
|
5
|
134
|
|
|
134
|
|
583
|
use parent "Perl::Lint::Policy"; |
|
134
|
|
|
|
|
165
|
|
|
134
|
|
|
|
|
565
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
134
|
|
|
|
|
43752
|
DESC => 'The names of or patterns for variables to forbid', |
9
|
|
|
|
|
|
|
EXPL => 'Find an alternative variable', |
10
|
134
|
|
|
134
|
|
6767
|
}; |
|
134
|
|
|
|
|
169
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
13
|
5
|
|
|
5
|
0
|
8
|
my ($class, $file, $tokens, $src, $args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
5
|
|
|
|
|
7
|
my @violations; |
16
|
5
|
|
|
|
|
16
|
for (my $i = 0, my $token_type; my $token = $tokens->[$i]; $i++) { |
17
|
131
|
|
|
|
|
88
|
$token_type = $token->{type}; |
18
|
|
|
|
|
|
|
|
19
|
131
|
100
|
|
|
|
225
|
if ($token_type == LOCAL_DECL) { |
20
|
18
|
|
|
|
|
15
|
$token = $tokens->[++$i]; |
21
|
18
|
|
|
|
|
17
|
$token_type = $token->{type}; |
22
|
|
|
|
|
|
|
|
23
|
18
|
100
|
66
|
|
|
38
|
if ($token_type == LEFT_PAREN) { |
|
|
100
|
|
|
|
|
|
24
|
9
|
|
|
|
|
8
|
my $violation; |
25
|
9
|
|
|
|
|
5
|
my $left_paren_num = 1; |
26
|
9
|
|
|
|
|
16
|
for ($i++; my $token = $tokens->[$i]; $i++) { |
27
|
36
|
|
|
|
|
27
|
$token_type = $token->{type}; |
28
|
36
|
50
|
100
|
|
|
104
|
if ($token_type == LEFT_PAREN) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
$left_paren_num++; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_PAREN) { |
32
|
9
|
50
|
|
|
|
16
|
if (--$left_paren_num <= 0) { |
33
|
9
|
100
|
|
|
|
11
|
if ($violation) { |
34
|
4
|
|
|
|
|
4
|
push @violations, $violation; |
35
|
4
|
|
|
|
|
5
|
undef $violation; |
36
|
|
|
|
|
|
|
} |
37
|
9
|
|
|
|
|
13
|
last; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
elsif ($token_type == GLOBAL_VAR || $token_type == VAR) { |
41
|
11
|
100
|
|
|
|
29
|
if ($token->{data} !~ /\A\$[A-Z_]+\Z/) { |
42
|
6
|
|
|
|
|
7
|
my $next_token = $tokens->[$i+1]; |
43
|
6
|
50
|
|
|
|
8
|
if ($next_token->{type} != NAMESPACE_RESOLVER) { |
44
|
|
|
|
|
|
|
$violation ||= +{ |
45
|
|
|
|
|
|
|
filename => $file, |
46
|
|
|
|
|
|
|
line => $token->{line}, |
47
|
6
|
|
100
|
|
|
27
|
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
|
|
|
|
18
|
if ($token->{data} !~ /\A\$[A-Z_]+\Z/) { |
58
|
3
|
|
|
|
|
4
|
my $next_token = $tokens->[$i+1]; |
59
|
3
|
100
|
|
|
|
7
|
if ($next_token->{type} != NAMESPACE_RESOLVER) { |
60
|
|
|
|
|
|
|
push @violations, { |
61
|
|
|
|
|
|
|
filename => $file, |
62
|
|
|
|
|
|
|
line => $token->{line}, |
63
|
2
|
|
|
|
|
12
|
description => DESC, |
64
|
|
|
|
|
|
|
explanation => EXPL, |
65
|
|
|
|
|
|
|
policy => __PACKAGE__, |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
5
|
|
|
|
|
18
|
return \@violations; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
|