| 1 | #!/bin/false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # PODNAME: Perl::Critic::Policy::Performance::ProhibitRegexForSimpleSubstring | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Use index() instead of regex for literal substring matching | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | package Perl::Critic::Policy::Performance::ProhibitRegexForSimpleSubstring; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | $Perl::Critic::Policy::Performance::ProhibitRegexForSimpleSubstring::VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Perl::Critic::Utils qw{ $EMPTY :severities is_function_call is_method_call }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | my $DESC = q{Regex used for a simple substring match}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ## no critic (RequireInterpolationOfMetachars) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | my $EXPLANATION_FORMAT = q{Use index($string, %s) instead of a regex when looking for literal text.}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | my $EXPLANATION_GENERIC = q{Use index($string, $substring) instead of a regex when looking for literal text.}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # index() is case sensitive. /m, /s, and /x do not change a pattern of literals. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | my $EXEMPTING_MODIFIER = 'i'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | my $APOSTROPHE = q{'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | my $BACKSLASH = q{\\}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | my $CARRIAGE_RETURN = "\r"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | my $NEWLINE = "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | my $PRINTABLE_ASCII_FIRST = q{ }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | my $PRINTABLE_ASCII_LAST = q{~}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | my $TAB = "\t"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # A neighbor operator ends the argument when it is one of these. Logical | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # operators bind the surrounding expression to the match instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | my %ARGUMENT_SEPARATOR = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | q{,} => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | q{=>} => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | ▶ | sub supported_parameters { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | { behavior => 'string list', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | default_string => $EMPTY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | description => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 'Functions and methods whose first argument may be a literal regex. split is always included.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | list_always_present_values => [qw{ split }], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | name => 'allow', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 51 | ▶ | sub default_severity { return $SEVERITY_MEDIUM } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub default_themes { return qw( performance ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 93 | ▶ | sub applies_to { return 'PPI::Token::Regexp::Match' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 94 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 94 | my ( $self, $elem, $doc ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 94 | my $literal = _decoded_literal( $elem, $doc ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 94 | ▶ | return if !$literal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 76 | ▶ | return if _allowed_call( $elem, $self->{_allow} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 51 | my $explanation = $EXPLANATION_GENERIC; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 51 | ▶ | if ( defined $literal->{text} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 50 | $explanation = sprintf $EXPLANATION_FORMAT, _quoted_literal( $literal->{text} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 51 | return $self->violation( $DESC, $explanation, $elem ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # A pure literal pattern, or nothing. text is the string index() searches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # for, and is missing when a literal has no ordinal. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 94 | ▶ | sub _decoded_literal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decoded_literal: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 94 | my ( $elem, $doc ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 94 | ▶ | my $re = $doc->ppix_regexp_from_element($elem) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 94 | ▶ | return if $re->failures(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 94 | ▶ | return if $re->modifier_asserted($EXEMPTING_MODIFIER); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 91 | ▶ | my $pattern = $re->regular_expression() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 91 | my $literal_count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 91 | my $saw_undefined_ordinal = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 91 | my @characters; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 91 | for my $token ( map { $_->tokens() } $pattern->children() ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 235 | ▶ | next if !$token->significant(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 230 | ▶ | return if !$token->isa('PPIx::Regexp::Token::Literal'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 216 | $literal_count++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 216 | my $ordinal = $token->ordinal(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 216 | ▶ | if ( !defined $ordinal ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | $saw_undefined_ordinal = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 215 | push @characters, chr $ordinal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 77 | ▶ | return if $literal_count == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # No ordinal means the explanation cannot name the literal. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 76 | ▶ | return {} if $saw_undefined_ordinal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 75 | return { text => join q{}, @characters }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # A Perl string literal for the text index() searches for. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 50 | ▶ | sub _quoted_literal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quoted_literal: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 50 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 50 | my $needs_double_quotes = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 50 | for my $character ( split //, $text ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 158 | my $ordinal = ord $character; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 158 | ▶ | if ( $ordinal < ord $PRINTABLE_ASCII_FIRST || $ordinal > ord $PRINTABLE_ASCII_LAST ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ordinal < ord $PRINTABLE_ASCII_FIRST or $ordinal > ord $PRINTABLE_ASCII_LAST
MC/DC100%2/2
$ordinal < ord $PRINTABLE_ASCII_FIRST or $ordinal > ord $PRINTABLE_ASCII_LAST
$ordinal < ord $PRINTABLE_ASCII_FIRST
$ordinal > ord $PRINTABLE_ASCII_LAST
Truth table100%3/3
A or B
A= $ordinal < ord $PRINTABLE_ASCII_FIRSTB= $ordinal > ord $PRINTABLE_ASCII_LAST
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 4 | $needs_double_quotes = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 4 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 50 | ▶ | return _double_quoted($text) if $needs_double_quotes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 46 | return _single_quoted($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 4 | ▶ | sub _double_quoted { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_double_quoted: called CC=11 SCAR=26.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 4 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 4 | my $body = q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | for my $character ( split //, $text ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 4 | ▶ | if ( $character eq $NEWLINE ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | $body .= q{\\n}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 3 | ▶ | if ( $character eq $CARRIAGE_RETURN ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | $body .= q{\\r}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | ▶ | if ( $character eq $TAB ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | $body .= q{\\t}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | ▶ | if ( $character eq q{"} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$character eq "\"" or $character eq "\$" or $character eq "\@" or $character eq $BACKSLASH
$character eq "\"" or $character eq "\$" or $character eq "\@"
$character eq "\"" or $character eq "\$"
MC/DC0%0/4
$character eq "\"" or $character eq "\$" or $character eq "\@" or $character eq $BACKSLASH
$character eq "\""
$character eq "\$"
$character eq "\@"
$character eq $BACKSLASH
Truth table20%1/5
A or B or C or D
A= $character eq "\""B= $character eq "\$"C= $character eq "\@"D= $character eq $BACKSLASH
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | || $character eq q{$} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | || $character eq q{@} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | || $character eq $BACKSLASH ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $body .= $BACKSLASH . $character; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | my $ordinal = ord $character; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | ▶ | if ( $ordinal < ord $PRINTABLE_ASCII_FIRST || $ordinal > ord $PRINTABLE_ASCII_LAST ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ordinal < ord $PRINTABLE_ASCII_FIRST or $ordinal > ord $PRINTABLE_ASCII_LAST
MC/DC0%0/2
$ordinal < ord $PRINTABLE_ASCII_FIRST or $ordinal > ord $PRINTABLE_ASCII_LAST
$ordinal < ord $PRINTABLE_ASCII_FIRST
$ordinal > ord $PRINTABLE_ASCII_LAST
Truth table33%1/3
A or B
A= $ordinal < ord $PRINTABLE_ASCII_FIRSTB= $ordinal > ord $PRINTABLE_ASCII_LAST
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | ## no critic (RequireInterpolationOfMetachars) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | $body .= sprintf q{\x{%x}}, $ordinal; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $body .= $character; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 4 | return q{"} . $body . q{"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 46 | ▶ | sub _single_quoted { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_single_quoted: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 46 | my ($text) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 46 | my $body = q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 46 | for my $character ( split //, $text ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 154 | ▶ | if ( $character eq $APOSTROPHE || $character eq $BACKSLASH ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$character eq $APOSTROPHE or $character eq $BACKSLASH
MC/DC50%1/2
$character eq $APOSTROPHE or $character eq $BACKSLASH
$character eq $APOSTROPHE
$character eq $BACKSLASH
Truth table66%2/3
A or B
A= $character eq $APOSTROPHEB= $character eq $BACKSLASH
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | $body .= $BACKSLASH . $character; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 153 | $body .= $character; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 46 | return $APOSTROPHE . $body . $APOSTROPHE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # The call whose entire first argument is this element, when that call is allowed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 76 | ▶ | sub _allowed_call { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_allowed_call: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 76 | my ( $elem, $allow ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 76 | my $word = _call_word($elem); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 76 | ▶ | return if !$word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 32 | return _name_is_allowed( $word, $allow ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 76 | ▶ | sub _call_word { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_call_word: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 76 | my ($elem) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 76 | ▶ | return if _glued($elem); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 42 | my $previous = _previous_sibling($elem); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 42 | ▶ | return $previous if _names_a_call($previous); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 27 | ▶ | return if $previous; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 23 | return _call_word_from_list($elem); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # Parentheses only. A block, a subscript, or an anonymous array stops the walk. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 23 | ▶ | sub _call_word_from_list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_call_word_from_list: called CC=7 SCAR=19.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 23 | my ($node) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 23 | my $statement = $node->parent(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 23 | ▶ | return if !$statement; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 23 | ▶ | return if !$statement->isa('PPI::Statement'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 23 | my $next = _next_sibling($node); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 23 | ▶ | return _word_before_list($statement) if $next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 10 | my $list = $statement->parent(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 10 | ▶ | return if !$list; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 10 | ▶ | return if !$list->isa('PPI::Structure::List'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 6 | ▶ | return if _previous_sibling($statement); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 6 | return _word_around_grouping($list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 76 | ▶ | sub _glued { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_glued: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 76 | my ($node) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 76 | ▶ | return 1 if _operator_binds( _previous_sibling($node) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 44 | ▶ | return 1 if _operator_binds( _next_sibling($node) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 42 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 1 | ▶ | sub _is_separator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_separator: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 1 | my ($sibling) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 1 | ▶ | return if !$sibling; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | ▶ | return if !$sibling->isa('PPI::Token::Operator'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 1 | return $ARGUMENT_SEPARATOR{$sibling}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 32 | ▶ | sub _name_is_allowed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_name_is_allowed: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 32 | my ( $word, $allow ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 32 | my $written_name = $word->content(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 32 | my $short_name = $written_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 32 | $short_name =~ s/\A.*:://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 32 | my $package_name = _package_name( $word, $written_name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 32 | my $qualified_name = $short_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 32 | ▶ | if ( defined $package_name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 7 | $qualified_name = $package_name . q{::} . $short_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 32 | ▶ | return 1 if $allow->{$qualified_name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 9 | for my $allowed_name ( sort keys %{$allow} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 20 | ▶ | next if index( $allowed_name, q{::} ) >= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 14 | ▶ | return 1 if $allowed_name eq $short_name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 60 | ▶ | sub _names_a_call { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_names_a_call: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 60 | my ($word) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 60 | ▶ | return if !$word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 36 | ▶ | return if !$word->isa('PPI::Token::Word'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 33 | ▶ | return if !is_function_call($word) && !is_method_call($word); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
is_function_call($word) or is_method_call($word)
MC/DC100%2/2
is_function_call($word) or is_method_call($word)
is_function_call($word)
is_method_call($word)
Truth table100%3/3
A or B
A= is_function_call($word)B= is_method_call($word)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 32 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 68 | ▶ | sub _next_sibling { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_next_sibling: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 68 | my ($elem) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 68 | my $sibling = $elem->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 68 | ▶ | return if !$sibling; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 46 | return $sibling; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 120 | ▶ | sub _operator_binds { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_operator_binds: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 120 | my ($sibling) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 120 | ▶ | return if !$sibling; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 84 | ▶ | return if !$sibling->isa('PPI::Token::Operator'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 61 | ▶ | return if $ARGUMENT_SEPARATOR{$sibling}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 34 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 32 | ▶ | sub _package_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_package_name: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 32 | my ( $word, $written_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 32 | ▶ | if ( is_method_call($word) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # A namespace written on the method wins; it sets the resolution start. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 7 | ▶ | if ( index( $written_name, q{::} ) >= 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 1 | my $package_name = $written_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | $package_name =~ s/::[^:]*\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | return $package_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 6 | my $arrow = _previous_sibling($word); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 6 | my $invocant = _previous_sibling($arrow); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 6 | ▶ | return if !$invocant; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 6 | ▶ | return if !$invocant->isa('PPI::Token::Word'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 2 | my $package_name = $invocant->content(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 2 | $package_name =~ s/::\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 2 | return $package_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 25 | ▶ | return if index( $written_name, q{::} ) < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 4 | my $package_name = $written_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 4 | $package_name =~ s/::[^:]*\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 4 | return $package_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 168 | ▶ | sub _previous_sibling { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_previous_sibling: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 168 | my ($elem) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 168 | my $sibling = $elem->sprevious_sibling(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 168 | ▶ | return if !$sibling; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 100 | return $sibling; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 6 | ▶ | sub _word_around_grouping { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_word_around_grouping: called CC=13 SCAR=29.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 6 | my ($list) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 6 | ▶ | while ($list) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 6 | my $word = _previous_sibling($list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 6 | ▶ | return $word if _names_a_call($word); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 1 | ▶ | return if $word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | my $list_statement = $list->parent(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 1 | ▶ | return if !$list_statement; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 1 | ▶ | return if !$list_statement->isa('PPI::Statement'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 1 | my $after = _next_sibling($list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | ▶ | return if $after && !_is_separator($after); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$after and not _is_separator($after)
MC/DC0%0/2
$after and not _is_separator($after)
$after
not _is_separator($after)
Truth table33%1/3
A and not(B)
A= $afterB= not _is_separator($after)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 1 | my $outer = $list_statement->parent(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 1 | ▶ | return if !$outer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 1 | ▶ | return if !$outer->isa('PPI::Structure::List'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 1 | ▶ | return if _previous_sibling($list_statement); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 1 | ▶ | if ($after) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 1 | my $outer_word = _previous_sibling($outer); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 1 | ▶ | return $outer_word if _names_a_call($outer_word); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | $list = $outer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 13 | ▶ | sub _word_before_list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_word_before_list: called CC=5 SCAR=16.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 13 | my ($statement) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 13 | ▶ | return if _previous_sibling($statement); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 13 | my $list = $statement->parent(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 13 | ▶ | return if !$list; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 13 | ▶ | return if !$list->isa('PPI::Structure::List'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 11 | my $word = _previous_sibling($list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 11 | ▶ | return $word if _names_a_call($word); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||