line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::TestingAndDebugging::ProhibitProlongedStrictureOverride; |
2
|
133
|
|
|
133
|
|
69770
|
use strict; |
|
133
|
|
|
|
|
176
|
|
|
133
|
|
|
|
|
3233
|
|
3
|
133
|
|
|
133
|
|
386
|
use warnings; |
|
133
|
|
|
|
|
135
|
|
|
133
|
|
|
|
|
2297
|
|
4
|
133
|
|
|
133
|
|
968
|
use utf8; |
|
133
|
|
|
|
|
141
|
|
|
133
|
|
|
|
|
588
|
|
5
|
133
|
|
|
133
|
|
2490
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
152
|
|
|
133
|
|
|
|
|
59950
|
|
6
|
133
|
|
|
133
|
|
5962
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
183
|
|
|
133
|
|
|
|
|
556
|
|
7
|
|
|
|
|
|
|
|
8
|
133
|
|
|
133
|
|
6045
|
use constant DEFAULT_ALLOW_STATEMENTS_NUM => 3; |
|
133
|
|
|
|
|
142
|
|
|
133
|
|
|
|
|
7126
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use constant { |
11
|
133
|
|
|
|
|
45769
|
DESC => q{Don't turn off strict for large blocks of code}, |
12
|
|
|
|
|
|
|
EXPL => [433], |
13
|
133
|
|
|
133
|
|
578
|
}; |
|
133
|
|
|
|
|
132
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub evaluate { |
16
|
8
|
|
|
8
|
0
|
15
|
my ($class, $file, $tokens, $src, $args) = @_; |
17
|
|
|
|
|
|
|
|
18
|
8
|
|
|
|
|
8
|
my $statements_arg; |
19
|
8
|
100
|
|
|
|
19
|
if (my $this_policies_arg = $args->{prohibit_prolonged_stricture_override}) { |
20
|
1
|
|
|
|
|
4
|
$statements_arg = $this_policies_arg->{statements}; |
21
|
|
|
|
|
|
|
} |
22
|
8
|
100
|
|
|
|
18
|
my $allow_statements_num = defined $statements_arg ? $statements_arg : DEFAULT_ALLOW_STATEMENTS_NUM; |
23
|
|
|
|
|
|
|
|
24
|
8
|
|
|
|
|
7
|
my @violations; |
25
|
8
|
|
|
|
|
12
|
my $token_num = scalar @$tokens; |
26
|
8
|
|
|
|
|
8
|
my $no_strict = undef; |
27
|
8
|
|
|
|
|
9
|
my $statements_num_of_after_no_strict = 0; |
28
|
8
|
|
|
|
|
21
|
TOP: for (my $i = 0; $i < $token_num; $i++) { |
29
|
79
|
|
|
|
|
61
|
my $token = $tokens->[$i]; |
30
|
79
|
|
|
|
|
57
|
my $token_type = $token->{type}; |
31
|
|
|
|
|
|
|
|
32
|
79
|
100
|
100
|
|
|
315
|
if ($token_type == FUNCTION_DECL) { |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
33
|
4
|
|
|
|
|
5
|
my $no_strict = undef; |
34
|
4
|
|
|
|
|
7
|
my $statements_num_of_after_no_strict = 0; |
35
|
4
|
|
|
|
|
5
|
my $left_brace_num = 0; |
36
|
4
|
|
|
|
|
12
|
for ($i++; $i < $token_num; $i++) { |
37
|
56
|
|
|
|
|
42
|
my $token = $tokens->[$i]; |
38
|
56
|
|
|
|
|
37
|
my $token_type = $token->{type}; |
39
|
|
|
|
|
|
|
|
40
|
56
|
100
|
100
|
|
|
229
|
if ($token_type == BUILTIN_FUNC and $token->{data} eq 'no') { |
|
|
100
|
66
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
41
|
4
|
|
|
|
|
7
|
$token = $tokens->[++$i]; |
42
|
4
|
|
|
|
|
5
|
$token_type = $token->{type}; |
43
|
|
|
|
|
|
|
|
44
|
4
|
|
|
|
|
5
|
my @allows; |
45
|
4
|
50
|
33
|
|
|
22
|
if ($token_type == KEY && $token->{data} eq 'strict') { |
46
|
4
|
|
|
|
|
5
|
$no_strict = $token; |
47
|
4
|
|
|
|
|
6
|
$i++; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
elsif ($token_type == SEMI_COLON && $no_strict) { |
51
|
14
|
|
|
|
|
4
|
$statements_num_of_after_no_strict++; |
52
|
14
|
100
|
|
|
|
32
|
if ($statements_num_of_after_no_strict > $allow_statements_num) { |
53
|
|
|
|
|
|
|
push @violations, { |
54
|
|
|
|
|
|
|
filename => $file, |
55
|
|
|
|
|
|
|
line => $no_strict->{line}, |
56
|
2
|
|
|
|
|
11
|
description => DESC, |
57
|
|
|
|
|
|
|
explanation => EXPL, |
58
|
|
|
|
|
|
|
policy => __PACKAGE__, |
59
|
|
|
|
|
|
|
}; |
60
|
2
|
|
|
|
|
7
|
next TOP; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif ($token_type == LEFT_BRACE) { |
64
|
4
|
|
|
|
|
7
|
$left_brace_num++; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_BRACE) { |
67
|
2
|
|
|
|
|
2
|
$left_brace_num--; |
68
|
2
|
50
|
|
|
|
6
|
if ($left_brace_num <= 0) { |
69
|
2
|
|
|
|
|
5
|
last; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
elsif ($token_type == BUILTIN_FUNC and $token->{data} eq 'no') { |
75
|
4
|
|
|
|
|
8
|
$token = $tokens->[++$i]; |
76
|
4
|
|
|
|
|
6
|
$token_type = $token->{type}; |
77
|
|
|
|
|
|
|
|
78
|
4
|
|
|
|
|
4
|
my @allows; |
79
|
4
|
50
|
33
|
|
|
18
|
if ($token_type == KEY && $token->{data} eq 'strict') { |
80
|
4
|
|
|
|
|
6
|
$no_strict = $token; |
81
|
4
|
|
|
|
|
8
|
$i++; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
elsif ($token_type == SEMI_COLON && $no_strict) { |
85
|
11
|
|
|
|
|
9
|
$statements_num_of_after_no_strict++; |
86
|
11
|
100
|
|
|
|
19
|
if ($statements_num_of_after_no_strict > $allow_statements_num) { |
87
|
|
|
|
|
|
|
push @violations, { |
88
|
|
|
|
|
|
|
filename => $file, |
89
|
|
|
|
|
|
|
line => $no_strict->{line}, |
90
|
2
|
|
|
|
|
14
|
description => DESC, |
91
|
|
|
|
|
|
|
explanation => EXPL, |
92
|
|
|
|
|
|
|
policy => __PACKAGE__, |
93
|
|
|
|
|
|
|
}; |
94
|
2
|
|
|
|
|
5
|
last; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
8
|
|
|
|
|
31
|
return \@violations; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|