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