Perl/Lint/Policy/RegularExpressions/ProhibitUnusedCapture.pm

filter: Statementstmt 6.1% 30 / 491 Branchbran 0.0% 0 / 388 Conditioncond 0.0% 0 / 145 MC/DCmcdc 0.0% 0 / 83 Subroutinesub 58.3% 7 / 12 Podpod 0.0% 0 / 1 totaltotal 3.3% 37 / 1120 CC 249 SCAR 105.6
CC
249
Cov
3%
evaluate
46440.0
_scan_regex
1260.0
__ANON__
2.0
CRAP 38572.0
↑ Summary Perl/Lint/Policy/ControlStructures/ProhibitMutatingListFunctions.pm »
1 package Perl::Lint::Policy::RegularExpressions::ProhibitUnusedCapture;
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 all/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Test::Deep::NoTest qw(eq_deeply);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 DESC => 'Only use a capturing group if you plan to use the captured value',
11 EXPL => [252],
12 2 };
13  
14 2 my %ignore_reg_op = (
15 &REG_LIST => 1,
16 &REG_EXEC => 1,
17 &REG_QUOTE => 1,
18 );
19  
20 2 my @captured_for_each_scope;
21 my $sub_depth;
22 2 my @violations;
23 2 my $file;
24 2 my $tokens;
25 2 my $just_before_regex_token;
26 2 my $reg_not_ctx;
27 2 my $assign_ctx;
28  
29 0 ▶sub evaluate {
Subroutine evaluate: not called CC=215 SCAR=107.5
Pod undocumented
30 0 my $class = shift;
31 0 $file = shift;
32 0 $tokens = shift;
33 0 my ($src, $args) = @_;
34  
35 0 my $is_used_english = 0;
36  
37 0 @violations = ();
38 0 @captured_for_each_scope = ({});
39 0 $just_before_regex_token = undef;
40 0 $assign_ctx = 'NONE';
41 0 $reg_not_ctx = 0;
42  
43 0 my %depth_for_each_subs;
44 0 my $lbnum_for_scope = 0;
45 0 $sub_depth = 0;
46  
47 0 ▶ TOP: 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
48 0 $token_type = $token->{type};
49 0 $token_data = $token->{data};
50  
51 0 ▶ if ($token_type == USED_NAME && $token_data eq 'English') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 94 and $token_data eq "English") 0 0 0
Condition0%0/3
$token_type == 94 and $token_data eq "English"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 94 and $token_data eq "English"
$token_type == 94 $token_data eq "English"
Truth table0%0/3
A and B
A= $token_type == 94B= $token_data eq "English"
ABresult
0X0
100
111
52 0 $is_used_english = 1;
53 0 next;
54 }
55  
56 # to ignore regexp which is not pattern matching
57 # NOTE: Compiler::Lexer handles all of the content of q*{} operator as regexp token
58 0 ▶ if ($ignore_reg_op{$token_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ignore_reg_op{$token_type}) 0 0 0
59 0 $i += 2; # skip content
60 0 next;
61 }
62  
63 0 ▶ if ($token_type == ASSIGN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 65) 0 0 0
64 0 ▶ $token = $tokens->[$i-1] or next;
Branch: 1 branch
BranchTrueFalseTotal
$token = $$tokens[$i - 1] or next 0 0 0
65 0 $token_type = $token->{type};
66  
67 0 $assign_ctx = 'ANY'; # XXX Any!?
68  
69 0 ▶ if (
Branch: 4 branches
BranchTrueFalseTotal
if ($token_type == 194 or $token_type == 191 or $token_type == 166) { } 0 0 0
elsif ($token_type == 195 or $token_type == 192 or $token_type == 168) { } 0 0 0
elsif ($token_type == 196 or $token_type == 193 or $token_type == 169) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
Condition0%0/6
$token_type == 194 or $token_type == 191 or $token_type == 166
l!l&&r!l&&!r
000
$token_type == 194 or $token_type == 191
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 194 or $token_type == 191 or $token_type == 166
$token_type == 194 $token_type == 191 $token_type == 166
Truth table0%0/4
A or B or C
A= $token_type == 194B= $token_type == 191C= $token_type == 166
ABCresult
1XX1
01X1
0011
0000
70 $token_type == GLOBAL_VAR ||
71 $token_type == LOCAL_VAR ||
72 $token_type == VAR
73 ) {
74 0 $assign_ctx = 'SUCCESS';
75 }
76 ▶ elsif (
Condition0%0/6
$token_type == 195 or $token_type == 192 or $token_type == 168
l!l&&r!l&&!r
000
$token_type == 195 or $token_type == 192
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 195 or $token_type == 192 or $token_type == 168
$token_type == 195 $token_type == 192 $token_type == 168
Truth table0%0/4
A or B or C
A= $token_type == 195B= $token_type == 192C= $token_type == 168
ABCresult
1XX1
01X1
0011
0000
77 $token_type == GLOBAL_ARRAY_VAR ||
78 $token_type == LOCAL_ARRAY_VAR ||
79 $token_type == ARRAY_VAR
80 ) {
81 0 $assign_ctx = 'UNLIMITED_ARRAY';
82 }
83 ▶ elsif (
Condition0%0/6
$token_type == 196 or $token_type == 193 or $token_type == 169
l!l&&r!l&&!r
000
$token_type == 196 or $token_type == 193
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 196 or $token_type == 193 or $token_type == 169
$token_type == 196 $token_type == 193 $token_type == 169
Truth table0%0/4
A or B or C
A= $token_type == 196B= $token_type == 193C= $token_type == 169
ABCresult
1XX1
01X1
0011
0000
84 $token_type == GLOBAL_HASH_VAR ||
85 $token_type == LOCAL_HASH_VAR ||
86 $token_type == HASH_VAR
87 ) {
88 0 $assign_ctx = 'UNLIMITED';
89 }
90 elsif ($token_type == RIGHT_PAREN) {
91 0 $assign_ctx = 'LIMITED';
92  
93 0 ▶ $token = $tokens->[$i-2] or next;
Branch: 1 branch
BranchTrueFalseTotal
$token = $$tokens[$i - 2] or next 0 0 0
94 0 $token_type = $token->{type};
95 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 207) { } 0 0 0
96 0 $assign_ctx = 'UNLIMITED';
97 }
98 elsif ($token_type == DEFAULT) {
99 0 ▶ $token = $tokens->[$i-3] or next;
Branch: 1 branch
BranchTrueFalseTotal
$token = $$tokens[$i - 3] or next 0 0 0
100 0 $token_type = $token->{type};
101 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 107) 0 0 0
102 0 $assign_ctx = 'UNLIMITED';
103 }
104 }
105 }
106  
107 0 ▶ $token = $tokens->[$i+1] or next;
Branch: 1 branch
BranchTrueFalseTotal
$token = $$tokens[$i + 1] or next 0 0 0
108 0 $token_type = $token->{type};
109 0 ▶ if ($token_type == LEFT_BRACE || $token_type == LEFT_BRACKET) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 109 or $token_type == 111) 0 0 0
Condition0%0/3
$token_type == 109 or $token_type == 111
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 109 or $token_type == 111
$token_type == 109 $token_type == 111
Truth table0%0/3
A or B
A= $token_type == 109B= $token_type == 111
ABresult
1X1
011
000
110 0 $assign_ctx = 'UNLIMITED';
111 }
112  
113 0 next;
114 }
115  
116 0 ▶ if ($token_type == SEMI_COLON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 106) 0 0 0
117 0 $assign_ctx = 'NONE';
118 0 next;
119 }
120  
121 0 ▶ if ($token_type == REG_NOT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 36) 0 0 0
122 0 $reg_not_ctx = 1;
123 0 next;
124 }
125  
126 0 ▶ if ($token_type == REG_DOUBLE_QUOTE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 146) 0 0 0
127 0 $i += 2; # jump to string
128 0 $token = $tokens->[$i];
129 0 $token_type = STRING; # XXX Violence!!
130 # fall through
131 }
132 0 ▶ if ($token_type == STRING || $token_type == HERE_DOCUMENT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 172 or $token_type == 181) 0 0 0
Condition0%0/3
$token_type == 172 or $token_type == 181
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 172 or $token_type == 181
$token_type == 172 $token_type == 181
Truth table0%0/3
A or B
A= $token_type == 172B= $token_type == 181
ABresult
1X1
011
000
133 0 my @chars = split //, $token_data;
134 0 my $is_var = 0;
135 0 my $escaped = 0;
136 0 ▶ for (my $j = 0; my $char = $chars[$j]; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $char = $chars[$j]) 0 0 0
137 0 ▶ if ($escaped) {
Branch: 1 branch
BranchTrueFalseTotal
if ($escaped) 0 0 0
138 0 ▶ if ($char =~ /[0-9]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /[0-9]/) 0 0 0
139 # TODO should track follows number
140 0 delete $captured_for_each_scope[$sub_depth]->{q<$> . $char};
141 }
142 0 $escaped = 0;
143 0 next;
144 }
145  
146 0 ▶ if ($is_var) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_var) 0 0 0
147 0 ▶ if ($char =~ /[a-zA-Z_]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /[a-zA-Z_]/) 0 0 0
148 0 my $var_name = $char;
149 0 ▶ for ($j++; $char = $chars[$j]; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char = $chars[$j]) 0 0 0
150 0 ▶ if ($char !~ /[0-9a-zA-Z_]/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($char =~ /[0-9a-zA-Z_]/) 0 0 0
151 0 $j--;
152 0 last;
153 }
154 0 $var_name .= $char;
155 }
156  
157 0 ▶ if (!$is_used_english) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $is_used_english) { } 0 0 0
elsif ($var_name eq 'LAST_PAREN_MATCH' or $var_name eq 'LAST_MATCH_END' or $var_name eq 'LAST_MATCH_START') { } 0 0 0
158 0 next;
159 }
160 ▶ elsif (
Condition0%0/6
$var_name eq "LAST_PAREN_MATCH" or $var_name eq "LAST_MATCH_END" or $var_name eq "LAST_MATCH_START"
l!l&&r!l&&!r
000
$var_name eq "LAST_PAREN_MATCH" or $var_name eq "LAST_MATCH_END"
l!l&&r!l&&!r
000
MC/DC0%0/3
$var_name eq "LAST_PAREN_MATCH" or $var_name eq "LAST_MATCH_END" or $var_name eq "LAST_MATCH_START"
$var_name eq "LAST_PAREN_MATCH" $var_name eq "LAST_MATCH_END" $var_name eq "LAST_MATCH_START"
Truth table0%0/4
A or B or C
A= $var_name eq "LAST_PAREN_MATCH"B= $var_name eq "LAST_MATCH_END"C= $var_name eq "LAST_MATCH_START"
ABCresult
1XX1
01X1
0011
0000
161 $var_name eq 'LAST_PAREN_MATCH' ||
162 $var_name eq 'LAST_MATCH_END' ||
163 $var_name eq 'LAST_MATCH_START'
164 ) {
165 0 $char = '+'; # XXX
166 }
167 else {
168 0 next;
169 }
170 }
171  
172 0 ▶ if ($char eq '{') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "{") 0 0 0
173 0 my $var_name = '';
174 0 ▶ for ($j++; $char = $chars[$j]; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char = $chars[$j]) 0 0 0
175 0 ▶ if ($char eq '}') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq '}') { } 0 0 0
176 0 last;
177 }
178 else {
179 0 $var_name .= $char;
180 }
181 }
182 0 delete $captured_for_each_scope[$sub_depth]->{q<$> . $var_name};
183 0 next;
184 }
185  
186 0 ▶ if ($char =~ /[0-9]/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($char =~ /[0-9]/) { } 0 0 0
elsif ($char eq '+' or $char eq '-') { } 0 0 0
187 # TODO should track follows number
188 0 delete $captured_for_each_scope[$sub_depth]->{q<$> . $char};
189 }
190 ▶ elsif (
Condition0%0/3
$char eq "+" or $char eq "-"
l!l&&r!l&&!r
000
MC/DC0%0/2
$char eq "+" or $char eq "-"
$char eq "+" $char eq "-"
Truth table0%0/3
A or B
A= $char eq "+"B= $char eq "-"
ABresult
1X1
011
000
191 $char eq '+' || $char eq '-'
192 ) {
193 0 my $lbnum = 1;
194 0 my $captured_name = '';
195  
196 0 my $begin_delimiter = '{';
197 0 my $end_delimiter = '}';
198 0 ▶ $char = $chars[++$j] or next;
Branch: 1 branch
BranchTrueFalseTotal
$char = $chars[++$j] or next 0 0 0
199 0 ▶ if ($char eq '[') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "[") 0 0 0
200 0 $begin_delimiter = '[';
201 0 $end_delimiter = ']';
202 }
203  
204 0 ▶ for ($j++; $char = $chars[$j]; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char = $chars[$j]) 0 0 0
205 0 ▶ if ($char eq $begin_delimiter) {
Branch: 3 branches
BranchTrueFalseTotal
if ($char eq $begin_delimiter) { } 0 0 0
elsif ($char eq $end_delimiter) { } 0 0 0
elsif ($char ne ' ') { } 0 0 0
206 0 $lbnum++;
207 }
208 elsif ($char eq $end_delimiter) {
209 0 ▶ last if --$lbnum <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$lbnum <= 0 0 0 0
210 }
211 elsif ($char ne ' ') {
212 0 $captured_name .= $char;
213 }
214 }
215  
216 0 ▶ if ($begin_delimiter eq '[') {
Branch: 1 branch
BranchTrueFalseTotal
if ($begin_delimiter eq '[') { } 0 0 0
217 0 ▶ $captured_name-- if $captured_name > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $captured_name > 0 0 0 0
218  
219 0 my @num_vars = sort {$a cmp $b} grep { $_ =~ /\A\$[0-9]+\Z/} keys %{$captured_for_each_scope[$sub_depth]};
220  
221 0 ▶ if (my $hit = $num_vars[$captured_name]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hit = $num_vars[$captured_name]) 0 0 0
222 0 delete $captured_for_each_scope[$sub_depth]->{$hit};
223 }
224 }
225 else {
226 0 delete $captured_for_each_scope[$sub_depth]->{$captured_name};
227 }
228 }
229  
230 0 $is_var = 0;
231 0 next;
232 }
233  
234 0 ▶ if ($char eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "\\") 0 0 0
235 0 $escaped = 1;
236 0 next;
237 }
238  
239 0 ▶ if ($char eq q<$>) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "\$") 0 0 0
240 0 $is_var = 1;
241 0 next;
242 }
243 }
244 0 next;
245 }
246  
247 0 ▶ if ($token_type == REG_REPLACE_TO) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 157) 0 0 0
248 0 my $escaped = 0;
249 0 my $is_var = 0;
250 0 my @re_chars = split //, $token_data;
251 0 ▶ for (my $j = 0; my $re_char = $re_chars[$j]; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $re_char = $re_chars[$j]) 0 0 0
252 0 ▶ if ($escaped) {
Branch: 1 branch
BranchTrueFalseTotal
if ($escaped) 0 0 0
253 0 ▶ if ($re_char =~ /[0-9]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char =~ /[0-9]/) 0 0 0
254 # TODO should track follows number
255 0 delete $captured_for_each_scope[$sub_depth]->{q<$> . $re_char};
256 }
257 0 $escaped = 0;
258 0 next;
259 }
260  
261 0 ▶ if ($is_var) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_var) 0 0 0
262 0 ▶ if ($re_char =~ /[a-zA-Z_]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char =~ /[a-zA-Z_]/) 0 0 0
263 0 my $var_name = $re_char;
264 0 ▶ for ($j++; $re_char = $re_chars[$j]; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char = $re_chars[$j]) 0 0 0
265 0 ▶ if ($re_char !~ /[0-9a-zA-Z_]/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($re_char =~ /[0-9a-zA-Z_]/) 0 0 0
266 0 $j--;
267 0 last;
268 }
269 0 $var_name .= $re_char;
270 }
271  
272 0 ▶ if (!$is_used_english) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $is_used_english) { } 0 0 0
elsif ($var_name eq 'LAST_PAREN_MATCH' or $var_name eq 'LAST_MATCH_END' or $var_name eq 'LAST_MATCH_START') { } 0 0 0
273 0 next;
274 }
275 ▶ elsif (
Condition0%0/6
$var_name eq "LAST_PAREN_MATCH" or $var_name eq "LAST_MATCH_END" or $var_name eq "LAST_MATCH_START"
l!l&&r!l&&!r
000
$var_name eq "LAST_PAREN_MATCH" or $var_name eq "LAST_MATCH_END"
l!l&&r!l&&!r
000
MC/DC0%0/3
$var_name eq "LAST_PAREN_MATCH" or $var_name eq "LAST_MATCH_END" or $var_name eq "LAST_MATCH_START"
$var_name eq "LAST_PAREN_MATCH" $var_name eq "LAST_MATCH_END" $var_name eq "LAST_MATCH_START"
Truth table0%0/4
A or B or C
A= $var_name eq "LAST_PAREN_MATCH"B= $var_name eq "LAST_MATCH_END"C= $var_name eq "LAST_MATCH_START"
ABCresult
1XX1
01X1
0011
0000
276 $var_name eq 'LAST_PAREN_MATCH' ||
277 $var_name eq 'LAST_MATCH_END' ||
278 $var_name eq 'LAST_MATCH_START'
279 ) {
280 0 $re_char = '+'; # XXX
281 }
282 else {
283 0 next;
284 }
285 }
286  
287 0 ▶ if ($re_char eq '{') {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char eq "{") 0 0 0
288 0 my $var_name = '';
289 0 ▶ for ($j++; $re_char = $re_chars[$j]; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char = $re_chars[$j]) 0 0 0
290 0 ▶ if ($re_char eq '}') {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char eq '}') { } 0 0 0
291 0 last;
292 }
293 else {
294 0 $var_name .= $re_char;
295 }
296 }
297 0 delete $captured_for_each_scope[$sub_depth]->{q<$> . $var_name};
298 0 next;
299 }
300  
301 0 ▶ if ($re_char =~ /[0-9]/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($re_char =~ /[0-9]/) { } 0 0 0
elsif ($re_char eq '+' or $re_char eq '-') { } 0 0 0
302 # TODO should track follows number
303 0 delete $captured_for_each_scope[$sub_depth]->{q<$> . $re_char};
304 }
305 ▶ elsif (
Condition0%0/3
$re_char eq "+" or $re_char eq "-"
l!l&&r!l&&!r
000
MC/DC0%0/2
$re_char eq "+" or $re_char eq "-"
$re_char eq "+" $re_char eq "-"
Truth table0%0/3
A or B
A= $re_char eq "+"B= $re_char eq "-"
ABresult
1X1
011
000
306 $re_char eq '+' || $re_char eq '-'
307 ) {
308 0 my $lbnum = 1;
309 0 my $captured_name = '';
310  
311 0 my $begin_delimiter = '{';
312 0 my $end_delimiter = '}';
313 0 ▶ $re_char = $re_chars[++$j] or next;
Branch: 1 branch
BranchTrueFalseTotal
$re_char = $re_chars[++$j] or next 0 0 0
314 0 ▶ if ($re_char eq '[') {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char eq "[") 0 0 0
315 0 $begin_delimiter = '[';
316 0 $end_delimiter = ']';
317 }
318  
319 0 ▶ for (; $re_char = $re_chars[$j]; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char = $re_chars[$j]) 0 0 0
320 0 ▶ if ($re_char eq $begin_delimiter) {
Branch: 3 branches
BranchTrueFalseTotal
if ($re_char eq $begin_delimiter) { } 0 0 0
elsif ($re_char eq $end_delimiter) { } 0 0 0
elsif ($re_char ne ' ') { } 0 0 0
321 0 $lbnum++;
322 }
323 elsif ($re_char eq $end_delimiter) {
324 0 ▶ last if --$lbnum <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$lbnum <= 0 0 0 0
325 }
326 elsif ($re_char ne ' ') {
327 0 $captured_name .= $re_char;
328 }
329 }
330  
331 0 ▶ if ($begin_delimiter eq '[') {
Branch: 1 branch
BranchTrueFalseTotal
if ($begin_delimiter eq '[') { } 0 0 0
332 0 ▶ $captured_name-- if $captured_name > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $captured_name > 0 0 0 0
333  
334 0 my @num_vars = sort {$a cmp $b} grep { $_ =~ /\A\$[0-9]+\Z/} keys %{$captured_for_each_scope[$sub_depth]};
335  
336 0 ▶ if (my $hit = $num_vars[$captured_name]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hit = $num_vars[$captured_name]) 0 0 0
337 0 delete $captured_for_each_scope[$sub_depth]->{$hit};
338 }
339 }
340 else {
341 0 delete $captured_for_each_scope[$sub_depth]->{$captured_name};
342 }
343 }
344  
345 0 $is_var = 0;
346 0 next;
347 }
348  
349 0 ▶ if ($re_char eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char eq "\\") 0 0 0
350 0 $escaped = 1;
351 0 next;
352 }
353  
354 0 ▶ if ($re_char eq q<$>) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char eq "\$") 0 0 0
355 0 $is_var = 1;
356 0 next;
357 }
358 }
359  
360 0 next;
361 }
362  
363 0 ▶ if ($token_type == REG_EXP || $token_type == REG_REPLACE_FROM) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 187 or $token_type == 156) 0 0 0
Condition0%0/3
$token_type == 187 or $token_type == 156
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 187 or $token_type == 156
$token_type == 187 $token_type == 156
Truth table0%0/3
A or B
A= $token_type == 187B= $token_type == 156
ABresult
1X1
011
000
364 0 ▶ if (defined $captured_for_each_scope[$sub_depth] && %{$captured_for_each_scope[$sub_depth]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $captured_for_each_scope[$sub_depth] and %{$captured_for_each_scope[$sub_depth];}) 0 0 0
Condition0%0/3
defined $captured_for_each_scope[$sub_depth] and %{$captured_for_each_scope[$sub_depth];}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $captured_for_each_scope[$sub_depth] and %{$captured_for_each_scope[$sub_depth];}
defined $captured_for_each_scope[$sub_depth] %{$captured_for_each_scope[$sub_depth];}
Truth table0%0/3
A and B
A= defined $captured_for_each_scope[$sub_depth]B= %{$captured_for_each_scope[$sub_depth];}
ABresult
0X0
100
111
365 push @violations, {
366 filename => $file,
367 line => $just_before_regex_token->{line},
368 0 description => DESC,
369 explanation => EXPL,
370 policy => __PACKAGE__,
371 };
372 }
373  
374 0 $captured_for_each_scope[$sub_depth] = {};
375 0 $just_before_regex_token = $token;
376  
377 0 my @re_chars = split //, $token_data;
378  
379 0 my $escaped = 0;
380 0 my $lbnum = 0;
381 0 my $captured_num = 0;
382 0 ▶ for (my $j = 0; my $re_char = $re_chars[$j]; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $re_char = $re_chars[$j]) 0 0 0
383 0 ▶ if ($escaped) {
Branch: 1 branch
BranchTrueFalseTotal
if ($escaped) 0 0 0
384 0 ▶ if ($re_char =~ /[0-9]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char =~ /[0-9]/) 0 0 0
385 # TODO should track follows number
386 0 delete $captured_for_each_scope[$sub_depth]->{q<$> . $re_char};
387 }
388 0 $escaped = 0;
389 0 next;
390 }
391  
392 0 ▶ if ($re_char eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char eq "\\") 0 0 0
393 0 $escaped = 1;
394 0 next;
395 }
396  
397 0 ▶ if ($re_char eq '[') {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char eq "[") 0 0 0
398 0 $lbnum++;
399 0 next;
400 }
401  
402 0 ▶ if ($lbnum > 0) { # in [...]
Branch: 1 branch
BranchTrueFalseTotal
if ($lbnum > 0) 0 0 0
403 0 ▶ if ($re_char eq ']') {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char eq "]") 0 0 0
404 0 $lbnum--;
405 0 next;
406 }
407  
408 0 next;
409 }
410  
411 0 ▶ if ($re_char eq '(') {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char eq "(") 0 0 0
412 0 my $captured_name = '';
413  
414 0 ▶ if ($re_chars[$j+1] eq '?') {
Branch: 2 branches
BranchTrueFalseTotal
if ($re_chars[$j + 1] eq '?') { } 0 0 0
elsif ($re_chars[$j + 1] ne '?' or $re_chars[$j + 2] ne ':') { } 0 0 0
415 0 my $delimiter = $re_chars[$j+2];
416  
417 0 ▶ if ($delimiter eq ':') {
Branch: 1 branch
BranchTrueFalseTotal
if ($delimiter eq ":") 0 0 0
418 0 next;
419 }
420  
421 0 ▶ if ($delimiter eq 'P') {
Branch: 1 branch
BranchTrueFalseTotal
if ($delimiter eq "P") 0 0 0
422 0 $delimiter = $re_chars[$j+3];
423 0 $j++;
424 }
425  
426 0 ▶ if ($delimiter eq '<' || $delimiter eq q{'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delimiter eq "<" or $delimiter eq "'") 0 0 0
Condition0%0/3
$delimiter eq "<" or $delimiter eq "'"
l!l&&r!l&&!r
000
MC/DC0%0/2
$delimiter eq "<" or $delimiter eq "'"
$delimiter eq "<" $delimiter eq "'"
Truth table0%0/3
A or B
A= $delimiter eq "<"B= $delimiter eq "'"
ABresult
1X1
011
000
427 0 ▶ for ($j += 3; $re_char = $re_chars[$j]; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char = $re_chars[$j]) 0 0 0
428 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($delimiter eq "<" and $re_char eq ">" or $delimiter eq "'" and $re_char eq "'") 0 0 0
Condition0%0/9
$delimiter eq "<" and $re_char eq ">" or $delimiter eq "'" and $re_char eq "'"
l!l&&r!l&&!r
000
$delimiter eq "<" and $re_char eq ">"
!ll&&!rl&&r
000
$delimiter eq "'" and $re_char eq "'"
!ll&&!rl&&r
000
MC/DC0%0/4
$delimiter eq "<" and $re_char eq ">" or $delimiter eq "'" and $re_char eq "'"
$delimiter eq "<" $re_char eq ">" $delimiter eq "'" $re_char eq "'"
Truth table0%0/7
A and B or C and D
A= $delimiter eq "<"B= $re_char eq ">"C= $delimiter eq "'"D= $re_char eq "'"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
429 ($delimiter eq '<' && $re_char eq '>') ||
430 ($delimiter eq q{'} && $re_char eq q{'})
431 ) {
432 0 last;
433 }
434 0 $captured_name .= $re_char;
435 }
436  
437  
438 0 ▶ if ($reg_not_ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reg_not_ctx) { } 0 0 0
439 push @violations, {
440 filename => $file,
441 line => $token->{line},
442 0 description => DESC,
443 explanation => EXPL,
444 policy => __PACKAGE__,
445 };
446 }
447 else {
448 0 $captured_num++;
449 0 $captured_for_each_scope[$sub_depth]->{$captured_name} = 1;
450 }
451 }
452 }
453 ▶ elsif ($re_chars[$j+1] ne '?' || $re_chars[$j+2] ne ':') {
Condition0%0/3
$re_chars[$j + 1] ne "?" or $re_chars[$j + 2] ne ":"
l!l&&r!l&&!r
000
MC/DC0%0/2
$re_chars[$j + 1] ne "?" or $re_chars[$j + 2] ne ":"
$re_chars[$j + 1] ne "?" $re_chars[$j + 2] ne ":"
Truth table0%0/3
A or B
A= $re_chars[$j + 1] ne "?"B= $re_chars[$j + 2] ne ":"
ABresult
1X1
011
000
454 0 ▶ if ($reg_not_ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reg_not_ctx) { } 0 0 0
455 push @violations, {
456 filename => $file,
457 line => $token->{line},
458 0 description => DESC,
459 explanation => EXPL,
460 policy => __PACKAGE__,
461 };
462 }
463 else {
464 0 $captured_num++;
465 0 $captured_for_each_scope[$sub_depth]->{q<$> . $captured_num} = 1;
466 }
467 }
468 }
469 }
470  
471 0 ▶ if ($assign_ctx ne 'NONE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($assign_ctx ne "NONE") 0 0 0
472 0 my $captured = $captured_for_each_scope[$sub_depth];
473  
474 0 ▶ if ($assign_ctx eq 'UNLIMITED_ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($assign_ctx eq "UNLIMITED_ARRAY") 0 0 0
475 0 ▶ if (%{$captured || {}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$captured or {};}) 0 0 0
Condition0%0/2
$captured || {}
l!l
00
MC/DC0%0/1
$captured || {}
$captured
Truth table0%0/2
A
A= $captured
Aresult
11
00
476 0 ▶ if (all {substr($_, 0, 1) eq q<$> } keys %$captured) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&all(sub { substr($_, 0, 1) eq "\$"; } , keys %$captured)) 0 0 0
477 0 $captured_for_each_scope[$sub_depth] = {};
478 }
479 }
480 0 next;
481 }
482  
483 0 $captured_for_each_scope[$sub_depth] = {};
484  
485 0 ▶ my $maybe_reg_opt = $tokens->[$i+2] or next;
Branch: 1 branch
BranchTrueFalseTotal
my $maybe_reg_opt = $$tokens[$i + 2] or next 0 0 0
486 0 ▶ if ($maybe_reg_opt->{type} == REG_OPT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($maybe_reg_opt->{"type"} == 144) 0 0 0
487 0 ▶ if ($assign_ctx ne 'UNLIMITED' && $maybe_reg_opt->{data} =~ /g/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($assign_ctx ne "UNLIMITED" and $maybe_reg_opt->{"data"} =~ /g/) 0 0 0
Condition0%0/3
$assign_ctx ne "UNLIMITED" and $maybe_reg_opt->{"data"} =~ /g/
!ll&&!rl&&r
000
MC/DC0%0/2
$assign_ctx ne "UNLIMITED" and $maybe_reg_opt->{"data"} =~ /g/
$assign_ctx ne "UNLIMITED" $maybe_reg_opt->{"data"} =~ /g/
Truth table0%0/3
A and B
A= $assign_ctx ne "UNLIMITED"B= $maybe_reg_opt->{"data"} =~ /g/
ABresult
0X0
100
111
488 push @violations, {
489 filename => $file,
490 line => $token->{line},
491 0 description => DESC,
492 explanation => EXPL,
493 policy => __PACKAGE__,
494 };
495 }
496 }
497  
498 0 next;
499 }
500  
501 0 $reg_not_ctx = 0;
502  
503 0 next;
504 }
505  
506 0 ▶ if ($token_type == BUILTIN_FUNC) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 70) 0 0 0
507 0 ▶ if ($token_data eq 'grep' || $token_data eq 'map') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data eq "grep" or $token_data eq "map") 0 0 0
Condition0%0/3
$token_data eq "grep" or $token_data eq "map"
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_data eq "grep" or $token_data eq "map"
$token_data eq "grep" $token_data eq "map"
Truth table0%0/3
A or B
A= $token_data eq "grep"B= $token_data eq "map"
ABresult
1X1
011
000
508 0 ▶ $token = $tokens->[++$i] or last;
Branch: 1 branch
BranchTrueFalseTotal
$token = $$tokens[++$i] or last 0 0 0
509 0 $token_type = $token->{type};
510  
511 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
512 0 my $lpnum = 1;
513 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
514 0 $token_type = $token->{type};
515 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
516 0 $lpnum++;
517 }
518 elsif ($token_type == RIGHT_PAREN) {
519 0 ▶ last if --$lpnum <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$lpnum <= 0 0 0 0
520 }
521 }
522 }
523 else {
524 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
525 0 ▶ if ($token->{type} == SEMI_COLON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 106) 0 0 0
526 0 last;
527 }
528 }
529 }
530  
531 0 next;
532 }
533 }
534  
535 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 70 or $token_type == 64 or $token_type == 122) 0 0 0
Condition0%0/6
$token_type == 70 or $token_type == 64 or $token_type == 122
l!l&&r!l&&!r
000
$token_type == 70 or $token_type == 64
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 70 or $token_type == 64 or $token_type == 122
$token_type == 70 $token_type == 64 $token_type == 122
Truth table0%0/4
A or B or C
A= $token_type == 70B= $token_type == 64C= $token_type == 122
ABCresult
1XX1
01X1
0011
0000
536 $token_type == BUILTIN_FUNC ||
537 $token_type == METHOD ||
538 $token_type == KEY
539 ) {
540 0 my $j = $i + 1;
541 0 ▶ $token = $tokens->[$j] or last;
Branch: 1 branch
BranchTrueFalseTotal
$token = $tokens->[$j] or last 0 0 0
542 0 $token_type = $token->{type};
543 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
544 0 my $lpnum = 1;
545 0 ▶ for ($j++; $token = $tokens->[$j]; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$j]) 0 0 0
546 0 $token_type = $token->{type};
547 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 == 187) { } 0 0 0
548 0 $lpnum++;
549 }
550 elsif ($token_type == RIGHT_PAREN) {
551 0 ▶ last if --$lpnum <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$lpnum <= 0 0 0 0
552 }
553 elsif ($token_type == REG_EXP) {
554 0 $token->{type} = -1; # XXX Replace to NOP
555 }
556 }
557 }
558 else {
559 0 ▶ for (my $j = $i + 1; $token = $tokens->[$j]; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$j]) 0 0 0
560 0 $token_type = $token->{type};
561 0 ▶ if ($token_type == SEMI_COLON) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 106) { } 0 0 0
elsif ($token_type == 187) { } 0 0 0
562 0 last;
563 }
564 elsif ($token_type == REG_EXP) {
565 0 $token->{type} = -1; # XXX Replace to NOP
566 }
567 }
568 }
569  
570 0 next;
571 }
572  
573 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 96 or $token_type == 98 or $token_type == 99) 0 0 0
Condition0%0/6
$token_type == 96 or $token_type == 98 or $token_type == 99
l!l&&r!l&&!r
000
$token_type == 96 or $token_type == 98
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 96 or $token_type == 98 or $token_type == 99
$token_type == 96 $token_type == 98 $token_type == 99
Truth table0%0/4
A or B or C
A= $token_type == 96B= $token_type == 98C= $token_type == 99
ABCresult
1XX1
01X1
0011
0000
574 $token_type == IF_STATEMENT ||
575 $token_type == ELSIF_STATEMENT ||
576 $token_type == UNLESS_STATEMENT
577 ) {
578 0 ▶ $token = $tokens->[++$i] or next;
Branch: 1 branch
BranchTrueFalseTotal
$token = $$tokens[++$i] or next 0 0 0
579  
580 0 my @regexs_at_before_and_op;
581 my @regexs_at_after_and_op;
582 0 my $and_op_token;
583  
584 0 ▶ if ($token->{type} eq LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{'type'} eq 107) { } 0 0 0
585 0 my $lpnum = 1;
586 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
587 0 $token_type = $token->{type};
588 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 5 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
elsif ($token_type == 187) { } 0 0 0
elsif ($token_type == 52 or $token_type == 16) { } 0 0 0
elsif ($ignore_reg_op{$token_type} or $token_type == 146) { } 0 0 0
589 0 $lpnum++;
590 }
591 elsif ($token_type == RIGHT_PAREN) {
592 0 ▶ last if --$lpnum <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$lpnum <= 0 0 0 0
593 }
594 elsif ($token_type == REG_EXP) {
595 0 ▶ if ($and_op_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($and_op_token) { } 0 0 0
596 0 push @regexs_at_after_and_op, $token;
597 }
598 else {
599 0 push @regexs_at_before_and_op, $token;
600 }
601 }
602 ▶ elsif ($token_type == AND || $token_type == ALPHABET_AND) {
Condition0%0/3
$token_type == 52 or $token_type == 16
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 52 or $token_type == 16
$token_type == 52 $token_type == 16
Truth table0%0/3
A or B
A= $token_type == 52B= $token_type == 16
ABresult
1X1
011
000
603 0 $and_op_token = $token;
604 }
605 ▶ elsif ($ignore_reg_op{$token_type} || $token_type == REG_DOUBLE_QUOTE) { # XXX
Condition0%0/3
$ignore_reg_op{$token_type} or $token_type == 146
l!l&&r!l&&!r
000
MC/DC0%0/2
$ignore_reg_op{$token_type} or $token_type == 146
$ignore_reg_op{$token_type} $token_type == 146
Truth table0%0/3
A or B
A= $ignore_reg_op{$token_type}B= $token_type == 146
ABresult
1X1
011
000
606 0 $i += 2;
607 }
608 }
609 }
610 else {
611 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
612 0 $token_type = $token->{type};
613 0 ▶ if ($token_type == SEMI_COLON) {
Branch: 4 branches
BranchTrueFalseTotal
if ($token_type == 106) { } 0 0 0
elsif ($token_type == 187) { } 0 0 0
elsif ($token_type == 52 or $token_type == 16) { } 0 0 0
elsif ($ignore_reg_op{$token_type} or $token_type == 146) { } 0 0 0
614 0 last;
615 }
616 elsif ($token_type == REG_EXP) {
617 0 ▶ if ($and_op_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($and_op_token) { } 0 0 0
618 0 push @regexs_at_after_and_op, $token;
619 }
620 else {
621 0 push @regexs_at_before_and_op, $token;
622 }
623 }
624 ▶ elsif ($token_type == AND || $token_type == ALPHABET_AND) {
Condition0%0/3
$token_type == 52 or $token_type == 16
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 52 or $token_type == 16
$token_type == 52 $token_type == 16
Truth table0%0/3
A or B
A= $token_type == 52B= $token_type == 16
ABresult
1X1
011
000
625 0 $and_op_token = $token;
626 }
627 ▶ elsif ($ignore_reg_op{$token_type} || $token_type == REG_DOUBLE_QUOTE) { # XXX
Condition0%0/3
$ignore_reg_op{$token_type} or $token_type == 146
l!l&&r!l&&!r
000
MC/DC0%0/2
$ignore_reg_op{$token_type} or $token_type == 146
$ignore_reg_op{$token_type} $token_type == 146
Truth table0%0/3
A or B
A= $ignore_reg_op{$token_type}B= $token_type == 146
ABresult
1X1
011
000
628 0 $i += 2;
629 }
630 }
631 }
632  
633 0 ▶ if (!@regexs_at_after_and_op) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @regexs_at_after_and_op) { } 0 0 0
634 0 my @captured;
635 0 for my $regex (@regexs_at_before_and_op) {
636 0 $class->_scan_regex($regex, $i);
637  
638 0 push @captured, $captured_for_each_scope[$sub_depth];
639 0 $captured_for_each_scope[++$sub_depth] = {};
640 }
641  
642 0 my $datam = pop @captured;
643 0 ▶ if ($datam) {
Branch: 1 branch
BranchTrueFalseTotal
if ($datam) 0 0 0
644 0 for my $cap (@captured) {
645 0 ▶ if (!eq_deeply($datam, $cap)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eq_deeply($datam, $cap)) 0 0 0
646 # TODO push violation?
647 0 next TOP;
648 }
649 }
650 }
651  
652 0 $captured_for_each_scope[$sub_depth] = $datam;
653 }
654 else {
655 0 my $is_captured_at_before_and_op = 0;
656 0 for my $b_regex (@regexs_at_before_and_op) {
657 0 $class->_scan_regex($b_regex, $i);
658  
659 0 ▶ my %captured_this_scope = %{$captured_for_each_scope[$sub_depth] || {}};
Condition0%0/2
$captured_for_each_scope[$sub_depth] || {}
l!l
00
MC/DC0%0/1
$captured_for_each_scope[$sub_depth] || {}
$captured_for_each_scope[$sub_depth]
Truth table0%0/2
A
A= $captured_for_each_scope[$sub_depth]
Aresult
11
00
660 0 ▶ if (%captured_this_scope) {
Branch: 1 branch
BranchTrueFalseTotal
if (%captured_this_scope) 0 0 0
661 0 $is_captured_at_before_and_op = 1;
662 0 last;
663 }
664 }
665  
666 0 for my $a_regex (@regexs_at_after_and_op) {
667 0 $class->_scan_regex($a_regex, $i);
668  
669 0 ▶ my %captured_this_scope = %{$captured_for_each_scope[$sub_depth] || {}};
Condition0%0/2
$captured_for_each_scope[$sub_depth] || {}
l!l
00
MC/DC0%0/1
$captured_for_each_scope[$sub_depth] || {}
$captured_for_each_scope[$sub_depth]
Truth table0%0/2
A
A= $captured_for_each_scope[$sub_depth]
Aresult
11
00
670 0 ▶ if (%captured_this_scope && $is_captured_at_before_and_op) {
Branch: 1 branch
BranchTrueFalseTotal
if (%captured_this_scope and $is_captured_at_before_and_op) 0 0 0
Condition0%0/3
%captured_this_scope and $is_captured_at_before_and_op
!ll&&!rl&&r
000
MC/DC0%0/2
%captured_this_scope and $is_captured_at_before_and_op
%captured_this_scope $is_captured_at_before_and_op
Truth table0%0/3
A and B
A= %captured_this_scopeB= $is_captured_at_before_and_op
ABresult
0X0
100
111
671 0 last;
672 }
673 }
674 }
675  
676 0 next;
677 }
678  
679 0 ▶ if ($token_type == SPECIFIC_VALUE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 137) 0 0 0
680 0 ▶ if ($token_data =~ /\A\$[0-9]+\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data =~ /\A\$[0-9]+\Z/) 0 0 0
681 0 delete $captured_for_each_scope[$sub_depth]->{$token_data};
682 0 next;
683 }
684  
685 0 ▶ if ($token_data eq '$+' || $token_data eq '$-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data eq "\$+" or $token_data eq "\$-") 0 0 0
Condition0%0/3
$token_data eq "\$+" or $token_data eq "\$-"
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_data eq "\$+" or $token_data eq "\$-"
$token_data eq "\$+" $token_data eq "\$-"
Truth table0%0/3
A or B
A= $token_data eq "\$+"B= $token_data eq "\$-"
ABresult
1X1
011
000
686 # TODO duplicated...
687 0 ▶ $token = $tokens->[$i+2] or next;
Branch: 1 branch
BranchTrueFalseTotal
$token = $$tokens[$i + 2] or next 0 0 0
688 0 $token_data = $token->{data};
689 0 ▶ if ($token_data =~ /\A -? [0-9]+ \Z/x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data =~ /\A -? [0-9]+ \Z/x) { } 0 0 0
690 0 ▶ $token_data-- if $token_data > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $token_data > 0 0 0 0
691  
692 0 my @num_vars = sort {$a cmp $b} grep { $_ =~ /\A\$[0-9]+\Z/} keys %{$captured_for_each_scope[$sub_depth]};
693  
694 0 ▶ if (my $hit = $num_vars[$token_data]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hit = $num_vars[$token_data]) 0 0 0
695 0 delete $captured_for_each_scope[$sub_depth]->{$hit};
696 }
697 }
698 else {
699 0 delete $captured_for_each_scope[$sub_depth]->{$token->{data}};
700 }
701 }
702  
703 0 next;
704 }
705  
706 0 ▶ if ($is_used_english) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_used_english) 0 0 0
707 0 ▶ if ($token_type == GLOBAL_VAR || $token_type == VAR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 194 or $token_type == 166) 0 0 0
Condition0%0/3
$token_type == 194 or $token_type == 166
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 194 or $token_type == 166
$token_type == 194 $token_type == 166
Truth table0%0/3
A or B
A= $token_type == 194B= $token_type == 166
ABresult
1X1
011
000
708 # TODO duplicated...
709 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data eq "\$LAST_PAREN_MATCH" or $token_data eq "\$LAST_MATCH_END" or $token_data eq "\$LAST_MATCH_START") 0 0 0
Condition0%0/6
$token_data eq "\$LAST_PAREN_MATCH" or $token_data eq "\$LAST_MATCH_END" or $token_data eq "\$LAST_MATCH_START"
l!l&&r!l&&!r
000
$token_data eq "\$LAST_PAREN_MATCH" or $token_data eq "\$LAST_MATCH_END"
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_data eq "\$LAST_PAREN_MATCH" or $token_data eq "\$LAST_MATCH_END" or $token_data eq "\$LAST_MATCH_START"
$token_data eq "\$LAST_PAREN_MATCH" $token_data eq "\$LAST_MATCH_END" $token_data eq "\$LAST_MATCH_START"
Truth table0%0/4
A or B or C
A= $token_data eq "\$LAST_PAREN_MATCH"B= $token_data eq "\$LAST_MATCH_END"C= $token_data eq "\$LAST_MATCH_START"
ABCresult
1XX1
01X1
0011
0000
710 $token_data eq '$LAST_PAREN_MATCH' ||
711 $token_data eq '$LAST_MATCH_END' ||
712 $token_data eq '$LAST_MATCH_START'
713 ) {
714 0 ▶ $token = $tokens->[$i+2] or next;
Branch: 1 branch
BranchTrueFalseTotal
$token = $$tokens[$i + 2] or next 0 0 0
715 0 $token_data = $token->{data};
716 0 ▶ if ($token_data =~ /\A -? [0-9]+ \Z/x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data =~ /\A -? [0-9]+ \Z/x) { } 0 0 0
717 0 ▶ $token_data-- if $token_data > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $token_data > 0 0 0 0
718  
719 0 my @num_vars = sort {$a cmp $b} grep { $_ =~ /\A\$[0-9]+\Z/} keys %{$captured_for_each_scope[$sub_depth]};
720  
721 0 ▶ if (my $hit = $num_vars[$token_data]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hit = $num_vars[$token_data]) 0 0 0
722 0 delete $captured_for_each_scope[$sub_depth]->{$hit};
723 }
724 }
725 else {
726 0 delete $captured_for_each_scope[$sub_depth]->{$token->{data}};
727 }
728 }
729 }
730 }
731  
732 0 ▶ if ($token_type == FUNCTION_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 63) 0 0 0
733 0 $depth_for_each_subs{$lbnum_for_scope} = 1;
734 0 $assign_ctx = 'NONE'; # XXX Umm...
735 0 $sub_depth++;
736 0 $captured_for_each_scope[$sub_depth] = {};
737 0 next;
738 }
739  
740 0 ▶ if ($token_type == LEFT_BRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 109) 0 0 0
741 0 $lbnum_for_scope++;
742 0 next;
743 }
744  
745 0 ▶ if ($token_type == RIGHT_BRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 110) 0 0 0
746 0 $lbnum_for_scope--;
747 0 ▶ if (delete $depth_for_each_subs{$lbnum_for_scope}) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $depth_for_each_subs{$lbnum_for_scope}) 0 0 0
748 0 my $regexp_in_return_ctx;
749 0 ▶ if ($token = $tokens->[$i-2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $$tokens[$i - 2]) 0 0 0
750 0 ▶ if ($token->{type} == REG_EXP) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token->{'type'} == 187) { } 0 0 0
elsif ($token = $$tokens[$i - 3]) { } 0 0 0
751 0 $regexp_in_return_ctx = $token;
752 }
753 elsif ($token = $tokens->[$i-3]) {
754 0 ▶ if ($token->{type} == REG_EXP) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 187) 0 0 0
755 0 $regexp_in_return_ctx = $token;
756 }
757 }
758 }
759  
760 0 my $captured = pop @captured_for_each_scope;
761 0 ▶ if (defined $captured and my %captured = %{$captured}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $captured and my(%captured) = %{$captured;}) 0 0 0
Condition0%0/3
defined $captured and my(%captured) = %{$captured;}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $captured and my(%captured) = %{$captured;}
defined $captured my(%captured) = %{$captured;}
Truth table0%0/3
A and B
A= defined $capturedB= my(%captured) = %{$captured;}
ABresult
0X0
100
111
762 0 ▶ if ($regexp_in_return_ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($regexp_in_return_ctx) 0 0 0
763 # should check equality between to just before regexp token?
764 0 ▶ if (all {substr($_, 0, 1) eq q<$>} keys %captured) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&all(sub { substr($_, 0, 1) eq "\$"; } , keys %captured)) 0 0 0
765 0 next;
766 }
767 }
768  
769 push @violations, {
770 filename => $file,
771 line => $just_before_regex_token->{line},
772 0 description => DESC,
773 explanation => EXPL,
774 policy => __PACKAGE__,
775 };
776 }
777 }
778 0 next;
779 }
780 }
781  
782 0 ▶ if (%{$captured_for_each_scope[-1] || {}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$captured_for_each_scope[-1] or {};}) 0 0 0
Condition0%0/2
$captured_for_each_scope[-1] || {}
l!l
00
MC/DC0%0/1
$captured_for_each_scope[-1] || {}
$captured_for_each_scope[-1]
Truth table0%0/2
A
A= $captured_for_each_scope[-1]
Aresult
11
00
783 push @violations, {
784 filename => $file,
785 line => $just_before_regex_token->{line},
786 0 description => DESC,
787 explanation => EXPL,
788 policy => __PACKAGE__,
789 };
790 }
791  
792 0 return \@violations;
793 }
794  
795 0 ▶sub _scan_regex {
Subroutine _scan_regex: not called CC=35 SCAR=71.4
796 0 my ($class, $token, $i) = @_;
797  
798 0 ▶ my $line_num = defined $just_before_regex_token ? $just_before_regex_token->{line} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $just_before_regex_token ? : 0 0 0
799 0 my $captured = $captured_for_each_scope[$sub_depth];
800 0 ▶ if (defined $captured && %$captured) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $captured and %$captured) 0 0 0
Condition0%0/3
defined $captured and %$captured
!ll&&!rl&&r
000
MC/DC0%0/2
defined $captured and %$captured
defined $captured %$captured
Truth table0%0/3
A and B
A= defined $capturedB= %$captured
ABresult
0X0
100
111
801 0 push @violations, {
802 filename => $file,
803 line => $line_num,
804 description => DESC,
805 explanation => EXPL,
806 policy => __PACKAGE__,
807 };
808 }
809  
810 0 $captured_for_each_scope[$sub_depth] = {};
811 0 $just_before_regex_token = $token;
812  
813 0 my $token_data = $token->{data};
814  
815 0 my @re_chars = split //, $token_data;
816  
817 0 my $escaped = 0;
818 0 my $lbnum = 0;
819 0 my $captured_num = 0;
820 0 ▶ for (my $j = 0; my $re_char = $re_chars[$j]; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $re_char = $re_chars[$j]) 0 0 0
821 0 ▶ if ($escaped) {
Branch: 1 branch
BranchTrueFalseTotal
if ($escaped) 0 0 0
822 0 ▶ if ($re_char =~ /[0-9]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char =~ /[0-9]/) 0 0 0
823 # TODO should track follows number
824 0 delete $captured_for_each_scope[$sub_depth]->{q<$> . $re_char};
825 }
826 0 $escaped = 0;
827 0 return;
828 }
829  
830 0 ▶ if ($re_char eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char eq "\\") 0 0 0
831 0 $escaped = 1;
832 0 return;
833 }
834  
835 0 ▶ if ($re_char eq '[') {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char eq "[") 0 0 0
836 0 $lbnum++;
837 0 return;
838 }
839  
840 0 ▶ if ($lbnum > 0) { # in [...]
Branch: 1 branch
BranchTrueFalseTotal
if ($lbnum > 0) 0 0 0
841 0 ▶ if ($re_char eq ']') {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char eq "]") 0 0 0
842 0 $lbnum--;
843 0 return;
844 }
845  
846 0 return;
847 }
848  
849 0 ▶ if ($re_char eq '(') {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char eq "(") 0 0 0
850 0 my $captured_name = '';
851  
852 0 ▶ if ($re_chars[$j+1] eq '?') {
Branch: 2 branches
BranchTrueFalseTotal
if ($re_chars[$j + 1] eq '?') { } 0 0 0
elsif ($re_chars[$j + 1] ne '?' or $re_chars[$j + 2] ne ':') { } 0 0 0
853 0 my $delimiter = $re_chars[$j+2];
854  
855 0 ▶ if ($delimiter eq ':') {
Branch: 1 branch
BranchTrueFalseTotal
if ($delimiter eq ":") 0 0 0
856 0 return;
857 }
858  
859 0 ▶ if ($delimiter eq 'P') {
Branch: 1 branch
BranchTrueFalseTotal
if ($delimiter eq "P") 0 0 0
860 0 $delimiter = $re_chars[$j+3];
861 0 $j++;
862 }
863  
864 0 ▶ if ($delimiter eq '<' || $delimiter eq q{'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delimiter eq "<" or $delimiter eq "'") 0 0 0
Condition0%0/3
$delimiter eq "<" or $delimiter eq "'"
l!l&&r!l&&!r
000
MC/DC0%0/2
$delimiter eq "<" or $delimiter eq "'"
$delimiter eq "<" $delimiter eq "'"
Truth table0%0/3
A or B
A= $delimiter eq "<"B= $delimiter eq "'"
ABresult
1X1
011
000
865 0 ▶ for ($j += 3; $re_char = $re_chars[$j]; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re_char = $re_chars[$j]) 0 0 0
866 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($delimiter eq "<" and $re_char eq ">" or $delimiter eq "'" and $re_char eq "'") 0 0 0
Condition0%0/9
$delimiter eq "<" and $re_char eq ">" or $delimiter eq "'" and $re_char eq "'"
l!l&&r!l&&!r
000
$delimiter eq "<" and $re_char eq ">"
!ll&&!rl&&r
000
$delimiter eq "'" and $re_char eq "'"
!ll&&!rl&&r
000
MC/DC0%0/4
$delimiter eq "<" and $re_char eq ">" or $delimiter eq "'" and $re_char eq "'"
$delimiter eq "<" $re_char eq ">" $delimiter eq "'" $re_char eq "'"
Truth table0%0/7
A and B or C and D
A= $delimiter eq "<"B= $re_char eq ">"C= $delimiter eq "'"D= $re_char eq "'"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
867 ($delimiter eq '<' && $re_char eq '>') ||
868 ($delimiter eq q{'} && $re_char eq q{'})
869 ) {
870 0 last;
871 }
872 0 $captured_name .= $re_char;
873 }
874  
875 0 ▶ if ($reg_not_ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reg_not_ctx) { } 0 0 0
876 push @violations, {
877 filename => $file,
878 line => $token->{line},
879 0 description => DESC,
880 explanation => EXPL,
881 policy => __PACKAGE__,
882 };
883 }
884 else {
885 0 $captured_num++;
886 0 $captured_for_each_scope[$sub_depth]->{$captured_name} = 1;
887 }
888 }
889 }
890 ▶ elsif ($re_chars[$j+1] ne '?' || $re_chars[$j+2] ne ':') {
Condition0%0/3
$re_chars[$j + 1] ne "?" or $re_chars[$j + 2] ne ":"
l!l&&r!l&&!r
000
MC/DC0%0/2
$re_chars[$j + 1] ne "?" or $re_chars[$j + 2] ne ":"
$re_chars[$j + 1] ne "?" $re_chars[$j + 2] ne ":"
Truth table0%0/3
A or B
A= $re_chars[$j + 1] ne "?"B= $re_chars[$j + 2] ne ":"
ABresult
1X1
011
000
891 0 ▶ if ($reg_not_ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reg_not_ctx) { } 0 0 0
892 push @violations, {
893 filename => $file,
894 line => $token->{line},
895 0 description => DESC,
896 explanation => EXPL,
897 policy => __PACKAGE__,
898 };
899 }
900 else {
901 0 $captured_num++;
902 0 $captured_for_each_scope[$sub_depth]->{q<$> . $captured_num} = 1;
903 }
904 }
905 }
906 }
907  
908 0 ▶ if ($assign_ctx ne 'NONE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($assign_ctx ne "NONE") 0 0 0
909 0 my $captured = $captured_for_each_scope[$sub_depth];
910  
911 0 ▶ if ($assign_ctx eq 'UNLIMITED_ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($assign_ctx eq "UNLIMITED_ARRAY") 0 0 0
912 0 ▶ if (%{$captured || {}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$captured or {};}) 0 0 0
Condition0%0/2
$captured || {}
l!l
00
MC/DC0%0/1
$captured || {}
$captured
Truth table0%0/2
A
A= $captured
Aresult
11
00
913 0 ▶ if (all {substr($_, 0, 1) eq q<$> } keys %$captured) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&all(sub { substr($_, 0, 1) eq "\$"; } , keys %$captured)) 0 0 0
914 0 $captured_for_each_scope[$sub_depth] = {};
915 }
916 }
917 0 return;
918 }
919  
920 0 $captured_for_each_scope[$sub_depth] = {};
921  
922 0 ▶ my $maybe_reg_opt = $tokens->[$i+2] or return;
Branch: 1 branch
BranchTrueFalseTotal
my $maybe_reg_opt = $$tokens[$i + 2] or return 0 0 0
923 0 ▶ if ($maybe_reg_opt->{type} == REG_OPT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($maybe_reg_opt->{"type"} == 144) 0 0 0
924 0 ▶ if ($assign_ctx ne 'UNLIMITED' && $maybe_reg_opt->{data} =~ /g/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($assign_ctx ne "UNLIMITED" and $maybe_reg_opt->{"data"} =~ /g/) 0 0 0
Condition0%0/3
$assign_ctx ne "UNLIMITED" and $maybe_reg_opt->{"data"} =~ /g/
!ll&&!rl&&r
000
MC/DC0%0/2
$assign_ctx ne "UNLIMITED" and $maybe_reg_opt->{"data"} =~ /g/
$assign_ctx ne "UNLIMITED" $maybe_reg_opt->{"data"} =~ /g/
Truth table0%0/3
A and B
A= $assign_ctx ne "UNLIMITED"B= $maybe_reg_opt->{"data"} =~ /g/
ABresult
0X0
100
111
925 push @violations, {
926 filename => $file,
927 line => $token->{line},
928 0 description => DESC,
929 explanation => EXPL,
930 policy => __PACKAGE__,
931 };
932 }
933 }
934  
935 0 return;
936 }
937  
938 0 $reg_not_ctx = 0;
939  
940 0 return;
941 }
942  
943 2 1;
944  
↑ Summary Perl/Lint/Policy/ControlStructures/ProhibitMutatingListFunctions.pm »