« utils/perl-hook
↑ Summary
lib/Perl/Critic/Policy/ValuesAndExpressions/RequireConsistentQuoting.pm »
| 1 | package Perl::Critic::PJCJ::Fixer v0.3.0; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 42 | ▶ | use v5.26.0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 42 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 42 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 42 | ▶ | use feature qw( signatures ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 42 | ▶ | use experimental qw( signatures ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 42 | ▶ | use List::Util qw( all any ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 42 | ▶ | use PPI (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 42 | ▶ | use Perl::Critic::Policy::ValuesAndExpressions::RequireConsistentQuoting (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 42 | my $Max_passes = 10; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 42 | my %Interpolating = map { $_ => 1 } qw( | |||||||||||||||||||||||||||||||||||||||||
| 15 | PPI::Token::Quote::Double | ||||||||||||||||||||||||||||||||||||||||||
| 16 | PPI::Token::Quote::Interpolate | ||||||||||||||||||||||||||||||||||||||||||
| 17 | PPI::Token::QuoteLike::Command | ||||||||||||||||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 26 | ▶ | sub _interpolates ($self, $elem) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_interpolates: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | # perlop: qx does not interpolate when its delimiter is '' | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 26 | ▶ | return 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $elem eq "PPI::Token::QuoteLike::Command" and $elem->content =~ /\Aqx\s*'/u
MC/DC100%2/2
ref $elem eq "PPI::Token::QuoteLike::Command" and $elem->content =~ /\Aqx\s*'/u
ref $elem eq "PPI::Token::QuoteLike::Command"
$elem->content =~ /\Aqx\s*'/u
Truth table100%3/3
A and B
A= ref $elem eq "PPI::Token::QuoteLike::Command"B= $elem->content =~ /\Aqx\s*'/u
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | if ref $elem eq "PPI::Token::QuoteLike::Command" | ||||||||||||||||||||||||||||||||||||||||||
| 24 | && $elem->content =~ /\Aqx\s*'/; | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 25 | ▶ | $Interpolating{ ref $elem } // 0 | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$Interpolating{ref $elem} // 0
MC/DC100%1/1
$Interpolating{ref $elem} // 0
$Interpolating{ref $elem}
Truth table100%2/2
A
A= $Interpolating{ref $elem}
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 59 | ▶ | sub new ($class) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 59 | my $policy | |||||||||||||||||||||||||||||||||||||||||
| 30 | = Perl::Critic::Policy::ValuesAndExpressions::RequireConsistentQuoting->new; | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 59 | bless { policy => $policy }, $class | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | # Only valid for content free of quote-sensitive escapes; conversion call | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # sites guard with the policy's has_quote_sensitive_escapes predicate | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 159 | ▶ | sub _decode_double ($self, $raw) { $raw =~ s/\\(.)/$1/gsr } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_double: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 175 | ▶ | sub _decode_q ($self, $raw, $start, $end) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_q: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 175 | $raw =~ s/\\([\\\Q$start$end\E])/$1/gr | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 142 | ▶ | sub _decode_delimiters ($self, $raw, $start, $end) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_delimiters: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 142 | ▶ | $raw =~ s/\\(.)/$1 eq $start || $1 eq $end ? $1 : "\\$1"/gser | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$1 eq $start or $1 eq $end
MC/DC100%2/2
$1 eq $start or $1 eq $end
$1 eq $start
$1 eq $end
Truth table100%3/3
A or B
A= $1 eq $startB= $1 eq $end
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 58 | ▶ | sub _encode_single ($self, $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_single: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 58 | "'" . $self->{policy}->escape_single_quoted($value) . "'" | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 95 | ▶ | sub _encode_double ($self, $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_double: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 95 | '"' . ($value =~ s/\\/\\\\/gr) . '"' | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 463 | ▶ | sub _normalised_value ($self, $elem) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalised_value: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 463 | my $class = ref $elem; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 463 | ▶ | return $elem->literal if $class eq "PPI::Token::Quote::Single"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 350 | ▶ | return $self->_decode_double($elem->string) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | if $class eq "PPI::Token::Quote::Double"; | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 232 | ▶ | return join "\0", $elem->literal if $class eq "PPI::Token::QuoteLike::Words"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 108 | my ($start, $end, $raw) = $self->{policy}->parse_quote_token($elem); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 108 | ▶ | return $self->_decode_q($raw, $start, $end) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | if $class eq "PPI::Token::Quote::Literal"; | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | # Interpolate; a Command never reaches here because _value_preserved | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # compares interpolating token pairs via _canonical | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 9 | $self->_decode_double($raw) | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | ▶ | sub _balanced ($self, $content, $start, $end) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_balanced: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 4 | my $depth = 0; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 4 | for my $char (split //, $content) { | |||||||||||||||||||||||||||||||||||||||||
| 73 | 101 | ▶ | $depth++ if $char eq $start; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 101 | ▶ | if ($char eq $end) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 4 | $depth--; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 4 | ▶ | return 0 if $depth < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | $depth == 0 | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 101 | ▶ | sub _delimit_content ($self, $content, $start, $end) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_delimit_content: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 101 | ▶ | return $content if $content !~ /[\Q$start$end\E]/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 7 | ▶ | return if $content =~ /\\/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 4 | ▶ | return $content if $self->_balanced($content, $start, $end); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | $content =~ s/([\Q$start$end\E])/\\$1/gr | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 106 | ▶ | sub _operator_replacement ($self, $elem, $op, $start, $end) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_operator_replacement: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 106 | my $class = ref $elem; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 106 | my $content; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 106 | ▶ | if ($class eq "PPI::Token::Quote::Single") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 5 | $content = $elem->literal =~ s/([\\\Q$start$end\E])/\\$1/gr; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 5 | return "$op$start$content$end"; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 101 | ▶ | if ($class eq "PPI::Token::Quote::Double") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | # An interpolating target keeps the escapes bar the quote; a literal | ||||||||||||||||||||||||||||||||||||||||||
| 100 | # target (q, qw) takes the fully decoded value | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 14 | ▶ | $content | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$op eq "qq" or $op eq "qx"
MC/DC50%1/2
$op eq "qq" or $op eq "qx"
$op eq "qq"
$op eq "qx"
Truth table66%2/3
A or B
A= $op eq "qq"B= $op eq "qx"
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | = $op eq "qq" || $op eq "qx" | ||||||||||||||||||||||||||||||||||||||||||
| 103 | ? $elem->string =~ s/\\"/"/gr | ||||||||||||||||||||||||||||||||||||||||||
| 104 | : $self->_decode_double($elem->string); | ||||||||||||||||||||||||||||||||||||||||||
| 105 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 87 | my ($old_start, $old_end, $raw) = $self->{policy}->parse_quote_token($elem); | |||||||||||||||||||||||||||||||||||||||||
| 107 | 87 | $content = $raw =~ s/\\([\Q$old_start$old_end\E])/$1/gr; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 101 | $content = $self->_delimit_content($content, $start, $end); | |||||||||||||||||||||||||||||||||||||||||
| 111 | 101 | ▶ | defined $content ? "$op$start$content$end" : undef | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 298 | ▶ | sub _replacement ($self, $elem, $fix) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_replacement: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 298 | my $class = ref $elem; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 298 | my $type = $fix->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | return $self->_operator_replacement($elem, $fix->{op}, $fix->{start}, | ||||||||||||||||||||||||||||||||||||||||||
| 119 | $fix->{end}) | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 298 | ▶ | if $type eq "operator"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 192 | ▶ | if ($class eq "PPI::Token::Quote::Single") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 52 | ▶ | return $self->_encode_double($elem->literal) if $type eq "double"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | } elsif ($class eq "PPI::Token::Quote::Double") { | ||||||||||||||||||||||||||||||||||||||||||
| 125 | return $self->_encode_single($self->_decode_double($elem->string)) | ||||||||||||||||||||||||||||||||||||||||||
| 126 | if $type eq "single" | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 20 | ▶ | && !$self->{policy}->has_quote_sensitive_escapes($elem->string); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$type eq "single" and not $self->{"policy"}->has_quote_sensitive_escapes($elem->string)
MC/DC100%2/2
$type eq "single" and not $self->{"policy"}->has_quote_sensitive_escapes($elem->string)
$type eq "single"
not $self->{"policy"}->has_quote_sensitive_escapes($elem->string)
Truth table100%3/3
A and not(B)
A= $type eq "single"B= not $self->{"policy"}->has_quote_sensitive_escapes($elem->string)
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | } elsif ($class eq "PPI::Token::Quote::Literal") { | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 76 | my ($start, $end, $raw) = $self->{policy}->parse_quote_token($elem); | |||||||||||||||||||||||||||||||||||||||||
| 130 | 76 | my $value = $self->_decode_q($raw, $start, $end); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 76 | ▶ | return $self->_encode_double($value) if $type eq "double"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 32 | ▶ | return $self->_encode_single($value) if $type eq "single"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | } elsif ($class eq "PPI::Token::Quote::Interpolate") { | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 43 | my ($start, $end, $raw) = $self->{policy}->parse_quote_token($elem); | |||||||||||||||||||||||||||||||||||||||||
| 135 | 43 | ▶ | return '"' . $self->_decode_delimiters($raw, $start, $end) . '"' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | if $type eq "double"; | ||||||||||||||||||||||||||||||||||||||||||
| 137 | return $self->_encode_single($self->_decode_double($raw)) | ||||||||||||||||||||||||||||||||||||||||||
| 138 | if $type eq "single" | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 11 | ▶ | && !$self->{policy}->has_quote_sensitive_escapes($raw); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$type eq "single" and not $self->{"policy"}->has_quote_sensitive_escapes($raw)
MC/DC100%2/2
$type eq "single" and not $self->{"policy"}->has_quote_sensitive_escapes($raw)
$type eq "single"
not $self->{"policy"}->has_quote_sensitive_escapes($raw)
Truth table100%3/3
A and not(B)
A= $type eq "single"B= not $self->{"policy"}->has_quote_sensitive_escapes($raw)
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | undef | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 7 | } | |||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 110 | ▶ | sub _canonical ($self, $elem) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_canonical: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 110 | my ($start, $end, $raw) = $self->{policy}->parse_quote_token($elem); | |||||||||||||||||||||||||||||||||||||||||
| 147 | 110 | $self->_decode_delimiters($raw, $start, $end) | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 288 | ▶ | sub _value_preserved ($self, $elem, $new_source) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_value_preserved: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 288 | my $code = "$new_source;"; | |||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | # uncoverable branch true note:code is never empty so PPI always parses | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 288 | ▶ | my $doc = PPI::Document->new(\$code) or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | my ($token) = grep { | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 288 | ▶ | $_->isa("PPI::Token::Quote") || $_->isa("PPI::Token::QuoteLike") | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_->isa('PPI::Token::Quote') || $_->isa('PPI::Token::QuoteLike')
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')
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | } $doc->tokens; | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | # uncoverable branch true | ||||||||||||||||||||||||||||||||||||||||||
| 160 | # uncoverable condition left note:every replacement contains a quote token | ||||||||||||||||||||||||||||||||||||||||||
| 161 | # uncoverable condition right note:PPI serialisation is faithful | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 288 | ▶ | return 0 unless $token && $doc->serialize eq $code; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%1/3
$token and $doc->serialize eq $code
MC/DC100%0/2
$token and $doc->serialize eq $code
$token
$doc->serialize eq $code
Truth table100%1/3
A and B
A= $tokenB= $doc->serialize eq $code
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 288 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$elem->isa("PPI::Token::QuoteLike::Command") or $token->isa("PPI::Token::QuoteLike::Command")
MC/DC100%2/2
$elem->isa("PPI::Token::QuoteLike::Command") or $token->isa("PPI::Token::QuoteLike::Command")
$elem->isa("PPI::Token::QuoteLike::Command")
$token->isa("PPI::Token::QuoteLike::Command")
Truth table100%3/3
A or B
A= $elem->isa("PPI::Token::QuoteLike::Command")B= $token->isa("PPI::Token::QuoteLike::Command")
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | $elem->isa("PPI::Token::QuoteLike::Command") | ||||||||||||||||||||||||||||||||||||||||||
| 165 | || $token->isa("PPI::Token::QuoteLike::Command") | ||||||||||||||||||||||||||||||||||||||||||
| 166 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 13 | ▶ | return 0 if $self->_interpolates($elem) != $self->_interpolates($token); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 11 | return $self->_canonical($token) eq $self->_canonical($elem); | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | return $self->_canonical($token) eq $self->_canonical($elem) | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 275 | ▶ | if $Interpolating{ ref $token } && $Interpolating{ ref $elem }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$Interpolating{ref $token} and $Interpolating{ref $elem}
MC/DC100%2/2
$Interpolating{ref $token} and $Interpolating{ref $elem}
$Interpolating{ref $token}
$Interpolating{ref $elem}
Truth table100%3/3
A and B
A= $Interpolating{ref $token}B= $Interpolating{ref $elem}
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 231 | $self->_normalised_value($token) eq $self->_normalised_value($elem) | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 298 | ▶ | sub _apply_replacement ($self, $elem, $fix) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_apply_replacement: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 298 | my $new = $self->_replacement($elem, $fix); | |||||||||||||||||||||||||||||||||||||||||
| 177 | 298 | ▶ | return 0 unless defined $new && $self->_value_preserved($elem, $new); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $new and $self->_value_preserved($elem, $new)
MC/DC100%2/2
defined $new and $self->_value_preserved($elem, $new)
defined $new
$self->_value_preserved($elem, $new)
Truth table100%3/3
A and B
A= defined $newB= $self->_value_preserved($elem, $new)
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 285 | $elem->set_content($new); | |||||||||||||||||||||||||||||||||||||||||
| 179 | 285 | 1 | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 15 | ▶ | sub _remove_include_parens ($self, $elem) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove_include_parens: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 15 | my $list = $self->{policy}->statement_level_list($elem); | |||||||||||||||||||||||||||||||||||||||||
| 184 | 15 | ▶ | return 0 unless $list; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 12 | my @kids = $list->children; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 12 | ▶ | while (@kids && !$kids[0]->significant) { (shift @kids)->delete } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@kids and not $kids[0]->significant
MC/DC100%2/2
@kids and not $kids[0]->significant
@kids
not $kids[0]->significant
Truth table100%3/3
A and not(B)
A= @kidsB= not $kids[0]->significant
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 12 | ▶ | while (@kids && !$kids[-1]->significant) { (pop @kids)->delete } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@kids and not $kids[-1]->significant
MC/DC100%2/2
@kids and not $kids[-1]->significant
@kids
not $kids[-1]->significant
Truth table100%3/3
A and not(B)
A= @kidsB= not $kids[-1]->significant
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 12 | ▶ | unless (@kids) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 2 | my $prev = $list->previous_sibling; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 2 | ▶ | $prev->delete unless $prev->significant; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 12 | $list->start->set_content(""); | |||||||||||||||||||||||||||||||||||||||||
| 194 | 12 | $list->finish->set_content(""); | |||||||||||||||||||||||||||||||||||||||||
| 195 | 12 | 1 | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 66 | ▶ | sub _include_argument_span ($self, $elem) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_include_argument_span: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | # No module means no import arguments; ->arguments dies on a bare "use" | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 66 | ▶ | return unless $elem->module; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 65 | ▶ | my @args = $elem->arguments or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 64 | my (@span, $in); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 64 | for my $child ($elem->children) { | |||||||||||||||||||||||||||||||||||||||||
| 204 | 452 | ▶ | $in ||= $child == $args[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$in ||= $child == $args[0]
MC/DC100%2/2
$in ||= $child == $args[0]
$in
$child == $args[0]
Truth table100%3/3
A ||= B
A= $inB= $child == $args[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 452 | ▶ | push @span, $child if $in; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 452 | ▶ | last if $child == $args[-1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | @span | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 64 | } | |||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 64 | ▶ | sub _span_has_comment ($self, @span) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_span_has_comment: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 183 | ▶ | any { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 183 | ▶ | $_->isa("PPI::Token::Comment") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$_->isa('PPI::Token::Comment') || $_->isa('PPI::Node') && $_->find_any('PPI::Token::Comment')
$_->isa("PPI::Node") and $_->find_any("PPI::Token::Comment")
MC/DC100%3/3
$_->isa('PPI::Token::Comment') || $_->isa('PPI::Node') && $_->find_any('PPI::Token::Comment')
$_->isa('PPI::Token::Comment')
$_->isa("PPI::Node")
$_->find_any("PPI::Token::Comment")
Truth table100%4/4
A || B and C
A= $_->isa('PPI::Token::Comment')B= $_->isa("PPI::Node")C= $_->find_any("PPI::Token::Comment")
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | || ($_->isa("PPI::Node") && $_->find_any("PPI::Token::Comment")) | ||||||||||||||||||||||||||||||||||||||||||
| 215 | } @span | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 64 | } | |||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 83 | ▶ | sub _fix_include ($self, $elem, $fix) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fix_include: called CC=13 SCAR=25.6
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | return $self->_remove_include_parens($elem) | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 83 | ▶ | if $fix->{type} eq "remove_parens"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 68 | ▶ | return 0 unless $fix->{type} eq "operator" && $fix->{op} eq "qw"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$fix->{"type"} eq "operator" and $fix->{"op"} eq "qw"
MC/DC100%2/2
$fix->{"type"} eq "operator" and $fix->{"op"} eq "qw"
$fix->{"type"} eq "operator"
$fix->{"op"} eq "qw"
Truth table100%3/3
A and B
A= $fix->{"type"} eq "operator"B= $fix->{"op"} eq "qw"
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 66 | my @span = $self->_include_argument_span($elem); | |||||||||||||||||||||||||||||||||||||||||
| 224 | 66 | ▶ | return 0 unless @span; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 64 | my @words; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 64 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not $self->_span_has_comment(@span) and $self->{"policy"}->collect_qw_words(\@words, @span) and &all(sub {
$self->{"policy"}->qw_word_ok($_);
}
, @words)
not $self->_span_has_comment(@span) and $self->{"policy"}->collect_qw_words(\@words, @span)
MC/DC100%3/3
not $self->_span_has_comment(@span) and $self->{"policy"}->collect_qw_words(\@words, @span) and &all(sub {
$self->{"policy"}->qw_word_ok($_);
}
, @words)
not $self->_span_has_comment(@span)
$self->{"policy"}->collect_qw_words(\@words, @span)
&all(sub {
$self->{"policy"}->qw_word_ok($_);
}
, @words)
Truth table100%4/4
not(A) and B and C
A= not $self->_span_has_comment(@span)B= $self->{"policy"}->collect_qw_words(\@words, @span)C= &all(sub {
$self->{"policy"}->qw_word_ok($_);
}
, @words)
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | !$self->_span_has_comment(@span) | ||||||||||||||||||||||||||||||||||||||||||
| 229 | && $self->{policy}->collect_qw_words(\@words, @span) | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 91 | ▶ | && all { $self->{policy}->qw_word_ok($_) } @words | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 55 | $span[0]->insert_before(PPI::Token->new("qw( @words )")); | |||||||||||||||||||||||||||||||||||||||||
| 233 | 55 | $_->delete for @span; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 55 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 9 | ▶ | my $qw_tokens = $elem->find("PPI::Token::QuoteLike::Words") or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 6 | my $applied = 0; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 6 | for my $token (@$qw_tokens) { | |||||||||||||||||||||||||||||||||||||||||
| 240 | 8 | ▶ | next if $token->content =~ /\Aqw\s*\Q$fix->{start}\E/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 7 | ▶ | $applied = 1 if $self->_apply_replacement($token, $fix); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | $applied | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 6 | } | |||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 374 | ▶ | sub _apply_fix ($self, $elem, $fix) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_apply_fix: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 374 | ▶ | $elem->isa("PPI::Statement::Include") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | ? $self->_fix_include($elem, $fix) | ||||||||||||||||||||||||||||||||||||||||||
| 249 | : $self->_apply_replacement($elem, $fix) | ||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 9326 | ▶ | sub _in_range ($self, $elem, $lines) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_in_range: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 9326 | ▶ | return 1 unless $lines; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 321 | my $line = $elem->line_number; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 321 | ▶ | $line >= $lines->[0] && $line <= $lines->[1] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 374 | ▶ | sub _shift_range ($self, $lines, $delta) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_shift_range: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 374 | ▶ | $lines->[1] += $delta if $lines; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 1029 | ▶ | sub _fix_once ($self, $source, $lines) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fix_once: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 1029 | ▶ | my $doc = PPI::Document->new(\$source) or return $source; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 1028 | my @fixes; | |||||||||||||||||||||||||||||||||||||||||
| 266 | $doc->find( | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 9326 | ▶ | sub ($top, $elem) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 9326 | ▶ | return 0 unless $self->_in_range($elem, $lines); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 9144 | my ($violation) = $self->{policy}->violates($elem, $doc); | |||||||||||||||||||||||||||||||||||||||||
| 270 | 9144 | ▶ | return 0 unless $violation; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | my $fix | ||||||||||||||||||||||||||||||||||||||||||
| 272 | = $violation->can("fix") | ||||||||||||||||||||||||||||||||||||||||||
| 273 | ? $violation->fix | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 377 | ▶ | : $self->{policy}->fix_data($violation->description); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 377 | ▶ | if ($fix) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 374 | push @fixes, [$elem, $fix]; | |||||||||||||||||||||||||||||||||||||||||
| 277 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 3 | my $msg = $violation->description; | |||||||||||||||||||||||||||||||||||||||||
| 279 | warn "Perl::Critic::PJCJ::Fixer: no fix mapping for '$msg' at line " | ||||||||||||||||||||||||||||||||||||||||||
| 280 | . $elem->line_number . "\n" | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 3 | ▶ | unless $self->{warned}{$msg}++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 377 | 0 | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 1028 | ); | |||||||||||||||||||||||||||||||||||||||||
| 286 | 1028 | ▶ | return $source unless @fixes; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 369 | my $applied = 0; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 369 | for my $entry (@fixes) { | |||||||||||||||||||||||||||||||||||||||||
| 289 | 374 | my ($elem, $fix) = @$entry; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 374 | my $before = $elem->content =~ tr/\n//; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 374 | ▶ | $applied = 1 if $self->_apply_fix($elem, $fix); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 374 | $self->_shift_range($lines, ($elem->content =~ tr/\n//) - $before); | |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 369 | ▶ | return $source unless $applied; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 346 | $doc->serialize | |||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 344 | ▶ | sub _restore_crlf ($self, $source, $fixed) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_restore_crlf: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 344 | ▶ | return $fixed unless $source =~ /\r\n/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 3 | ▶ | return $fixed if $source =~ /\r(?!\n)|(?<!\r)\n/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | $fixed =~ s/\n/\r\n/gr | |||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 686 | ▶ | sub _finish ($self, $source, $current) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finish: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 686 | ▶ | return $current if $current eq $source; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 344 | $self->_restore_crlf($source, $current) | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 686 | ▶ | sub fix ($self, $source, %opts) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fix: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 686 | ▶ | my $lines = $opts{lines} ? [$opts{lines}->@*] : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 686 | my $current = $source; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 686 | $self->{warned} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 314 | 686 | my %seen; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 686 | for (1 .. $Max_passes) { | |||||||||||||||||||||||||||||||||||||||||
| 316 | 1039 | $seen{$current} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 1039 | my $next = $self->_fix_once($current, $lines); | |||||||||||||||||||||||||||||||||||||||||
| 318 | 1039 | ▶ | return $self->_finish($source, $next) if $next eq $current; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 355 | ▶ | if ($seen{$next}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 1 | warn "Perl::Critic::PJCJ::Fixer: fixes oscillate without " | |||||||||||||||||||||||||||||||||||||||||
| 321 | . "converging; the result may still violate the policy\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 1 | return $self->_finish($source, $next); | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 354 | $current = $next; | |||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 1 | warn "Perl::Critic::PJCJ::Fixer: fixes still changing after " | |||||||||||||||||||||||||||||||||||||||||
| 327 | . "$Max_passes passes; giving up\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | $self->_finish($source, $current) | |||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 42 | " | |||||||||||||||||||||||||||||||||||||||||
| 332 | A painter on the shore | ||||||||||||||||||||||||||||||||||||||||||
| 333 | Imagined all the world | ||||||||||||||||||||||||||||||||||||||||||
| 334 | Within the snowflake on his palm | ||||||||||||||||||||||||||||||||||||||||||
| 335 | " | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | __END__ | ||||||||||||||||||||||||||||||||||||||||||