Perl/Lint/Policy/Modules/ProhibitConditionalUseStatements.pm

filter: Statementstmt 32.2% 19 / 59 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 81 MC/DCmcdc 0.0% 0 / 33 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 1 totaltotal 11.8% 25 / 211 CC 43 SCAR 74.1
CC
43
Cov
11%
evaluate
1892.0
BEGIN
1.0
BEGIN
1.0
CRAP 1660.4
« Perl/Lint/Policy/ValuesAndExpressions/ProhibitMismatchedOperators.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/ProhibitMagicNumbers.pm »
1 package Perl::Lint::Policy::Modules::ProhibitConditionalUseStatements;
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 Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Perl::Lint::Keywords;
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 => 'Conditional "use" statement',
10 EXPL => 'Use "require" to conditionally include a module',
11 2 };
12  
13 0 ▶sub evaluate {
Subroutine evaluate: not called CC=43 SCAR=75.5
Pod undocumented
14 0 my ($class, $file, $tokens, $args) = @_;
15  
16 0 my @violations;
17 0 my $is_in_cond = 0;
18 0 my $is_in_if = 0;
19 0 my $is_in_do = 0;
20 0 my $is_in_BEGIN = 0;
21 0 my $left_brace_num = 0;
22 0 my $is_in_illegal_do = 0;
23 0 my $previous_violation;
24 0 ▶ for (my $i = 0, my $next_token, my $token_type, my $token_data; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
25 0 $next_token = $tokens->[$i+1];
26 0 $token_type = $token->{type};
27 0 $token_data = $token->{data};
28  
29 0 ▶ if (
Branch: 8 branches
BranchTrueFalseTotal
if ($token_type == 99 or $token_type == 97 or $token_type == 98 or $token_type == 132 or $token_type == 100 or $token_type == 133 or $token_type == 134 or $token_type == 86 or $token_type == 70 and $token_data eq 'eval') { } 0 0 0
elsif ($token_type == 52 || $token_type == 53 || $token_type == 14 || $token_type == 16 and $next_token->{'type'} == 87) { } 0 0 0
elsif ($token_type == 87) { } 0 0 0
elsif ($token_type == 96) { } 0 0 0
elsif ($token_type == 75 and $token_data eq 'BEGIN') { } 0 0 0
elsif ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
elsif ($is_in_cond or $is_in_illegal_do or $is_in_do or $is_in_BEGIN and $is_in_if) { } 0 0 0
Condition0%0/27
$token_type == 99 or $token_type == 97 or $token_type == 98 or $token_type == 132 or $token_type == 100 or $token_type == 133 or $token_type == 134 or $token_type == 86 or $token_type == 70 and $token_data eq "eval"
l!l&&r!l&&!r
000
$token_type == 99 or $token_type == 97 or $token_type == 98 or $token_type == 132 or $token_type == 100 or $token_type == 133 or $token_type == 134 or $token_type == 86
l!l&&r!l&&!r
000
$token_type == 99 or $token_type == 97 or $token_type == 98 or $token_type == 132 or $token_type == 100 or $token_type == 133 or $token_type == 134
l!l&&r!l&&!r
000
$token_type == 99 or $token_type == 97 or $token_type == 98 or $token_type == 132 or $token_type == 100 or $token_type == 133
l!l&&r!l&&!r
000
$token_type == 99 or $token_type == 97 or $token_type == 98 or $token_type == 132 or $token_type == 100
l!l&&r!l&&!r
000
$token_type == 99 or $token_type == 97 or $token_type == 98 or $token_type == 132
l!l&&r!l&&!r
000
$token_type == 99 or $token_type == 97 or $token_type == 98
l!l&&r!l&&!r
000
$token_type == 99 or $token_type == 97
l!l&&r!l&&!r
000
$token_type == 70 and $token_data eq "eval"
!ll&&!rl&&r
000
MC/DC0%0/10
$token_type == 99 or $token_type == 97 or $token_type == 98 or $token_type == 132 or $token_type == 100 or $token_type == 133 or $token_type == 134 or $token_type == 86 or $token_type == 70 and $token_data eq "eval"
$token_type == 99 $token_type == 97 $token_type == 98 $token_type == 132 $token_type == 100 $token_type == 133 $token_type == 134 $token_type == 86 $token_type == 70 $token_data eq "eval"
Truth table0%0/11
A or B or C or D or E or F or G or H or I and J
A= $token_type == 99B= $token_type == 97C= $token_type == 98D= $token_type == 132E= $token_type == 100F= $token_type == 133G= $token_type == 134H= $token_type == 86I= $token_type == 70J= $token_data eq "eval"
ABCDEFGHIJresult
1XXXXXXXXX1
01XXXXXXXX1
001XXXXXXX1
0001XXXXXX1
00001XXXXX1
000001XXXX1
0000001XXX1
00000001XX1
00000000111
000000000X0
00000000100
30 $token_type == UNLESS_STATEMENT ||
31 $token_type == ELSE_STATEMENT ||
32 $token_type == ELSIF_STATEMENT ||
33 $token_type == WHILE_STATEMENT ||
34 $token_type == UNTIL_STATEMENT ||
35 $token_type == FOR_STATEMENT ||
36 $token_type == FOREACH_STATEMENT ||
37 $token_type == CONTINUE ||
38 ($token_type == BUILTIN_FUNC && $token_data eq 'eval')
39 ) {
40 0 $is_in_cond = 1;
41 0 next;
42 }
43 ▶ elsif (
Condition0%0/12
$token_type == 52 || $token_type == 53 || $token_type == 14 || $token_type == 16 and $next_token->{"type"} == 87
!ll&&!rl&&r
000
$token_type == 52 or $token_type == 53 or $token_type == 14 or $token_type == 16
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53 or $token_type == 14
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53
l!l&&r!l&&!r
000
MC/DC0%0/5
$token_type == 52 || $token_type == 53 || $token_type == 14 || $token_type == 16 and $next_token->{"type"} == 87
$token_type == 52 $token_type == 53 $token_type == 14 $token_type == 16 $next_token->{"type"} == 87
Truth table0%0/9
A or B or C or D and E
A= $token_type == 52B= $token_type == 53C= $token_type == 14D= $token_type == 16E= $next_token->{"type"} == 87
ABCDEresult
0000X0
1XXX00
01XX00
001X00
000100
1XXX11
01XX11
001X11
000111
44 ($token_type == AND || $token_type == OR || $token_type == ALPHABET_OR || $token_type == ALPHABET_AND) && $next_token->{type} == DO
45 ) {
46 0 $is_in_illegal_do = 1;
47 0 $i++;
48 0 $next_token = undef;
49 }
50 elsif ($token_type == DO) {
51 0 $is_in_do = 1;
52 }
53 elsif ($token_type == IF_STATEMENT) {
54 0 $is_in_if = 1;
55 }
56 ▶ elsif ($token_type == MOD_WORD && $token_data eq 'BEGIN') {
Condition0%0/3
$token_type == 75 and $token_data eq "BEGIN"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 75 and $token_data eq "BEGIN"
$token_type == 75 $token_data eq "BEGIN"
Truth table0%0/3
A and B
A= $token_type == 75B= $token_data eq "BEGIN"
ABresult
0X0
100
111
57 0 $is_in_BEGIN = 1;
58 }
59 elsif ($token_type == LEFT_BRACE) {
60 0 $left_brace_num++;
61 }
62 elsif ($token_type == RIGHT_BRACE) {
63 0 ▶ if (--$left_brace_num == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$left_brace_num == 0) 0 0 0
64 0 my $next_token_type = $next_token->{type};
65 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($is_in_do and $next_token_type and $next_token_type eq 96 || $next_token_type eq 133 || $next_token_type eq 132 || $next_token_type eq 100 || $next_token_type eq 99 || $next_token_type eq 134) 0 0 0
Condition0%0/21
$is_in_do and $next_token_type and $next_token_type eq 96 || $next_token_type eq 133 || $next_token_type eq 132 || $next_token_type eq 100 || $next_token_type eq 99 || $next_token_type eq 134
!ll&&!rl&&r
000
$is_in_do and $next_token_type
!ll&&!rl&&r
000
$next_token_type eq 96 or $next_token_type eq 133 or $next_token_type eq 132 or $next_token_type eq 100 or $next_token_type eq 99 or $next_token_type eq 134
l!l&&r!l&&!r
000
$next_token_type eq 96 or $next_token_type eq 133 or $next_token_type eq 132 or $next_token_type eq 100 or $next_token_type eq 99
l!l&&r!l&&!r
000
$next_token_type eq 96 or $next_token_type eq 133 or $next_token_type eq 132 or $next_token_type eq 100
l!l&&r!l&&!r
000
$next_token_type eq 96 or $next_token_type eq 133 or $next_token_type eq 132
l!l&&r!l&&!r
000
$next_token_type eq 96 or $next_token_type eq 133
l!l&&r!l&&!r
000
MC/DC0%0/8
$is_in_do and $next_token_type and $next_token_type eq 96 || $next_token_type eq 133 || $next_token_type eq 132 || $next_token_type eq 100 || $next_token_type eq 99 || $next_token_type eq 134
$is_in_do $next_token_type $next_token_type eq 96 $next_token_type eq 133 $next_token_type eq 132 $next_token_type eq 100 $next_token_type eq 99 $next_token_type eq 134
Truth table0%0/9
A and B and C or D or E or F or G or H
A= $is_in_doB= $next_token_typeC= $next_token_type eq 96D= $next_token_type eq 133E= $next_token_type eq 132F= $next_token_type eq 100G= $next_token_type eq 99H= $next_token_type eq 134
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110000000
111XXXXX1
1101XXXX1
11001XXX1
110001XX1
1100001X1
110000011
66 $is_in_do && $next_token_type &&
67 (
68 $next_token_type eq IF_STATEMENT ||
69 $next_token_type eq FOR_STATEMENT ||
70 $next_token_type eq WHILE_STATEMENT ||
71 $next_token_type eq UNTIL_STATEMENT ||
72 $next_token_type eq UNLESS_STATEMENT ||
73 $next_token_type eq FOREACH_STATEMENT
74 )
75 ) {
76 0 ▶ push @violations, $previous_violation if $previous_violation;
Branch: 1 branch
BranchTrueFalseTotal
if $previous_violation 0 0 0
77 }
78 0 $is_in_cond = 0;
79 0 $is_in_BEGIN = 0;
80 0 $is_in_if = 0;
81 0 $is_in_do = 0;
82 0 $is_in_illegal_do = 0;
83 0 $previous_violation = undef;
84 }
85 }
86 ▶ elsif ($is_in_cond || $is_in_illegal_do || $is_in_do || ($is_in_BEGIN && $is_in_if)) {
Condition0%0/12
$is_in_cond or $is_in_illegal_do or $is_in_do or $is_in_BEGIN and $is_in_if
l!l&&r!l&&!r
000
$is_in_cond or $is_in_illegal_do or $is_in_do
l!l&&r!l&&!r
000
$is_in_cond or $is_in_illegal_do
l!l&&r!l&&!r
000
$is_in_BEGIN and $is_in_if
!ll&&!rl&&r
000
MC/DC0%0/5
$is_in_cond or $is_in_illegal_do or $is_in_do or $is_in_BEGIN and $is_in_if
$is_in_cond $is_in_illegal_do $is_in_do $is_in_BEGIN $is_in_if
Truth table0%0/6
A or B or C or D and E
A= $is_in_condB= $is_in_illegal_doC= $is_in_doD= $is_in_BEGINE= $is_in_if
ABCDEresult
1XXXX1
01XXX1
001XX1
000111
0000X0
000100
87 0 ▶ if ($token_type == USE_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 93) 0 0 0
88 0 my $next_token_type = $next_token->{type};
89 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token_type == 127 or $next_token_type == 94 and not is_perl_pragma($next_token->{"data"})) 0 0 0
Condition0%0/6
$next_token_type == 127 or $next_token_type == 94 and not is_perl_pragma($next_token->{"data"})
l!l&&r!l&&!r
000
$next_token_type == 94 and not is_perl_pragma($next_token->{"data"})
!ll&&!rl&&r
000
MC/DC0%0/3
$next_token_type == 127 or $next_token_type == 94 and not is_perl_pragma($next_token->{"data"})
$next_token_type == 127 $next_token_type == 94 not is_perl_pragma($next_token->{"data"})
Truth table0%0/4
A or B and not(C)
A= $next_token_type == 127B= $next_token_type == 94C= not is_perl_pragma($next_token->{"data"})
ABCresult
1XX1
0111
00X0
0100
90 $next_token_type == NAMESPACE ||
91 ($next_token_type == USED_NAME && !is_perl_pragma($next_token->{data}))
92 ) {
93 $previous_violation = {
94 filename => $file,
95 line => $token->{line},
96 0 description => DESC,
97 explanation => EXPL,
98 policy => __PACKAGE__,
99 };
100 0 ▶ if (!$is_in_do) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_in_do) 0 0 0
101 0 push @violations, $previous_violation;
102 }
103 }
104 }
105 }
106 }
107  
108 0 return \@violations;
109 }
110  
111 # TODO support post conditional notation
112  
113 2 1;
114  
« Perl/Lint/Policy/ValuesAndExpressions/ProhibitMismatchedOperators.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/ProhibitMagicNumbers.pm »