Branch Coverage

blib/lib/Perl/Critic/Policy/RegularExpressions/ProhibitUnusedCapture.pm
Criterion Covered Total %
branch 179 218 82.1


line true false branch
62 5 140 if 0 > index($elem->content, "(")
64 0 140 unless my $re = $doc->ppix_regexp_from_element($elem)
65 2 138 if $re->failures
67 1 137 unless my $ncaptures = $re->max_capture_number
77 124 13 unless $re->find("PPIx::Regexp::Structure::NamedCapture")
87 17 120 if _enough_uses_in_regexp($re, \@captures, \%named_captures, $doc)
89 14 106 if ($re->modifier_asserted("g") and not _check_if_in_while_condition_or_block($elem))
95 33 87 if _enough_assignments($elem, \@captures) and not %named_captures
96 16 71 if _is_in_slurpy_array_context($elem) and not %named_captures
97 46 25 if _enough_magic($elem, $re, \@captures, \%named_captures, $doc)
109 135 2 unless $re->find("PPIx::Regexp::Token::Reference")
111 0 2 if ($token->is_named) { }
118 116 21 unless $re->find("PPIx::Regexp::Token::Code")
120 0 22 unless my $ppi = $token->ppi
141 79 116 unless $psib
142 70 46 if ($psib->isa("PPI::Token::Operator"))
143 38 32 if "=" eq $psib->content
144 3 29 if "!~" eq $psib->content
150 0 38 unless $psib
152 13 25 if ($psib->isa('PPI::Token::Symbol')) { }
2 23 elsif ($psib->isa('PPI::Structure::Block')) { }
23 0 elsif ($psib->isa('PPI::Structure::List')) { }
157 13 0 if _symbol_is_slurpy($psib)
162 2 0 if _is_preceded_by_array_or_hash_cast($psib)
174 2 21 unless @args
178 21 0 if (1 == @args and $args[0]->isa("PPI::Statement::Expression"))
185 29 4 if (1 == @{$parts[$i];})
187 24 5 if ($var->isa("PPI::Token::Symbol") or $var->isa("PPI::Token::Cast"))
188 5 19 if _has_array_sigil($var)
202 10 3 if _has_array_sigil($symbol)
203 1 2 if _has_hash_sigil($symbol)
204 2 0 if _is_preceded_by_array_or_hash_cast($symbol)
228 0 4 unless $cast
241 2 85 if ($psib and $psib->content eq "=~")
246 60 27 unless ($psib)
248 0 60 unless $parent
249 60 0 if ($parent->isa("PPI::Statement"))
251 0 60 unless $parent
259 5 55 if ($parent->isa("PPI::Structure::List"))
260 0 5 unless my $parent_statement = $parent->statement
261 3 2 unless $parent_statement->isa("PPI::Statement::Compound")
263 0 2 if $parent_statement->type ne "foreach"
266 2 55 if $parent->isa("PPI::Structure::Constructor")
267 5 50 if ($parent->isa("PPI::Structure::Block"))
268 2 3 if &refaddr(scalar $elem->statement) eq &refaddr([$parent->schildren]->[-1])
275 19 8 if ($psib->isa("PPI::Token::Operator"))
277 2 17 if "," eq $psib->content
323 18 53 if (my $prior_token = $elem->sprevious_sibling)
328 5 66 unless _check_rest_of_statement($elem, $arg)
332 34 131 unless _check_rest_of_statement($parent, $arg)
342 0 17 unless $elem
344 0 17 unless my $parent = $elem->parent
345 0 17 unless $parent->isa("PPI::Statement")
347 0 17 unless my $item = $parent = $parent->parent
348 1 16 if ($item->isa("PPI::Structure::Block"))
349 0 1 unless $item = $item->sprevious_sibling
351 14 3 unless $item->isa("PPI::Structure::Condition")
353 0 3 unless $item = $item->sprevious_sibling
354 0 3 unless $item->isa("PPI::Token::Word")
411 0 596 if $parent and not &$parent()
419 338 819 unless $elem
421 48 771 if ($elem->isa("PPI::Token::Regexp"))
422 1 47 _regexp_is_in_split($elem) ? :
425 87 684 if ($elem->isa("PPI::Token::Structure") and ";" eq $elem->content)
432 601 83 unless $elem->isa("PPI::Token::Operator")
436 62 21 unless defined(my $oper_check = $SHORTCUT_OPERATOR{$content})
440 1 20 unless $oper_precedence >= $precedence
457 32 16 unless ($prev = $elem->sprevious_sibling)
459 0 32 unless my $stmt = $elem->statement
461 0 32 unless my $list = $stmt->parent
463 32 0 unless $prev = $elem->sprevious_sibling
493 1 235 if ($arg->{'negated'} and _is_condition_of_if_statement($elem))
497 1 0 if $nsib
501 5 198 if &$checker($nsib)
502 88 110 if ($nsib->isa('PPI::Node')) { }
503 34 54 unless _check_node_children($nsib, $arg, $checker)
521 10 1 unless $elem and $elem->isa("PPI::Structure::Condition")
524 0 1 unless my $psib = $elem->sprevious_sibling
526 0 1 unless $psib->isa("PPI::Token::Word")
560 34 582 if &$checker($child)
561 228 354 if ($child->isa('PPI::Node')) { }
562 49 179 unless _check_node_children($child, $arg, $checker)
577 14 450 if (_is_double_quotish_element($elem))
584 3 447 if ($elem->isa("PPI::Token::HereDoc"))
585 3 0 unless $elem->content =~ / \A << ~? \s* ' /msx
594 44 403 $doc->uses_module('English') ? :
598 366 12 unless $elem->isa("PPI::Token::Magic") or $capture_ref->{$content}
601 43 38 if ($content =~ / \A \$ ( \d+ ) /msx) { }
1 37 elsif ($capture_array->{$content}) { }
30 7 elsif ($capture_ref->{$content}) { }
605 42 1 if (0 < $num)
607 41 1 if ($num <= @{$captures;})
629 0 30 unless my $subscr = $elem->snext_sibling
630 0 30 unless $subscr->isa("PPI::Structure::Subscript")
647 1 16 $doc->uses_module('English') ? :
654 1 9 if $name =~ s/ \A ( [\$\@] ) [{] (?! \^ ) /$1/msx
657 5 5 if ($name =~ / \A \$ ( \d+ ) \z /msx) { }
1 4 elsif ($capture_array->{$name}) { }
4 0 elsif ($capture_ref->{$name} and $content =~ / \G ( [{] [^}]+ [}] | [[] [^]] []] ) /cgmsx) { }
661 5 0 if 0 < $num and $num <= @{$captures;}
686 0 464 unless $elem
690 0 464 if ($elem->isa("PPI::Token::QuoteLike::Command"))
700 14 1800 if $elem->isa($class)
712 8 26 if ($suffix =~ / \A [{] ( .*? ) [}] /msx) { }
26 0 elsif ($suffix =~ / \A [[] \s* ( [-+]? \d+ ) \s* []] /msx) { }
722 2 14 if $num >= 0 and $ZERO_BASED_CAPTURE_REFERENCE{$variable_name}
733 0 8 unless defined(my $numbers = $named_captures->{$name})
743 10 104 if $re and $number < 0
745 0 114 if $number <= 0