Branch Coverage

blib/lib/Perl/Critic/Policy/RegularExpressions/ProhibitUnusedCapture.pm
Criterion Covered Total %
branch 177 216 81.9


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"))
322 18 53 if (my $prior_token = $elem->sprevious_sibling)
327 5 66 unless _check_rest_of_statement($elem, $arg)
331 34 131 unless _check_rest_of_statement($parent, $arg)
341 0 17 unless $elem
343 0 17 unless my $parent = $elem->parent
344 0 17 unless $parent->isa("PPI::Statement")
346 0 17 unless my $item = $parent = $parent->parent
347 1 16 if ($item->isa("PPI::Structure::Block"))
348 0 1 unless $item = $item->sprevious_sibling
350 14 3 unless $item->isa("PPI::Structure::Condition")
352 0 3 unless $item = $item->sprevious_sibling
353 0 3 unless $item->isa("PPI::Token::Word")
410 0 596 if $parent and not &$parent()
418 338 819 unless $elem
420 48 771 if ($elem->isa("PPI::Token::Regexp"))
421 1 47 _regexp_is_in_split($elem) ? :
424 87 684 if ($elem->isa("PPI::Token::Structure") and ";" eq $elem->content)
431 601 83 unless $elem->isa("PPI::Token::Operator")
435 62 21 unless defined(my $oper_check = $SHORTCUT_OPERATOR{$content})
439 1 20 unless $oper_precedence >= $precedence
456 32 16 unless ($prev = $elem->sprevious_sibling)
458 0 32 unless my $stmt = $elem->statement
460 0 32 unless my $list = $stmt->parent
462 32 0 unless $prev = $elem->sprevious_sibling
492 1 235 if ($arg->{'negated'} and _is_condition_of_if_statement($elem))
496 1 0 if $nsib
500 5 198 if &$checker($nsib)
501 88 110 if ($nsib->isa('PPI::Node')) { }
502 34 54 unless _check_node_children($nsib, $arg, $checker)
520 10 1 unless $elem and $elem->isa("PPI::Structure::Condition")
523 0 1 unless my $psib = $elem->sprevious_sibling
525 0 1 unless $psib->isa("PPI::Token::Word")
559 34 582 if &$checker($child)
560 228 354 if ($child->isa('PPI::Node')) { }
561 49 179 unless _check_node_children($child, $arg, $checker)
576 14 450 if (_is_double_quotish_element($elem))
583 3 447 if ($elem->isa("PPI::Token::HereDoc"))
584 3 0 unless $elem->content =~ / \A << ~? \s* ' /msx
593 44 403 $doc->uses_module('English') ? :
597 366 12 unless $elem->isa("PPI::Token::Magic") or $capture_ref->{$content}
600 43 38 if ($content =~ / \A \$ ( \d+ ) /msx) { }
1 37 elsif ($capture_array->{$content}) { }
30 7 elsif ($capture_ref->{$content}) { }
604 42 1 if (0 < $num)
606 41 1 if ($num <= @{$captures;})
628 0 30 unless my $subscr = $elem->snext_sibling
629 0 30 unless $subscr->isa("PPI::Structure::Subscript")
646 1 16 $doc->uses_module('English') ? :
653 1 9 if $name =~ s/ \A ( [\$\@] ) [{] (?! \^ ) /$1/msx
656 5 5 if ($name =~ / \A \$ ( \d+ ) \z /msx) { }
1 4 elsif ($capture_array->{$name}) { }
4 0 elsif ($capture_ref->{$name} and $content =~ / \G ( [{] [^}]+ [}] | [[] [^]] []] ) /cgmsx) { }
660 5 0 if 0 < $num and $num <= @{$captures;}
685 0 464 unless $elem
689 0 464 if ($elem->isa("PPI::Token::QuoteLike::Command"))
699 14 1800 if $elem->isa($class)
711 8 26 if ($suffix =~ / \A [{] ( .*? ) [}] /msx) { }
26 0 elsif ($suffix =~ / \A [[] \s* ( [-+]? \d+ ) \s* []] /msx) { }
721 2 14 if $num >= 0 and $ZERO_BASED_CAPTURE_REFERENCE{$variable_name}
732 0 8 unless defined(my $numbers = $named_captures->{$name})
742 10 104 if $re and $number < 0
744 0 114 if $number <= 0