line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::Modules::ProhibitEvilModules; |
2
|
133
|
|
|
133
|
|
66770
|
use strict; |
|
133
|
|
|
|
|
184
|
|
|
133
|
|
|
|
|
3121
|
|
3
|
133
|
|
|
133
|
|
394
|
use warnings; |
|
133
|
|
|
|
|
165
|
|
|
133
|
|
|
|
|
2933
|
|
4
|
133
|
|
|
133
|
|
413
|
use List::Util qw/any/; |
|
133
|
|
|
|
|
155
|
|
|
133
|
|
|
|
|
6067
|
|
5
|
133
|
|
|
133
|
|
820
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
163
|
|
|
133
|
|
|
|
|
58026
|
|
6
|
133
|
|
|
133
|
|
534
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
139
|
|
|
133
|
|
|
|
|
638
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use constant { |
9
|
133
|
|
|
|
|
7764
|
DESC => 'The names of or patterns for modules to forbid', |
10
|
|
|
|
|
|
|
EXPL => 'Find an alternative module', |
11
|
133
|
|
|
133
|
|
6732
|
}; |
|
133
|
|
|
|
|
180
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# TODO Should use Module::Adviser? |
14
|
133
|
|
|
|
|
49288
|
use constant EVILS => [qw/ |
15
|
|
|
|
|
|
|
Class::ISA |
16
|
|
|
|
|
|
|
Pod::Plainer |
17
|
|
|
|
|
|
|
Shell |
18
|
|
|
|
|
|
|
Switch |
19
|
133
|
|
|
133
|
|
437
|
/]; |
|
133
|
|
|
|
|
156
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub evaluate { |
22
|
15
|
|
|
15
|
0
|
34
|
my ($class, $file, $tokens, $src, $args) = @_; |
23
|
|
|
|
|
|
|
|
24
|
15
|
|
100
|
|
|
75
|
my $modules_arg = $args->{prohibit_evil_modules}->{modules} || ''; |
25
|
15
|
|
|
|
|
46
|
$modules_arg =~ s/{.*?}//g; |
26
|
15
|
|
|
|
|
56
|
my @evils = split(/ /, $modules_arg); |
27
|
|
|
|
|
|
|
|
28
|
15
|
|
|
|
|
35
|
my $modules_file = $args->{prohibit_evil_modules}->{modules_file}; |
29
|
15
|
100
|
|
|
|
42
|
if ($modules_file) { |
30
|
2
|
|
|
|
|
76
|
open my $fh, '<', $modules_file; |
31
|
2
|
|
|
|
|
5
|
my $content = do { local $/; <$fh> }; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
23
|
|
32
|
2
|
|
|
|
|
84
|
push @evils, ($content =~ /^\s*?([^ \n\r\f\t#]+)/gm); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
15
|
|
|
|
|
34
|
my @evils_re = map {m!/(.+?)/!; $1} @evils; |
|
29
|
|
|
|
|
64
|
|
|
29
|
|
|
|
|
58
|
|
36
|
|
|
|
|
|
|
|
37
|
15
|
|
|
|
|
31
|
my @violations; |
38
|
15
|
|
|
|
|
73
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
39
|
70
|
|
|
|
|
76
|
my $token_type = $token->{type}; |
40
|
70
|
100
|
|
|
|
147
|
if ($token_type == USE_DECL) { |
41
|
31
|
|
|
|
|
27
|
my $used_name = ''; |
42
|
31
|
|
|
|
|
71
|
for ($i++; my $token = $tokens->[$i]; $i++) { |
43
|
115
|
|
|
|
|
89
|
my $token_type = $token->{type}; |
44
|
115
|
100
|
100
|
|
|
357
|
if ( |
|
|
|
100
|
|
|
|
|
45
|
|
|
|
|
|
|
$token_type != NAMESPACE && |
46
|
|
|
|
|
|
|
$token_type != NAMESPACE_RESOLVER && |
47
|
|
|
|
|
|
|
$token_type != USED_NAME |
48
|
|
|
|
|
|
|
) { |
49
|
30
|
|
|
|
|
46
|
last; |
50
|
|
|
|
|
|
|
} |
51
|
85
|
|
|
|
|
171
|
$used_name .= $token->{data}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
31
|
100
|
100
|
|
|
131
|
if ( |
55
|
188
|
|
|
188
|
|
223
|
any {$used_name eq $_} (@{+EVILS}, @evils) or |
|
31
|
|
|
|
|
146
|
|
56
|
37
|
100
|
|
37
|
|
352
|
any {$_ && $used_name =~ /$_/} @evils_re |
57
|
|
|
|
|
|
|
) { |
58
|
|
|
|
|
|
|
push @violations, { |
59
|
|
|
|
|
|
|
filename => $file, |
60
|
|
|
|
|
|
|
line => $token->{line}, |
61
|
30
|
|
|
|
|
242
|
description => DESC, |
62
|
|
|
|
|
|
|
explanation => EXPL, |
63
|
|
|
|
|
|
|
policy => __PACKAGE__, |
64
|
|
|
|
|
|
|
}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
15
|
|
|
|
|
74
|
return \@violations; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|