line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::Modules::ProhibitExcessMainComplexity; |
2
|
133
|
|
|
133
|
|
67872
|
use strict; |
|
133
|
|
|
|
|
167
|
|
|
133
|
|
|
|
|
3224
|
|
3
|
133
|
|
|
133
|
|
407
|
use warnings; |
|
133
|
|
|
|
|
143
|
|
|
133
|
|
|
|
|
2279
|
|
4
|
133
|
|
|
133
|
|
773
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
141
|
|
|
133
|
|
|
|
|
58553
|
|
5
|
133
|
|
|
133
|
|
538
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
166
|
|
|
133
|
|
|
|
|
1186
|
|
6
|
|
|
|
|
|
|
|
7
|
133
|
|
|
133
|
|
5842
|
use constant DEFAULT_MAX_MCCABE => 20; |
|
133
|
|
|
|
|
160
|
|
|
133
|
|
|
|
|
6558
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use constant { |
10
|
133
|
|
|
|
|
32684
|
DESC => 'The maximum complexity score allowed', |
11
|
|
|
|
|
|
|
EXPL => 'Consider refactoring', |
12
|
133
|
|
|
133
|
|
450
|
}; |
|
133
|
|
|
|
|
158
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub evaluate { |
15
|
7
|
|
|
7
|
0
|
18
|
my ($class, $file, $tokens, $src, $args) = @_; |
16
|
|
|
|
|
|
|
|
17
|
7
|
|
100
|
|
|
39
|
my $max_mccabe = $args->{prohibit_excess_main_complexity}->{max_mccabe} || DEFAULT_MAX_MCCABE; |
18
|
|
|
|
|
|
|
|
19
|
7
|
|
|
|
|
12
|
my @violations; |
20
|
7
|
|
|
|
|
11
|
my $mccabe = 0; |
21
|
7
|
|
|
|
|
36
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
22
|
348
|
|
|
|
|
253
|
my $token_type = $token->{type}; |
23
|
|
|
|
|
|
|
|
24
|
348
|
|
|
|
|
216
|
my $left_brace_num = 0; |
25
|
348
|
100
|
100
|
|
|
6962
|
if ($token_type == FUNCTION_DECL) { |
|
|
100
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
26
|
1
|
|
|
|
|
5
|
for ($i++; my $token = $tokens->[$i]; $i++) { |
27
|
111
|
|
|
|
|
72
|
my $token_type = $token->{type}; |
28
|
111
|
100
|
|
|
|
202
|
if ($token_type == LEFT_BRACE) { |
|
|
100
|
|
|
|
|
|
29
|
8
|
|
|
|
|
13
|
$left_brace_num++; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_BRACE) { |
32
|
8
|
50
|
|
|
|
20
|
if (--$left_brace_num < 0) { |
33
|
0
|
|
|
|
|
0
|
last; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif ( |
39
|
|
|
|
|
|
|
$token_type == AND || |
40
|
|
|
|
|
|
|
$token_type == OR || |
41
|
|
|
|
|
|
|
$token_type == ALPHABET_AND || |
42
|
|
|
|
|
|
|
$token_type == ALPHABET_OR || |
43
|
|
|
|
|
|
|
$token_type == ALPHABET_XOR || |
44
|
|
|
|
|
|
|
$token_type == OR_EQUAL || |
45
|
|
|
|
|
|
|
$token_type == AND_EQUAL || |
46
|
|
|
|
|
|
|
$token_type == THREE_TERM_OP || |
47
|
|
|
|
|
|
|
$token_type == IF_STATEMENT || |
48
|
|
|
|
|
|
|
$token_type == ELSIF_STATEMENT || |
49
|
|
|
|
|
|
|
$token_type == ELSE_STATEMENT || |
50
|
|
|
|
|
|
|
$token_type == UNLESS_STATEMENT || |
51
|
|
|
|
|
|
|
$token_type == WHILE_STATEMENT || |
52
|
|
|
|
|
|
|
$token_type == UNTIL_STATEMENT || |
53
|
|
|
|
|
|
|
$token_type == FOR_STATEMENT || |
54
|
|
|
|
|
|
|
$token_type == FOREACH_STATEMENT || |
55
|
|
|
|
|
|
|
$token_type == LEFT_SHIFT_EQUAL || |
56
|
|
|
|
|
|
|
$token_type == RIGHT_SHIFT_EQUAL |
57
|
|
|
|
|
|
|
) { |
58
|
80
|
|
|
|
|
127
|
$mccabe++; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
7
|
100
|
|
|
|
20
|
if ($mccabe > $max_mccabe) { |
63
|
3
|
|
|
|
|
24
|
push @violations, { |
64
|
|
|
|
|
|
|
filename => $file, |
65
|
|
|
|
|
|
|
line => 1, |
66
|
|
|
|
|
|
|
description => DESC, |
67
|
|
|
|
|
|
|
explanation => EXPL, |
68
|
|
|
|
|
|
|
policy => __PACKAGE__, |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
7
|
|
|
|
|
37
|
return \@violations; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|