line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::Modules::RequireExplicitPackage; |
2
|
133
|
|
|
133
|
|
68456
|
use strict; |
|
133
|
|
|
|
|
174
|
|
|
133
|
|
|
|
|
2929
|
|
3
|
133
|
|
|
133
|
|
400
|
use warnings; |
|
133
|
|
|
|
|
143
|
|
|
133
|
|
|
|
|
2658
|
|
4
|
133
|
|
|
133
|
|
432
|
use List::Util qw/any/; |
|
133
|
|
|
|
|
150
|
|
|
133
|
|
|
|
|
6048
|
|
5
|
133
|
|
|
133
|
|
861
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
166
|
|
|
133
|
|
|
|
|
58035
|
|
6
|
133
|
|
|
133
|
|
540
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
160
|
|
|
133
|
|
|
|
|
529
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use constant { |
9
|
133
|
|
|
|
|
37957
|
DESC => 'Code not contained in explicit package', |
10
|
|
|
|
|
|
|
EXPL => 'Violates encapsulation', |
11
|
133
|
|
|
133
|
|
6199
|
}; |
|
133
|
|
|
|
|
179
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub evaluate { |
14
|
13
|
|
|
13
|
0
|
20
|
my ($class, $file, $tokens, $src, $args) = @_; |
15
|
|
|
|
|
|
|
|
16
|
13
|
|
|
|
|
14
|
my @violations; |
17
|
13
|
|
|
|
|
25
|
my $exempt_scripts = $args->{require_explicit_package}->{exempt_scripts}; |
18
|
13
|
|
|
|
|
15
|
my $allow_import_of = $args->{require_explicit_package}->{allow_import_of}; |
19
|
13
|
|
|
|
|
14
|
my $token = $tokens->[0]; |
20
|
13
|
100
|
100
|
|
|
99
|
if (($exempt_scripts || !$token || $token->{type} == PACKAGE) && !$allow_import_of) { |
|
|
|
66
|
|
|
|
|
21
|
5
|
|
|
|
|
21
|
return []; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
else { |
24
|
8
|
|
|
|
|
22
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
25
|
10
|
|
|
|
|
11
|
my $token_type = $token->{type}; |
26
|
10
|
|
|
|
|
11
|
my $token_data = $token->{data}; |
27
|
|
|
|
|
|
|
|
28
|
10
|
100
|
|
|
|
26
|
if ($token_type == USE_DECL) { |
|
|
100
|
|
|
|
|
|
29
|
4
|
|
|
|
|
6
|
my $used_name = ''; |
30
|
4
|
|
|
|
|
12
|
for ($i++; my $token = $tokens->[$i]; $i++) { |
31
|
12
|
|
|
|
|
11
|
my $token_type = $token->{type}; |
32
|
12
|
|
|
|
|
10
|
my $token_data = $token->{data}; |
33
|
12
|
100
|
100
|
|
|
43
|
if ( |
|
|
|
100
|
|
|
|
|
34
|
|
|
|
|
|
|
$token_type != NAMESPACE && |
35
|
|
|
|
|
|
|
$token_type != NAMESPACE_RESOLVER && |
36
|
|
|
|
|
|
|
$token_type != USED_NAME |
37
|
|
|
|
|
|
|
) { |
38
|
4
|
|
|
|
|
5
|
last; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else { |
41
|
8
|
|
|
|
|
18
|
$used_name .= $token_data; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
4
|
100
|
|
3
|
|
41
|
if (!any {$_ eq $used_name} @$allow_import_of) { |
|
3
|
|
|
|
|
11
|
|
45
|
|
|
|
|
|
|
push @violations, { |
46
|
|
|
|
|
|
|
filename => $file, |
47
|
|
|
|
|
|
|
line => $token->{line}, |
48
|
2
|
|
|
|
|
12
|
description => DESC, |
49
|
|
|
|
|
|
|
explanation => EXPL, |
50
|
|
|
|
|
|
|
policy => __PACKAGE__, |
51
|
|
|
|
|
|
|
}; |
52
|
2
|
|
|
|
|
4
|
last; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
elsif ($token_type == PACKAGE) { |
56
|
1
|
|
|
|
|
2
|
last; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
else { |
59
|
|
|
|
|
|
|
push @violations, { |
60
|
|
|
|
|
|
|
filename => $file, |
61
|
|
|
|
|
|
|
line => $token->{line}, |
62
|
5
|
|
|
|
|
23
|
description => DESC, |
63
|
|
|
|
|
|
|
explanation => EXPL, |
64
|
|
|
|
|
|
|
policy => __PACKAGE__, |
65
|
|
|
|
|
|
|
}; |
66
|
5
|
|
|
|
|
8
|
last; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
8
|
|
|
|
|
27
|
return \@violations; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|