« lib/Perl/Critic/Policy/Subroutines/ProhibitUnusedPrivateSubroutines.pm
↑ Summary
lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitReverseSortBlock.pm »
| 1 | package Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 40 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 40 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 40 | ▶ | use Scalar::Util qw< refaddr >; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 40 | ▶ | use Perl::Critic::Utils qw< :booleans :characters :severities hashify | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 40 | precedence_of >; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 40 | our $VERSION = '1.156'; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 40 | Readonly::Scalar my $DESC => 'Return value of eval not tested.'; | |||||||||||||||||||||||||||||||||||||||||
| 20 | ## no critic (RequireInterpolationOfMetachars) | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 40 | Readonly::Scalar my $EXPL => | |||||||||||||||||||||||||||||||||||||||||
| 22 | q<You can't depend upon the value of $@/$EVAL_ERROR to tell whether an eval failed.>; | ||||||||||||||||||||||||||||||||||||||||||
| 23 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 40 | Readonly::Hash my %BOOLEAN_OPERATORS => hashify qw< || && // or and >; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 40 | Readonly::Hash my %POSTFIX_OPERATORS => | |||||||||||||||||||||||||||||||||||||||||
| 27 | hashify qw< for foreach if unless while until >; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 40 | Readonly::Scalar my $PRECEDENCE_OF_EQUALS => precedence_of( q{=} ); | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 90 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 74 | ▶ | sub default_severity { return $SEVERITY_MEDIUM } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 73 | ▶ | sub default_themes { return qw( core bugs ) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | ▶ | sub applies_to { return 'PPI::Token::Word' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 12 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=12 SCAR=48.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 12 | my ( $self, $elem, undef ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 12 | ▶ | return if $elem->content() ne 'eval'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my $evaluated = $elem->snext_sibling() or return; # Nothing to eval! | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $following = $evaluated->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | return if _is_returned( $elem ); # GitHub #324 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return if _is_in_right_hand_side_of_assignment($elem); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | return if _is_in_postfix_expression($elem); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | return if | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | _is_in_correct_position_in_a_condition_or_foreach_loop_collection( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | $elem, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | $following, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | return if _scan_backwards_for_grep( $elem ); # RT 69489 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if ( $following and $following->isa('PPI::Token::Operator') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$following and $following->isa("PPI::Token::Operator")
MC/DC0%0/2
$following and $following->isa("PPI::Token::Operator")
$following
$following->isa("PPI::Token::Operator")
Truth table0%0/3
A and B
A= $followingB= $following->isa("PPI::Token::Operator")
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | return if $BOOLEAN_OPERATORS{ $following->content() }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | return if q{?} eq $following->content; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | return $self->violation($DESC, $EXPL, $elem); | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub _is_in_right_hand_side_of_assignment { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_in_right_hand_side_of_assignment: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my ($elem) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $previous = $elem->sprevious_sibling(); | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if (not $previous) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $previous = | |||||||||||||||||||||||||||||||||||||||||
| 76 | _grandparent_for_is_in_right_hand_side_of_assignment($elem); | ||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | while ($previous) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my $base_previous = $previous; | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | EQUALS_SCAN: | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | while ($previous) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ( $previous->isa('PPI::Token::Operator') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | return $TRUE if $previous->content() =~ m/= \Z/xms; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | last EQUALS_SCAN if _is_effectively_a_comma($previous); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $previous = $previous->sprevious_sibling(); | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | $previous = | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | _grandparent_for_is_in_right_hand_side_of_assignment($base_previous); | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub _grandparent_for_is_in_right_hand_side_of_assignment { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_grandparent_for_is_in_right_hand_side_of_assignment: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my ($elem) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my $parent = $elem->parent() or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | $parent->isa('PPI::Statement') or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | my $grandparent = $parent->parent() or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$grandparent->isa("PPI::Structure::Constructor") or $grandparent->isa("PPI::Structure::List")
MC/DC0%0/2
$grandparent->isa("PPI::Structure::Constructor") or $grandparent->isa("PPI::Structure::List")
$grandparent->isa("PPI::Structure::Constructor")
$grandparent->isa("PPI::Structure::List")
Truth table0%0/3
A or B
A= $grandparent->isa("PPI::Structure::Constructor")B= $grandparent->isa("PPI::Structure::List")
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | $grandparent->isa('PPI::Structure::Constructor') | ||||||||||||||||||||||||||||||||||||||||||
| 108 | or $grandparent->isa('PPI::Structure::List') | ||||||||||||||||||||||||||||||||||||||||||
| 109 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return $grandparent; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 40 | Readonly::Scalar my $CONDITION_POSITION_IN_C_STYLE_FOR_LOOP => 1; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub _is_in_correct_position_in_a_condition_or_foreach_loop_collection { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_in_correct_position_in_a_condition_or_foreach_loop_collection: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my ($elem, $following) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $parent = $elem->parent(); | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | while ($parent) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if ( $parent->isa('PPI::Structure::Condition') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | return | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | _is_in_correct_position_in_a_structure_condition( | |||||||||||||||||||||||||||||||||||||||||
| 128 | $elem, $parent, $following, | ||||||||||||||||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | # TECHNICAL DEBT: This code is basically shared with | ||||||||||||||||||||||||||||||||||||||||||
| 133 | # ProhibitUnusedCapture. I don't want to put this code | ||||||||||||||||||||||||||||||||||||||||||
| 134 | # into Perl::Critic::Utils::*, but I don't have time to sort out | ||||||||||||||||||||||||||||||||||||||||||
| 135 | # PPIx::Utilities::Structure::List yet. | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$parent->isa("PPI::Structure::List") and my $parent_statement = $parent->statement
MC/DC0%0/2
$parent->isa("PPI::Structure::List") and my $parent_statement = $parent->statement
$parent->isa("PPI::Structure::List")
my $parent_statement = $parent->statement
Truth table0%0/3
A and B
A= $parent->isa("PPI::Structure::List")B= my $parent_statement = $parent->statement
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | $parent->isa('PPI::Structure::List') | ||||||||||||||||||||||||||||||||||||||||||
| 138 | and my $parent_statement = $parent->statement() | ||||||||||||||||||||||||||||||||||||||||||
| 139 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | return $TRUE if | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$parent_statement->isa("PPI::Statement::Compound") and $parent_statement->type eq "foreach"
MC/DC0%0/2
$parent_statement->isa("PPI::Statement::Compound") and $parent_statement->type eq "foreach"
$parent_statement->isa("PPI::Statement::Compound")
$parent_statement->type eq "foreach"
Truth table0%0/3
A and B
A= $parent_statement->isa("PPI::Statement::Compound")B= $parent_statement->type eq "foreach"
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | $parent_statement->isa('PPI::Statement::Compound') | ||||||||||||||||||||||||||||||||||||||||||
| 142 | and $parent_statement->type() eq 'foreach'; | ||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if ( $parent->isa('PPI::Structure::For') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my @for_loop_components = $parent->schildren(); | |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | my $condition = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | $for_loop_components[$CONDITION_POSITION_IN_C_STYLE_FOR_LOOP] | ||||||||||||||||||||||||||||||||||||||||||
| 150 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | return _descendant_of($elem, $condition); | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | $parent = $parent->parent(); | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | sub _is_in_correct_position_in_a_structure_condition { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_in_correct_position_in_a_structure_condition: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my ($elem, $parent, $following) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my $level = $elem; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | while ($level and refaddr $level != $parent) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$level and builtin::refaddr($level) != $parent
MC/DC0%0/2
$level and builtin::refaddr($level) != $parent
$level
builtin::refaddr($level) != $parent
Truth table0%0/3
A and B
A= $levelB= builtin::refaddr($level) != $parent
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | my $cursor = refaddr $elem == refaddr $level ? $following : $level; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | IS_FINAL_EXPRESSION_AT_DEPTH: | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | while ($cursor) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | if ( _is_effectively_a_comma($cursor) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $cursor = $cursor->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | while ( _is_effectively_a_comma($cursor) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $cursor = $cursor->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | # Semicolon would be a syntax error here. | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | return if $cursor; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | last IS_FINAL_EXPRESSION_AT_DEPTH; | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $cursor = $cursor->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | my $statement = $level->parent(); | |||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | return $TRUE if not $statement; # Shouldn't happen. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | return $TRUE if not $statement->isa('PPI::Statement'); # Shouldn't happen. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $level = $statement->parent(); | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$level and $level->isa("PPI::Structure::List") || $level->isa("PPI::Structure::Condition")
$level->isa("PPI::Structure::List") or $level->isa("PPI::Structure::Condition")
MC/DC0%0/3
$level and $level->isa("PPI::Structure::List") || $level->isa("PPI::Structure::Condition")
$level
$level->isa("PPI::Structure::List")
$level->isa("PPI::Structure::Condition")
Truth table0%0/4
A and B or C
A= $levelB= $level->isa("PPI::Structure::List")C= $level->isa("PPI::Structure::Condition")
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | not $level | ||||||||||||||||||||||||||||||||||||||||||
| 191 | or ( | ||||||||||||||||||||||||||||||||||||||||||
| 192 | not $level->isa('PPI::Structure::List') | ||||||||||||||||||||||||||||||||||||||||||
| 193 | and not $level->isa('PPI::Structure::Condition') | ||||||||||||||||||||||||||||||||||||||||||
| 194 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 195 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 196 | # Shouldn't happen. | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | return $TRUE; | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | return $TRUE; | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | # Replace with PPI implementation once it is released. | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | sub _descendant_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_descendant_of: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my ($cursor, $potential_ancestor) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | return $EMPTY if not $potential_ancestor; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | while ( refaddr $cursor != refaddr $potential_ancestor ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | $cursor = $cursor->parent() or return $EMPTY; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | sub _is_in_postfix_expression { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_in_postfix_expression: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my ($elem) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my $current_base = $elem; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | while ($TRUE) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my $previous = $current_base->sprevious_sibling(); | |||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | while ($previous) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$previous->isa("PPI::Token::Word") and $POSTFIX_OPERATORS{$previous->content}
MC/DC0%0/2
$previous->isa("PPI::Token::Word") and $POSTFIX_OPERATORS{$previous->content}
$previous->isa("PPI::Token::Word")
$POSTFIX_OPERATORS{$previous->content}
Truth table0%0/3
A and B
A= $previous->isa("PPI::Token::Word")B= $POSTFIX_OPERATORS{$previous->content}
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | $previous->isa('PPI::Token::Word') | ||||||||||||||||||||||||||||||||||||||||||
| 228 | and $POSTFIX_OPERATORS{ $previous->content() } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | return $TRUE; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $previous = $previous->sprevious_sibling(); | |||||||||||||||||||||||||||||||||||||||||
| 233 | } # end while | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | my $parent = $current_base->parent() or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | if ( $parent->isa('PPI::Statement') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | return if $parent->specialized(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | my $grandparent = $parent->parent() or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | return if not $grandparent->isa('PPI::Structure::List'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | $current_base = $grandparent; | |||||||||||||||||||||||||||||||||||||||||
| 243 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $current_base = $parent; | |||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | return if not $current_base->isa('PPI::Structure::List'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | sub _scan_backwards_for_grep { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_scan_backwards_for_grep: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my ( $elem ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | while ( $elem ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | my $parent = $elem->parent(); | |||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | while ( $elem = $elem->sprevious_sibling() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | $elem->isa( 'PPI::Token::Word' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$elem->isa("PPI::Token::Word") and "grep" eq $elem->content
MC/DC0%0/2
$elem->isa("PPI::Token::Word") and "grep" eq $elem->content
$elem->isa("PPI::Token::Word")
"grep" eq $elem->content
Truth table0%0/3
A and B
A= $elem->isa("PPI::Token::Word")B= "grep" eq $elem->content
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | and 'grep' eq $elem->content() | ||||||||||||||||||||||||||||||||||||||||||
| 265 | and return $TRUE; | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | $elem->isa( 'PPI::Token::Operator' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$elem->isa("PPI::Token::Operator") and precedence_of($elem) >= $PRECEDENCE_OF_EQUALS
MC/DC0%0/2
$elem->isa("PPI::Token::Operator") and precedence_of($elem) >= $PRECEDENCE_OF_EQUALS
$elem->isa("PPI::Token::Operator")
precedence_of($elem) >= $PRECEDENCE_OF_EQUALS
Truth table0%0/3
A and B
A= $elem->isa("PPI::Token::Operator")B= precedence_of($elem) >= $PRECEDENCE_OF_EQUALS
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | and precedence_of( $elem ) >= $PRECEDENCE_OF_EQUALS | ||||||||||||||||||||||||||||||||||||||||||
| 268 | and return $FALSE; | ||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | $elem = $parent; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | return $FALSE; | |||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | sub _is_effectively_a_comma { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_effectively_a_comma: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | my ($elem) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | return if not $elem; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | return | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | $elem->isa('PPI::Token::Operator') | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$elem->isa('PPI::Token::Operator') && ($elem->content eq $Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval::COMMA || $elem->content eq $Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval::FATCOMMA)
$elem->content eq $Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval::COMMA or $elem->content eq $Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval::FATCOMMA
MC/DC0%0/3
$elem->isa('PPI::Token::Operator') && ($elem->content eq $Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval::COMMA || $elem->content eq $Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval::FATCOMMA)
$elem->isa('PPI::Token::Operator')
$elem->content eq $Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval::COMMA
$elem->content eq $Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval::FATCOMMA
Truth table0%0/4
A && B or C
A= $elem->isa('PPI::Token::Operator')B= $elem->content eq $Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval::COMMAC= $elem->content eq $Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval::FATCOMMA
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | && ( | ||||||||||||||||||||||||||||||||||||||||||
| 288 | $elem->content() eq $COMMA | ||||||||||||||||||||||||||||||||||||||||||
| 289 | || $elem->content() eq $FATCOMMA | ||||||||||||||||||||||||||||||||||||||||||
| 290 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 294 | # GitHub #324 (https://github.com/Perl-Critic/Perl-Critic/issues/324) | ||||||||||||||||||||||||||||||||||||||||||
| 295 | { | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 40 | Readonly::Scalar my $RETURN => 'return'; | |||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | sub _is_returned { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_returned: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | my ( $elem ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | my $prev = $elem->sprevious_sibling(); | |||||||||||||||||||||||||||||||||||||||||
| 301 | return | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | $prev | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$prev && $prev->isa('PPI::Token::Word') && $RETURN eq $prev->content
$prev and $prev->isa("PPI::Token::Word")
MC/DC0%0/3
$prev && $prev->isa('PPI::Token::Word') && $RETURN eq $prev->content
$prev
$prev->isa("PPI::Token::Word")
$RETURN eq $prev->content
Truth table0%0/4
A and B && C
A= $prevB= $prev->isa("PPI::Token::Word")C= $RETURN eq $prev->content
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | && | ||||||||||||||||||||||||||||||||||||||||||
| 304 | $prev->isa( 'PPI::Token::Word' ) | ||||||||||||||||||||||||||||||||||||||||||
| 305 | && | ||||||||||||||||||||||||||||||||||||||||||
| 306 | $RETURN eq $prev->content(); | ||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 40 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | __END__ | ||||||||||||||||||||||||||||||||||||||||||