lib/Perl/Critic/Policy/Performance/ProhibitRegexForSimpleSubstring.pm

filter: Statementstmt 96.0% 195 / 203 Branchbran 81.0% 107 / 132 Conditioncond 54.1% 13 / 24 MC/DCmcdc 35.7% 5 / 14 Subroutinesub 96.1% 25 / 26 Podpod 100% 5 / 5 totaltotal 86.6% 350 / 404 CC 80 SCAR 20.7
CC
80
Cov
88%
_word_around_grouping
19.3
_double_quoted
14.3
_decoded_literal
11.1
CRAP 7.9
↑ Summary
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
BranchTrueFalseTotal
unless $literal 18 76 94
64  
65 76 ▶ return if _allowed_call( $elem, $self->{_allow} );
Branch: 1 branch
BranchTrueFalseTotal
if _allowed_call($elem, $self->{"_allow"}) 25 51 76
66  
67 51 my $explanation = $EXPLANATION_GENERIC;
68 51 ▶ if ( defined $literal->{text} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $literal->{"text"}) 50 1 51
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
BranchTrueFalseTotal
my $re = $doc->ppix_regexp_from_element($elem) or return 94 0 94
81 or return;
82 94 ▶ return if $re->failures();
Branch: 1 branch
BranchTrueFalseTotal
if $re->failures 0 94 94
83 94 ▶ return if $re->modifier_asserted($EXEMPTING_MODIFIER);
Branch: 1 branch
BranchTrueFalseTotal
if $re->modifier_asserted($EXEMPTING_MODIFIER) 3 91 94
84  
85 91 ▶ my $pattern = $re->regular_expression()
Branch: 1 branch
BranchTrueFalseTotal
my $pattern = $re->regular_expression or return 91 0 91
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
BranchTrueFalseTotal
unless $token->significant 5 230 235
94 230 ▶ return if !$token->isa('PPIx::Regexp::Token::Literal');
Branch: 1 branch
BranchTrueFalseTotal
unless $token->isa("PPIx::Regexp::Token::Literal") 14 216 230
95  
96 216 $literal_count++;
97  
98 216 my $ordinal = $token->ordinal();
99 216 ▶ if ( !defined $ordinal ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ordinal) 1 215 216
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
BranchTrueFalseTotal
if $literal_count == 0 1 76 77
108  
109 # No ordinal means the explanation cannot name the literal.
110 76 ▶ return {} if $saw_undefined_ordinal;
Branch: 1 branch
BranchTrueFalseTotal
if $saw_undefined_ordinal 1 75 76
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
BranchTrueFalseTotal
if ($ordinal < ord $PRINTABLE_ASCII_FIRST or $ordinal > ord $PRINTABLE_ASCII_LAST) 4 154 158
Condition100%3/3
$ordinal < ord $PRINTABLE_ASCII_FIRST or $ordinal > ord $PRINTABLE_ASCII_LAST
l!l&&r!l&&!r
31154
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if $needs_double_quotes 4 46 50
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
BranchTrueFalseTotal
if ($character eq $NEWLINE) 1 3 4
141 1 $body .= q{\\n};
142 1 next;
143 }
144  
145 3 ▶ if ( $character eq $CARRIAGE_RETURN ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($character eq $CARRIAGE_RETURN) 1 2 3
146 1 $body .= q{\\r};
147 1 next;
148 }
149  
150 2 ▶ if ( $character eq $TAB ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($character eq $TAB) 1 1 2
151 1 $body .= q{\\t};
152 1 next;
153 }
154  
155 1 ▶ if ( $character eq q{"}
Branch: 1 branch
BranchTrueFalseTotal
if ($character eq "\"" or $character eq "\$" or $character eq "\@" or $character eq $BACKSLASH) 0 1 1
Condition33%3/9
$character eq "\"" or $character eq "\$" or $character eq "\@" or $character eq $BACKSLASH
l!l&&r!l&&!r
001
$character eq "\"" or $character eq "\$" or $character eq "\@"
l!l&&r!l&&!r
001
$character eq "\"" or $character eq "\$"
l!l&&r!l&&!r
001
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
ABCDresult
1XXX1
01XX1
001X1
00011
00000
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
BranchTrueFalseTotal
if ($ordinal < ord $PRINTABLE_ASCII_FIRST or $ordinal > ord $PRINTABLE_ASCII_LAST) 1 0 1
Condition33%1/3
$ordinal < ord $PRINTABLE_ASCII_FIRST or $ordinal > ord $PRINTABLE_ASCII_LAST
l!l&&r!l&&!r
010
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($character eq $APOSTROPHE or $character eq $BACKSLASH) 1 153 154
Condition66%2/3
$character eq $APOSTROPHE or $character eq $BACKSLASH
l!l&&r!l&&!r
01153
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless $word 44 32 76
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
BranchTrueFalseTotal
if _glued($elem) 34 42 76
208  
209 42 my $previous = _previous_sibling($elem);
210 42 ▶ return $previous if _names_a_call($previous);
Branch: 1 branch
BranchTrueFalseTotal
if _names_a_call($previous) 15 27 42
211 27 ▶ return if $previous;
Branch: 1 branch
BranchTrueFalseTotal
if $previous 4 23 27
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
BranchTrueFalseTotal
unless $statement 0 23 23
222 23 ▶ return if !$statement->isa('PPI::Statement');
Branch: 1 branch
BranchTrueFalseTotal
unless $statement->isa("PPI::Statement") 0 23 23
223  
224 23 my $next = _next_sibling($node);
225 23 ▶ return _word_before_list($statement) if $next;
Branch: 1 branch
BranchTrueFalseTotal
if $next 13 10 23
226  
227 10 my $list = $statement->parent();
228 10 ▶ return if !$list;
Branch: 1 branch
BranchTrueFalseTotal
unless $list 0 10 10
229 10 ▶ return if !$list->isa('PPI::Structure::List');
Branch: 1 branch
BranchTrueFalseTotal
unless $list->isa("PPI::Structure::List") 4 6 10
230 6 ▶ return if _previous_sibling($statement);
Branch: 1 branch
BranchTrueFalseTotal
if _previous_sibling($statement) 0 6 6
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
BranchTrueFalseTotal
if _operator_binds(_previous_sibling($node)) 32 44 76
239 44 ▶ return 1 if _operator_binds( _next_sibling($node) );
Branch: 1 branch
BranchTrueFalseTotal
if _operator_binds(_next_sibling($node)) 2 42 44
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
BranchTrueFalseTotal
unless $sibling 0 1 1
248 1 ▶ return if !$sibling->isa('PPI::Token::Operator');
Branch: 1 branch
BranchTrueFalseTotal
unless $sibling->isa("PPI::Token::Operator") 0 1 1
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
BranchTrueFalseTotal
if (defined $package_name) 7 25 32
263 7 $qualified_name = $package_name . q{::} . $short_name;
264 }
265  
266 32 ▶ return 1 if $allow->{$qualified_name};
Branch: 1 branch
BranchTrueFalseTotal
if $allow->{$qualified_name} 23 9 32
267  
268 9 for my $allowed_name ( sort keys %{$allow} ) {
269 20 ▶ next if index( $allowed_name, q{::} ) >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($allowed_name, "::") != -1 6 14 20
270  
271 14 ▶ return 1 if $allowed_name eq $short_name;
Branch: 1 branch
BranchTrueFalseTotal
if $allowed_name eq $short_name 2 12 14
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
BranchTrueFalseTotal
unless $word 24 36 60
281 36 ▶ return if !$word->isa('PPI::Token::Word');
Branch: 1 branch
BranchTrueFalseTotal
unless $word->isa("PPI::Token::Word") 3 33 36
282 33 ▶ return if !is_function_call($word) && !is_method_call($word);
Branch: 1 branch
BranchTrueFalseTotal
unless is_function_call($word) or is_method_call($word) 1 32 33
Condition100%3/3
is_function_call($word) or is_method_call($word)
l!l&&r!l&&!r
2571
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)
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless $sibling 22 46 68
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
BranchTrueFalseTotal
unless $sibling 36 84 120
300 84 ▶ return if !$sibling->isa('PPI::Token::Operator');
Branch: 1 branch
BranchTrueFalseTotal
unless $sibling->isa("PPI::Token::Operator") 23 61 84
301 61 ▶ return if $ARGUMENT_SEPARATOR{$sibling};
Branch: 1 branch
BranchTrueFalseTotal
if $ARGUMENT_SEPARATOR{$sibling} 27 34 61
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
BranchTrueFalseTotal
if (is_method_call($word)) 7 25 32
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
BranchTrueFalseTotal
if (index($written_name, "::") != -1) 1 6 7
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
BranchTrueFalseTotal
unless $invocant 0 6 6
322 6 ▶ return if !$invocant->isa('PPI::Token::Word');
Branch: 1 branch
BranchTrueFalseTotal
unless $invocant->isa("PPI::Token::Word") 4 2 6
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
BranchTrueFalseTotal
if index($written_name, "::") == -1 21 4 25
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
BranchTrueFalseTotal
unless $sibling 68 100 168
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
BranchTrueFalseTotal
if ($list) 6 0 6
351 6 my $word = _previous_sibling($list);
352 6 ▶ return $word if _names_a_call($word);
Branch: 1 branch
BranchTrueFalseTotal
if _names_a_call($word) 5 1 6
353 1 ▶ return if $word;
Branch: 1 branch
BranchTrueFalseTotal
if $word 0 1 1
354  
355 1 my $list_statement = $list->parent();
356 1 ▶ return if !$list_statement;
Branch: 1 branch
BranchTrueFalseTotal
unless $list_statement 0 1 1
357 1 ▶ return if !$list_statement->isa('PPI::Statement');
Branch: 1 branch
BranchTrueFalseTotal
unless $list_statement->isa("PPI::Statement") 0 1 1
358  
359 1 my $after = _next_sibling($list);
360 1 ▶ return if $after && !_is_separator($after);
Branch: 1 branch
BranchTrueFalseTotal
if $after and not _is_separator($after) 0 1 1
Condition33%1/3
$after and not _is_separator($after)
!ll&&!rl&&r
010
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)
ABresult
0X0
100
111
361  
362 1 my $outer = $list_statement->parent();
363 1 ▶ return if !$outer;
Branch: 1 branch
BranchTrueFalseTotal
unless $outer 0 1 1
364 1 ▶ return if !$outer->isa('PPI::Structure::List');
Branch: 1 branch
BranchTrueFalseTotal
unless $outer->isa("PPI::Structure::List") 0 1 1
365 1 ▶ return if _previous_sibling($list_statement);
Branch: 1 branch
BranchTrueFalseTotal
if _previous_sibling($list_statement) 0 1 1
366  
367 1 ▶ if ($after) {
Branch: 1 branch
BranchTrueFalseTotal
if ($after) 1 0 1
368 1 my $outer_word = _previous_sibling($outer);
369 1 ▶ return $outer_word if _names_a_call($outer_word);
Branch: 1 branch
BranchTrueFalseTotal
if _names_a_call($outer_word) 1 0 1
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
BranchTrueFalseTotal
if _previous_sibling($statement) 0 13 13
384  
385 13 my $list = $statement->parent();
386 13 ▶ return if !$list;
Branch: 1 branch
BranchTrueFalseTotal
unless $list 0 13 13
387 13 ▶ return if !$list->isa('PPI::Structure::List');
Branch: 1 branch
BranchTrueFalseTotal
unless $list->isa("PPI::Structure::List") 2 11 13
388  
389 11 my $word = _previous_sibling($list);
390 11 ▶ return $word if _names_a_call($word);
Branch: 1 branch
BranchTrueFalseTotal
if _names_a_call($word) 11 0 11
391  
392 0 return;
393 }
394  
395 2 1;
396  
397 #-----------------------------------------------------------------------------
398  
399 __END__
↑ Summary