line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::ClassHierarchies::ProhibitOneArgBless; |
2
|
133
|
|
|
133
|
|
70115
|
use strict; |
|
133
|
|
|
|
|
184
|
|
|
133
|
|
|
|
|
3245
|
|
3
|
133
|
|
|
133
|
|
420
|
use warnings; |
|
133
|
|
|
|
|
208
|
|
|
133
|
|
|
|
|
2564
|
|
4
|
133
|
|
|
133
|
|
869
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
160
|
|
|
133
|
|
|
|
|
60823
|
|
5
|
133
|
|
|
133
|
|
596
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
163
|
|
|
133
|
|
|
|
|
582
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
133
|
|
|
|
|
37323
|
DESC => 'One-argument "bless" used', |
9
|
|
|
|
|
|
|
EXPL => [365], |
10
|
133
|
|
|
133
|
|
6774
|
}; |
|
133
|
|
|
|
|
201
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
13
|
3
|
|
|
3
|
0
|
6
|
my ($class, $file, $tokens, $args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
|
|
4
|
my @violations; |
16
|
3
|
|
|
|
|
5
|
my $token_num = scalar @$tokens; |
17
|
3
|
|
|
|
|
9
|
for (my $i = 0; $i < $token_num; $i++) { |
18
|
70
|
|
|
|
|
48
|
my $token = $tokens->[$i]; |
19
|
70
|
|
|
|
|
52
|
my $token_type = $token->{type}; |
20
|
70
|
|
|
|
|
56
|
my $token_data = $token->{data}; |
21
|
|
|
|
|
|
|
|
22
|
70
|
100
|
66
|
|
|
149
|
if ($token_type == BUILTIN_FUNC && $token_data eq 'bless') { |
23
|
14
|
|
|
|
|
10
|
my $left_paren_num = 0; |
24
|
14
|
|
|
|
|
7
|
my $left_brace_num = 0; |
25
|
14
|
|
|
|
|
12
|
my $left_bracket_num = 0; |
26
|
14
|
|
|
|
|
8
|
my $comma_num = 0; |
27
|
|
|
|
|
|
|
|
28
|
14
|
100
|
|
|
|
29
|
$i++ if $tokens->[$i+1]->{type} == LEFT_PAREN; |
29
|
|
|
|
|
|
|
|
30
|
14
|
|
|
|
|
18
|
for ($i++; $i < $token_num; $i++) { |
31
|
66
|
|
|
|
|
53
|
my $token = $tokens->[$i]; |
32
|
66
|
|
|
|
|
75
|
my $token_type = $token->{type}; |
33
|
66
|
|
|
|
|
44
|
my $token_data = $token->{data}; |
34
|
|
|
|
|
|
|
|
35
|
66
|
50
|
100
|
|
|
327
|
if ($token_type == LEFT_PAREN) { |
|
|
100
|
66
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
33
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
33
|
|
|
|
|
|
|
100
|
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
$left_paren_num++; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif ($token_type == LEFT_BRACE) { |
39
|
7
|
|
|
|
|
10
|
$left_brace_num++; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif ($token_type == LEFT_BRACKET) { |
42
|
8
|
|
|
|
|
11
|
$left_bracket_num++; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_PAREN) { |
45
|
7
|
|
|
|
|
8
|
$left_paren_num--; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_BRACE) { |
48
|
7
|
|
|
|
|
12
|
$left_brace_num--; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_BRACKET) { |
51
|
8
|
|
|
|
|
13
|
$left_bracket_num--; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
elsif ( |
54
|
|
|
|
|
|
|
($token_type == COMMA || $token_type == ARROW) && |
55
|
|
|
|
|
|
|
$left_paren_num <= 0 && |
56
|
|
|
|
|
|
|
$left_brace_num <= 0 && |
57
|
|
|
|
|
|
|
$left_bracket_num <= 0 |
58
|
|
|
|
|
|
|
) { |
59
|
6
|
|
|
|
|
9
|
$comma_num++; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
elsif ( |
62
|
|
|
|
|
|
|
$token_type == SEMI_COLON && |
63
|
|
|
|
|
|
|
$left_paren_num <= 0 && |
64
|
|
|
|
|
|
|
$left_brace_num <= 0 && |
65
|
|
|
|
|
|
|
$left_bracket_num <= 0 |
66
|
|
|
|
|
|
|
) { |
67
|
14
|
100
|
|
|
|
19
|
if ($comma_num == 0) { |
68
|
|
|
|
|
|
|
push @violations, { |
69
|
|
|
|
|
|
|
filename => $file, |
70
|
|
|
|
|
|
|
line => $token->{line}, |
71
|
8
|
|
|
|
|
31
|
description => DESC, |
72
|
|
|
|
|
|
|
explanation => EXPL, |
73
|
|
|
|
|
|
|
policy => __PACKAGE__, |
74
|
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
} |
76
|
14
|
|
|
|
|
28
|
last; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
3
|
|
|
|
|
13
|
return \@violations; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
|