lib/Perl/Critic/Policy/ValuesAndExpressions/RequireConsistentQuoting.pm

filter: Statementstmt 99.6% 262 / 263 Branchbran 94.8% 165 / 174 (2 uncoverable) Conditioncond 91.5% 108 / 118 MC/DCmcdc 83.1% 59 / 71 Subroutinesub 100% 65 / 65 Podpod 100% 27 / 27 totaltotal 95.5% 686 / 718 (2 uncoverable) CC 137 SCAR 18.8
CC
137
Cov
96%
collect_qw_words
18.0
check_use_statement
15.0
_extract_list_arguments
10.1
CRAP 6.6
« lib/Perl/Critic/PJCJ/Fixer.pm ↑ Summary lib/Perl/Critic/Policy/CodeLayout/ProhibitLongLines.pm »
1 package Perl::Critic::Policy::ValuesAndExpressions::RequireConsistentQuoting v0.3.0;
2  
3 44 ▶use v5.26.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 44 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 44 ▶use feature "signatures";
Subroutine BEGIN: called CC=1 SCAR=0.0
7 44 ▶use experimental "signatures";
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 44 ▶use parent qw( Perl::Critic::Policy );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 44 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 44 ▶use List::Util qw( all any );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 44 ▶use Perl::Critic::Utils qw( $SEVERITY_MEDIUM );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 44 ▶use Scalar::Util qw( refaddr weaken );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 44 ▶use Perl::Critic::PJCJ::Violation ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 44 our @EXPORT_OK = qw(
19 desc_double desc_optimal desc_remove_parens desc_single desc_use_qw
20 );
21  
22 319 ▶sub desc_double () { 'use ""' }
Subroutine desc_double: called CC=1 SCAR=0.0
Pod documented
23 162 ▶sub desc_single () { "use ''" }
Subroutine desc_single: called CC=1 SCAR=0.0
Pod documented
24 82 ▶sub desc_use_qw () { "use qw()" }
Subroutine desc_use_qw: called CC=1 SCAR=0.0
Pod documented
25 36 ▶sub desc_remove_parens () { "remove parentheses" }
Subroutine desc_remove_parens: called CC=1 SCAR=0.0
Pod documented
26 370 ▶sub desc_optimal ($display) { "use $display" }
Subroutine desc_optimal: called CC=1 SCAR=0.0
Pod documented
27  
28 44 my $Expl = "Quoting should be consistent and minimal";
29  
30 44 my $Fix_double = { type => "double" };
31 44 my $Fix_single = { type => "single" };
32 44 my $Fix_remove_parens = { type => "remove_parens" };
33 44 my $Fix_use_qw = { type => "operator", op => "qw", start => "(", end => ")" };
34  
35 221 ▶sub _operator_fix ($self, $op, $delim) { {
Subroutine _operator_fix: called CC=1 SCAR=0.0
36 type => "operator",
37 op => $op,
38 start => $delim->{start},
39 end => $delim->{end},
40 221 } }
41  
42 682 ▶sub _render_fix ($self, $fix) {
Subroutine _render_fix: called CC=4 SCAR=13.9
43 682 my $type = $fix->{type};
44 682 ▶ return desc_double if $type eq "double";
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "double" 227 455 682
45 455 ▶ return desc_single if $type eq "single";
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "single" 107 348 455
46 348 ▶ return desc_remove_parens if $type eq "remove_parens";
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "remove_parens" 22 326 348
47 326 desc_optimal("$fix->{op}$fix->{start}$fix->{end}")
48 }
49  
50 625 ▶sub _fix_violation ($self, $fix, $elem) {
Subroutine _fix_violation: called CC=1 SCAR=0.0
51 625 Perl::Critic::PJCJ::Violation->new(
52 $self->_render_fix($fix),
53 $Expl, $elem, $self->get_severity,
54 )->set_fix($fix)
55 }
56  
57 sub supported_parameters ($self) { }
58 627 ▶sub default_severity ($self) { $SEVERITY_MEDIUM }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
59 2 ▶sub default_themes ($self) { qw( cosmetic pjcj ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
60  
61 795 ▶sub applies_to ($self) {
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
62 #<<<
63 795 qw(
64 PPI::Statement::Include
65 PPI::Token::Quote::Double
66 PPI::Token::Quote::Interpolate
67 PPI::Token::Quote::Literal
68 PPI::Token::Quote::Single
69 PPI::Token::QuoteLike::Command
70 PPI::Token::QuoteLike::Words
71 )
72 #>>>
73 }
74  
75 1122 ▶sub would_interpolate ($self, $string) {
Subroutine would_interpolate: called CC=2 SCAR=6.9
Pod documented
76 # This is the authoritative way to check - let PPI decide
77 1122 state %cache;
78 1122 ▶ return $cache{$string} if exists $cache{$string};
Branch: 1 branch
BranchTrueFalseTotal
if exists $cache{$string} 833 289 1122
79  
80 # Neutralise embedded double quotes so wrapping in "..." is valid PPI
81 289 my $safe = $string =~ s/"/ /gr;
82 289 my $test_content = qq("$safe");
83 289 my $test_doc = PPI::Document->new(\$test_content);
84  
85 289 my $would_interpolate = 0;
86 $test_doc->find(
87 578 ▶ sub ($top, $test_elem) {
Subroutine __ANON__: called CC=2 SCAR=6.9
88 578 ▶ $would_interpolate = $test_elem->interpolations
Branch: 1 branch
BranchTrueFalseTotal
if $test_elem->isa("PPI::Token::Quote::Double") 289 289 578
89 if $test_elem->isa("PPI::Token::Quote::Double");
90 578 0
91 }
92 289 );
93  
94 289 $cache{$string} = $would_interpolate
95 }
96  
97 382 ▶sub escape_single_quoted ($self, $string) {
Subroutine escape_single_quoted: called CC=1 SCAR=0.0
Pod documented
98 # The inner content of a '...' literal: backslash-escape \ and '
99 382 $string =~ s/([\\'])/\\$1/gr
100 }
101  
102 324 ▶sub would_interpolate_from_single_quotes ($self, $string) {
Subroutine would_interpolate_from_single_quotes: called CC=1 SCAR=0.0
Pod documented
103 324 $self->would_interpolate($self->escape_single_quoted($string))
104 }
105  
106 886 ▶sub parse_quote_token ($self, $elem) {
Subroutine parse_quote_token: called CC=2 SCAR=7.0
Pod documented
107 886 my $content = $elem->content;
108  
109 # Handle all possible delimiters, not just bracket pairs
110 # q must be last so qw/qq/qx aren't consumed as q + letter
111 886 ▶ if ($content =~ /\A(?:(qw|qq|qx|q)\s*)?(.)(.*)(.)\z/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /\A(?:(qw|qq|qx|q)\s*)?(.)(.*)(.)\z/su) 886 0 886
112 886 my ($op, $start_delim, $str, $end_delim) = ($1, $2, $3, $4);
113 886 ($start_delim, $end_delim, $str, $op)
114 }
115 }
116  
117 477 ▶sub _get_supported_delimiters ($self, $operator) {
Subroutine _get_supported_delimiters: called CC=2 SCAR=6.9
118 477 state %tables;
119 (
120 477 ▶ $tables{$operator} //= [
Condition100%2/2
$tables{$operator} //= [{"start", "(", "end", ")", "display", "$operator()"}, {"start", "[", "end", "]", "display", "${operator}[]"}, {"start", "<", "end", ">", "display", "$operator<>"}, {"start", "{", "end", "}", "display", "${operator}{}"}]
l!l
43641
MC/DC100%1/1
$tables{$operator} //= [{"start", "(", "end", ")", "display", "$operator()"}, {"start", "[", "end", "]", "display", "${operator}[]"}, {"start", "<", "end", ">", "display", "$operator<>"}, {"start", "{", "end", "}", "display", "${operator}{}"}]
$tables{$operator}
Truth table100%2/2
A
A= $tables{$operator}
Aresult
11
00
121 { start => "(", end => ")", display => "${operator}()" },
122 { start => "[", end => "]", display => "${operator}[]" },
123 { start => "<", end => ">", display => "${operator}<>" },
124 { start => "{", end => "}", display => "${operator}{}" },
125 ]
126 )->@*
127 }
128  
129 465 ▶sub find_optimal_delimiter ($self, $content, $operator, $start, $end) {
Subroutine find_optimal_delimiter: called CC=5 SCAR=16.1
Pod documented
130 465 my @delimiters = $self->_get_supported_delimiters($operator);
131  
132 465 my %count = (
133 "(" => $content =~ tr/()//,
134 "[" => $content =~ tr/[]//,
135 "<" => $content =~ tr/<>//,
136 "{" => $content =~ tr/{}//,
137 );
138  
139 # Fewest delimiter occurrences in the content wins; ties are broken by the
140 # order of @delimiters, which encodes the preference () > [] > <> > {}
141 465 my $optimal = $delimiters[0];
142 465 for my $delim (@delimiters) {
143 $optimal = $delim
144 1860 ▶ if $count{ $delim->{start} } < $count{ $optimal->{start} };
Branch: 1 branch
BranchTrueFalseTotal
if $count{$delim->{"start"}} < $count{$optimal->{"start"}} 69 1791 1860
145 }
146  
147 my $current_is_optimal
148 465 ▶ = $optimal->{start} eq $start && $optimal->{end} eq $end ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$optimal->{'start'} eq $start && $optimal->{'end'} eq $end ? : 288 177 465
Condition66%2/3
$optimal->{"start"} eq $start and $optimal->{"end"} eq $end
!ll&&!rl&&r
1770288
MC/DC50%1/2
$optimal->{"start"} eq $start and $optimal->{"end"} eq $end
$optimal->{"start"} eq $start $optimal->{"end"} eq $end
Truth table66%2/3
A and B
A= $optimal->{"start"} eq $startB= $optimal->{"end"} eq $end
ABresult
0X0
100
111
149  
150 465 ($optimal, $current_is_optimal)
151 }
152  
153 3 ▶sub _known_fixes ($self) {
Subroutine _known_fixes: called CC=2 SCAR=6.9
154 3 my @fixes = ($Fix_double, $Fix_single, $Fix_remove_parens);
155 3 for my $op (qw( q qq qw qx )) {
156 12 push @fixes, map $self->_operator_fix($op, $_),
157 $self->_get_supported_delimiters($op);
158 }
159 @fixes
160 3 }
161  
162 49 ▶sub fix_data ($self, $description) {
Subroutine fix_data: called CC=1 SCAR=0.0
Pod documented
163 49 state $map = { map { ($self->_render_fix($_) => $_) } $self->_known_fixes };
164 49 $map->{$description}
165 }
166  
167 115 ▶sub check_delimiter_optimisation ($self, $elem) {
Subroutine check_delimiter_optimisation: called CC=5 SCAR=16.2
Pod documented
168 115 my ($start, $end, $content, $operator) = $self->parse_quote_token($elem);
169 115 ▶ return unless defined $start;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start 0 115 115
170  
171 115 ▶ $operator //= "q" if $start eq "'";
Branch: 1 branch
BranchTrueFalseTotal
if $start eq "'" 5 110 115
Condition50%1/2
$operator //= "q"
l!l
05
MC/DC0%0/1
$operator //= "q"
$operator
Truth table50%1/2
A
A= $operator
Aresult
11
00
172 115 my ($optimal_delim, $current_is_optimal)
173 = $self->find_optimal_delimiter($content, $operator, $start, $end);
174 115 ▶ return $self->_fix_violation(
Branch: 1 branch
BranchTrueFalseTotal
unless $current_is_optimal 25 90 115
175 $self->_operator_fix($operator, $optimal_delim), $elem
176 ) unless $current_is_optimal;
177  
178 return
179 90 }
180  
181 2146 ▶sub _quote_token_complete ($self, $elem) {
Subroutine _quote_token_complete: called CC=5 SCAR=16.2
182 # Only the final token of a document can be unterminated: the
183 # tokeniser runs an unterminated quote to end of file
184 2146 ▶ return 1 if $elem->next_token;
Branch: 1 branch
BranchTrueFalseTotal
if $elem->next_token 634 1512 2146
185  
186 # A terminated token reparses to itself; an unterminated one absorbs
187 # the appended semicolon
188 1512 my $code = $elem->content . ";";
189  
190 # uncoverable branch true note:the probe code is never empty
191 1512 ▶ my $doc = PPI::Document->new(\$code) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $doc = "PPI::Document"->new(\$code) or return 0 1512 0 1512
192 my ($token) = grep {
193 1512 ▶ $_->isa("PPI::Token::Quote") || $_->isa("PPI::Token::QuoteLike")
Condition100%3/3
$_->isa('PPI::Token::Quote') || $_->isa('PPI::Token::QuoteLike')
l!l&&r!l&&!r
10674451489
MC/DC100%2/2
$_->isa('PPI::Token::Quote') || $_->isa('PPI::Token::QuoteLike')
$_->isa('PPI::Token::Quote') $_->isa('PPI::Token::QuoteLike')
Truth table100%3/3
A || B
A= $_->isa('PPI::Token::Quote')B= $_->isa('PPI::Token::QuoteLike')
ABresult
1X1
011
000
194 } $doc->tokens;
195  
196 # uncoverable branch false note:the probe starts with a quote token
197 1512 ▶ $token && $token->content eq $elem->content
Branch: 1 branch
BranchTrueFalseTotal
$token and $token->content eq $elem->content 1512 0 1512
198 }
199  
200 453 ▶sub has_quote_sensitive_escapes ($self, $string) {
Subroutine has_quote_sensitive_escapes: called CC=1 SCAR=0.0
Pod documented
201 453 $string =~ /
202 \\(?:
203 [tnrfbae] | # Single char escapes: \t \n \r \f \b \a \e
204 x[0-9a-fA-F]* | # Hex escapes: \x1b \xff
205 x\{[^}]*\} | # Hex braces: \x{1b} \x{263A}
206 [0-7]{1,3} | # Octal: \033 \377
207 o\{[^}]*\} | # Octal braces: \o{033}
208 c. | # Control chars: \c[ \cA
209 N\{[^}]*\} | # Named chars: \N{name} \N{U+263A}
210 [luLUEQF] # String modification: \l \u \L \U \E \Q \F
211 )
212 /x
213 }
214  
215 1201 ▶sub _has_newlines ($self, $string) {
Subroutine _has_newlines: called CC=1 SCAR=0.0
216 # Check if string contains literal newlines (not \n escape sequences)
217 1201 index($string, "\n") != -1
218 }
219  
220 83 ▶sub _extract_list_arguments ($self, $list) {
Subroutine _extract_list_arguments: called CC=10 SCAR=23.2
221 83 my @args;
222 83 for my $child ($list->children) {
223 123 ▶ if ($child->isa("PPI::Statement::Expression")) {
Branch: 2 branches
BranchTrueFalseTotal
if ($child->isa('PPI::Statement::Expression')) { } 69 54 123
elsif ($child->isa('PPI::Statement') or $child->isa('PPI::Structure')) { } 4 50 54
224 69 for my $expr_child ($child->children) {
225 429 ▶ next unless $expr_child->significant;
Branch: 1 branch
BranchTrueFalseTotal
unless $expr_child->significant 172 257 429
226 # Skip commas but keep fat comma (=>) and other significant operators
227 next
228 257 ▶ if $expr_child->isa("PPI::Token::Operator")
Branch: 1 branch
BranchTrueFalseTotal
if $expr_child->isa("PPI::Token::Operator") and $expr_child->content eq "," 42 215 257
Condition100%3/3
$expr_child->isa("PPI::Token::Operator") and $expr_child->content eq ","
!ll&&!rl&&r
1635242
MC/DC100%2/2
$expr_child->isa("PPI::Token::Operator") and $expr_child->content eq ","
$expr_child->isa("PPI::Token::Operator") $expr_child->content eq ","
Truth table100%3/3
A and B
A= $expr_child->isa("PPI::Token::Operator")B= $expr_child->content eq ","
ABresult
0X0
100
111
229 && $expr_child->content eq ",";
230 215 push @args, $expr_child;
231 }
232 ▶ } elsif ($child->isa("PPI::Statement") || $child->isa("PPI::Structure")) {
Condition66%2/3
$child->isa("PPI::Statement") or $child->isa("PPI::Structure")
l!l&&r!l&&!r
4050
MC/DC50%1/2
$child->isa("PPI::Statement") or $child->isa("PPI::Structure")
$child->isa("PPI::Statement") $child->isa("PPI::Structure")
Truth table66%2/3
A or B
A= $child->isa("PPI::Statement")B= $child->isa("PPI::Structure")
ABresult
1X1
011
000
233 # Handle other statements and structures (like hash constructors)
234 4 push @args, $child;
235 } else {
236 50 ▶ next unless $child->significant;
Branch: 1 branch
BranchTrueFalseTotal
unless $child->significant 50 0 50
237 0 push @args, $child;
238 }
239 }
240 @args
241 83 }
242  
243 749 ▶sub _extract_use_arguments ($self, $elem) {
Subroutine _extract_use_arguments: called CC=6 SCAR=17.9
244 # No module means no import arguments; ->arguments dies on a bare "use"
245 749 ▶ return () unless $elem->module;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->module 1 748 749
246 748 my @args;
247 748 for my $child ($elem->arguments) {
248 # Skip commas but keep fat comma (=>) and other significant operators
249 1575 ▶ next if $child->isa("PPI::Token::Operator") && $child->content eq ",";
Branch: 1 branch
BranchTrueFalseTotal
if $child->isa("PPI::Token::Operator") and $child->content eq "," 294 1281 1575
Condition100%3/3
$child->isa("PPI::Token::Operator") and $child->content eq ","
!ll&&!rl&&r
1163118294
MC/DC100%2/2
$child->isa("PPI::Token::Operator") and $child->content eq ","
$child->isa("PPI::Token::Operator") $child->content eq ","
Truth table100%3/3
A and B
A= $child->isa("PPI::Token::Operator")B= $child->content eq ","
ABresult
0X0
100
111
250  
251 # If it's a list structure (parentheses), extract its contents
252 1281 ▶ if ($child->isa("PPI::Structure::List")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($child->isa('PPI::Structure::List')) { } 83 1198 1281
253 83 push @args, $self->_extract_list_arguments($child);
254 } else {
255 1198 push @args, $child;
256 }
257 }
258 @args
259 748 }
260  
261 413 ▶sub _is_pragma ($self, $elem) {
Subroutine _is_pragma: called CC=1 SCAR=0.0
262 413 !!$elem->pragma
263 }
264  
265 551 ▶sub _any_arg_interpolates ($self, @args) {
Subroutine _any_arg_interpolates: called CC=5 SCAR=16.1
266 551 for my $arg (@args) {
267 927 ▶ next if $arg->isa("PPI::Token::QuoteLike::Words");
Branch: 1 branch
BranchTrueFalseTotal
if $arg->isa("PPI::Token::QuoteLike::Words") 229 698 927
268 698 ▶ next unless $arg->can("string");
Branch: 1 branch
BranchTrueFalseTotal
unless $arg->can("string") 221 477 698
269 477 ▶ return 1 if $self->would_interpolate($arg->string);
Branch: 1 branch
BranchTrueFalseTotal
if $self->would_interpolate($arg->string) 75 402 477
270 }
271 0
272 476 }
273  
274 359 ▶sub _use_statement_verdict ($self, $stmt) {
Subroutine _use_statement_verdict: called CC=4 SCAR=13.9
275 359 my @args = $self->_extract_use_arguments($stmt);
276  
277 # Single-arg pragmas follow normal quoting rules
278 359 ▶ return 0 if @args == 1 && $self->_is_pragma($stmt);
Branch: 1 branch
BranchTrueFalseTotal
if @args == 1 and $self->_is_pragma($stmt) 49 310 359
Condition100%3/3
@args == 1 and $self->_is_pragma($stmt)
!ll&&!rl&&r
15915149
MC/DC100%2/2
@args == 1 and $self->_is_pragma($stmt)
@args == 1 $self->_is_pragma($stmt)
Truth table100%3/3
A and B
A= @args == 1B= $self->_is_pragma($stmt)
ABresult
0X0
100
111
279  
280 # If interpolation is needed, don't treat this as a use statement
281 # so individual strings get checked normally
282 310 ▶ return 0 if $self->_any_arg_interpolates(@args);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_any_arg_interpolates(@args) 38 272 310
283 272 1
284 }
285  
286 501 ▶sub _cached_use_statement_verdict ($self, $stmt) {
Subroutine _cached_use_statement_verdict: called CC=5 SCAR=16.1
287 501 ▶ my $doc = $stmt->document or return $self->_use_statement_verdict($stmt);
Branch: 1 branch
BranchTrueFalseTotal
my $doc = $stmt->document or return $self->_use_statement_verdict($stmt) 500 1 501
288  
289 500 my $cached = $self->{_use_cache_doc};
290 500 ▶ if (!$cached || refaddr($cached) != refaddr($doc)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $cached or builtin::refaddr($cached) != builtin::refaddr($doc)) 358 142 500
Condition100%3/3
not $cached or builtin::refaddr($cached) != builtin::refaddr($doc)
l!l&&r!l&&!r
3571142
MC/DC100%2/2
not $cached or builtin::refaddr($cached) != builtin::refaddr($doc)
not $cached builtin::refaddr($cached) != builtin::refaddr($doc)
Truth table100%3/3
not(A) or B
A= not $cachedB= builtin::refaddr($cached) != builtin::refaddr($doc)
ABresult
1X1
011
000
291 358 $self->{_use_cache_doc} = $doc;
292 358 weaken $self->{_use_cache_doc};
293 358 $self->{_use_cache} = {};
294 }
295 500 ▶ $self->{_use_cache}{ refaddr $stmt } //= $self->_use_statement_verdict($stmt)
Condition66%2/3
$self->{"_use_cache"}{builtin::refaddr($stmt)} //= $self->_use_statement_verdict($stmt)
l!l&&r!l&&!r
1423580
MC/DC0%0/2
$self->{"_use_cache"}{builtin::refaddr($stmt)} //= $self->_use_statement_verdict($stmt)
$self->{"_use_cache"}{builtin::refaddr($stmt)} $self->_use_statement_verdict($stmt)
Truth table66%2/3
A //= B
A= $self->{"_use_cache"}{builtin::refaddr($stmt)}B= $self->_use_statement_verdict($stmt)
ABresult
1X1
011
000
296 }
297  
298 1903 ▶sub _is_in_use_statement ($self, $elem) {
Subroutine _is_in_use_statement: called CC=4 SCAR=13.9
299 1903 my $current = $elem;
300 1903 ▶ while ($current) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current) 5380 1402 6782
301 5380 ▶ return $self->_cached_use_statement_verdict($current)
Branch: 1 branch
BranchTrueFalseTotal
if $current->isa("PPI::Statement::Include") and $current->type =~ /^(use|no)$/u 501 4879 5380
Condition100%3/3
$current->isa("PPI::Statement::Include") and $current->type =~ /^(use|no)$/u
!ll&&!rl&&r
48754501
MC/DC100%2/2
$current->isa("PPI::Statement::Include") and $current->type =~ /^(use|no)$/u
$current->isa("PPI::Statement::Include") $current->type =~ /^(use|no)$/u
Truth table100%3/3
A and B
A= $current->isa("PPI::Statement::Include")B= $current->type =~ /^(use|no)$/u
ABresult
0X0
100
111
302 if $current->isa("PPI::Statement::Include")
303 && $current->type =~ /^(use|no)$/;
304 4879 $current = $current->parent;
305 }
306 0
307 1402 }
308  
309 9944 ▶sub violates ($self, $elem, $) {
Subroutine violates: called CC=9 SCAR=22.0
Pod documented
310 9944 state $dispatch = {
311 "PPI::Token::Quote::Single" => "check_single_quoted",
312 "PPI::Token::Quote::Double" => "check_double_quoted",
313 "PPI::Token::Quote::Literal" => "check_q_literal",
314 "PPI::Token::Quote::Interpolate" => "check_qq_interpolate",
315 "PPI::Token::QuoteLike::Words" => "check_quote_operators",
316 "PPI::Token::QuoteLike::Command" => "check_quote_operators",
317 "PPI::Statement::Include" => "check_use_statement",
318 };
319  
320 9944 my $class = ref $elem;
321 9944 ▶ my $method = $dispatch->{$class} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $method = $dispatch->{$class} or return 2322 7622 9944
322  
323 # An unterminated quote token at end of file parses with its final
324 # content character taken as the closing delimiter, so any suggestion
325 # (and any autofix built on it) would delete characters. Leave broken
326 # source alone.
327 2322 my $last = $elem->last_token;
328 return
329 2322 ▶ if ($last->isa("PPI::Token::Quote") || $last->isa("PPI::Token::QuoteLike"))
Branch: 1 branch
BranchTrueFalseTotal
if $last->isa("PPI::Token::Quote") || $last->isa("PPI::Token::QuoteLike") and not $self->_quote_token_complete($last) 23 2299 2322
Condition100%6/6
$last->isa("PPI::Token::Quote") || $last->isa("PPI::Token::QuoteLike") and not $self->_quote_token_complete($last)
!ll&&!rl&&r
176212323
$last->isa("PPI::Token::Quote") or $last->isa("PPI::Token::QuoteLike")
l!l&&r!l&&!r
1612534176
MC/DC100%3/3
$last->isa("PPI::Token::Quote") || $last->isa("PPI::Token::QuoteLike") and not $self->_quote_token_complete($last)
$last->isa("PPI::Token::Quote") $last->isa("PPI::Token::QuoteLike") not $self->_quote_token_complete($last)
Truth table100%5/5
A or B and not(C)
A= $last->isa("PPI::Token::Quote")B= $last->isa("PPI::Token::QuoteLike")C= not $self->_quote_token_complete($last)
ABCresult
00X0
1X00
0100
1X11
0111
330 && !$self->_quote_token_complete($last);
331  
332 # Two shared guards apply to token classes before dispatch: tokens inside
333 # a use/no statement are handled by check_use_statement, and string tokens
334 # with literal newlines are exempt (see the Newlines POD section)
335 2299 ▶ if ($elem->isa("PPI::Token")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Token")) 1903 396 2299
336 1903 ▶ return if $self->_is_in_use_statement($elem);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_in_use_statement($elem) 376 1527 1903
337 return
338 1527 ▶ if $elem->isa("PPI::Token::Quote") && $self->_has_newlines($elem->string);
Branch: 1 branch
BranchTrueFalseTotal
if $elem->isa("PPI::Token::Quote") and $self->_has_newlines($elem->string) 31 1496 1527
Condition100%3/3
$elem->isa("PPI::Token::Quote") and $self->_has_newlines($elem->string)
!ll&&!rl&&r
326117031
MC/DC100%2/2
$elem->isa("PPI::Token::Quote") and $self->_has_newlines($elem->string)
$elem->isa("PPI::Token::Quote") $self->_has_newlines($elem->string)
Truth table100%3/3
A and B
A= $elem->isa("PPI::Token::Quote")B= $self->_has_newlines($elem->string)
ABresult
0X0
100
111
339 }
340  
341 1892 $self->$method($elem)
342 }
343  
344 2 ▶sub prepare_to_scan_document ($self, $) {
Subroutine prepare_to_scan_document: called CC=1 SCAR=0.0
Pod documented
345 2 delete $self->{_use_cache_doc};
346 2 delete $self->{_use_cache};
347 2 1
348 }
349  
350 301 ▶sub check_single_quoted ($self, $elem) {
Subroutine check_single_quoted: called CC=6 SCAR=17.9
Pod documented
351 301 my $string = $elem->string;
352  
353 301 my $has_single_quotes = index($string, "'") != -1;
354 301 my $has_double_quotes = index($string, '"') != -1;
355  
356 301 ▶ return $self->check_delimiter_optimisation($elem)
Branch: 1 branch
BranchTrueFalseTotal
if $has_single_quotes and $has_double_quotes 5 296 301
Condition100%3/3
$has_single_quotes and $has_double_quotes
!ll&&!rl&&r
28975
MC/DC100%2/2
$has_single_quotes and $has_double_quotes
$has_single_quotes $has_double_quotes
Truth table100%3/3
A and B
A= $has_single_quotesB= $has_double_quotes
ABresult
0X0
100
111
357 if $has_single_quotes && $has_double_quotes;
358  
359 return if
360 # Keep single quotes if the string contains double quotes
361 296 ▶ $has_double_quotes ||
Branch: 1 branch
BranchTrueFalseTotal
if $has_double_quotes or $self->has_quote_sensitive_escapes($string) or $self->would_interpolate_from_single_quotes($string) 216 80 296
Condition100%6/6
$has_double_quotes or $self->has_quote_sensitive_escapes($string) or $self->would_interpolate_from_single_quotes($string)
l!l&&r!l&&!r
10111580
$has_double_quotes or $self->has_quote_sensitive_escapes($string)
l!l&&r!l&&!r
5447195
MC/DC100%3/3
$has_double_quotes or $self->has_quote_sensitive_escapes($string) or $self->would_interpolate_from_single_quotes($string)
$has_double_quotes $self->has_quote_sensitive_escapes($string) $self->would_interpolate_from_single_quotes($string)
Truth table100%4/4
A or B or C
A= $has_double_quotesB= $self->has_quote_sensitive_escapes($string)C= $self->would_interpolate_from_single_quotes($string)
ABCresult
1XX1
01X1
0011
0000
362 # Check if string contains escape sequences that would have different
363 # meanings between single vs double quotes. If so, preserve single quotes.
364 $self->has_quote_sensitive_escapes($string) ||
365 # Keep single quotes if double would introduce interpolation
366 $self->would_interpolate_from_single_quotes($string);
367  
368 80 $self->_fix_violation($Fix_double, $elem)
369 }
370  
371 539 ▶sub check_double_quoted ($self, $elem) {
Subroutine check_double_quoted: called CC=6 SCAR=17.9
Pod documented
372 539 my $string = $elem->string;
373 539 my $content = $elem->content;
374  
375 # Strip delimiters and remove \\ pairs so escaped backslashes before the
376 # closing delimiter aren't mistaken for escaped specials
377 539 my $inner = substr $content, 1, -1;
378 539 (my $cleaned = $inner) =~ s/\\\\//g;
379  
380 # Check for escaped dollar/at signs or double quotes, but only suggest single
381 # quotes if no other interpolation exists AND no dangerous escape sequences
382 539 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($cleaned =~ /\\[\$\@\"]/u and not $self->has_quote_sensitive_escapes($string) and not $self->would_interpolate($string)) 34 505 539
Condition100%6/6
$cleaned =~ /\\[\$\@\"]/u and not $self->has_quote_sensitive_escapes($string) and not $self->would_interpolate($string)
!ll&&!rl&&r
4951034
$cleaned =~ /\\[\$\@\"]/u and not $self->has_quote_sensitive_escapes($string)
!ll&&!rl&&r
4851044
MC/DC100%3/3
$cleaned =~ /\\[\$\@\"]/u and not $self->has_quote_sensitive_escapes($string) and not $self->would_interpolate($string)
$cleaned =~ /\\[\$\@\"]/u not $self->has_quote_sensitive_escapes($string) not $self->would_interpolate($string)
Truth table100%4/4
A and not(B) and not(C)
A= $cleaned =~ /\\[\$\@\"]/uB= not $self->has_quote_sensitive_escapes($string)C= not $self->would_interpolate($string)
ABCresult
0XX0
10X0
1100
1111
383 $cleaned =~ /\\[\$\@\"]/
384 && !$self->has_quote_sensitive_escapes($string)
385 && !$self->would_interpolate($string)
386 ) {
387 # An apostrophe would need escaping in '', so prefer q(), which adds no
388 # escaping for the literal value
389 34 ▶ return $self->_fix_violation($Fix_single, $elem)
Branch: 1 branch
BranchTrueFalseTotal
if index($string, "'") == -1 28 6 34
390 if index($string, "'") == -1;
391 6 my $value = $string =~ s/\\(.)/$1/gsr;
392 6 my ($optimal) = $self->find_optimal_delimiter($value, "q", '"', '"');
393 6 return $self->_fix_violation($self->_operator_fix("q", $optimal), $elem);
394 }
395  
396 # If has escaped double quotes, suggest qq() - by this point, the ''
397 # suggestion was ruled out (escape sequences or interpolation present),
398 # so qq() eliminates the quote escaping while preserving both
399 505 ▶ if ($cleaned =~ /\\"/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cleaned =~ /\\"/u) 16 489 505
400 16 my ($optimal) = $self->find_optimal_delimiter($string, "qq", '"', '"');
401 16 return $self->_fix_violation($self->_operator_fix("qq", $optimal), $elem);
402 }
403  
404 return
405 489 }
406  
407 202 ▶sub check_q_literal ($self, $elem) {
Subroutine check_q_literal: called CC=7 SCAR=19.5
Pod documented
408 202 my $string = $elem->string;
409  
410 202 my $has_single_quotes = index($string, "'") != -1;
411 202 my $has_double_quotes = index($string, '"') != -1;
412  
413 # Has both quote types - q() handles this cleanly
414 202 ▶ return $self->check_delimiter_optimisation($elem)
Branch: 1 branch
BranchTrueFalseTotal
if $has_single_quotes and $has_double_quotes 48 154 202
Condition100%3/3
$has_single_quotes and $has_double_quotes
!ll&&!rl&&r
1371748
MC/DC100%2/2
$has_single_quotes and $has_double_quotes
$has_single_quotes $has_double_quotes
Truth table100%3/3
A and B
A= $has_single_quotesB= $has_double_quotes
ABresult
0X0
100
111
415 if $has_single_quotes && $has_double_quotes;
416  
417 154 ▶ if ($has_single_quotes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_single_quotes) 17 137 154
418 17 ▶ return $self->would_interpolate_from_single_quotes($string)
Branch: 1 branch
BranchTrueFalseTotal
$self->would_interpolate_from_single_quotes($string) ? : 9 8 17
419 ? $self->check_delimiter_optimisation($elem)
420 : $self->_fix_violation($Fix_double, $elem);
421 }
422  
423 # Only double quotes (no single quotes) - single quotes always work:
424 # they don't interpolate and can hold " without escaping
425 137 ▶ return $self->_fix_violation($Fix_single, $elem) if $has_double_quotes;
Branch: 1 branch
BranchTrueFalseTotal
if $has_double_quotes 25 112 137
426  
427 112 ▶ return $self->_fix_violation($Fix_single, $elem)
Branch: 1 branch
BranchTrueFalseTotal
if $self->would_interpolate_from_single_quotes($string) 35 77 112
428 if $self->would_interpolate_from_single_quotes($string);
429  
430 77 $self->_fix_violation($Fix_double, $elem)
431 }
432  
433 100 ▶sub _what_would_double_quotes_suggest ($self, $string) {
Subroutine _what_would_double_quotes_suggest: called CC=6 SCAR=17.9
434 100 my $would_interpolate = $self->would_interpolate($string);
435  
436 # Rules 1,2: If has escaped variables but no interpolation → suggest
437 # single quotes
438 100 ▶ return "''" if !$would_interpolate && ($string =~ /\\[\$\@]/);
Branch: 1 branch
BranchTrueFalseTotal
if not $would_interpolate and $string =~ /\\[\$\@]/u 9 91 100
Condition100%3/3
not $would_interpolate and $string =~ /\\[\$\@]/u
!ll&&!rl&&r
28639
MC/DC100%2/2
not $would_interpolate and $string =~ /\\[\$\@]/u
not $would_interpolate $string =~ /\\[\$\@]/u
Truth table100%3/3
not(A) and B
A= not $would_interpolateB= $string =~ /\\[\$\@]/u
ABresult
0X0
100
111
439  
440 # Rule 1: If has quotes that need handling → suggest qq()
441 91 my $has_single_quotes = index($string, "'") != -1;
442 91 my $has_double_quotes = index($string, '"') != -1;
443  
444 91 ▶ if ($has_double_quotes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_double_quotes) 32 59 91
445 32 ▶ return "qq()" if $would_interpolate || $has_single_quotes;
Branch: 1 branch
BranchTrueFalseTotal
if $would_interpolate or $has_single_quotes 25 7 32
Condition100%3/3
$would_interpolate or $has_single_quotes
l!l&&r!l&&!r
2147
MC/DC100%2/2
$would_interpolate or $has_single_quotes
$would_interpolate $has_single_quotes
Truth table100%3/3
A or B
A= $would_interpolateB= $has_single_quotes
ABresult
1X1
011
000
446 7 return "''"; # Only double quotes, no interpolation
447 }
448  
449 # Rules 1,2: Otherwise double quotes are fine
450 undef
451 59 }
452  
453 128 ▶sub check_qq_interpolate ($self, $elem) {
Subroutine check_qq_interpolate: called CC=6 SCAR=17.9
Pod documented
454 128 my $string = $elem->string;
455  
456 # Only preserve qq() if escape sequences are actually needed
457 128 ▶ return $self->check_delimiter_optimisation($elem)
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_quote_sensitive_escapes($string) 28 100 128
458 if $self->has_quote_sensitive_escapes($string);
459  
460 100 my $double_quote_suggestion
461 = $self->_what_would_double_quotes_suggest($string);
462  
463 # Rules 1,2: If double quotes would suggest single quotes, use single quotes
464 100 ▶ if ($double_quote_suggestion && $double_quote_suggestion eq "''") {
Branch: 1 branch
BranchTrueFalseTotal
if ($double_quote_suggestion and $double_quote_suggestion eq "''") 16 84 100
Condition100%3/3
$double_quote_suggestion and $double_quote_suggestion eq "''"
!ll&&!rl&&r
592516
MC/DC100%2/2
$double_quote_suggestion and $double_quote_suggestion eq "''"
$double_quote_suggestion $double_quote_suggestion eq "''"
Truth table100%3/3
A and B
A= $double_quote_suggestionB= $double_quote_suggestion eq "''"
ABresult
0X0
100
111
465 16 return $self->_fix_violation($Fix_single, $elem);
466 }
467  
468 # Rule 1: If double quotes would suggest qq(), qq() is appropriate
469 84 ▶ return $self->check_delimiter_optimisation($elem)
Branch: 1 branch
BranchTrueFalseTotal
if $double_quote_suggestion and $double_quote_suggestion eq "qq()" 25 59 84
Condition66%2/3
$double_quote_suggestion and $double_quote_suggestion eq "qq()"
!ll&&!rl&&r
59025
MC/DC50%1/2
$double_quote_suggestion and $double_quote_suggestion eq "qq()"
$double_quote_suggestion $double_quote_suggestion eq "qq()"
Truth table66%2/3
A and B
A= $double_quote_suggestionB= $double_quote_suggestion eq "qq()"
ABresult
0X0
100
111
470 if $double_quote_suggestion && $double_quote_suggestion eq "qq()";
471  
472 # Rule 1: Otherwise prefer simple double quotes. Every string containing a
473 # double quote was handled above, so nothing here needs qq(); an apostrophe
474 # needs no escaping in double quotes
475 59 $self->_fix_violation($Fix_double, $elem)
476 }
477  
478 326 ▶sub check_quote_operators ($self, $elem) {
Subroutine check_quote_operators: called CC=5 SCAR=16.1
Pod documented
479 326 my ($current_start, $current_end, $content, $operator)
480 = $self->parse_quote_token($elem);
481 326 ▶ return unless defined $current_start;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $current_start 0 326 326
482  
483 # perlop: qx interpolates "unless the delimiter is ''". The single-quote
484 # delimiter is semantic, not stylistic, so it is exempt from the
485 # delimiter rules
486 326 ▶ return if $operator eq "qx" && $current_start eq "'";
Branch: 1 branch
BranchTrueFalseTotal
if $operator eq "qx" and $current_start eq "'" 4 322 326
Condition100%3/3
$operator eq "qx" and $current_start eq "'"
!ll&&!rl&&r
277454
MC/DC100%2/2
$operator eq "qx" and $current_start eq "'"
$operator eq "qx" $current_start eq "'"
Truth table100%3/3
A and B
A= $operator eq "qx"B= $current_start eq "'"
ABresult
0X0
100
111
487  
488 # Don't skip empty content - () is preferred even for empty quotes
489 322 my ($optimal_delim, $current_is_optimal) = $self->find_optimal_delimiter(
490 $content, $operator, $current_start, $current_end
491 );
492  
493 322 ▶ return $self->_fix_violation(
Branch: 1 branch
BranchTrueFalseTotal
unless $current_is_optimal 126 196 322
494 $self->_operator_fix($operator, $optimal_delim), $elem
495 ) if !$current_is_optimal;
496  
497 return
498 196 }
499  
500 387 ▶sub statement_level_list ($self, $elem) {
Subroutine statement_level_list: called CC=4 SCAR=13.9
Pod documented
501 # No module means no arguments; ->arguments dies on a bare "use"
502 387 ▶ return unless $elem->module;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->module 0 387 387
503 387 my ($first) = $elem->arguments;
504 387 ▶ $first && $first->isa("PPI::Structure::List") ? $first : undef
Branch: 1 branch
BranchTrueFalseTotal
$first && $first->isa('PPI::Structure::List') ? : 46 341 387
Condition100%3/3
$first and $first->isa("PPI::Structure::List")
!ll&&!rl&&r
333846
MC/DC100%2/2
$first and $first->isa("PPI::Structure::List")
$first $first->isa("PPI::Structure::List")
Truth table100%3/3
A and B
A= $firstB= $first->isa("PPI::Structure::List")
ABresult
0X0
100
111
505 }
506  
507 372 ▶sub _analyse_argument_types ($self, $elem, @args) {
Subroutine _analyse_argument_types: called CC=1 SCAR=0.0
508  
509 my $fat_comma
510 372 ▶ = any { $_->isa("PPI::Token::Operator") && $_->content eq "=>" } @args;
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_->isa("PPI::Token::Operator") and $_->content eq "=>" 45 534 579
511 # Anything the qw rewrite doesn't understand makes the statement
512 # complex. A real module version never gets here: ->arguments excludes
513 # it, so any number is part of the import list itself.
514 501 ▶ my $complex_expr = any {
Subroutine __ANON__: called CC=6 SCAR=18.0
515 501 ▶ !( $_->isa("PPI::Token::Quote")
Condition86%13/15
$_->isa('PPI::Token::Quote') || $_->isa('PPI::Token::QuoteLike::Words') || $_->isa('PPI::Token::Operator') && $_->content eq '=>' || $_->isa('PPI::Token::Word') && $_->content =~ /\A-\w+\z/u
l!l&&r!l&&!r
422376
$_->isa("PPI::Token::Quote") or $_->isa("PPI::Token::QuoteLike::Words") or $_->isa("PPI::Token::Operator") and $_->content eq "=>"
l!l&&r!l&&!r
422079
$_->isa("PPI::Token::Quote") or $_->isa("PPI::Token::QuoteLike::Words")
l!l&&r!l&&!r
28214079
$_->isa("PPI::Token::Operator") and $_->content eq "=>"
!ll&&!rl&&r
7630
$_->isa("PPI::Token::Word") and $_->content =~ /\A-\w+\z/u
!ll&&!rl&&r
43333
MC/DC66%4/6
$_->isa('PPI::Token::Quote') || $_->isa('PPI::Token::QuoteLike::Words') || $_->isa('PPI::Token::Operator') && $_->content eq '=>' || $_->isa('PPI::Token::Word') && $_->content =~ /\A-\w+\z/u
$_->isa("PPI::Token::Quote") $_->isa("PPI::Token::QuoteLike::Words") $_->isa("PPI::Token::Operator") $_->content eq "=>" $_->isa("PPI::Token::Word") $_->content =~ /\A-\w+\z/u
Truth table66%6/9
A or B or C and D || E and F
A= $_->isa("PPI::Token::Quote")B= $_->isa("PPI::Token::QuoteLike::Words")C= $_->isa("PPI::Token::Operator")D= $_->content eq "=>"E= $_->isa("PPI::Token::Word")F= $_->content =~ /\A-\w+\z/u
ABCDEFresult
1XXXXX1
01XXXX1
0011XX1
000X111
0010111
000X0X0
000X100
00100X0
0010100
516 || $_->isa("PPI::Token::QuoteLike::Words")
517 || ($_->isa("PPI::Token::Operator") && $_->content eq "=>")
518 || ($_->isa("PPI::Token::Word") && $_->content =~ /\A-\w+\z/))
519 372 } @args;
520 717 ▶ my $version = any {
Subroutine __ANON__: called CC=2 SCAR=7.6
521 717 ▶ $_->isa("PPI::Token::Number::Version")
Branch: 1 branch
BranchTrueFalseTotal
$_->isa("PPI::Token::Number::Version") or $_->isa("PPI::Token::Number::Float") 0 717 717
522 || $_->isa("PPI::Token::Number::Float")
523 372 } @args;
524 600 ▶ my $simple_strings = any {
Subroutine __ANON__: called CC=2 SCAR=6.9
525 600 ▶ $_->isa("PPI::Token::Quote::Single")
Branch: 1 branch
BranchTrueFalseTotal
$_->isa("PPI::Token::Quote::Single") or $_->isa("PPI::Token::Quote::Double") 33 567 600
526 || $_->isa("PPI::Token::Quote::Double")
527 372 } @args;
528 712 ▶ my $q_operators = any {
Subroutine __ANON__: called CC=2 SCAR=6.9
529 712 ▶ $_->isa("PPI::Token::Quote::Literal")
Branch: 1 branch
BranchTrueFalseTotal
$_->isa("PPI::Token::Quote::Literal") or $_->isa("PPI::Token::Quote::Interpolate") 12 700 712
530 || $_->isa("PPI::Token::Quote::Interpolate")
531 372 } @args;
532  
533 # Statement-level parentheses: a list wrapping the whole argument list
534 372 my $parens = defined $self->statement_level_list($elem);
535  
536 372 ($fat_comma, $complex_expr, $version, $simple_strings, $q_operators, $parens)
537 }
538  
539 182 ▶sub collect_qw_words ($self, $words, @elements) {
Subroutine collect_qw_words: called CC=18 SCAR=28.9
Pod documented
540 182 for my $el (@elements) {
541 365 ▶ next unless $el->significant;
Branch: 1 branch
BranchTrueFalseTotal
unless $el->significant 41 324 365
542 324 my $class = ref $el;
543 324 ▶ if ($class eq "PPI::Token::Quote::Single") {
Branch: 7 branches
BranchTrueFalseTotal
if ($class eq 'PPI::Token::Quote::Single') { } 46 278 324
elsif ($class eq 'PPI::Token::Quote::Literal') { } 21 257 278
elsif ($class eq 'PPI::Token::Quote::Double' or $class eq 'PPI::Token::Quote::Interpolate') { } 173 84 257
elsif ($class eq 'PPI::Token::QuoteLike::Words') { } 27 57 84
elsif ($class eq 'PPI::Token::Word' and $el->content =~ /\A-\w+\z/u) { } 5 52 57
elsif ($class eq 'PPI::Token::Operator' and $el->content eq ',') { } 39 13 52
elsif ($el->isa('PPI::Structure::List') or $el->isa('PPI::Statement::Expression')) { } 9 4 13
544 46 push @$words, $el->literal;
545 } elsif ($class eq "PPI::Token::Quote::Literal") {
546 21 my ($start, $end, $raw) = $self->parse_quote_token($el);
547 21 push @$words, $raw =~ s/\\([\\\Q$start$end\E])/$1/gr;
548 ▶ } elsif (
Condition100%3/3
$class eq "PPI::Token::Quote::Double" or $class eq "PPI::Token::Quote::Interpolate"
l!l&&r!l&&!r
1522184
MC/DC100%2/2
$class eq "PPI::Token::Quote::Double" or $class eq "PPI::Token::Quote::Interpolate"
$class eq "PPI::Token::Quote::Double" $class eq "PPI::Token::Quote::Interpolate"
Truth table100%3/3
A or B
A= $class eq "PPI::Token::Quote::Double"B= $class eq "PPI::Token::Quote::Interpolate"
ABresult
1X1
011
000
549 $class eq "PPI::Token::Quote::Double"
550 || $class eq "PPI::Token::Quote::Interpolate"
551 ) {
552 173 my $raw = $el->string;
553 173 ▶ return 0 if $self->would_interpolate($raw);
Branch: 1 branch
BranchTrueFalseTotal
if $self->would_interpolate($raw) 1 172 173
554 172 ▶ return 0 if $raw =~ /\\(?![\\"])/;
Branch: 1 branch
BranchTrueFalseTotal
if $raw =~ /\\(?![\\"])/u 2 170 172
555 170 push @$words, $raw =~ s/\\([\\"])/$1/gr;
556 } elsif ($class eq "PPI::Token::QuoteLike::Words") {
557 27 push @$words, $el->literal;
558 ▶ } elsif ($class eq "PPI::Token::Word" && $el->content =~ /\A-\w+\z/) {
Condition66%2/3
$class eq "PPI::Token::Word" and $el->content =~ /\A-\w+\z/u
!ll&&!rl&&r
5205
MC/DC50%1/2
$class eq "PPI::Token::Word" and $el->content =~ /\A-\w+\z/u
$class eq "PPI::Token::Word" $el->content =~ /\A-\w+\z/u
Truth table66%2/3
A and B
A= $class eq "PPI::Token::Word"B= $el->content =~ /\A-\w+\z/u
ABresult
0X0
100
111
559 5 push @$words, $el->content;
560 ▶ } elsif ($class eq "PPI::Token::Operator" && $el->content eq ",") {
Condition66%2/3
$class eq "PPI::Token::Operator" and $el->content eq ","
!ll&&!rl&&r
13039
MC/DC50%1/2
$class eq "PPI::Token::Operator" and $el->content eq ","
$class eq "PPI::Token::Operator" $el->content eq ","
Truth table66%2/3
A and B
A= $class eq "PPI::Token::Operator"B= $el->content eq ","
ABresult
0X0
100
111
561 39 next;
562 ▶ } elsif (
Condition100%3/3
$el->isa("PPI::Structure::List") or $el->isa("PPI::Statement::Expression")
l!l&&r!l&&!r
544
MC/DC100%2/2
$el->isa("PPI::Structure::List") or $el->isa("PPI::Statement::Expression")
$el->isa("PPI::Structure::List") $el->isa("PPI::Statement::Expression")
Truth table100%3/3
A or B
A= $el->isa("PPI::Structure::List")B= $el->isa("PPI::Statement::Expression")
ABresult
1X1
011
000
563 $el->isa("PPI::Structure::List")
564 || $el->isa("PPI::Statement::Expression")
565 ) {
566 9 ▶ return 0 unless $self->collect_qw_words($words, $el->children);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->collect_qw_words($words, $el->children) 1 8 9
567 } else {
568 4 return 0;
569 }
570 }
571 174 ▶ @$words ? 1 : 0
Branch: 1 branch
BranchTrueFalseTotal
@$words ? : 173 1 174
572 }
573  
574 261 ▶sub qw_word_ok ($self, $word) {
Subroutine qw_word_ok: called CC=1 SCAR=0.0
Pod documented
575 261 $word =~ /\A[^\s()\\]+\z/
576 }
577  
578 110 ▶sub _use_args_qw_representable ($self, @args) {
Subroutine _use_args_qw_representable: called CC=2 SCAR=6.9
579 110 my @words;
580 110 ▶ return 0 unless $self->collect_qw_words(\@words, @args);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->collect_qw_words(\@words, @args) 2 108 110
581 170 ▶ all { $self->qw_word_ok($_) } @words
Subroutine __ANON__: called CC=1 SCAR=0.0
582 108 }
583  
584 110 ▶sub _use_qw_violation ($self, $elem, @args) {
Subroutine _use_qw_violation: called CC=2 SCAR=6.9
585 110 ▶ return () unless $self->_use_args_qw_representable(@args);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_use_args_qw_representable(@args) 15 95 110
586 95 $self->_fix_violation($Fix_use_qw, $elem)
587 }
588  
589 976 ▶sub _scan_qw ($self, $elem, $qw_ref, $qw_parens_ref) {
Subroutine _scan_qw: called CC=5 SCAR=16.1
590 976 ▶ if ($elem->isa("PPI::Token::QuoteLike::Words")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Token::QuoteLike::Words")) 140 836 976
591 140 $$qw_ref = 1;
592 140 ▶ $$qw_parens_ref = 0 if $elem->content !~ /\Aqw\s*\(/;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->content =~ /\Aqw\s*\(/u 11 129 140
593 }
594  
595 # Recursively check children (for structures like lists)
596 976 ▶ if ($elem->can("children")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->can("children")) 62 914 976
597 62 $self->_scan_qw($_, $qw_ref, $qw_parens_ref) for $elem->children;
598 }
599 }
600  
601 372 ▶sub _summarise_use_arguments ($self, @args) {
Subroutine _summarise_use_arguments: called CC=2 SCAR=6.9
602 372 my $has_qw = 0;
603 372 my $qw_uses_parens = 1;
604  
605 372 $self->_scan_qw($_, \$has_qw, \$qw_uses_parens) for @args;
606  
607 372 ($has_qw, $qw_uses_parens)
608 }
609  
610 396 ▶sub check_use_statement ($self, $elem) {
Subroutine check_use_statement: called CC=15 SCAR=27.1
Pod documented
611 # Check "use" and "no" statements, but not "require"
612 396 ▶ return unless $elem->type =~ /^(use|no)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->type =~ /^(use|no)$/u 6 390 396
613  
614 390 ▶ my @args = $self->_extract_use_arguments($elem) or return;
Branch: 1 branch
BranchTrueFalseTotal
my(@args) = $self->_extract_use_arguments($elem) or return 372 18 390
615  
616 372 my ($has_qw, $qw_uses_parens) = $self->_summarise_use_arguments(@args);
617  
618 # Check for different types of arguments
619 my (
620 372 $has_fat_comma, $has_complex_expr, $has_version,
621 $has_simple_strings, $has_q_operators, $has_parens,
622 ) = $self->_analyse_argument_types($elem, @args);
623  
624 # Rule 4: Special cases - no violation
625 372 ▶ return () if $has_version && @args == 1; # Single version number
Branch: 1 branch
BranchTrueFalseTotal
if $has_version and @args == 1 0 372 372
Condition66%2/3
$has_version and @args == 1
!ll&&!rl&&r
36480
MC/DC0%0/2
$has_version and @args == 1
$has_version @args == 1
Truth table66%2/3
A and B
A= $has_versionB= @args == 1
ABresult
0X0
100
111
626  
627 # Pragmas with a single argument allow quotes
628 372 ▶ return () if @args == 1 && $self->_is_pragma($elem);
Branch: 1 branch
BranchTrueFalseTotal
if @args == 1 and $self->_is_pragma($elem) 49 323 372
Condition100%3/3
@args == 1 and $self->_is_pragma($elem)
!ll&&!rl&&r
15916449
MC/DC100%2/2
@args == 1 and $self->_is_pragma($elem)
@args == 1 $self->_is_pragma($elem)
Truth table100%3/3
A and B
A= @args == 1B= $self->_is_pragma($elem)
ABresult
0X0
100
111
629  
630 # Rule 1: qw() without parens should use qw()
631 323 ▶ return $self->_fix_violation($Fix_use_qw, $elem)
Branch: 1 branch
BranchTrueFalseTotal
if $has_qw and not $qw_uses_parens 10 313 323
Condition100%3/3
$has_qw and not $qw_uses_parens
!ll&&!rl&&r
20410910
MC/DC100%2/2
$has_qw and not $qw_uses_parens
$has_qw not $qw_uses_parens
Truth table100%3/3
A and not(B)
A= $has_qwB= not $qw_uses_parens
ABresult
0X0
100
111
632 if $has_qw && !$qw_uses_parens;
633  
634 # Rules 2, 3: fat comma or complex expressions should have no parentheses
635 313 ▶ if ($has_fat_comma || $has_complex_expr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_fat_comma or $has_complex_expr) 72 241 313
Condition100%3/3
$has_fat_comma or $has_complex_expr
l!l&&r!l&&!r
2547241
MC/DC100%2/2
$has_fat_comma or $has_complex_expr
$has_fat_comma $has_complex_expr
Truth table100%3/3
A or B
A= $has_fat_commaB= $has_complex_expr
ABresult
1X1
011
000
636 72 ▶ return $self->_fix_violation($Fix_remove_parens, $elem) if $has_parens;
Branch: 1 branch
BranchTrueFalseTotal
if $has_parens 19 53 72
637 53 return ();
638 }
639  
640 # If interpolation is needed, don't suggest qw() - let normal rules apply
641 241 ▶ return () if $self->_any_arg_interpolates(@args);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_any_arg_interpolates(@args) 37 204 241
642  
643 # Rule 1: string arguments, with or without qw(), should be qw() alone
644 204 ▶ return $self->_use_qw_violation($elem, @args)
Branch: 1 branch
BranchTrueFalseTotal
if $has_simple_strings or $has_q_operators 110 94 204
Condition100%3/3
$has_simple_strings or $has_q_operators
l!l&&r!l&&!r
902094
MC/DC100%2/2
$has_simple_strings or $has_q_operators
$has_simple_strings $has_q_operators
Truth table100%3/3
A or B
A= $has_simple_stringsB= $has_q_operators
ABresult
1X1
011
000
645 if $has_simple_strings || $has_q_operators;
646  
647 ()
648 94 }
649  
650 44 "
651 I see the people working
652 And see it working for them
653 And so I want to join in
654 But then I find it hurt me
655 "
656  
657 __END__
« lib/Perl/Critic/PJCJ/Fixer.pm ↑ Summary lib/Perl/Critic/Policy/CodeLayout/ProhibitLongLines.pm »