QuoteLike.pm

filter: Statementstmt 91.0% 417 / 458 Branchbran 68.5% 155 / 226 Conditioncond 65.3% 49 / 75 MC/DCmcdc 39.5% 17 / 43 Subroutinesub 90.2% 65 / 72 Podpod 100% 24 / 24 totaltotal 80.9% 727 / 898 CC 159 SCAR 29.1
CC
159
Cov
82%
new
58.5
_has_postderef
19.4
_update_location
16.3
CRAP 18.3
« QuoteLike/Dumper.pm ↑ Summary QuoteLike/Token/Interpolation.pm »
1 package PPIx::QuoteLike;
2  
3 7 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use PPIx::QuoteLike::Constant qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
12 ARRAY_REF
13 LOCATION_LINE
14 LOCATION_CHARACTER
15 LOCATION_COLUMN
16 LOCATION_LOGICAL_LINE
17 LOCATION_LOGICAL_FILE
18 MINIMUM_PERL
19 VARIABLE_RE
20 @CARP_NOT
21 7 };
22 7 ▶use PPIx::QuoteLike::Token::Control;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 7 ▶use PPIx::QuoteLike::Token::Delimiter;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 7 ▶use PPIx::QuoteLike::Token::Interpolation;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 7 ▶use PPIx::QuoteLike::Token::String;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 7 ▶use PPIx::QuoteLike::Token::Structure;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 7 ▶use PPIx::QuoteLike::Token::Unknown;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 7 ▶use PPIx::QuoteLike::Token::Whitespace;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 7 ▶use PPIx::QuoteLike::Utils qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
30 column_number
31 line_number
32 logical_filename
33 logical_line_number
34 statement
35 visual_column_number
36 __instance
37 __match_enclosed
38 __matching_delimiter
39 7 };
40 7 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 7 our $VERSION = '0.024';
43  
44 7 ▶use constant CLASS_CONTROL => 'PPIx::QuoteLike::Token::Control';
Subroutine BEGIN: called CC=1 SCAR=0.0
45 7 ▶use constant CLASS_DELIMITER => 'PPIx::QuoteLike::Token::Delimiter';
Subroutine BEGIN: called CC=1 SCAR=0.0
46 7 ▶use constant CLASS_INTERPOLATION => 'PPIx::QuoteLike::Token::Interpolation';
Subroutine BEGIN: called CC=1 SCAR=0.0
47 7 ▶use constant CLASS_STRING => 'PPIx::QuoteLike::Token::String';
Subroutine BEGIN: called CC=1 SCAR=0.0
48 7 ▶use constant CLASS_STRUCTURE => 'PPIx::QuoteLike::Token::Structure';
Subroutine BEGIN: called CC=1 SCAR=0.0
49 7 ▶use constant CLASS_UNKNOWN => 'PPIx::QuoteLike::Token::Unknown';
Subroutine BEGIN: called CC=1 SCAR=0.0
50 7 ▶use constant CLASS_WHITESPACE => 'PPIx::QuoteLike::Token::Whitespace';
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 7 ▶use constant CODE_REF => ref sub {};
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
53  
54 7 ▶use constant ILLEGAL_FIRST =>
Subroutine BEGIN: called CC=1 SCAR=0.0
55 7 'Tokenizer found illegal first characters';
56 7 ▶use constant MISMATCHED_DELIM =>
Subroutine BEGIN: called CC=1 SCAR=0.0
57 7 'Tokenizer found mismatched delimiters';
58 7 ▶use constant NO_INDENTATION =>
Subroutine BEGIN: called CC=1 SCAR=0.0
59 7 'No indentation string found';
60  
61 {
62 7 my $match_sq = __match_enclosed( qw< ' > );
63 7 my $match_dq = __match_enclosed( qw< " > );
64 7 my $match_bt = __match_enclosed( qw< ` > );
65  
66 114 ▶ sub new { ## no critic (RequireArgUnpacking)
Subroutine new: called CC=48 SCAR=40.7
Pod documented
67 114 my ( $class, $source, %arg ) = @_;
68  
69 114 my @children;
70  
71 114 ▶ if ( $arg{location} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg{"location"}) 2 112 114
72 ARRAY_REF eq ref $arg{location}
73 2 ▶ or croak q<Argument 'location' must be an array reference>;
Branch: 1 branch
BranchTrueFalseTotal
"ARRAY" eq ref $arg{"location"} or croak("Argument 'location' must be an array reference") 2 0 2
74 2 foreach my $inx ( 0 .. 3 ) {
75 8 ▶ $arg{location}[$inx] =~ m/ [^0-9] /smx
Branch: 1 branch
BranchTrueFalseTotal
$arg{"location"}[$inx] =~ / [^0-9] /msx and croak("Argument 'location' element $inx must be an unsigned integer") 0 8 8
76 and croak "Argument 'location' element $inx must be an unsigned integer";
77 }
78 }
79  
80 114 ▶ if ( ! defined $arg{index_locations} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $arg{"index_locations"}) 114 0 114
81 $arg{index_locations} = !! $arg{location} ||
82 114 ▶ __instance( $source, 'PPI::Element' );
Condition100%3/3
!!$arg{'location'} || __instance($source, 'PPI::Element')
l!l&&r!l&&!r
26943
MC/DC100%2/2
!!$arg{'location'} || __instance($source, 'PPI::Element')
!!$arg{'location'} __instance($source, 'PPI::Element')
Truth table100%3/3
A || B
A= !!$arg{'location'}B= __instance($source, 'PPI::Element')
ABresult
1X1
011
000
83 }
84  
85 my $self = {
86 index_locations => $arg{index_locations},
87 children => \@children,
88 encoding => $arg{encoding},
89 failures => 0,
90 location => $arg{location},
91 114 source => $source,
92 };
93  
94 114 ▶ bless $self, ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
01140
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
95  
96 114 ▶ defined( my $string = $self->_stringify_source( $source ) )
Branch: 1 branch
BranchTrueFalseTotal
defined(my $string = $self->_stringify_source($source)) or return 62 52 114
97 or return;
98  
99 62 my ( $type, $gap, $gap2, $content, $end_delim, $indented, $start_delim );
100  
101 $arg{trace}
102 62 ▶ and warn "Initial match of $string\n";
Branch: 1 branch
BranchTrueFalseTotal
$arg{"trace"} and warn "Initial match of $string\n" 0 62 62
103  
104 # q<>, qq<>, qx<>
105 62 ▶ if ( $string =~ m/ \A \s* ( q [qx]? ) ( \s* ) ( . ) /smxgc ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($string =~ / \A \s* ( q [qx]? ) ( \s* ) ( . ) /cgmsx) { } 9 53 62
elsif ($string =~ / \A \s* ( << ) ( \s* ) ( ~? ) ( \s* ) ( [\\]? \w+ | $match_sq | $match_dq | $match_bt ) \n /cgmsx) { } 7 46 53
elsif ($string =~ / \A \s* ( [`'"<] ) /cgmsx) { } 46 0 46
106 9 ( $type, $gap, $start_delim ) = ( $1, $2, $3 );
107 9 ▶ not $gap
Branch: 1 branch
BranchTrueFalseTotal
not $gap and $start_delim =~ / \A \w \z /msx and return $self->_link_elems($self->_make_token("PPIx::QuoteLike::Token::Unknown", $string, "error", "Tokenizer found illegal first characters")) 0 9 9
Condition66%2/3
not $gap and $start_delim =~ / \A \w \z /msx
!ll&&!rl&&r
450
MC/DC0%0/2
not $gap and $start_delim =~ / \A \w \z /msx
not $gap $start_delim =~ / \A \w \z /msx
Truth table66%2/3
not(A) and B
A= not $gapB= $start_delim =~ / \A \w \z /msx
ABresult
0X0
100
111
108 and $start_delim =~ m< \A \w \z >smx
109 and return $self->_link_elems( $self->_make_token(
110 CLASS_UNKNOWN, $string, error => ILLEGAL_FIRST ) );
111 $arg{trace}
112 9 ▶ and warn "Initial match '$type$start_delim'\n";
Branch: 1 branch
BranchTrueFalseTotal
$arg{"trace"} and warn "Initial match '$type${start_delim}'\n" 0 9 9
113 9 ▶ $self->{interpolates} = 'qq' eq $type ||
Condition100%6/6
'qq' eq $type || 'qx' eq $type && q['] ne $start_delim
l!l&&r!l&&!r
513
"qx" eq $type and "'" ne $start_delim
!ll&&!rl&&r
211
MC/DC100%3/3
'qq' eq $type || 'qx' eq $type && q['] ne $start_delim
'qq' eq $type "qx" eq $type "'" ne $start_delim
Truth table100%4/4
A || B and C
A= 'qq' eq $typeB= "qx" eq $typeC= "'" ne $start_delim
ABCresult
1XX1
0111
00X0
0100
114 'qx' eq $type && q<'> ne $start_delim;
115 9 ▶ $content = substr $string, ( pos $string || 0 );
Condition50%1/2
pos $string || 0
l!l
90
MC/DC0%0/1
pos $string || 0
pos $string
Truth table50%1/2
A
A= pos $string
Aresult
11
00
116 9 $end_delim = __matching_delimiter( $start_delim );
117 9 ▶ if ( $end_delim eq substr $content, -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end_delim eq substr($content, -1)) { } 9 0 9
118 9 chop $content;
119 } else {
120 0 $end_delim = '';
121 }
122  
123 # here doc
124 # Note that the regexp used here is slightly wrong in that white
125 # space between the '<<' and the termination string is not
126 # allowed if the termination string is not quoted in some way.
127 } elsif ( $string =~ m/ \A \s* ( << ) ( \s* ) ( ~? ) ( \s* )
128 ( [\\]? \w+ | $match_sq | $match_dq | $match_bt ) \n /smxgc ) {
129 7 ( $type, $gap, $indented, $gap2, $start_delim ) = (
130 $1, $2, $3, $4, $5 );
131 $arg{trace}
132 7 ▶ and warn "Initial match '$type$start_delim$gap$indented'\n";
Branch: 1 branch
BranchTrueFalseTotal
$arg{"trace"} and warn "Initial match '$type$start_delim$gap${indented}'\n" 0 7 7
133 7 $self->{interpolates} = $start_delim !~ m/ \A [\\'] /smx;
134 7 ▶ $content = substr $string, ( pos $string || 0 );
Condition50%1/2
pos $string || 0
l!l
70
MC/DC0%0/1
pos $string || 0
pos $string
Truth table50%1/2
A
A= pos $string
Aresult
11
00
135 7 $end_delim = _unquote( $start_delim );
136 # NOTE that the indentation is specifically space or tab
137 # only.
138 7 ▶ if ( $content =~ s/ ^ ( [ \t]* ) \Q$end_delim\E \n? \z //smx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ s/ ^ ( [ \t]* ) \Q$end_delim\E \n? \z //msx) { } 7 0 7
139 # NOTE PPI::Token::HereDoc does not preserve the
140 # indentation of an indented here document, so the
141 # indentation will appear to be '' if we came from PPI.
142 7 ▶ if ( $indented ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($indented) 4 3 7
143 # Version per perldelta.pod for that release.
144 4 $self->{perl_version_introduced} = '5.025007';
145 4 $self->{indentation} = "$1";
146 4 $self->{_indentation_re} = qr/
147 ^ \Q$self->{indentation}\E /smx;
148 }
149 } else {
150 0 $end_delim = '';
151 }
152 $self->{start} = [
153 7 $self->_make_token( CLASS_DELIMITER, $start_delim ),
154 $self->_make_token( CLASS_WHITESPACE, "\n" ),
155 ];
156  
157 # Don't instantiate yet -- we'll do them at the end.
158 $self->{finish} = [
159 7 [ CLASS_DELIMITER, $end_delim ],
160 [ CLASS_WHITESPACE, "\n" ],
161 ];
162  
163 # ``, '', "", <>
164 } elsif ( $string =~ m/ \A \s* ( [`'"<] ) /smxgc ) {
165 46 ( $type, $gap, $start_delim ) = ( '', '', $1 );
166 $arg{trace}
167 46 ▶ and warn "Initial match '$type$start_delim'\n";
Branch: 1 branch
BranchTrueFalseTotal
$arg{"trace"} and warn "Initial match '$type${start_delim}'\n" 0 46 46
168 46 $self->{interpolates} = q<'> ne $start_delim;
169 46 ▶ $content = substr $string, ( pos $string || 0 );
Condition50%1/2
pos $string || 0
l!l
460
MC/DC0%0/1
pos $string || 0
pos $string
Truth table50%1/2
A
A= pos $string
Aresult
11
00
170 46 $end_delim = __matching_delimiter( $start_delim );
171 46 ▶ if ( $end_delim eq substr $content, -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end_delim eq substr($content, -1)) { } 46 0 46
172 46 chop $content;
173 } else {
174 0 $end_delim = '';
175 }
176  
177 # Something we do not recognize
178 } else {
179 $arg{trace}
180 0 ▶ and warn "No initial match\n";
Branch: 1 branch
BranchTrueFalseTotal
$arg{"trace"} and warn "No initial match\n" 0 0 0
181 0 return $self->_link_elems( $self->_make_token(
182 CLASS_UNKNOWN, $string, error => ILLEGAL_FIRST ) );
183 }
184  
185 62 ▶ $self->{interpolates} = $self->{interpolates} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'interpolates'} ? : 49 13 62
186  
187 62 ▶ defined or $_ = '' for $indented, $gap2;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or $_ = "" 14 110 124
188 $self->{type} = [
189 62 ▶ $self->_make_token( CLASS_STRUCTURE, $type ),
Branch: 3 branches
BranchTrueFalseTotal
length $gap ? : 7 55 62
length $indented ? : 4 58 62
length $gap2 ? : 0 62 62
190 length $gap ?
191 $self->_make_token( CLASS_WHITESPACE, $gap ) :
192 (),
193 length $indented ?
194 $self->_make_token( CLASS_STRUCTURE, $indented ) :
195 (),
196 length $gap2 ?
197 $self->_make_token( CLASS_WHITESPACE, $gap2 ) :
198 (),
199 ];
200 $self->{start} ||= [
201 62 ▶ $self->_make_token( CLASS_DELIMITER, $start_delim ),
Condition100%2/2
$self->{"start"} ||= [$self->_make_token("PPIx::QuoteLike::Token::Delimiter", $start_delim)]
l!l
755
MC/DC100%1/1
$self->{"start"} ||= [$self->_make_token("PPIx::QuoteLike::Token::Delimiter", $start_delim)]
$self->{"start"}
Truth table100%2/2
A
A= $self->{"start"}
Aresult
11
00
202 ];
203  
204 $arg{trace}
205 62 ▶ and warn "Without delimiters: '$content'\n";
Branch: 1 branch
BranchTrueFalseTotal
$arg{"trace"} and warn "Without delimiters: '${content}'\n" 0 62 62
206  
207 # We accumulate data and manufacure tokens at the end to reduce
208 # the overhead involved in merging strings.
209 62 ▶ if ( $self->{interpolates} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'interpolates'}) { } 49 13 62
210 49 push @children, [ '' => '' ]; # Prime the pump
211 49 while ( 1 ) {
212  
213 148 ▶ if ( $content =~ m/ \G ( \\ [ULulQEF] ) /smxgc ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($content =~ / \G ( \\ [ULulQEF] ) /cgmsx) { } 4 144 148
elsif ($content =~ / \G ( \\ N [{] ( [^}]+ ) [}] ) /cgmsx) { } 1 143 144
elsif ($content =~ / \G ( [\$\@] \#? \$* ) /cgmsx) { } 51 92 143
elsif ($content =~ / \G ( \\ . | [^\\\$\@]+ ) /cgmsx) { } 43 49 92
214 4 push @children, [ CLASS_CONTROL, "$1" ];
215 } elsif (
216 $content =~ m/ \G ( \\ N [{] ( [^}]+ ) [}] ) /smxgc
217 ) {
218 # Handle \N{...} separately because it can not
219 # contain an interpolation even inside of an
220 # otherwise-interpolating string. That is to say,
221 # "\N{$foo}" is simply invalid, and does not even
222 # try to interpolate $foo. {
223 # TODO use $re = __match_enclosed( '{' ); # }
224 1 my ( $seq, $name ) = ( $1, $2 );
225 # TODO The Regexp is certainly too permissive. For
226 # the moment all I am doing is disallowing
227 # interpolation.
228 1 ▶ push @children, $name =~ m/ [\$\@] /smx ?
Branch: 1 branch
BranchTrueFalseTotal
$name =~ / [\$\@] /msx ? : 1 0 1
229 [ CLASS_UNKNOWN, $seq,
230 error => "Unknown charname '$name'" ] :
231 [ CLASS_STRING, $seq ];
232 # NOTE in the following that I do not read perldata as
233 # saying there can be space between the sigil and the
234 # variable name, but Perl itself seems to accept it as
235 # of 5.30.1.
236 } elsif ( $content =~ m/ \G ( [\$\@] \#? \$* ) /smxgc ) {
237 51 push @children, $self->_interpolation( "$1", $content );
238 } elsif ( $content =~ m/ \G ( \\ . | [^\\\$\@]+ ) /smxgc ) {
239 43 push @children, $self->_remove_here_doc_indentation(
240 "$1",
241 sibling => \@children,
242 );
243 } else {
244 49 last;
245 }
246 }
247  
248 49 @children = _merge_strings( @children );
249 49 shift @children; # remove the priming
250  
251 # Make the tokens, at long last.
252 49 foreach ( @children ) {
253 96 $_ = $self->_make_token( @{ $_ } );
254 }
255  
256 } else {
257  
258 length $content
259 13 ▶ and push @children, map { $self->_make_token( @{ $_ } ) }
Branch: 1 branch
BranchTrueFalseTotal
length $content and push @children, map({$self->_make_token(@{$_;});} _merge_strings($self->_remove_here_doc_indentation($content))) 10 3 13
260 _merge_strings(
261 $self->_remove_here_doc_indentation( $content )
262 );
263  
264 }
265  
266 # Add the indentation before the end marker, if needed
267 $self->{indentation}
268 and push @children, $self->_make_token(
269 62 ▶ CLASS_WHITESPACE, $self->{indentation} );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"indentation"} and push @children, $self->_make_token("PPIx::QuoteLike::Token::Whitespace", $self->{"indentation"}) 4 58 62
270  
271 62 ▶ if ( $self->{finish} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'finish'}) { } 7 55 62
272 # If we already have something here it is data, not objects.
273 7 foreach ( @{ $self->{finish} } ) {
274 14 $_ = $self->_make_token( @{ $_ } );
275 }
276 } else {
277 $self->{finish} = [
278 55 $self->_make_token( CLASS_DELIMITER, $end_delim ),
279 ];
280 }
281  
282 62 ▶ ref $_[1]
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] and pos $_[1] = pos $string 17 45 62
283 and pos( $_[1] ) = pos $string;
284  
285 62 return $self->_link_elems();
286 }
287 }
288  
289 7 ▶sub child {
Subroutine child: called CC=1 SCAR=0.0
Pod documented
290 46 my ( $self, $number ) = @_;
291 46 return $self->{children}[$number];
292 }
293  
294 116 ▶sub children {
Subroutine children: called CC=1 SCAR=0.0
Pod documented
295 116 my ( $self ) = @_;
296 116 return @{ $self->{children} };
297 }
298  
299 27 ▶sub content {
Subroutine content: called CC=1 SCAR=0.0
Pod documented
300 27 my ( $self ) = @_;
301 27 return join '', map { $_->content() } grep { $_ } $self->elements();
302 }
303  
304 27 ▶sub delimiters {
Subroutine delimiters: called CC=1 SCAR=0.0
Pod documented
305 27 my ( $self ) = @_;
306 54 return join '', grep { defined }
307 27 map { $self->_get_value_scalar( $_ ) }
308 qw{ start finish };
309 }
310  
311 # $self->_deprecation_notice( $type, $name );
312 #
313 # This method centralizes deprecation. Type is 'attribute' or
314 # 'method'. Deprecation is driven of the %deprecate hash. Values
315 # are:
316 # false - no warning
317 # 1 - warn on first use
318 # 2 - warn on each use
319 # 3 - die on each use.
320 #
321 # $self->_deprecation_in_progress( $type, $name )
322 #
323 # This method returns true if the deprecation is in progress. In
324 # fact it returns the deprecation level.
325  
326 =begin comment
327  
328 # Abandoned in place, against future need.
329  
330 {
331  
332 my %deprecate = (
333 attribute => {
334 postderef => 3,
335 },
336 );
337  
338 sub _deprecation_notice {
339 my ( undef, $type, $name, $repl ) = @_; # Invocant unused
340 $deprecate{$type} or return;
341 $deprecate{$type}{$name} or return;
342 my $msg = sprintf 'The %s %s is %s', $name, $type,
343 $deprecate{$type}{$name} > 2 ? 'removed' : 'deprecated';
344 defined $repl
345 and $msg .= "; use $repl instead";
346 $deprecate{$type}{$name} >= 3
347 and croak $msg;
348 warnings::enabled( 'deprecated' )
349 and carp $msg;
350 $deprecate{$type}{$name} == 1
351 and $deprecate{$type}{$name} = 0;
352 return;
353 }
354  
355 }
356  
357 =end comment
358  
359 =cut
360  
361 54 ▶sub _get_value_scalar {
Subroutine _get_value_scalar: called CC=3 SCAR=11.7
362 54 my ( $self, $method ) = @_;
363 54 ▶ defined( my $val = $self->$method() )
Branch: 1 branch
BranchTrueFalseTotal
defined(my $val = $self->$method) or return 54 0 54
364 or return;
365 54 ▶ return ref $val ? $val->content() : $val;
Branch: 1 branch
BranchTrueFalseTotal
ref $val ? : 54 0 54
366 }
367  
368 84 ▶sub elements {
Subroutine elements: called CC=2 SCAR=6.9
Pod documented
369 84 my ( $self ) = @_;
370 84 return @{ $self->{elements} ||= [
371 84 ▶ map { $self->$_() } qw{ type start children finish }
Condition100%2/2
$self->{"elements"} ||= [map({$self->$_;} "type", "start", "children", "finish")]
l!l
3648
MC/DC100%1/1
$self->{"elements"} ||= [map({$self->$_;} "type", "start", "children", "finish")]
$self->{"elements"}
Truth table100%2/2
A
A= $self->{"elements"}
Aresult
11
00
372 ] };
373 }
374  
375 34 ▶sub encoding {
Subroutine encoding: called CC=1 SCAR=0.0
Pod documented
376 34 my ( $self ) = @_;
377 34 return $self->{encoding};
378 }
379  
380 36 ▶sub failures {
Subroutine failures: called CC=1 SCAR=0.0
Pod documented
381 36 my ( $self ) = @_;
382 36 return $self->{failures};
383 }
384  
385 1 ▶sub find {
Subroutine find: called CC=6 SCAR=18.3
Pod documented
386 1 my ( $self, $target ) = @_;
387  
388 my $check = CODE_REF eq ref $target ? $target :
389 ref $target ? croak 'find() target may not be ' . ref $target :
390 1 ▶ sub { $_[0]->isa( $target ) };
Subroutine __ANON__: called CC=1 SCAR=0.4
Branch: 2 branches
BranchTrueFalseTotal
'CODE' eq ref $target ? : 0 1 1
ref $target ? : 0 1 1
391 1 my @found;
392 1 foreach my $elem ( $self, $self->elements() ) {
393 5 ▶ $check->( $elem )
Branch: 1 branch
BranchTrueFalseTotal
&$check($elem) and push @found, $elem 1 4 5
394 and push @found, $elem;
395 }
396  
397 @found
398 1 ▶ or return 0;
Branch: 1 branch
BranchTrueFalseTotal
@found or return 0 1 0 1
399  
400 1 return \@found;
401 }
402  
403 109 ▶sub finish {
Subroutine finish: called CC=4 SCAR=14.1
Pod documented
404 109 my ( $self, $inx ) = @_;
405 $self->{finish}
406 109 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"finish"} or return 109 0 109
407 wantarray
408 109 ▶ and return @{ $self->{finish} };
Branch: 1 branch
BranchTrueFalseTotal
wantarray and return @{$self->{"finish"};} 55 54 109
409 54 ▶ return $self->{finish}[ $inx || 0 ];
Condition50%1/2
$inx || 0
l!l
054
MC/DC0%0/1
$inx || 0
$inx
Truth table50%1/2
A
A= $inx
Aresult
11
00
410 }
411  
412 0 ▶sub handles {
Subroutine handles: not called CC=1 SCAR=6.9
Pod documented
413 0 my ( $self, $string ) = @_;
414 0 return $self->_stringify_source( $string, test => 1 );
415 }
416  
417 10 ▶sub indentation {
Subroutine indentation: called CC=1 SCAR=0.0
Pod documented
418 10 my ( $self ) = @_;
419 10 return $self->{indentation};
420 }
421  
422 84 ▶sub interpolates {
Subroutine interpolates: called CC=1 SCAR=0.0
Pod documented
423 84 my ( $self ) = @_;
424 84 return $self->{interpolates};
425 }
426  
427 6 ▶sub location {
Subroutine location: called CC=1 SCAR=0.0
Pod documented
428 6 my ( $self ) = @_;
429 6 return $self->type()->location();
430 }
431  
432 326 ▶sub _make_token {
Subroutine _make_token: called CC=3 SCAR=11.0
433 326 my ( $self, $class, $content, %arg ) = @_;
434 326 my $token = $class->__new( content => $content, %arg );
435 CLASS_UNKNOWN eq $class
436 326 ▶ and $self->{failures}++;
Branch: 1 branch
BranchTrueFalseTotal
"PPIx::QuoteLike::Token::Unknown" eq $class and ++$self->{"failures"} 1 325 326
437 $self->{index_locations}
438 326 ▶ and $self->_update_location( $token );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"index_locations"} and $self->_update_location($token) 100 226 326
439 326 return $token;
440 }
441  
442 100 ▶sub _update_location {
Subroutine _update_location: called CC=16 SCAR=27.9
443 100 my ( $self, $token ) = @_;
444 $token->{location} # Idempotent
445 100 ▶ and return;
Branch: 1 branch
BranchTrueFalseTotal
$token->{"location"} and return 0 100 100
446 100 ▶ my $loc = $self->{_location} ||= do {
Condition66%2/3
$self->{"_location"} ||= do { my(%loc) = ("line_content", "", "location", $self->{"location"}); if (__instance($self->{"source"}, "PPI::Element")) { $loc{"location"} ||= $self->{"source"}->location; if (my $doc = $self->{"source"}->document) { $loc{"tab_width"} = $doc->tab_width; } ; } ; $loc{"tab_width"} ||= 1; \%loc }
l!l&&r!l&&!r
81190
MC/DC0%0/2
$self->{"_location"} ||= do { my(%loc) = ("line_content", "", "location", $self->{"location"}); if (__instance($self->{"source"}, "PPI::Element")) { $loc{"location"} ||= $self->{"source"}->location; if (my $doc = $self->{"source"}->document) { $loc{"tab_width"} = $doc->tab_width; } ; } ; $loc{"tab_width"} ||= 1; \%loc }
$self->{"_location"} do { my(%loc) = ("line_content", "", "location", $self->{"location"}); if (__instance($self->{"source"}, "PPI::Element")) { $loc{"location"} ||= $self->{"source"}->location; if (my $doc = $self->{"source"}->document) { $loc{"tab_width"} = $doc->tab_width; } ; } ; $loc{"tab_width"} ||= 1; \%loc }
Truth table66%2/3
A ||= B
A= $self->{"_location"}B= do { my(%loc) = ("line_content", "", "location", $self->{"location"}); if (__instance($self->{"source"}, "PPI::Element")) { $loc{"location"} ||= $self->{"source"}->location; if (my $doc = $self->{"source"}->document) { $loc{"tab_width"} = $doc->tab_width; } ; } ; $loc{"tab_width"} ||= 1; \%loc }
ABresult
1X1
011
000
447 my %loc = (
448 line_content => '',
449 location => $self->{location},
450 19 );
451 19 ▶ if ( __instance( $self->{source}, 'PPI::Element' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (__instance($self->{"source"}, "PPI::Element")) 17 2 19
452 17 ▶ $loc{location} ||= $self->{source}->location();
Condition33%1/3
$loc{"location"} ||= $self->{"source"}->location
l!l&&r!l&&!r
0170
MC/DC0%0/2
$loc{"location"} ||= $self->{"source"}->location
$loc{"location"} $self->{"source"}->location
Truth table33%1/3
A ||= B
A= $loc{"location"}B= $self->{"source"}->location
ABresult
1X1
011
000
453 17 ▶ if ( my $doc = $self->{source}->document() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $doc = $self->{"source"}->document) 17 0 17
454 17 $loc{tab_width} = $doc->tab_width();
455 }
456 }
457 19 ▶ $loc{tab_width} ||= 1;
Condition100%2/2
$loc{"tab_width"} ||= 1
l!l
172
MC/DC100%1/1
$loc{"tab_width"} ||= 1
$loc{"tab_width"}
Truth table100%2/2
A
A= $loc{"tab_width"}
Aresult
11
00
458 19 \%loc;
459 };
460 $loc->{location}
461 100 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
$loc->{"location"} or return 100 0 100
462 100 $token->{location} = [ @{ $loc->{location} } ];
463  
464 100 ▶ if ( defined( my $content = $token->content() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $content = $token->content)) 100 0 100
465  
466 100 my $lines;
467 100 pos( $content ) = 0;
468 100 ▶ $lines++ while $content =~ m/ \n /smxgc;
Branch: 1 branch
BranchTrueFalseTotal
$content =~ / \n /cgmsx and do { ++$lines } 7 100 107
469 100 ▶ if ( pos $content ) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $content) 4 96 100
470 4 $loc->{location}[LOCATION_LINE] += $lines;
471 4 $loc->{location}[LOCATION_LOGICAL_LINE] += $lines;
472 $loc->{location}[LOCATION_CHARACTER] =
473 4 $loc->{location}[LOCATION_COLUMN] = 1;
474 }
475  
476 100 ▶ if ( my $chars = length( $content ) - pos( $content ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $chars = length($content) - pos($content)) 83 17 100
477 83 $loc->{location}[LOCATION_CHARACTER] += $chars;
478 83 ▶ if ( $loc->{tab_width} > 1 && $content =~ m/ \t /smx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loc->{'tab_width'} > 1 and $content =~ / \t /msx) { } 4 79 83
Condition100%3/3
$loc->{"tab_width"} > 1 and $content =~ / \t /msx
!ll&&!rl&&r
7454
MC/DC100%2/2
$loc->{"tab_width"} > 1 and $content =~ / \t /msx
$loc->{"tab_width"} > 1 $content =~ / \t /msx
Truth table100%3/3
A and B
A= $loc->{"tab_width"} > 1B= $content =~ / \t /msx
ABresult
0X0
100
111
479 4 my $pos = $loc->{location}[LOCATION_COLUMN];
480 4 my $tab_width = $loc->{tab_width};
481 # Stolen shamelessly from PPI::Document::_visual_length
482 4 my ( $vis_inc );
483 4 foreach my $part ( split /(\t)/, $content ) {
484 10 ▶ if ($part eq "\t") {
Branch: 1 branch
BranchTrueFalseTotal
if ($part eq "\t") { } 5 5 10
485 5 $vis_inc = $tab_width - ($pos-1) % $tab_width;
486 } else {
487 5 $vis_inc = length $part;
488 }
489 10 $pos += $vis_inc;
490 }
491 4 $loc->{location}[LOCATION_COLUMN] = $pos;
492 } else {
493 79 $loc->{location}[LOCATION_COLUMN] += $chars;
494 }
495 }
496  
497 }
498  
499 100 return;
500 }
501  
502 1 ▶sub parent {
Subroutine parent: called CC=1 SCAR=0.0
Pod documented
503 1 return;
504 }
505  
506 18 ▶sub perl_version_introduced {
Subroutine perl_version_introduced: called CC=1 SCAR=0.0
Pod documented
507 18 my ( $self ) = @_;
508 133 return List::Util::max( grep { defined $_ } MINIMUM_PERL,
509 $self->{perl_version_introduced},
510 18 map { $_->perl_version_introduced() } $self->elements() );
511 }
512  
513 9 ▶sub perl_version_removed {
Subroutine perl_version_removed: called CC=5 SCAR=22.7
Pod documented
514 9 my ( $self ) = @_;
515 9 my $max;
516 9 foreach my $elem ( $self->elements() ) {
517 58 ▶ if ( defined ( my $ver = $elem->perl_version_removed() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ver = $elem->perl_version_removed)) 0 58 58
518 0 ▶ if ( defined $max ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max) { } 0 0 0
519 0 ▶ $ver < $max and $max = $ver;
Branch: 1 branch
BranchTrueFalseTotal
$ver < $max and $max = $ver 0 0 0
520 } else {
521 0 $max = $ver;
522 }
523 }
524 }
525 9 return $max;
526 }
527  
528 0 ▶sub schild {
Subroutine schild: not called CC=2 SCAR=17.9
Pod documented
529 0 my ( $self, $inx ) = @_;
530 0 ▶ $inx ||= 0;
Condition0%0/2
$inx ||= 0
l!l
00
MC/DC0%0/1
$inx ||= 0
$inx
Truth table0%0/2
A
A= $inx
Aresult
11
00
531 0 my @kids = $self->schildren();
532 0 return $kids[$inx];
533 }
534  
535 0 ▶sub schildren {
Subroutine schildren: not called CC=1 SCAR=6.9
Pod documented
536 0 my ( $self ) = @_;
537 return (
538 0 grep { $_->significant() } $self->children()
539 );
540 }
541  
542 10 ▶sub source {
Subroutine source: called CC=1 SCAR=0.0
Pod documented
543 10 my ( $self ) = @_;
544 10 return $self->{source};
545 }
546  
547 109 ▶sub start {
Subroutine start: called CC=4 SCAR=14.1
Pod documented
548 109 my ( $self, $inx ) = @_;
549 $self->{start}
550 109 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"start"} or return 109 0 109
551 wantarray
552 109 ▶ and return @{ $self->{start} };
Branch: 1 branch
BranchTrueFalseTotal
wantarray and return @{$self->{"start"};} 55 54 109
553 54 ▶ return $self->{start}[ $inx || 0 ];
Condition50%1/2
$inx || 0
l!l
054
MC/DC0%0/1
$inx || 0
$inx
Truth table50%1/2
A
A= $inx
Aresult
11
00
554 }
555  
556 2 ▶sub top {
Subroutine top: called CC=1 SCAR=0.0
Pod documented
557 2 my ( $self ) = @_;
558 2 return $self;
559 }
560  
561 88 ▶sub type {
Subroutine type: called CC=4 SCAR=14.1
Pod documented
562 88 my ( $self, $inx ) = @_;
563 $self->{type}
564 88 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"type"} or return 88 0 88
565 wantarray
566 88 ▶ and return @{ $self->{type} };
Branch: 1 branch
BranchTrueFalseTotal
wantarray and return @{$self->{"type"};} 55 33 88
567 33 ▶ return $self->{type}[ $inx || 0 ];
Condition50%1/2
$inx || 0
l!l
033
MC/DC0%0/1
$inx || 0
$inx
Truth table50%1/2
A
A= $inx
Aresult
11
00
568 }
569  
570 40 ▶sub variables {
Subroutine variables: called CC=4 SCAR=13.9
Pod documented
571 40 my ( $self ) = @_;
572  
573 40 ▶ $self->interpolates()
Branch: 1 branch
BranchTrueFalseTotal
$self->interpolates or return 34 6 40
574 or return;
575  
576 34 my %var;
577 34 foreach my $kid ( $self->children() ) {
578 67 foreach my $sym ( $kid->variables() ) {
579 35 $var{$sym} = 1;
580 }
581 }
582 34 return ( keys %var );
583 }
584  
585 0 ▶sub _chop {
Subroutine _chop: not called CC=1 SCAR=6.9
586 0 my ( $middle ) = @_;
587 0 my $left = substr $middle, 0, 1, '';
588 0 my $right = substr $middle, -1, 1, '';
589 0 return ( $left, $middle, $right );
590 }
591  
592 # decode data using the object's {encoding}
593 # It is anticipated that if I make PPIx::Regexp depend on this package,
594 # that this will be called there.
595  
596 23 ▶sub __decode {
Subroutine __decode: called CC=4 SCAR=17.9
597 23 my ( $self, $data, $encoding ) = @_;
598 23 ▶ $encoding ||= $self->{encoding};
Condition33%1/3
$encoding ||= $self->{"encoding"}
l!l&&r!l&&!r
0023
MC/DC0%0/2
$encoding ||= $self->{"encoding"}
$encoding $self->{"encoding"}
Truth table33%1/3
A ||= B
A= $encodingB= $self->{"encoding"}
ABresult
1X1
011
000
599 23 ▶ defined $encoding
Branch: 1 branch
BranchTrueFalseTotal
defined $encoding and _encode_available() or return $data 0 23 23
Condition33%1/3
defined $encoding and _encode_available()
!ll&&!rl&&r
2300
MC/DC0%0/2
defined $encoding and _encode_available()
defined $encoding _encode_available()
Truth table33%1/3
A and B
A= defined $encodingB= _encode_available()
ABresult
0X0
100
111
600 and _encode_available()
601 or return $data;
602 0 return Encode::decode( $encoding, $data );
603 }
604  
605 {
606  
607 7 my $encode_available;
608  
609 0 ▶ sub _encode_available {
Subroutine _encode_available: not called CC=3 SCAR=24.8
610 0 ▶ defined $encode_available and return $encode_available;
Branch: 1 branch
BranchTrueFalseTotal
defined $encode_available and return $encode_available 0 0 0
611 0 ▶ return ( $encode_available = eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Encode; 1 } } ? : 0 0 0
612 0 require Encode;
613 0 1;
614 } ? 1 : 0
615 );
616 }
617  
618 }
619  
620 {
621 7 my ( $cached_doc, $cached_encoding );
622  
623 # These are the byte order marks documented as being recognized by
624 # PPI. Only utf-8 is documented as supported.
625 7 my %known_bom = (
626 'EFBBBF' => 'utf-8',
627 '0000FEFF' => 'utf-32be',
628 'FFFE0000' => 'utf-32le',
629 'FEFF' => 'utf-16be',
630 'FFFE' => 'utf-16le',
631 );
632  
633 17 ▶ sub _get_ppi_encoding {
Subroutine _get_ppi_encoding: called CC=11 SCAR=26.3
634 17 my ( $elem ) = @_;
635  
636 17 ▶ my $doc = $elem->top()
Branch: 1 branch
BranchTrueFalseTotal
my $doc = $elem->top or return 17 0 17
637 or return;
638  
639 17 ▶ $cached_doc
Branch: 1 branch
BranchTrueFalseTotal
$cached_doc and $doc == $cached_doc and return $cached_encoding 6 11 17
Condition66%2/3
$cached_doc and $doc == $cached_doc
!ll&&!rl&&r
1106
MC/DC50%1/2
$cached_doc and $doc == $cached_doc
$cached_doc $doc == $cached_doc
Truth table66%2/3
A and B
A= $cached_docB= $doc == $cached_doc
ABresult
0X0
100
111
640 and $doc == $cached_doc
641 and return $cached_encoding;
642  
643 11 ▶ my $bom = $doc->first_element()
Branch: 1 branch
BranchTrueFalseTotal
my $bom = $doc->first_element or return 11 0 11
644 or return;
645  
646 11 Scalar::Util::weaken( $cached_doc = $doc );
647  
648 11 ▶ if ( $bom->isa( 'PPI::Token::BOM' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bom->isa("PPI::Token::BOM")) 0 11 11
649 return ( $cached_encoding = $known_bom{
650 0 uc unpack 'H*', $bom->content() } );
651 }
652  
653 11 $cached_encoding = undef;
654  
655 11 foreach my $use (
656 11 ▶ @{ $doc->find( 'PPI::Statement::Include' ) || [] }
Condition100%2/2
$doc->find('PPI::Statement::Include') || []
l!l
110
MC/DC100%1/1
$doc->find('PPI::Statement::Include') || []
$doc->find('PPI::Statement::Include')
Truth table100%2/2
A
A= $doc->find('PPI::Statement::Include')
Aresult
11
00
657 ) {
658 2 ▶ 'use' eq $use->type()
Branch: 1 branch
BranchTrueFalseTotal
"use" eq $use->type or next 2 0 2
659 or next;
660 2 ▶ defined( my $module = $use->module() )
Branch: 1 branch
BranchTrueFalseTotal
defined(my $module = $use->module) or next 2 0 2
661 or next;
662 2 ▶ 'utf8' eq $module
Branch: 1 branch
BranchTrueFalseTotal
"utf8" eq $module or next 0 2 2
663 or next;
664 0 $cached_encoding = 'utf-8';
665 0 last;
666 }
667  
668 11 return $cached_encoding;
669  
670 }
671  
672 }
673  
674 # This subroutine was created in an attempt to simplify control flow.
675 # Argument 2 (from 0) is not unpacked because the caller needs to see
676 # the side effects of matches made on it.
677  
678 {
679  
680 7 my %special = (
681 0 ▶ '$$' => sub { # Process ID.
Subroutine __ANON__: not called CC=1 SCAR=6.9
682 0 my ( undef, $sigil ) = @_;
683 0 return [ CLASS_INTERPOLATION, $sigil ];
684 },
685 1 ▶ '$' => sub { # Called if we find (e.g.) '$@'
Subroutine __ANON__: called CC=2 SCAR=7.1
686 1 my ( undef, $sigil ) = @_;
687 1 ▶ $_[2] =~ m/ \G ( [\@] ) /smxgc
Branch: 1 branch
BranchTrueFalseTotal
$_[2] =~ / \G ( [\@] ) /cgmsx or return 1 0 1
688 or return;
689 1 return [ CLASS_INTERPOLATION, "$sigil$1" ];
690 },
691 2 ▶ '@' => sub { # Called if we find '@@'.
Subroutine __ANON__: called CC=1 SCAR=0.0
692 2 my ( undef, $sigil ) = @_;
693 2 return [ CLASS_STRING, $sigil ];
694 },
695 7 );
696  
697 51 ▶ sub _interpolation { ## no critic (RequireArgUnpacking)
Subroutine _interpolation: called CC=12 SCAR=25.9
698 51 my ( $self, $sigil ) = @_;
699 # Argument $_[2] is $content, but we can't unpack it because we
700 # need the caller to see any changes to pos().
701  
702 51 ▶ if ( $_[2] =~ m/ \G (?= \{ ) /smxgc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2] =~ / \G (?= \{ ) /cgmsx) 14 37 51
703 # variable name enclosed in {}
704 14 my $delim_re = __match_enclosed( qw< { > );
705 14 ▶ if ( $_[2] =~ m/ \G $delim_re /smxgc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2] =~ / \G $delim_re /cgmsx) 14 0 14
706 14 my $rest = $1;
707 14 ▶ $rest =~ m/ \A \{ \s* \[ ( .* ) \] \s* \} \z /smx
Branch: 1 branch
BranchTrueFalseTotal
$rest =~ / \A \{ \s* \[ ( .* ) \] \s* \} \z /msx or return ["PPIx::QuoteLike::Token::Interpolation", "$sigil$rest"] 5 9 14
708 or return [ CLASS_INTERPOLATION, "$sigil$rest" ];
709 # At this point we have @{[ ... ]}.
710 5 my @arg;
711 5 ▶ _has_postderef( "$1" )
Branch: 1 branch
BranchTrueFalseTotal
_has_postderef("$1") and push @arg, "postderef", 1 3 2 5
712 and push @arg, postderef => 1;
713 5 return [ CLASS_INTERPOLATION, "$sigil$rest", @arg ];
714 }
715 0 ▶ $_[2] =~ m/ \G ( .* ) /smxgc
Branch: 1 branch
BranchTrueFalseTotal
$_[2] =~ / \G ( .* ) /cgmsx and return ["PPIx::QuoteLike::Token::Unknown", "$sigil$1", "error", "Tokenizer found mismatched delimiters"] 0 0 0
716 and return [ CLASS_UNKNOWN, "$sigil$1",
717 error => MISMATCHED_DELIM ];
718 0 confess 'Failed to match /./';
719 }
720  
721 37 ▶ if ( $_[2] =~ m< \G ( @{[ VARIABLE_RE ]} ) >smxgco
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2] =~ m( \G ( @{[qr/ [[:alpha:]_]\w* (?: :: [[:alpha:]_] \w* )* | \^ [A-Z_] | [0-9]+ | [-!"#\$%&'()+,.\/:;<=>?[\\\]^_`{|}~] /msx];} ) )cgmosx) 34 3 37
722 ) {
723 # variable name not enclosed in {}
724 34 my $interp = "$sigil$1";
725 34 ▶ while ( $_[2] =~ m/ \G ( (?: -> )? ) (?= ( [[{] ) ) /smxgc ) { # }]
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2] =~ / \G ( (?: -> )? ) (?= ( [[{] ) ) /cgmsx) 2 34 36
726 2 my $lead_in = $1;
727 2 my $delim_re = __match_enclosed( $2 );
728 2 ▶ if ( $_[2] =~ m/ \G ( $delim_re ) /smxgc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2] =~ / \G ( $delim_re ) /cgmsx) { } 2 0 2
729 2 $interp .= "$lead_in$1";
730 } else {
731 0 $_[2] =~ m/ ( .* ) /smxgc;
732 return (
733 0 [ CLASS_INTERPOLATION, $interp ],
734 [ CLASS_UNKNOWN, "$1", error => MISMATCHED_DELIM ],
735 );
736 }
737 }
738  
739 34 my @arg;
740  
741 34 ▶ if ( defined( my $deref = _match_postderef( $_[2] ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $deref = _match_postderef($_[2]))) 6 28 34
742 6 $interp .= $deref;
743 6 push @arg, postderef => 1;
744 }
745  
746 34 return [ CLASS_INTERPOLATION, $interp, @arg ];
747 }
748  
749 3 my $code;
750 3 ▶ $code = $special{$sigil}
Branch: 1 branch
BranchTrueFalseTotal
$code = $special{$sigil} and my $elem = &$code($self, $sigil, $_[2]) or return ["PPIx::QuoteLike::Token::Unknown", $sigil, "error", "Sigil without interpolation"] 3 0 3
Condition33%1/3
$code = $special{$sigil} and my $elem = &$code($self, $sigil, $_[2])
!ll&&!rl&&r
003
MC/DC0%0/2
$code = $special{$sigil} and my $elem = &$code($self, $sigil, $_[2])
$code = $special{$sigil} my $elem = &$code($self, $sigil, $_[2])
Truth table33%1/3
A and B
A= $code = $special{$sigil}B= my $elem = &$code($self, $sigil, $_[2])
ABresult
0X0
100
111
751 and my $elem = $code->( $self, $sigil, $_[2] )
752 or return [ CLASS_UNKNOWN, $sigil,
753 error => 'Sigil without interpolation' ];
754  
755 3 return $elem;
756 }
757  
758 }
759  
760 7 ▶sub _link_elems {
Subroutine _link_elems: called CC=4 SCAR=13.9
761 62 my ( $self, @arg ) = @_;
762  
763 62 push @{ $self->{children} }, @arg;
764  
765 62 foreach my $key ( qw{ type start children finish } ) {
766 248 my $prev;
767 248 foreach my $elem ( @{ $self->{$key} } ) {
768 326 Scalar::Util::weaken( $elem->{parent} = $self );
769 326 ▶ if ( $prev ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev) 81 245 326
770 81 Scalar::Util::weaken( $elem->{previous_sibling} = $prev );
771 81 Scalar::Util::weaken( $prev->{next_sibling} = $elem );
772 }
773 326 $prev = $elem;
774 }
775 }
776  
777 62 return $self;
778 }
779  
780 {
781 7 my %allow_subscr = map { $_ => 1 } qw{ % @ };
782  
783 # Match a postfix deref at the current position in the argument. If
784 # a match occurs it is returned, and the current position is
785 # updated. If not, nothing is returned, and the current position in
786 # the argument remains unchanged.
787 # This would all be much easier if I could count on Perl 5.10
788 34 ▶ sub _match_postderef { ## no critic (RequireArgUnpacking)
Subroutine _match_postderef: called CC=6 SCAR=19.2
789 34 my $pos = pos $_[0];
790 # Only scalars and arrays interpolate
791 34 ▶ $_[0] =~ m/ \G ( -> ) ( \$ \# | [\$\@] ) /smxgc
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ / \G ( -> ) ( \$ \# | [\$\@] ) /cgmsx or return 6 28 34
792 or return;
793 6 my $match = "$1$2";
794 6 my $sigil = $2;
795 6 ▶ $_[0] =~ m/ \G ( [*] ) /smxgc
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ / \G ( [*] ) /cgmsx and return "$match$1" 5 1 6
796 and return "$match$1";
797  
798 1 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($allow_subscr{$sigil} and $_[0] =~ / \G (?= ( [[{] ) ) /cgmsx) 1 0 1
Condition33%1/3
$allow_subscr{$sigil} and $_[0] =~ / \G (?= ( [[{] ) ) /cgmsx
!ll&&!rl&&r
001
MC/DC0%0/2
$allow_subscr{$sigil} and $_[0] =~ / \G (?= ( [[{] ) ) /cgmsx
$allow_subscr{$sigil} $_[0] =~ / \G (?= ( [[{] ) ) /cgmsx
Truth table33%1/3
A and B
A= $allow_subscr{$sigil}B= $_[0] =~ / \G (?= ( [[{] ) ) /cgmsx
ABresult
0X0
100
111
799 $allow_subscr{$sigil} &&
800 $_[0] =~ m/ \G (?= ( [[{] ) ) /smxgc # }]
801 ) {
802 1 my $re = __match_enclosed( "$1" );
803 1 ▶ $_[0] =~ m/ \G $re /smxgc
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ / \G $re /cgmsx and return "$match$1" 1 0 1
804 and return "$match$1";
805 }
806  
807 0 pos $_[0] = $pos;
808 0 return;
809 }
810 }
811  
812 {
813 7 ▶ no warnings qw{ qw }; ## no critic (ProhibitNoWarnings)
Subroutine BEGIN: called CC=1 SCAR=0.0
814 7 my %is_postderef = map { $_ => 1 } qw{ $ $# @ % & * $* $#* @* %* &* ** };
815 5 ▶ sub _has_postderef {
Subroutine _has_postderef: called CC=12 SCAR=29.6
816 5 my ( $string ) = @_;
817 5 my $doc = PPI::Document->new( \$string );
818 5 ▶ foreach my $elem ( @{ $doc->find( 'PPI::Token::Symbol' ) || [] } ) {
Condition100%2/2
$doc->find('PPI::Token::Symbol') || []
l!l
32
MC/DC100%1/1
$doc->find('PPI::Token::Symbol') || []
$doc->find('PPI::Token::Symbol')
Truth table100%2/2
A
A= $doc->find('PPI::Token::Symbol')
Aresult
11
00
819 3 ▶ my $next = $elem->snext_sibling()
Branch: 1 branch
BranchTrueFalseTotal
my $next = $elem->snext_sibling or next 3 0 3
820 or next;
821 3 ▶ $next->isa( 'PPI::Token::Operator' )
Branch: 1 branch
BranchTrueFalseTotal
$next->isa("PPI::Token::Operator") or next 3 0 3
822 or next;
823 3 ▶ $next->content() eq '->'
Branch: 1 branch
BranchTrueFalseTotal
$next->content eq "->" or next 3 0 3
824 or next;
825 3 ▶ $next = $next->snext_sibling()
Branch: 1 branch
BranchTrueFalseTotal
$next = $next->snext_sibling or next 3 0 3
826 or next;
827 3 ▶ $next->isa( 'PPI::Token::Cast' )
Branch: 1 branch
BranchTrueFalseTotal
$next->isa("PPI::Token::Cast") or next 3 0 3
828 or next;
829 3 my $content = $next->content();
830 3 ▶ $is_postderef{$content}
Branch: 1 branch
BranchTrueFalseTotal
$is_postderef{$content} or next 3 0 3
831 or next;
832 3 ▶ $content =~ m/ \* \z /smx
Branch: 1 branch
BranchTrueFalseTotal
$content =~ / \* \z /msx and return 1 3 0 3
833 and return 1;
834 0 ▶ $next = $next->snext_sibling()
Branch: 1 branch
BranchTrueFalseTotal
$next = $next->snext_sibling or next 0 0 0
835 or next;
836 0 ▶ $next->isa( 'PPI::Structure::Subscript' )
Branch: 1 branch
BranchTrueFalseTotal
$next->isa("PPI::Structure::Subscript") and return 1 0 0 0
837 and return 1;
838 }
839 2 return 0;
840 }
841 }
842  
843 # For various reasons we may get consecutive literals -- typically
844 # strings. We want to merge these. The arguments are array refs, with
845 # the class name of the token in [0] and the content in [1]. I know of
846 # no way we can generate consecutive white space tokens, but if I did I
847 # would want them merged.
848 #
849 # NOTE that merger loses all attributes of the second token, so we MUST
850 # NOT merge CLASS_UNKNOWN tokens, or any class that might have
851 # attributes other than content.
852 {
853 7 my %can_merge = map { $_ => 1 } CLASS_STRING, CLASS_WHITESPACE;
854  
855 59 ▶ sub _merge_strings {
Subroutine _merge_strings: called CC=5 SCAR=16.1
856 59 my @arg = @_;
857 59 my @rslt;
858 59 foreach my $elem ( @arg ) {
859 165 ▶ if ( @rslt && $can_merge{$elem->[0]}
Branch: 1 branch
BranchTrueFalseTotal
if (@rslt and $can_merge{$elem->[0]} and $elem->[0] eq $rslt[-1][0]) { } 5 160 165
Condition100%6/6
@rslt and $can_merge{$elem->[0]} and $elem->[0] eq $rslt[-1][0]
!ll&&!rl&&r
113475
@rslt and $can_merge{$elem->[0]}
!ll&&!rl&&r
595452
MC/DC100%3/3
@rslt and $can_merge{$elem->[0]} and $elem->[0] eq $rslt[-1][0]
@rslt $can_merge{$elem->[0]} $elem->[0] eq $rslt[-1][0]
Truth table100%4/4
A and B and C
A= @rsltB= $can_merge{$elem->[0]}C= $elem->[0] eq $rslt[-1][0]
ABCresult
0XX0
10X0
1100
1111
860 && $elem->[0] eq $rslt[-1][0]
861 ) {
862 5 $rslt[-1][1] .= $elem->[1];
863 } else {
864 160 push @rslt, $elem;
865 }
866 }
867 59 return @rslt;
868 }
869 }
870  
871 # If we're processing an indented here document, strings must be split
872 # on new lines and un-indented. We return array refs rather than
873 # objects because we may be called before we're ready to build the
874 # objects.
875 7 ▶sub _remove_here_doc_indentation {
Subroutine _remove_here_doc_indentation: called CC=9 SCAR=22.3
876 53 my ( $self, $string, %arg ) = @_;
877  
878 # NOTE that we rely on the fact that both undef (not indented) and
879 # '' (indented by zero characters) evaluate false.
880 $self->{indentation}
881 53 ▶ or return [ CLASS_STRING, $string ];
Branch: 1 branch
BranchTrueFalseTotal
$self->{"indentation"} or return ["PPIx::QuoteLike::Token::String", $string] 5 48 53
882  
883 5 my $ignore_first;
884 5 ▶ if ( $arg{sibling} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg{'sibling'}) { } 2 3 5
885 # Because the calling code primes the pump, @sibling will never
886 # be empty, even when processing the first token. So:
887 # * The pump-priming specifies class '', so if that is what we
888 # see we must process the first line; otherwise
889 # * If the previous token is a string ending in "\n", we must
890 # process the first line.
891 $ignore_first = '' ne $arg{sibling}[-1][0] && (
892 CLASS_STRING ne $arg{sibling}[-1][0] ||
893 2 ▶ $arg{sibling}[-1][1] !~ m/ \n \z /smx );
Condition50%3/6
'' ne $arg{'sibling'}[-1][0] && ('PPIx::QuoteLike::Token::String' ne $arg{'sibling'}[-1][0] || !($arg{'sibling'}[-1][1] =~ / \n \z /msx))
!ll&&!rl&&r
101
"PPIx::QuoteLike::Token::String" ne $arg{"sibling"}[-1][0] or not $arg{"sibling"}[-1][1] =~ / \n \z /msx
l!l&&r!l&&!r
100
MC/DC33%1/3
'' ne $arg{'sibling'}[-1][0] && ('PPIx::QuoteLike::Token::String' ne $arg{'sibling'}[-1][0] || !($arg{'sibling'}[-1][1] =~ / \n \z /msx))
'' ne $arg{'sibling'}[-1][0] "PPIx::QuoteLike::Token::String" ne $arg{"sibling"}[-1][0] not $arg{"sibling"}[-1][1] =~ / \n \z /msx
Truth table50%2/4
A && B or not(C)
A= '' ne $arg{'sibling'}[-1][0]B= "PPIx::QuoteLike::Token::String" ne $arg{"sibling"}[-1][0]C= not $arg{"sibling"}[-1][1] =~ / \n \z /msx
ABCresult
0XX0
1000
11X1
1011
894 } else {
895 # Without @sibling, we unconditionally process the first line.
896 3 $ignore_first = 0;
897 }
898  
899 5 my @rslt;
900  
901 5 foreach ( split qr/ (?<= \n ) /smx, $string ) {
902 7 ▶ if ( $ignore_first ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ignore_first) { } 1 6 7
903 1 push @rslt, [ CLASS_STRING, "$_" ];
904 1 $ignore_first = 0;
905 } else {
906 6 ▶ if ( "\n" eq $_ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ("\n" eq $_) { } 1 5 6
elsif (s/ ( $self->{'_indentation_re'} ) //msx) { } 5 0 5
907 1 push @rslt,
908 [ CLASS_STRING, "$_" ],
909 ;
910 } elsif ( s/ ( $self->{_indentation_re} ) //smx ) {
911 5 push @rslt,
912 [ CLASS_WHITESPACE, "$1" ],
913 [ CLASS_STRING, "$_" ],
914 ;
915 } else {
916 0 push @rslt,
917 [ CLASS_UNKNOWN, "$_", error => NO_INDENTATION ],
918 ;
919 }
920 }
921 }
922  
923 5 return @rslt;
924 }
925  
926 114 ▶sub _stringify_source {
Subroutine _stringify_source: called CC=11 SCAR=24.6
927 114 my ( $self, $string, %opt ) = @_;
928  
929 114 ▶ if ( Scalar::Util::blessed( $string ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($string)) 69 45 114
930  
931 69 ▶ $string->isa( 'PPI::Element' )
Branch: 1 branch
BranchTrueFalseTotal
$string->isa("PPI::Element") or return 69 0 69
932 or return;
933  
934 69 foreach my $class ( qw{
935 PPI::Token::Quote
936 PPI::Token::QuoteLike::Backtick
937 PPI::Token::QuoteLike::Command
938 PPI::Token::QuoteLike::Readline
939 } ) {
940 228 ▶ $string->isa( $class )
Branch: 1 branch
BranchTrueFalseTotal
$string->isa($class) or next 16 212 228
941 or next;
942 $opt{test}
943 16 ▶ and return 1;
Branch: 1 branch
BranchTrueFalseTotal
$opt{"test"} and return 1 0 16 16
944  
945 16 my $encoding = _get_ppi_encoding( $string );
946 16 return $self->__decode( $string->content(), $encoding );
947 }
948  
949 53 ▶ if ( $string->isa( 'PPI::Token::HereDoc' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string->isa("PPI::Token::HereDoc")) 1 52 53
950 $opt{test}
951 1 ▶ and return 1;
Branch: 1 branch
BranchTrueFalseTotal
$opt{"test"} and return 1 0 1 1
952  
953 1 my $encoding = _get_ppi_encoding( $string );
954 my $heredoc = join '',
955 1 map { $self->__decode( $_, $encoding) }
956 $string->heredoc();
957 1 my $terminator = $self->__decode( $string->terminator(),
958 $encoding );
959 1 $terminator =~ s/ (?<= \n ) \z /\n/smx;
960 1 return $self->__decode( $string->content(), $encoding ) .
961 "\n" . $heredoc . $terminator;
962 }
963  
964 52 return;
965  
966 }
967  
968 45 ▶ ref $string
Branch: 1 branch
BranchTrueFalseTotal
ref $string and return 0 45 45
969 and return;
970  
971 $string =~ m/ \A \s* (?: q [qx]? | << | [`'"<] ) /smx
972 45 ▶ and return $opt{test} ? 1 : $string;
Branch: 2 branches
BranchTrueFalseTotal
$string =~ / \A \s* (?: q [qx]? | << | [`'"<] ) /msx and return $opt{"test"} ? 1 : $string 45 0 45
$opt{'test'} ? : 0 45 45
973  
974 0 return;
975 }
976  
977 7 ▶sub _unquote {
Subroutine _unquote: called CC=2 SCAR=6.9
978 7 my ( $string ) = @_;
979 7 ▶ $string =~ s/ \A ['"] //smx
Branch: 1 branch
BranchTrueFalseTotal
$string =~ s/ \A ['"] //msx and chop $string 4 3 7
980 and chop $string;
981 7 $string =~ s/ \\ (?= . ) //smxg;
982 7 return $string;
983 }
984  
985 7 1;
986  
987 __END__
« QuoteLike/Dumper.pm ↑ Summary QuoteLike/Token/Interpolation.pm »