Perl/Lint/Policy/Modules/ProhibitEvilModules.pm

filter: Statementstmt 42.3% 22 / 52 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 1 totaltotal 30.8% 29 / 94 CC 12 SCAR 42.5
CC
12
Cov
29%
evaluate
132.0
__ANON__
6.0
__ANON__
2.0
CRAP 70.1
« Perl/Lint/Policy/InputOutput/ProhibitJoinedReadline.pm ↑ Summary Perl/Lint/Policy/Variables/ProhibitPerl4PackageNames.pm »
1 package Perl::Lint::Policy::Modules::ProhibitEvilModules;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use List::Util qw/any/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 DESC => 'The names of or patterns for modules to forbid',
10 EXPL => 'Find an alternative module',
11 2 };
12  
13 # TODO Should use Module::Adviser?
14 2 ▶use constant EVILS => [qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
15 Class::ISA
16 Pod::Plainer
17 Shell
18 Switch
19 2 /];
20  
21 0 ▶sub evaluate {
Subroutine evaluate: not called CC=11 SCAR=48.8
Pod undocumented
22 0 my ($class, $file, $tokens, $src, $args) = @_;
23  
24 0 ▶ my $modules_arg = $args->{prohibit_evil_modules}->{modules} || '';
Condition0%0/2
$args->{'prohibit_evil_modules'}{'modules'} || ''
l!l
00
MC/DC0%0/1
$args->{'prohibit_evil_modules'}{'modules'} || ''
$args->{'prohibit_evil_modules'}{'modules'}
Truth table0%0/2
A
A= $args->{'prohibit_evil_modules'}{'modules'}
Aresult
11
00
25 0 $modules_arg =~ s/{.*?}//g;
26 0 my @evils = split(/ /, $modules_arg);
27  
28 0 my $modules_file = $args->{prohibit_evil_modules}->{modules_file};
29 0 ▶ if ($modules_file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($modules_file) 0 0 0
30 0 open my $fh, '<', $modules_file;
31 0 my $content = do { local $/; <$fh> };
32 0 push @evils, ($content =~ /^\s*?([^ \n\r\f\t#]+)/gm);
33 }
34  
35 0 my @evils_re = map {m!/(.+?)/!; $1} @evils;
36  
37 0 my @violations;
38 0 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
39 0 my $token_type = $token->{type};
40 0 ▶ if ($token_type == USE_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 93) 0 0 0
41 0 my $used_name = '';
42 0 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
43 0 my $token_type = $token->{type};
44 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type != 127 and $token_type != 126 and $token_type != 94) 0 0 0
Condition0%0/6
$token_type != 127 and $token_type != 126 and $token_type != 94
!ll&&!rl&&r
000
$token_type != 127 and $token_type != 126
!ll&&!rl&&r
000
MC/DC0%0/3
$token_type != 127 and $token_type != 126 and $token_type != 94
$token_type != 127 $token_type != 126 $token_type != 94
Truth table0%0/4
A and B and C
A= $token_type != 127B= $token_type != 126C= $token_type != 94
ABCresult
0XX0
10X0
1100
1111
45 $token_type != NAMESPACE &&
46 $token_type != NAMESPACE_RESOLVER &&
47 $token_type != USED_NAME
48 ) {
49 0 last;
50 }
51 0 $used_name .= $token->{data};
52 }
53  
54 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $used_name eq $_; } , @{["Class::ISA","Pod::Plainer","Shell","Switch"];}, @evils) or &any(sub { $_ and $used_name =~ /$_/; } , @evils_re)) 0 0 0
Condition0%0/3
&any(sub { $used_name eq $_; } , @{["Class::ISA","Pod::Plainer","Shell","Switch"];}, @evils) or &any(sub { $_ and $used_name =~ /$_/; } , @evils_re)
l!l&&r!l&&!r
000
MC/DC0%0/2
&any(sub { $used_name eq $_; } , @{["Class::ISA","Pod::Plainer","Shell","Switch"];}, @evils) or &any(sub { $_ and $used_name =~ /$_/; } , @evils_re)
&any(sub { $used_name eq $_; } , @{["Class::ISA","Pod::Plainer","Shell","Switch"];}, @evils) &any(sub { $_ and $used_name =~ /$_/; } , @evils_re)
Truth table0%0/3
A or B
A= &any(sub { $used_name eq $_; } , @{["Class::ISA","Pod::Plainer","Shell","Switch"];}, @evils)B= &any(sub { $_ and $used_name =~ /$_/; } , @evils_re)
ABresult
1X1
011
000
55 0 ▶ any {$used_name eq $_} (@{+EVILS}, @evils) or
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 0 ▶ any {$_ && $used_name =~ /$_/} @evils_re
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_ and $used_name =~ /$_/ 0 0 0
57 ) {
58 push @violations, {
59 filename => $file,
60 line => $token->{line},
61 0 description => DESC,
62 explanation => EXPL,
63 policy => __PACKAGE__,
64 };
65 }
66 }
67 }
68  
69 0 return \@violations;
70 }
71  
72 2 1;
73  
« Perl/Lint/Policy/InputOutput/ProhibitJoinedReadline.pm ↑ Summary Perl/Lint/Policy/Variables/ProhibitPerl4PackageNames.pm »