line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::Modules::RequireExplicitPackage; |
2
|
133
|
|
|
133
|
|
67338
|
use strict; |
|
133
|
|
|
|
|
163
|
|
|
133
|
|
|
|
|
3081
|
|
3
|
133
|
|
|
133
|
|
379
|
use warnings; |
|
133
|
|
|
|
|
154
|
|
|
133
|
|
|
|
|
2736
|
|
4
|
133
|
|
|
133
|
|
402
|
use List::Util qw/any/; |
|
133
|
|
|
|
|
144
|
|
|
133
|
|
|
|
|
6280
|
|
5
|
133
|
|
|
133
|
|
817
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
161
|
|
|
133
|
|
|
|
|
58311
|
|
6
|
133
|
|
|
133
|
|
537
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
179
|
|
|
133
|
|
|
|
|
538
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use constant { |
9
|
133
|
|
|
|
|
38302
|
DESC => 'Code not contained in explicit package', |
10
|
|
|
|
|
|
|
EXPL => 'Violates encapsulation', |
11
|
133
|
|
|
133
|
|
6561
|
}; |
|
133
|
|
|
|
|
153
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub evaluate { |
14
|
13
|
|
|
13
|
0
|
30
|
my ($class, $file, $tokens, $src, $args) = @_; |
15
|
|
|
|
|
|
|
|
16
|
13
|
|
|
|
|
14
|
my @violations; |
17
|
13
|
|
|
|
|
33
|
my $exempt_scripts = $args->{require_explicit_package}->{exempt_scripts}; |
18
|
13
|
|
|
|
|
18
|
my $allow_import_of = $args->{require_explicit_package}->{allow_import_of}; |
19
|
13
|
|
|
|
|
19
|
my $token = $tokens->[0]; |
20
|
13
|
100
|
100
|
|
|
116
|
if (($exempt_scripts || !$token || $token->{type} == PACKAGE) && !$allow_import_of) { |
|
|
|
66
|
|
|
|
|
21
|
5
|
|
|
|
|
23
|
return []; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
else { |
24
|
8
|
|
|
|
|
23
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
25
|
10
|
|
|
|
|
14
|
my $token_type = $token->{type}; |
26
|
10
|
|
|
|
|
11
|
my $token_data = $token->{data}; |
27
|
|
|
|
|
|
|
|
28
|
10
|
100
|
|
|
|
22
|
if ($token_type == USE_DECL) { |
|
|
100
|
|
|
|
|
|
29
|
4
|
|
|
|
|
6
|
my $used_name = ''; |
30
|
4
|
|
|
|
|
12
|
for ($i++; my $token = $tokens->[$i]; $i++) { |
31
|
12
|
|
|
|
|
15
|
my $token_type = $token->{type}; |
32
|
12
|
|
|
|
|
10
|
my $token_data = $token->{data}; |
33
|
12
|
100
|
100
|
|
|
50
|
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
|
|
|
|
|
18
|
$used_name .= $token_data; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
4
|
100
|
|
3
|
|
59
|
if (!any {$_ eq $used_name} @$allow_import_of) { |
|
3
|
|
|
|
|
11
|
|
45
|
|
|
|
|
|
|
push @violations, { |
46
|
|
|
|
|
|
|
filename => $file, |
47
|
|
|
|
|
|
|
line => $token->{line}, |
48
|
2
|
|
|
|
|
14
|
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
|
|
|
|
|
|
|
push @violations, { |
60
|
|
|
|
|
|
|
filename => $file, |
61
|
|
|
|
|
|
|
line => $token->{line}, |
62
|
5
|
|
|
|
|
27
|
description => DESC, |
63
|
|
|
|
|
|
|
explanation => EXPL, |
64
|
|
|
|
|
|
|
policy => __PACKAGE__, |
65
|
|
|
|
|
|
|
}; |
66
|
5
|
|
|
|
|
12
|
last; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
8
|
|
|
|
|
35
|
return \@violations; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|