line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::Subroutines::ProhibitNestedSubs; |
2
|
133
|
|
|
133
|
|
68711
|
use strict; |
|
133
|
|
|
|
|
193
|
|
|
133
|
|
|
|
|
3156
|
|
3
|
133
|
|
|
133
|
|
474
|
use warnings; |
|
133
|
|
|
|
|
172
|
|
|
133
|
|
|
|
|
2544
|
|
4
|
133
|
|
|
133
|
|
818
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
205
|
|
|
133
|
|
|
|
|
59583
|
|
5
|
133
|
|
|
133
|
|
597
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
185
|
|
|
133
|
|
|
|
|
623
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# TODO msg! |
8
|
|
|
|
|
|
|
use constant { |
9
|
133
|
|
|
|
|
25585
|
DESC => 'Nested named subroutine', |
10
|
|
|
|
|
|
|
EXPL => 'Declaring a named sub inside another named sub does not prevent the ' |
11
|
|
|
|
|
|
|
. 'inner sub from being global', |
12
|
133
|
|
|
133
|
|
7493
|
}; |
|
133
|
|
|
|
|
185
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub evaluate { |
15
|
6
|
|
|
6
|
0
|
8
|
my ($class, $file, $tokens, $args) = @_; |
16
|
|
|
|
|
|
|
|
17
|
6
|
|
|
|
|
6
|
my @violations; |
18
|
6
|
|
|
|
|
18
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
19
|
26
|
|
|
|
|
21
|
my $token_type = $token->{type}; |
20
|
|
|
|
|
|
|
|
21
|
26
|
100
|
|
|
|
47
|
if ($token_type == FUNCTION) { |
22
|
9
|
|
|
|
|
7
|
my $left_brace_num = 0; |
23
|
9
|
|
|
|
|
14
|
for ($i++; my $token = $tokens->[$i]; $i++) { |
24
|
81
|
|
|
|
|
59
|
my $token_type = $token->{type}; |
25
|
81
|
100
|
|
|
|
146
|
if ($token_type == FUNCTION) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
26
|
4
|
50
|
|
|
|
33
|
if ($left_brace_num > 0) { |
27
|
|
|
|
|
|
|
push @violations, { |
28
|
|
|
|
|
|
|
filename => $file, |
29
|
|
|
|
|
|
|
line => $token->{line}, |
30
|
4
|
|
|
|
|
23
|
description => DESC, |
31
|
|
|
|
|
|
|
explanation => EXPL, |
32
|
|
|
|
|
|
|
policy => __PACKAGE__, |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
elsif ($token_type == LEFT_BRACE) { |
37
|
18
|
|
|
|
|
22
|
$left_brace_num++; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_BRACE) { |
40
|
18
|
|
|
|
|
13
|
$left_brace_num--; |
41
|
18
|
100
|
|
|
|
41
|
last if $left_brace_num <= 0; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
6
|
|
|
|
|
17
|
return \@violations; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
|