| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/ControlStructures/ProhibitMutatingListFunctions.pm |
| Statements | Executed 33157 statements in 68.2ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 13481 | 1 | 1 | 59.6ms | 167ms | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::violates |
| 55 | 1 | 1 | 10.2ms | 50.5ms | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_has_topic_side_effect |
| 321 | 1 | 1 | 3.96ms | 9.37ms | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_assignment_to_topic |
| 321 | 1 | 1 | 1.59ms | 2.33ms | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_topic_mutating_regex |
| 321 | 1 | 1 | 1.24ms | 4.13ms | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_topic_mutating_func |
| 321 | 1 | 1 | 1.20ms | 2.40ms | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_topic |
| 321 | 1 | 1 | 1.06ms | 7.29ms | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_topic_mutating_substr |
| 144 | 1 | 1 | 291µs | 291µs | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::applies_to |
| 38 | 1 | 1 | 155µs | 209µs | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_assignment_operator |
| 19 | 1 | 1 | 77µs | 99µs | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_increment_operator |
| 1 | 1 | 1 | 74µs | 103µs | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::supported_parameters |
| 1 | 1 | 1 | 30µs | 35µs | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::initialize_if_enabled |
| 1 | 1 | 1 | 16µs | 16µs | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@10 |
| 1 | 1 | 1 | 12µs | 226µs | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@15 |
| 1 | 1 | 1 | 10µs | 13µs | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_get_cpan_list_funcs |
| 1 | 1 | 1 | 10µs | 21µs | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@11 |
| 1 | 1 | 1 | 8µs | 12µs | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@12 |
| 1 | 1 | 1 | 8µs | 703µs | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@17 |
| 1 | 1 | 1 | 7µs | 28µs | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@13 |
| 1 | 1 | 1 | 7µs | 59µs | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@21 |
| 1 | 1 | 1 | 6µs | 7µs | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::default_severity |
| 1 | 1 | 1 | 3µs | 3µs | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_get_list_moreutils_funcs |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::__ANON__[:209] |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_binding_operator |
| 0 | 0 | 0 | 0s | 0s | Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::default_themes |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | ############################################################################## | ||||
| 2 | # $URL$ | ||||
| 3 | # $Date$ | ||||
| 4 | # $Author$ | ||||
| 5 | # $Revision$ | ||||
| 6 | ############################################################################## | ||||
| 7 | |||||
| 8 | package Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions; | ||||
| 9 | |||||
| 10 | 2 | 37µs | 1 | 16µs | # spent 16µs within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@10 which was called:
# once (16µs+0s) by Module::Pluggable::Object::_require at line 10 # spent 16µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@10 |
| 11 | 2 | 34µs | 2 | 32µs | # spent 21µs (10+11) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@11 which was called:
# once (10µs+11µs) by Module::Pluggable::Object::_require at line 11 # spent 21µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@11
# spent 11µs making 1 call to strict::import |
| 12 | 2 | 21µs | 2 | 16µs | # spent 12µs (8+4) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@12 which was called:
# once (8µs+4µs) by Module::Pluggable::Object::_require at line 12 # spent 12µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@12
# spent 4µs making 1 call to warnings::import |
| 13 | 2 | 23µs | 2 | 48µs | # spent 28µs (7+20) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@13 which was called:
# once (7µs+20µs) by Module::Pluggable::Object::_require at line 13 # spent 28µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@13
# spent 20µs making 1 call to Exporter::import |
| 14 | |||||
| 15 | 2 | 32µs | 2 | 440µs | # spent 226µs (12+214) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@15 which was called:
# once (12µs+214µs) by Module::Pluggable::Object::_require at line 15 # spent 226µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@15
# spent 214µs making 1 call to Exporter::Tiny::import |
| 16 | |||||
| 17 | 1 | 200ns | # spent 703µs (8+695) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@17 which was called:
# once (8µs+695µs) by Module::Pluggable::Object::_require at line 19 | ||
| 18 | :booleans :characters :severities :data_conversion :classification :ppi | ||||
| 19 | 1 | 26µs | 2 | 1.40ms | }; # spent 703µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@17
# spent 695µs making 1 call to Exporter::import |
| 20 | |||||
| 21 | 2 | 900µs | 2 | 111µs | # spent 59µs (7+52) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@21 which was called:
# once (7µs+52µs) by Module::Pluggable::Object::_require at line 21 # spent 59µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::BEGIN@21
# spent 52µs making 1 call to base::import |
| 22 | |||||
| 23 | 1 | 600ns | our $VERSION = '1.121'; | ||
| 24 | |||||
| 25 | #----------------------------------------------------------------------------- | ||||
| 26 | |||||
| 27 | 1 | 2µs | 1 | 30µs | Readonly::Array my @BUILTIN_LIST_FUNCS => qw( map grep ); # spent 30µs making 1 call to Readonly::Array |
| 28 | 1 | 5µs | 2 | 42µs | Readonly::Array my @CPAN_LIST_FUNCS => _get_cpan_list_funcs(); # spent 29µs making 1 call to Readonly::Array
# spent 13µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_get_cpan_list_funcs |
| 29 | |||||
| 30 | #----------------------------------------------------------------------------- | ||||
| 31 | |||||
| 32 | # spent 13µs (10+3) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_get_cpan_list_funcs which was called:
# once (10µs+3µs) by Module::Pluggable::Object::_require at line 28 | ||||
| 33 | return qw( List::Util::first ), | ||||
| 34 | 1 | 9µs | 1 | 3µs | map { 'List::MoreUtils::'.$_ } _get_list_moreutils_funcs(); # spent 3µs making 1 call to Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_get_list_moreutils_funcs |
| 35 | } | ||||
| 36 | |||||
| 37 | #----------------------------------------------------------------------------- | ||||
| 38 | |||||
| 39 | # spent 3µs within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_get_list_moreutils_funcs which was called:
# once (3µs+0s) by Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_get_cpan_list_funcs at line 34 | ||||
| 40 | 1 | 6µs | return qw(any all none notall true false firstidx first_index | ||
| 41 | lastidx last_index insert_after insert_after_string); | ||||
| 42 | } | ||||
| 43 | |||||
| 44 | #----------------------------------------------------------------------------- | ||||
| 45 | |||||
| 46 | # spent 2.40ms (1.20+1.20) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_topic which was called 321 times, avg 7µs/call:
# 321 times (1.20ms+1.20ms) by Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_assignment_to_topic at line 134, avg 7µs/call | ||||
| 47 | 321 | 40µs | my $elem = shift; | ||
| 48 | 321 | 3.89ms | 378 | 1.20ms | return defined $elem # spent 879µs making 57 calls to PPI::Element::__eq, avg 15µs/call
# spent 323µs making 321 calls to UNIVERSAL::isa, avg 1µs/call |
| 49 | && $elem->isa('PPI::Token::Magic') | ||||
| 50 | && $elem eq q{$_}; ##no critic (InterpolationOfMetachars) | ||||
| 51 | } | ||||
| 52 | |||||
| 53 | |||||
| 54 | #----------------------------------------------------------------------------- | ||||
| 55 | |||||
| 56 | 1 | 1µs | 1 | 25µs | Readonly::Scalar my $DESC => q{Don't modify $_ in list functions}; ##no critic (InterpolationOfMetachars) # spent 25µs making 1 call to Readonly::Scalar |
| 57 | 1 | 2µs | 1 | 44µs | Readonly::Scalar my $EXPL => [ 114 ]; # spent 44µs making 1 call to Readonly::Scalar |
| 58 | |||||
| 59 | #----------------------------------------------------------------------------- | ||||
| 60 | |||||
| 61 | # spent 103µs (74+30) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::supported_parameters which was called:
# once (74µs+30µs) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm | ||||
| 62 | return ( | ||||
| 63 | { | ||||
| 64 | 1 | 48µs | 20 | 30µs | name => 'list_funcs', # spent 23µs making 15 calls to Readonly::Array::FETCH, avg 2µs/call
# spent 4µs making 3 calls to Readonly::Scalar::FETCH, avg 1µs/call
# spent 3µs making 2 calls to Readonly::Array::FETCHSIZE, avg 2µs/call |
| 65 | description => 'The base set of functions to check.', | ||||
| 66 | default_string => join ($SPACE, @BUILTIN_LIST_FUNCS, @CPAN_LIST_FUNCS ), | ||||
| 67 | behavior => 'string list', | ||||
| 68 | }, | ||||
| 69 | { | ||||
| 70 | name => 'add_list_funcs', | ||||
| 71 | description => 'The set of functions to check, in addition to those given in list_funcs.', | ||||
| 72 | default_string => $EMPTY, | ||||
| 73 | behavior => 'string list', | ||||
| 74 | }, | ||||
| 75 | ); | ||||
| 76 | } | ||||
| 77 | |||||
| 78 | 1 | 2µs | # spent 7µs (6+1) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::default_severity which was called:
# once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm | ||
| 79 | sub default_themes { return qw(core bugs pbp certrule ) } | ||||
| 80 | 144 | 375µs | # spent 291µs within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::applies_to which was called 144 times, avg 2µs/call:
# 144 times (291µs+0s) by Perl::Critic::_critique at line 165 of Perl/Critic.pm, avg 2µs/call | ||
| 81 | |||||
| 82 | #----------------------------------------------------------------------------- | ||||
| 83 | |||||
| 84 | # spent 35µs (30+6) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::initialize_if_enabled which was called:
# once (30µs+6µs) by Perl::Critic::Config::_add_policy_if_enabled at line 202 of Perl/Critic/Config.pm | ||||
| 85 | 1 | 400ns | my ($self, $config) = @_; | ||
| 86 | |||||
| 87 | $self->{_all_list_funcs} = { | ||||
| 88 | 1 | 10µs | 1 | 4µs | hashify keys %{ $self->{_list_funcs} }, keys %{ $self->{_add_list_funcs} } # spent 4µs making 1 call to Perl::Critic::Utils::hashify |
| 89 | }; | ||||
| 90 | |||||
| 91 | 1 | 2µs | return $TRUE; | ||
| 92 | } | ||||
| 93 | |||||
| 94 | #----------------------------------------------------------------------------- | ||||
| 95 | |||||
| 96 | # spent 167ms (59.6+107) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::violates which was called 13481 times, avg 12µs/call:
# 13481 times (59.6ms+107ms) by Perl::Critic::_critique at line 183 of Perl/Critic.pm, avg 12µs/call | ||||
| 97 | 13481 | 2.90ms | my ($self, $elem, $doc) = @_; | ||
| 98 | |||||
| 99 | # Is this element a list function? | ||||
| 100 | 13481 | 46.8ms | 13481 | 14.9ms | return if not $self->{_all_list_funcs}->{$elem}; # spent 14.9ms making 13481 calls to PPI::Token::content, avg 1µs/call |
| 101 | 55 | 119µs | 55 | 39.3ms | return if not is_function_call($elem); # spent 39.3ms making 55 calls to Perl::Critic::Utils::is_function_call, avg 714µs/call |
| 102 | |||||
| 103 | # Only the block form of list functions can be analyzed. | ||||
| 104 | 55 | 239µs | 110 | 2.53ms | return if not my $first_arg = first_arg( $elem ); # spent 2.50ms making 55 calls to Perl::Critic::Utils::first_arg, avg 45µs/call
# spent 30µs making 55 calls to PPI::Util::TRUE, avg 540ns/call |
| 105 | 55 | 179µs | 55 | 42µs | return if not $first_arg->isa('PPI::Structure::Block'); # spent 42µs making 55 calls to UNIVERSAL::isa, avg 755ns/call |
| 106 | 55 | 199µs | 55 | 50.5ms | return if not $self->_has_topic_side_effect( $first_arg, $doc ); # spent 50.5ms making 55 calls to Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_has_topic_side_effect, avg 917µs/call |
| 107 | |||||
| 108 | # Must be a violation | ||||
| 109 | return $self->violation( $DESC, $EXPL, $elem ); | ||||
| 110 | } | ||||
| 111 | |||||
| 112 | #----------------------------------------------------------------------------- | ||||
| 113 | |||||
| 114 | # spent 50.5ms (10.2+40.2) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_has_topic_side_effect which was called 55 times, avg 917µs/call:
# 55 times (10.2ms+40.2ms) by Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::violates at line 106, avg 917µs/call | ||||
| 115 | 55 | 25µs | my ( $self, $node, $doc ) = @_; | ||
| 116 | |||||
| 117 | # Search through all significant elements in the block, | ||||
| 118 | # testing each element to see if it mutates the topic. | ||||
| 119 | 55 | 108µs | 55 | 16.6ms | my $tokens = $node->find( 'PPI::Token' ) || []; # spent 16.6ms making 55 calls to PPI::Node::find, avg 302µs/call |
| 120 | 55 | 93µs | for my $elem ( @{ $tokens } ) { | ||
| 121 | 526 | 628µs | 526 | 492µs | next if not $elem->significant(); # spent 283µs making 321 calls to PPI::Element::significant, avg 882ns/call
# spent 209µs making 205 calls to PPI::Token::Whitespace::significant, avg 1µs/call |
| 122 | 321 | 341µs | 321 | 9.37ms | return 1 if _is_assignment_to_topic( $elem ); # spent 9.37ms making 321 calls to Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_assignment_to_topic, avg 29µs/call |
| 123 | 321 | 395µs | 321 | 2.33ms | return 1 if $self->_is_topic_mutating_regex( $elem, $doc ); # spent 2.33ms making 321 calls to Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_topic_mutating_regex, avg 7µs/call |
| 124 | 321 | 331µs | 321 | 4.13ms | return 1 if _is_topic_mutating_func( $elem ); # spent 4.13ms making 321 calls to Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_topic_mutating_func, avg 13µs/call |
| 125 | 321 | 454µs | 321 | 7.29ms | return 1 if _is_topic_mutating_substr( $elem ); # spent 7.29ms making 321 calls to Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_topic_mutating_substr, avg 23µs/call |
| 126 | } | ||||
| 127 | 55 | 175µs | return; | ||
| 128 | } | ||||
| 129 | |||||
| 130 | #----------------------------------------------------------------------------- | ||||
| 131 | |||||
| 132 | # spent 9.37ms (3.96+5.42) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_assignment_to_topic which was called 321 times, avg 29µs/call:
# 321 times (3.96ms+5.42ms) by Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_has_topic_side_effect at line 122, avg 29µs/call | ||||
| 133 | 321 | 70µs | my $elem = shift; | ||
| 134 | 321 | 716µs | 321 | 2.40ms | return if not _is_topic( $elem ); # spent 2.40ms making 321 calls to Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_topic, avg 7µs/call |
| 135 | |||||
| 136 | 57 | 91µs | 57 | 1.39ms | my $sib = $elem->snext_sibling(); # spent 1.39ms making 57 calls to PPI::Element::snext_sibling, avg 24µs/call |
| 137 | 57 | 287µs | 114 | 262µs | if ($sib && $sib->isa('PPI::Token::Operator')) { # spent 209µs making 38 calls to Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_assignment_operator, avg 5µs/call
# spent 31µs making 38 calls to UNIVERSAL::isa, avg 818ns/call
# spent 22µs making 38 calls to PPI::Util::TRUE, avg 582ns/call |
| 138 | return 1 if _is_assignment_operator( $sib ); | ||||
| 139 | } | ||||
| 140 | |||||
| 141 | 57 | 101µs | 57 | 1.23ms | my $psib = $elem->sprevious_sibling(); # spent 1.23ms making 57 calls to PPI::Element::sprevious_sibling, avg 22µs/call |
| 142 | 57 | 162µs | 61 | 127µs | if ($psib && $psib->isa('PPI::Token::Operator')) { # spent 99µs making 19 calls to Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_increment_operator, avg 5µs/call
# spent 15µs making 21 calls to UNIVERSAL::isa, avg 724ns/call
# spent 12µs making 21 calls to PPI::Util::TRUE, avg 571ns/call |
| 143 | return 1 if _is_increment_operator( $psib ); | ||||
| 144 | } | ||||
| 145 | |||||
| 146 | 57 | 128µs | return; | ||
| 147 | } | ||||
| 148 | |||||
| 149 | #----------------------------------------------------------------------------- | ||||
| 150 | |||||
| 151 | # spent 2.33ms (1.59+745µs) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_topic_mutating_regex which was called 321 times, avg 7µs/call:
# 321 times (1.59ms+745µs) by Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_has_topic_side_effect at line 123, avg 7µs/call | ||||
| 152 | 321 | 89µs | my ( $self, $elem, $doc ) = @_; | ||
| 153 | 321 | 2.45ms | 642 | 745µs | return if ! ( $elem->isa('PPI::Token::Regexp::Substitute') # spent 745µs making 642 calls to UNIVERSAL::isa, avg 1µs/call |
| 154 | || $elem->isa('PPI::Token::Regexp::Transliterate') ); | ||||
| 155 | |||||
| 156 | # Exempt PPI::Token::Regexp::Transliterate objects IF the replacement | ||||
| 157 | # string is empty AND neither the /d or /s flags are specified, OR the | ||||
| 158 | # replacement string equals the match string AND neither the /c or /s | ||||
| 159 | # flags are specified. RT 44515. | ||||
| 160 | # | ||||
| 161 | # NOTE that, at least as of 5.14.2, tr/// does _not_ participate in the | ||||
| 162 | # 'use re /modifiers' mechanism. And a good thing, too, since the | ||||
| 163 | # modifiers that _are_ common (/s and /d) mean something completely | ||||
| 164 | # different in tr///. | ||||
| 165 | if ( $elem->isa( 'PPI::Token::Regexp::Transliterate') ) { | ||||
| 166 | my $subs = $elem->get_substitute_string(); | ||||
| 167 | my %mods = $elem->get_modifiers(); | ||||
| 168 | $mods{r} and return; # Introduced in Perl 5.13.7 | ||||
| 169 | if ( $EMPTY eq $subs ) { | ||||
| 170 | $mods{d} or $mods{s} or return; | ||||
| 171 | } elsif ( $elem->get_match_string() eq $subs ) { | ||||
| 172 | $mods{c} or $mods{s} or return; | ||||
| 173 | } | ||||
| 174 | } | ||||
| 175 | |||||
| 176 | # As of 5.13.2, the substitute built-in supports the /r modifier, which | ||||
| 177 | # causes the operation to return the modified string and leave the | ||||
| 178 | # original unmodified. This does not parse under earlier Perls, so there | ||||
| 179 | # is no version check. | ||||
| 180 | |||||
| 181 | if ( $elem->isa( 'PPI::Token::Regexp::Substitute' ) ) { | ||||
| 182 | my $re = $doc->ppix_regexp_from_element( $elem ) | ||||
| 183 | or return; | ||||
| 184 | $re->modifier_asserted( 'r' ) | ||||
| 185 | and return; | ||||
| 186 | } | ||||
| 187 | |||||
| 188 | # If the previous sibling does not exist, then | ||||
| 189 | # the regex implicitly binds to $_ | ||||
| 190 | my $prevsib = $elem->sprevious_sibling; | ||||
| 191 | return 1 if not $prevsib; | ||||
| 192 | |||||
| 193 | # If the previous sibling does exist, then it | ||||
| 194 | # should be a binding operator. | ||||
| 195 | return 1 if not _is_binding_operator( $prevsib ); | ||||
| 196 | |||||
| 197 | # Check if the sibling before the biding operator | ||||
| 198 | # is explicitly set to $_ | ||||
| 199 | my $bound_to = $prevsib->sprevious_sibling; | ||||
| 200 | return _is_topic( $bound_to ); | ||||
| 201 | } | ||||
| 202 | |||||
| 203 | #----------------------------------------------------------------------------- | ||||
| 204 | |||||
| 205 | # spent 4.13ms (1.24+2.89) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_topic_mutating_func which was called 321 times, avg 13µs/call:
# 321 times (1.24ms+2.89ms) by Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_has_topic_side_effect at line 124, avg 13µs/call | ||||
| 206 | 321 | 61µs | my $elem = shift; | ||
| 207 | 321 | 1.38ms | 321 | 280µs | return if not $elem->isa('PPI::Token::Word'); # spent 280µs making 321 calls to UNIVERSAL::isa, avg 873ns/call |
| 208 | 42 | 53µs | my @mutator_funcs = qw(chop chomp undef); | ||
| 209 | 168 | 479µs | 168 | 3.92ms | return if not any { $elem eq $_ } @mutator_funcs; # spent 2.14ms making 42 calls to List::MoreUtils::any, avg 51µs/call
# spent 1.78ms making 126 calls to PPI::Element::__eq, avg 14µs/call |
| 210 | 1 | 1µs | 1 | 431µs | return if not is_function_call( $elem ); # spent 431µs making 1 call to Perl::Critic::Utils::is_function_call |
| 211 | |||||
| 212 | # If these functions have no argument, | ||||
| 213 | # they default to mutating $_ | ||||
| 214 | 1 | 1µs | 1 | 26µs | my $first_arg = first_arg( $elem ); # spent 26µs making 1 call to Perl::Critic::Utils::first_arg |
| 215 | 1 | 400ns | if (not defined $first_arg) { | ||
| 216 | # undef does not default to $_, unlike the others | ||||
| 217 | 1 | 4µs | 1 | 14µs | return if $elem eq 'undef'; # spent 14µs making 1 call to PPI::Element::__eq |
| 218 | return 1; | ||||
| 219 | } | ||||
| 220 | return _is_topic( $first_arg ); | ||||
| 221 | } | ||||
| 222 | |||||
| 223 | #----------------------------------------------------------------------------- | ||||
| 224 | |||||
| 225 | 1 | 1µs | 1 | 21µs | Readonly::Scalar my $MUTATING_SUBSTR_ARG_COUNT => 4; # spent 21µs making 1 call to Readonly::Scalar |
| 226 | |||||
| 227 | # spent 7.29ms (1.06+6.24) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_topic_mutating_substr which was called 321 times, avg 23µs/call:
# 321 times (1.06ms+6.24ms) by Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_has_topic_side_effect at line 125, avg 23µs/call | ||||
| 228 | 321 | 56µs | my $elem = shift; | ||
| 229 | 321 | 3.39ms | 321 | 5.37ms | return if $elem ne 'substr'; # spent 5.37ms making 321 calls to PPI::Element::__ne, avg 17µs/call |
| 230 | 1 | 18µs | 1 | 432µs | return if not is_function_call( $elem ); # spent 432µs making 1 call to Perl::Critic::Utils::is_function_call |
| 231 | |||||
| 232 | # check and see if the first arg is $_ | ||||
| 233 | 1 | 3µs | 1 | 433µs | my @args = parse_arg_list( $elem ); # spent 433µs making 1 call to Perl::Critic::Utils::parse_arg_list |
| 234 | 1 | 5µs | 1 | 1µs | return @args >= $MUTATING_SUBSTR_ARG_COUNT && _is_topic( $args[0]->[0] ); # spent 1µs making 1 call to Readonly::Scalar::FETCH |
| 235 | } | ||||
| 236 | |||||
| 237 | #----------------------------------------------------------------------------- | ||||
| 238 | |||||
| 239 | { | ||||
| 240 | ##no critic(ArgUnpacking) | ||||
| 241 | |||||
| 242 | 2 | 12µs | 1 | 7µs | my %assignment_ops = hashify qw( # spent 7µs making 1 call to Perl::Critic::Utils::hashify |
| 243 | = *= /= += -= %= **= x= .= &= |= ^= &&= ||= <<= >>= //= ++ -- | ||||
| 244 | ); | ||||
| 245 | 38 | 134µs | 38 | 54µs | # spent 209µs (155+54) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_assignment_operator which was called 38 times, avg 5µs/call:
# 38 times (155µs+54µs) by Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_assignment_to_topic at line 137, avg 5µs/call # spent 54µs making 38 calls to PPI::Token::content, avg 1µs/call |
| 246 | |||||
| 247 | 1 | 2µs | 1 | 2µs | my %increment_ops = hashify qw( ++ -- ); # spent 2µs making 1 call to Perl::Critic::Utils::hashify |
| 248 | 19 | 70µs | 19 | 22µs | # spent 99µs (77+22) within Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_increment_operator which was called 19 times, avg 5µs/call:
# 19 times (77µs+22µs) by Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_is_assignment_to_topic at line 142, avg 5µs/call # spent 22µs making 19 calls to PPI::Token::content, avg 1µs/call |
| 249 | |||||
| 250 | 1 | 2µs | 1 | 2µs | my %binding_ops = hashify qw( =~ !~ ); # spent 2µs making 1 call to Perl::Critic::Utils::hashify |
| 251 | sub _is_binding_operator { return exists $binding_ops{$_[0]} } | ||||
| 252 | } | ||||
| 253 | |||||
| 254 | 1 | 9µs | 1; | ||
| 255 | |||||
| 256 | #----------------------------------------------------------------------------- | ||||
| 257 | |||||
| 258 | __END__ |