line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::TestingAndDebugging::ProhibitProlongedStrictureOverride; |
2
|
133
|
|
|
133
|
|
68797
|
use strict; |
|
133
|
|
|
|
|
155
|
|
|
133
|
|
|
|
|
3110
|
|
3
|
133
|
|
|
133
|
|
396
|
use warnings; |
|
133
|
|
|
|
|
138
|
|
|
133
|
|
|
|
|
2374
|
|
4
|
133
|
|
|
133
|
|
903
|
use utf8; |
|
133
|
|
|
|
|
137
|
|
|
133
|
|
|
|
|
584
|
|
5
|
133
|
|
|
133
|
|
2732
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
137
|
|
|
133
|
|
|
|
|
60769
|
|
6
|
133
|
|
|
133
|
|
6099
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
182
|
|
|
133
|
|
|
|
|
595
|
|
7
|
|
|
|
|
|
|
|
8
|
133
|
|
|
133
|
|
6171
|
use constant DEFAULT_ALLOW_STATEMENTS_NUM => 3; |
|
133
|
|
|
|
|
133
|
|
|
133
|
|
|
|
|
6910
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use constant { |
11
|
133
|
|
|
|
|
46044
|
DESC => q{Don't turn off strict for large blocks of code}, |
12
|
|
|
|
|
|
|
EXPL => [433], |
13
|
133
|
|
|
133
|
|
529
|
}; |
|
133
|
|
|
|
|
146
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub evaluate { |
16
|
8
|
|
|
8
|
0
|
14
|
my ($class, $file, $tokens, $src, $args) = @_; |
17
|
|
|
|
|
|
|
|
18
|
8
|
|
|
|
|
5
|
my $statements_arg; |
19
|
8
|
100
|
|
|
|
20
|
if (my $this_policies_arg = $args->{prohibit_prolonged_stricture_override}) { |
20
|
1
|
|
|
|
|
3
|
$statements_arg = $this_policies_arg->{statements}; |
21
|
|
|
|
|
|
|
} |
22
|
8
|
100
|
|
|
|
17
|
my $allow_statements_num = defined $statements_arg ? $statements_arg : DEFAULT_ALLOW_STATEMENTS_NUM; |
23
|
|
|
|
|
|
|
|
24
|
8
|
|
|
|
|
7
|
my @violations; |
25
|
8
|
|
|
|
|
8
|
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
|
|
|
|
|
32
|
TOP: for (my $i = 0; $i < $token_num; $i++) { |
29
|
79
|
|
|
|
|
63
|
my $token = $tokens->[$i]; |
30
|
79
|
|
|
|
|
61
|
my $token_type = $token->{type}; |
31
|
|
|
|
|
|
|
|
32
|
79
|
100
|
100
|
|
|
303
|
if ($token_type == FUNCTION_DECL) { |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
|
|
|
|
|
33
|
4
|
|
|
|
|
6
|
my $no_strict = undef; |
34
|
4
|
|
|
|
|
5
|
my $statements_num_of_after_no_strict = 0; |
35
|
4
|
|
|
|
|
3
|
my $left_brace_num = 0; |
36
|
4
|
|
|
|
|
13
|
for ($i++; $i < $token_num; $i++) { |
37
|
56
|
|
|
|
|
40
|
my $token = $tokens->[$i]; |
38
|
56
|
|
|
|
|
37
|
my $token_type = $token->{type}; |
39
|
|
|
|
|
|
|
|
40
|
56
|
100
|
100
|
|
|
210
|
if ($token_type == BUILTIN_FUNC and $token->{data} eq 'no') { |
|
|
100
|
66
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
41
|
4
|
|
|
|
|
8
|
$token = $tokens->[++$i]; |
42
|
4
|
|
|
|
|
5
|
$token_type = $token->{type}; |
43
|
|
|
|
|
|
|
|
44
|
4
|
|
|
|
|
3
|
my @allows; |
45
|
4
|
50
|
33
|
|
|
17
|
if ($token_type == KEY && $token->{data} eq 'strict') { |
46
|
4
|
|
|
|
|
5
|
$no_strict = $token; |
47
|
4
|
|
|
|
|
36
|
$i++; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
elsif ($token_type == SEMI_COLON && $no_strict) { |
51
|
14
|
|
|
|
|
8
|
$statements_num_of_after_no_strict++; |
52
|
14
|
100
|
|
|
|
28
|
if ($statements_num_of_after_no_strict > $allow_statements_num) { |
53
|
|
|
|
|
|
|
push @violations, { |
54
|
|
|
|
|
|
|
filename => $file, |
55
|
|
|
|
|
|
|
line => $no_strict->{line}, |
56
|
2
|
|
|
|
|
9
|
description => DESC, |
57
|
|
|
|
|
|
|
explanation => EXPL, |
58
|
|
|
|
|
|
|
policy => __PACKAGE__, |
59
|
|
|
|
|
|
|
}; |
60
|
2
|
|
|
|
|
6
|
next TOP; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif ($token_type == LEFT_BRACE) { |
64
|
4
|
|
|
|
|
6
|
$left_brace_num++; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_BRACE) { |
67
|
2
|
|
|
|
|
3
|
$left_brace_num--; |
68
|
2
|
50
|
|
|
|
6
|
if ($left_brace_num <= 0) { |
69
|
2
|
|
|
|
|
6
|
last; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
elsif ($token_type == BUILTIN_FUNC and $token->{data} eq 'no') { |
75
|
4
|
|
|
|
|
6
|
$token = $tokens->[++$i]; |
76
|
4
|
|
|
|
|
5
|
$token_type = $token->{type}; |
77
|
|
|
|
|
|
|
|
78
|
4
|
|
|
|
|
5
|
my @allows; |
79
|
4
|
50
|
33
|
|
|
17
|
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
|
|
|
|
|
12
|
$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
|
|
|
|
|
11
|
description => DESC, |
91
|
|
|
|
|
|
|
explanation => EXPL, |
92
|
|
|
|
|
|
|
policy => __PACKAGE__, |
93
|
|
|
|
|
|
|
}; |
94
|
2
|
|
|
|
|
3
|
last; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
8
|
|
|
|
|
31
|
return \@violations; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|