Perl/Lint/Policy/ValuesAndExpressions/ProhibitComplexVersion.pm

filter: Statementstmt 20.2% 16 / 79 Branchbran 0.0% 0 / 68 Conditioncond 0.0% 0 / 30 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 10.5% 21 / 200 CC 45 SCAR 75.3
CC
45
Cov
9%
evaluate
2070.0
BEGIN
1.0
BEGIN
1.0
CRAP 1863.1
« Perl/Lint/Policy/Variables/RequireLocalizedPunctuationVars.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/ProhibitMismatchedOperators.pm »
1 package Perl::Lint::Policy::ValuesAndExpressions::ProhibitComplexVersion;
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 parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 DESC => '$VERSION value should not come from outside module',
9 EXPL => 'If the version comes from outside the module, you can get everything from unexpected version changes to denial-of-service attacks.',
10 2 };
11  
12 0 ▶sub evaluate {
Subroutine evaluate: not called CC=45 SCAR=76.4
Pod undocumented
13 0 my ($class, $file, $tokens, $src, $args) = @_;
14  
15 0 my $forbid_use_version;
16 0 ▶ if (my $this_policies_arg = $args->{prohibit_complex_version}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $this_policies_arg = $args->{"prohibit_complex_version"}) 0 0 0
17 0 $forbid_use_version = $this_policies_arg->{forbid_use_version};
18 }
19  
20 0 my @violations;
21 0 ▶ for (my $i = 0, my $token_type, my $token_data; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
22 0 $token_type = $token->{type};
23 0 $token_data = $token->{data};
24  
25 0 ▶ if ($token_type == OUR_DECL) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 91) { } 0 0 0
elsif ($token_type == 94 and $token_data eq 'version') { } 0 0 0
26 0 $token = $tokens->[++$i];
27 0 $token_type = $token->{type};
28 0 $token_data = $token->{data};
29  
30 0 my $is_version_assigned = 0;
31  
32 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 166 || $token_type == 194 and $token_data eq '$VERSION') { } 0 0 0
33 0 my $left_paren_num = 1;
34 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
35 0 $token_type = $token->{type};
36 0 $token_data = $token->{data};
37 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
elsif ($token_type == 166 || $token_type == 194 and $token_data eq '$VERSION') { } 0 0 0
38 0 $left_paren_num++;
39 }
40 elsif ($token_type == RIGHT_PAREN) {
41 0 ▶ if (--$left_paren_num <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$left_paren_num <= 0) 0 0 0
42 0 last;
43 }
44 }
45 ▶ elsif (
Condition0%0/6
$token_type == 166 || $token_type == 194 and $token_data eq "\$VERSION"
!ll&&!rl&&r
000
$token_type == 166 or $token_type == 194
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 166 || $token_type == 194 and $token_data eq "\$VERSION"
$token_type == 166 $token_type == 194 $token_data eq "\$VERSION"
Truth table0%0/5
A or B and C
A= $token_type == 166B= $token_type == 194C= $token_data eq "\$VERSION"
ABCresult
00X0
1X00
0100
1X11
0111
46 ($token_type == VAR || $token_type == GLOBAL_VAR) &&
47 $token_data eq '$VERSION'
48 ) {
49 0 $is_version_assigned = 1;
50 }
51 }
52 }
53 ▶ elsif (
Condition0%0/6
$token_type == 166 || $token_type == 194 and $token_data eq "\$VERSION"
!ll&&!rl&&r
000
$token_type == 166 or $token_type == 194
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 166 || $token_type == 194 and $token_data eq "\$VERSION"
$token_type == 166 $token_type == 194 $token_data eq "\$VERSION"
Truth table0%0/5
A or B and C
A= $token_type == 166B= $token_type == 194C= $token_data eq "\$VERSION"
ABCresult
00X0
1X00
0100
1X11
0111
54 ($token_type == VAR || $token_type == GLOBAL_VAR) &&
55 $token_data eq '$VERSION'
56 ) {
57 0 $is_version_assigned = 1;
58 }
59  
60 0 ▶ if ($is_version_assigned) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_version_assigned) 0 0 0
61 0 $i++; # skip assign symbol
62  
63 0 $token = $tokens->[++$i];
64 0 $token_type = $token->{type};
65 0 $token_data = $token->{data};
66 0 ▶ if (
Branch: 6 branches
BranchTrueFalseTotal
if ($token_type == 166 or $token_type == 194) { } 0 0 0
elsif ($token_type == 172) { } 0 0 0
elsif ($token_type == 146) { } 0 0 0
elsif ($token_type == 127) { } 0 0 0
elsif ($token_type == 107) { } 0 0 0
elsif ($token_type == 87 or $token_type == 70 and $token_data eq 'eval') { } 0 0 0
Condition0%0/3
$token_type == 166 or $token_type == 194
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 166 or $token_type == 194
$token_type == 166 $token_type == 194
Truth table0%0/3
A or B
A= $token_type == 166B= $token_type == 194
ABresult
1X1
011
000
67 $token_type == VAR || $token_type == GLOBAL_VAR
68 ) {
69 0 my $next_token = $tokens->[$i+1];
70 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data ne "\$VERSION" and $token_data =~ /\A\$[A-Z0-9_]+\Z/ or $next_token->{"type"} == 126) 0 0 0
Condition0%0/6
$token_data ne "\$VERSION" and $token_data =~ /\A\$[A-Z0-9_]+\Z/ or $next_token->{"type"} == 126
l!l&&r!l&&!r
000
$token_data ne "\$VERSION" and $token_data =~ /\A\$[A-Z0-9_]+\Z/
!ll&&!rl&&r
000
MC/DC0%0/3
$token_data ne "\$VERSION" and $token_data =~ /\A\$[A-Z0-9_]+\Z/ or $next_token->{"type"} == 126
$token_data ne "\$VERSION" $token_data =~ /\A\$[A-Z0-9_]+\Z/ $next_token->{"type"} == 126
Truth table0%0/5
A and B or C
A= $token_data ne "\$VERSION"B= $token_data =~ /\A\$[A-Z0-9_]+\Z/C= $next_token->{"type"} == 126
ABCresult
11X1
0X11
1011
0X00
1000
71 ($token_data ne '$VERSION' && $token_data =~ /\A\$[A-Z0-9_]+\Z/) ||
72 $next_token->{type} == NAMESPACE_RESOLVER
73 ) {
74 push @violations, {
75 filename => $file,
76 line => $token->{line},
77 0 description => DESC,
78 explanation => EXPL,
79 policy => __PACKAGE__,
80 };
81 }
82 }
83 elsif ($token_type == STRING) {
84 0 ▶ if ($token_data =~ /\A\$(?:\S+::)+\S+\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data =~ /\A\$(?:\S+::)+\S+\Z/) 0 0 0
85 push @violations, {
86 filename => $file,
87 line => $token->{line},
88 0 description => DESC,
89 explanation => EXPL,
90 policy => __PACKAGE__,
91 };
92 }
93 }
94 elsif ($token_type == REG_DOUBLE_QUOTE) {
95 0 $i++; # skip reg delimiter
96 0 $token = $tokens->[++$i];
97 0 ▶ if ($token->{data} =~ /\A\$(?:\S+::)+\S+\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"data"} =~ /\A\$(?:\S+::)+\S+\Z/) 0 0 0
98 push @violations, {
99 filename => $file,
100 line => $token->{line},
101 0 description => DESC,
102 explanation => EXPL,
103 policy => __PACKAGE__,
104 };
105 }
106 }
107 elsif ($token_type == NAMESPACE) {
108 0 $token = $tokens->[++$i];
109 0 ▶ if ($token->{type} == NAMESPACE_RESOLVER) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 126) 0 0 0
110 push @violations, {
111 filename => $file,
112 line => $token->{line},
113 0 description => DESC,
114 explanation => EXPL,
115 policy => __PACKAGE__,
116 };
117 }
118 }
119 elsif ($token_type == LEFT_PAREN) {
120 0 my $left_paren_num = 1;
121 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
122 0 $token_type = $token->{type};
123 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
elsif ($token_type == 126) { } 0 0 0
124 0 $left_paren_num++;
125 }
126 elsif ($token_type == RIGHT_PAREN) {
127 0 ▶ if (--$left_paren_num <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$left_paren_num <= 0) 0 0 0
128 0 last;
129 }
130 }
131 elsif ($token_type == NAMESPACE_RESOLVER) {
132 push @violations, {
133 filename => $file,
134 line => $token->{line},
135 0 description => DESC,
136 explanation => EXPL,
137 policy => __PACKAGE__,
138 };
139 }
140 }
141 }
142 ▶ elsif ($token_type == DO || ($token_type == BUILTIN_FUNC && $token_data eq 'eval')) {
Condition0%0/6
$token_type == 87 or $token_type == 70 and $token_data eq "eval"
l!l&&r!l&&!r
000
$token_type == 70 and $token_data eq "eval"
!ll&&!rl&&r
000
MC/DC0%0/3
$token_type == 87 or $token_type == 70 and $token_data eq "eval"
$token_type == 87 $token_type == 70 $token_data eq "eval"
Truth table0%0/4
A or B and C
A= $token_type == 87B= $token_type == 70C= $token_data eq "eval"
ABCresult
1XX1
0111
00X0
0100
143 0 $token = $tokens->[++$i];
144 0 ▶ if ($token->{type} == LEFT_BRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 109) 0 0 0
145 0 my $left_brace_num = 1;
146 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
147 0 $token_type = $token->{type};
148 0 ▶ if ($token_type == LEFT_BRACE) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
elsif ($token_type == 126) { } 0 0 0
149 0 $left_brace_num++;
150 }
151 elsif ($token_type == RIGHT_BRACE) {
152 0 ▶ if (--$left_brace_num <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$left_brace_num <= 0) 0 0 0
153 0 last;
154 }
155 }
156 elsif ($token_type == NAMESPACE_RESOLVER) {
157 push @violations, {
158 filename => $file,
159 line => $token->{line},
160 0 description => DESC,
161 explanation => EXPL,
162 policy => __PACKAGE__,
163 };
164 }
165 }
166 }
167 }
168 }
169 }
170 ▶ elsif ($token_type == USED_NAME && $token_data eq 'version') {
Condition0%0/3
$token_type == 94 and $token_data eq "version"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 94 and $token_data eq "version"
$token_type == 94 $token_data eq "version"
Truth table0%0/3
A and B
A= $token_type == 94B= $token_data eq "version"
ABresult
0X0
100
111
171 0 ▶ if ($forbid_use_version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($forbid_use_version) 0 0 0
172 push @violations, {
173 filename => $file,
174 line => $token->{line},
175 0 description => DESC,
176 explanation => EXPL,
177 policy => __PACKAGE__,
178 };
179 }
180 }
181 }
182  
183 0 return \@violations;
184 }
185  
186 2 1;
187  
« Perl/Lint/Policy/Variables/RequireLocalizedPunctuationVars.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/ProhibitMismatchedOperators.pm »