Regexp/Element.pm

filter: Statementstmt 90.8% 228 / 251 Branchbran 81.4% 101 / 124 Conditioncond 69.5% 16 / 23 MC/DCmcdc 38.4% 5 / 13 Subroutinesub 82.6% 62 / 75 Podpod 100% 49 / 49 totaltotal 86.1% 461 / 535 CC 77 SCAR 11.4
CC
77
Cov
87%
modifier_asserted
6.2
__my_nav
6.1
__explanation
6.0
CRAP 3.1
« Regexp/Token/CharClass/POSIX.pm ↑ Summary Regexp/Token/Whitespace.pm »
1 =head1 NAME
2  
3 PPIx::Regexp::Element - Base of the PPIx::Regexp hierarchy.
4  
5 =head1 SYNOPSIS
6  
7 No user-serviceable parts inside.
8  
9 =head1 INHERITANCE
10  
11 C<PPIx::Regexp::Element> is not descended from any other class.
12  
13 C<PPIx::Regexp::Element> is the parent of
14 L<PPIx::Regexp::Node|PPIx::Regexp::Node> and
15 L<PPIx::Regexp::Token|PPIx::Regexp::Token>.
16  
17 =head1 DESCRIPTION
18  
19 This class is the base of the L<PPIx::Regexp|PPIx::Regexp>
20 object hierarchy. It provides the same kind of navigational
21 functionality that is provided by L<PPI::Element|PPI::Element>.
22  
23 =head1 METHODS
24  
25 This class provides the following public methods. Methods not documented
26 here are private, and unsupported in the sense that the author reserves
27 the right to change or remove them without notice.
28  
29 =cut
30  
31 package PPIx::Regexp::Element;
32  
33 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 9 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 9 ▶use List::Util qw{ first max min };
Subroutine BEGIN: called CC=1 SCAR=0.0
40 9 ▶use PPIx::Regexp::Util qw{ __instance };
Subroutine BEGIN: called CC=1 SCAR=0.0
41 9 ▶use Scalar::Util qw{ refaddr weaken };
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 9 ▶use PPIx::Regexp::Constant qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
44 FALSE
45 LITERAL_LEFT_CURLY_REMOVED_PHASE_1
46 LOCATION_LINE
47 LOCATION_CHARACTER
48 LOCATION_COLUMN
49 LOCATION_LOGICAL_LINE
50 LOCATION_LOGICAL_FILE
51 MINIMUM_PERL
52 TOKEN_UNKNOWN
53 TRUE
54 @CARP_NOT
55 9 };
56  
57 9 our $VERSION = '0.092';
58  
59 =head2 accepts_perl
60  
61 $token->accepts_perl( '5.020' )
62 and say 'This works under Perl 5.20';
63  
64 This method returns a true value if the token is acceptable under the
65 specified version of Perl, and a false value otherwise. Unless the token
66 (or its contents) have been equivocated on, the result is simply what
67 you would expect based on testing the results of
68 L<perl_version_introduced()|/perl_version_introduced> and
69 L<perl_version_removed()|/perl_version_removed> versus the given Perl
70 version number.
71  
72 This method was added in version 0.051_01.
73  
74 =cut
75  
76 12 ▶sub accepts_perl {
Subroutine accepts_perl: called CC=5 SCAR=16.1
Pod documented
77 12 my ( $self, $version ) = @_;
78 12 foreach my $check ( $self->__perl_requirements() ) {
79 $version < $check->{introduced}
80 15 ▶ and next;
Branch: 1 branch
BranchTrueFalseTotal
$version < $check->{"introduced"} and next 4 11 15
81 defined $check->{removed}
82 and $version >= $check->{removed}
83 11 ▶ and next;
Branch: 1 branch
BranchTrueFalseTotal
defined $check->{"removed"} and $version >= $check->{"removed"} and next 3 8 11
Condition100%3/3
defined $check->{"removed"} and $version >= $check->{"removed"}
!ll&&!rl&&r
533
MC/DC100%2/2
defined $check->{"removed"} and $version >= $check->{"removed"}
defined $check->{"removed"} $version >= $check->{"removed"}
Truth table100%3/3
A and B
A= defined $check->{"removed"}B= $version >= $check->{"removed"}
ABresult
0X0
100
111
84 8 return TRUE;
85 }
86 4 return FALSE;
87 }
88  
89 # Return the Perl requirements, constructing if necessary. The
90 # requirements are simply an array of hashes containing keys:
91 # {introduced} - The Perl version introduced;
92 # {removed} - The Perl version removed (or undef)
93 # The requirements are evaluated by iterating through the array,
94 # returning a true value if the version of Perl being tested falls
95 # inside any of the half-open (on the right) intervals.
96 18 ▶sub __perl_requirements {
Subroutine __perl_requirements: called CC=2 SCAR=6.9
97 18 my ( $self ) = @_;
98 18 return @{ $self->{perl_requirements} ||=
99 18 ▶ [ $self->__perl_requirements_setup() ] };
Condition100%2/2
$self->{"perl_requirements"} ||= [$self->__perl_requirements_setup]
l!l
414
MC/DC100%1/1
$self->{"perl_requirements"} ||= [$self->__perl_requirements_setup]
$self->{"perl_requirements"}
Truth table100%2/2
A
A= $self->{"perl_requirements"}
Aresult
11
00
100 }
101  
102 # Construct the array returned by __perl_requirements().
103 22 ▶sub __perl_requirements_setup {
Subroutine __perl_requirements_setup: called CC=1 SCAR=0.0
104 22 my ( $self ) = @_;
105 return {
106 22 introduced => $self->perl_version_introduced(),
107 removed => $self->perl_version_removed(),
108 };
109 }
110  
111 =head2 ancestor_of
112  
113 This method returns true if the object is an ancestor of the argument,
114 and false otherwise. By the definition of this method, C<$self> is its
115 own ancestor.
116  
117 =cut
118  
119 5 ▶sub ancestor_of {
Subroutine ancestor_of: called CC=4 SCAR=13.9
Pod documented
120 5 my ( $self, $elem ) = @_;
121 5 ▶ __instance( $elem, __PACKAGE__ ) or return;
Branch: 1 branch
BranchTrueFalseTotal
__instance($elem, __PACKAGE__) or return 4 1 5
122 4 my $addr = refaddr( $self );
123 4 ▶ while ( $addr != refaddr( $elem ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($addr != builtin::refaddr($elem)) 14 2 16
124 14 ▶ $elem = $elem->_parent() or return;
Branch: 1 branch
BranchTrueFalseTotal
$elem = $elem->_parent or return 12 2 14
125 }
126 2 return 1;
127 }
128  
129 =head2 can_be_quantified
130  
131 $token->can_be_quantified()
132 and print "This element can be quantified.\n";
133  
134 This method returns true if the element can be quantified.
135  
136 =cut
137  
138 680 ▶sub can_be_quantified { return 1; }
Subroutine can_be_quantified: called CC=1 SCAR=0.0
Pod documented
139  
140 =head2 class
141  
142 This method returns the class name of the element. It is the same as
143 C<ref $self>.
144  
145 =cut
146  
147 50 ▶sub class : method { ## no critic (ProhibitBuiltinHomonyms)
Subroutine class: called CC=1 SCAR=0.0
Pod documented
148 50 my ( $self ) = @_;
149 50 return ref $self;
150 }
151  
152 =head2 column_number
153  
154 This method returns the column number of the first character in the
155 element, or C<undef> if that can not be determined.
156  
157 =cut
158  
159 1 ▶sub column_number {
Subroutine column_number: called CC=2 SCAR=7.2
Pod documented
160 1 my ( $self ) = @_;
161 1 ▶ return ( $self->location() || [] )->[LOCATION_CHARACTER];
Condition50%1/2
$self->location || []
l!l
10
MC/DC0%0/1
$self->location || []
$self->location
Truth table50%1/2
A
A= $self->location
Aresult
11
00
162 }
163  
164 =head2 comment
165  
166 This method returns true if the element is a comment and false
167 otherwise.
168  
169 =cut
170  
171 2 ▶sub comment {
Subroutine comment: called CC=1 SCAR=0.0
Pod documented
172 2 return;
173 }
174  
175 =head2 content
176  
177 This method returns the content of the element.
178  
179 =cut
180  
181 0 ▶sub content {
Subroutine content: not called CC=1 SCAR=6.9
Pod documented
182 0 return;
183 }
184  
185 =head2 descendant_of
186  
187 This method returns true if the object is a descendant of the argument,
188 and false otherwise. By the definition of this method, C<$self> is its
189 own descendant.
190  
191 =cut
192  
193 3 ▶sub descendant_of {
Subroutine descendant_of: called CC=2 SCAR=6.9
Pod documented
194 3 my ( $self, $node ) = @_;
195 3 ▶ __instance( $node, __PACKAGE__ ) or return;
Branch: 1 branch
BranchTrueFalseTotal
__instance($node, __PACKAGE__) or return 2 1 3
196 2 return $node->ancestor_of( $self );
197 }
198  
199 =head2 explain
200  
201 This method returns a brief explanation of what the element does. The
202 return will be either a string or C<undef> in scalar context, but may be
203 multiple values or an empty array in list context.
204  
205 This method should be considered experimental. What it returns may
206 change without notice as my understanding of what all the pieces/parts
207 of a Perl regular expression evolves. The worst case is that it will
208 prove entirely infeasible to implement satisfactorily, in which case it
209 will be put through a deprecation cycle and retracted.
210  
211 =cut
212  
213 83 ▶sub explain {
Subroutine explain: called CC=4 SCAR=13.9
Pod documented
214 83 my ( $self ) = @_;
215 defined $self->{explanation}
216 83 ▶ and return $self->{explanation};
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"explanation"} and return $self->{"explanation"} 1 82 83
217 82 my $explanation = $self->__explanation();
218 82 my $content = $self->content();
219 82 ▶ if ( my $main = $self->main_structure() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $main = $self->main_structure) 81 1 82
220 81 my $delim = $main->delimiters();
221 81 $delim = qr{ \\ (?= [\Q$delim\E] ) }smx;
222 81 $content =~ s/$delim//smxg;
223 }
224 82 ▶ if ( defined( my $splain = $explanation->{$content} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $splain = $explanation->{$content})) 82 0 82
225 82 return $splain;
226 }
227 0 return $self->__no_explanation();
228 }
229  
230 # Return explanation hash
231 0 ▶sub __explanation {
Subroutine __explanation: not called CC=2 SCAR=17.9
232 0 ▶ $PPIx::Regexp::NO_EXPLANATION_FATAL
Branch: 1 branch
BranchTrueFalseTotal
$PPIx::Regexp::NO_EXPLANATION_FATAL and confess("Neither explain() nor __explanation() overridden") 0 0 0
233 and confess 'Neither explain() nor __explanation() overridden';
234 0 return {};
235 }
236  
237 # Called if no explanation available
238 0 ▶sub __no_explanation {
Subroutine __no_explanation: not called CC=2 SCAR=17.9
239 ## my ( $self ) = @_; # Invocant unused
240 0 my $msg = sprintf q<No explanation>;
241 0 ▶ $PPIx::Regexp::NO_EXPLANATION_FATAL
Branch: 1 branch
BranchTrueFalseTotal
$PPIx::Regexp::NO_EXPLANATION_FATAL and confess($msg) 0 0 0
242 and confess $msg;
243 0 return $msg;
244 }
245  
246 =head2 error
247  
248 say $token->error();
249  
250 If an element is one of the classes that represents a parse error, this
251 method B<may> return a brief message saying why. Otherwise it will
252 return C<undef>.
253  
254 =cut
255  
256 73 ▶sub error {
Subroutine error: called CC=1 SCAR=0.0
Pod documented
257 73 my ( $self ) = @_;
258 73 return $self->{error};
259 }
260  
261 =begin comment
262  
263 =head2 first_element
264  
265 This method throws an exception saying that it must be overridden.
266  
267 =end comment
268  
269 =cut
270  
271 0 ▶sub first_element {
Subroutine first_element: not called CC=1 SCAR=6.9
Pod documented
272 0 confess 'Bug - first_element must be overridden';
273 }
274  
275 =begin comment
276  
277 =head2 first_token
278  
279 This method throws an exception saying that it must be overridden.
280  
281 =end comment
282  
283 =cut
284  
285 0 ▶sub first_token {
Subroutine first_token: not called CC=1 SCAR=6.9
Pod documented
286 0 confess 'Bug - first_token must be overridden';
287 }
288  
289 =head2 is_matcher
290  
291 This method reports on whether the element potentially matches
292 something. Possible returns are a true value if it does, a false (but
293 defined) value if it does not, or C<undef> if this can not be
294 determined.
295  
296 The idea is to classify elements based on whether they potentially match
297 something in the target string.
298  
299 This method is overridden to return C<undef> in
300 L<PPIx::Regexp::Token::Code|PPIx::Regexp::Token::Code/is_matcher>,
301 L<PPIx::Regexp::Token::Interpolation|PPIx::Regexp::Token::Interpolation/is_matcher>, and
302 L<PPIx::Regexp::Token::Unknown|PPIx::Regexp::Token::Unknown/is_matcher>.
303  
304 This method is overridden to return a true value in
305 L<PPIx::Regexp::Token::Assertion|PPIx::Regexp::Token::Assertion/is_matcher>,
306 L<PPIx::Regexp::Token::CharClass|PPIx::Regexp::Token::CharClass/is_matcher>,
307 L<PPIx::Regexp::Token::Literal|PPIx::Regexp::Token::Literal/is_matcher>,
308 and
309 L<PPIx::Regexp::Token::Reference|PPIx::Regexp::Token::Reference/is_matcher>.
310  
311 For L<PPIx::Regexp::Node|PPIx::Regexp::Node/is_matcher>, this method is
312 overridden to return a value computed from the node's children.
313  
314 For anything else this method returns a false (but defined) value.
315  
316 =cut
317  
318 3 ▶sub is_matcher { return 0; }
Subroutine is_matcher: called CC=1 SCAR=0.0
Pod documented
319  
320 # NOTE retracted this as a public method until I can investigate whether
321 # the tokenizer can actually produce nested assertions.
322  
323 #=head2 in_assertion
324 #
325 #This method returns an array of assertions that contain the element,
326 #most-local first. For the purpose of this method, a look-around
327 #structure does not contain itself. If called in scalar context you get
328 #the size of the array.
329 #
330 #This method was added in version 0.075_01.
331 #
332 #=cut
333  
334 80 ▶sub __in_assertion {
Subroutine __in_assertion: called CC=3 SCAR=11.0
335 80 my ( $self ) = @_;
336 80 my $elem = $self;
337 80 my @assertions;
338 80 ▶ while ( $elem = $elem->parent() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem = $elem->parent) 98 80 178
339 98 ▶ $elem->isa( 'PPIx::Regexp::Structure::Assertion' )
Branch: 1 branch
BranchTrueFalseTotal
$elem->isa("PPIx::Regexp::Structure::Assertion") and push @assertions, $elem 6 92 98
340 and push @assertions, $elem;
341 }
342 80 return @assertions;
343 }
344  
345 # Convenience method that returns the number of look-behind
346 # assertions that contain the current element. This is really only
347 # here so it can be shared between PPIx::Regexp::Token::Quantifier
348 # and PPIx::Regexp::Structure::Quantifier
349  
350 80 ▶sub __in_look_behind {
Subroutine __in_look_behind: called CC=3 SCAR=11.0
351 80 my ( $self ) = @_;
352 80 my @look_behind;
353 80 foreach my $assertion ( $self->__in_assertion() ) {
354 6 ▶ $assertion->is_look_ahead()
Branch: 1 branch
BranchTrueFalseTotal
$assertion->is_look_ahead and next 2 4 6
355 and next;
356 4 push @look_behind, $assertion;
357 }
358 80 return @look_behind;
359 }
360  
361 =head2 in_regex_set
362  
363 This method returns a true value if the invocant is contained in an
364 extended bracketed character class (also known as a regex set), and a
365 false value otherwise. This method returns true if the invocant is a
366 L<PPIx::Regexp::Structure::RegexSet|PPIx::Regexp::Structure::RegexSet>.
367  
368 =cut
369  
370 2 ▶sub in_regex_set {
Subroutine in_regex_set: called CC=3 SCAR=11.0
Pod documented
371 2 my ( $self ) = @_;
372 2 my $ele = $self;
373 2 while ( 1 ) {
374 5 ▶ $ele->isa( 'PPIx::Regexp::Structure::RegexSet' )
Branch: 1 branch
BranchTrueFalseTotal
$ele->isa("PPIx::Regexp::Structure::RegexSet") and return 1 1 4 5
375 and return 1;
376 4 ▶ $ele = $ele->parent()
Branch: 1 branch
BranchTrueFalseTotal
$ele = $ele->parent or last 3 1 4
377 or last;
378 }
379 1 return 0;
380 }
381  
382 =head2 is_quantifier
383  
384 $token->is_quantifier()
385 and print "This element is a quantifier.\n";
386  
387 This method returns true if the element is a quantifier. You can not
388 tell this from the element's class, because a right curly bracket may
389 represent a quantifier for the purposes of figuring out whether a
390 greediness token is possible.
391  
392 =cut
393  
394 597 ▶sub is_quantifier { return; }
Subroutine is_quantifier: called CC=1 SCAR=0.0
Pod documented
395  
396 =begin comment
397  
398 =head2 last_element
399  
400 This method throws an exception saying that it must be overridden.
401  
402 =end comment
403  
404 =cut
405  
406 0 ▶sub last_element {
Subroutine last_element: not called CC=1 SCAR=6.9
Pod documented
407 0 confess 'Bug - last_element must be overridden';
408 }
409  
410 =begin comment
411  
412 =head2 last_token
413  
414 This method throws an exception saying that it must be overridden.
415  
416 =end comment
417  
418 =cut
419  
420 0 ▶sub last_token {
Subroutine last_token: not called CC=1 SCAR=6.9
Pod documented
421 0 confess 'Bug - last_token must be overridden';
422 }
423  
424 =head2 line_number
425  
426 This method returns the line number of the first character in the
427 element, or C<undef> if that can not be determined.
428  
429 =cut
430  
431 1 ▶sub line_number {
Subroutine line_number: called CC=2 SCAR=7.2
Pod documented
432 1 my ( $self ) = @_;
433 1 ▶ return ( $self->location() || [] )->[LOCATION_LINE];
Condition50%1/2
$self->location || []
l!l
10
MC/DC0%0/1
$self->location || []
$self->location
Truth table50%1/2
A
A= $self->location
Aresult
11
00
434 }
435  
436 =head2 location
437  
438 This method returns a reference to an array describing the position of
439 the element in the regular expression, or C<undef> if locations were not
440 indexed.
441  
442 The array is compatible with the corresponding
443 L<PPI::Element|PPI::Element> method.
444  
445 =cut
446  
447 54 ▶sub location {
Subroutine location: called CC=2 SCAR=7.1
Pod documented
448 54 my ( $self ) = @_;
449 54 ▶ return $self->{location} ? [ @{ $self->{location} } ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'location'} ? : 54 0 54
450 }
451  
452 =pod
453  
454 =head2 logical_filename
455  
456 This method returns the logical file name (taking C<#line> directives
457 into account) of the file containing first character in the element, or
458 C<undef> if that can not be determined.
459  
460 =cut
461  
462 1 ▶sub logical_filename {
Subroutine logical_filename: called CC=2 SCAR=7.2
Pod documented
463 1 my ( $self ) = @_;
464 1 ▶ return ( $self->location() || [] )->[LOCATION_LOGICAL_FILE];
Condition50%1/2
$self->location || []
l!l
10
MC/DC0%0/1
$self->location || []
$self->location
Truth table50%1/2
A
A= $self->location
Aresult
11
00
465 }
466  
467 =head2 logical_line_number
468  
469 This method returns the logical line number (taking C<#line> directives
470 into account) of the first character in the element, or C<undef> if that
471 can not be determined.
472  
473 =cut
474  
475 1 ▶sub logical_line_number {
Subroutine logical_line_number: called CC=2 SCAR=7.2
Pod documented
476 1 my ( $self ) = @_;
477 1 ▶ return ( $self->location() || [] )->[LOCATION_LOGICAL_LINE];
Condition50%1/2
$self->location || []
l!l
10
MC/DC0%0/1
$self->location || []
$self->location
Truth table50%1/2
A
A= $self->location
Aresult
11
00
478 }
479  
480 =head2 main_structure
481  
482 This method returns the
483 L<PPIx::Regexp::Structure::Main|PPIx::Regexp::Structure::Main> that
484 contains the element. In practice this will be a
485 L<PPIx::Regexp::Structure::Regexp|PPIx::Regexp::Structure::Regexp> or a
486 L<PPIx::Regexp::Structure::Replacement|PPIx::Regexp::Structure::Replacement>,
487  
488 If the element is not contained in any such structure, C<undef> is
489 returned. This will happen if the element is a
490 L<PPIx::Regexp|PPIx::Regexp> or one of its immediate children.
491  
492 =cut
493  
494 258 ▶sub main_structure {
Subroutine main_structure: called CC=3 SCAR=11.0
Pod documented
495 258 my ( $self ) = @_;
496 258 ▶ while ( $self = $self->parent()
Branch: 1 branch
BranchTrueFalseTotal
if ($self = $self->parent and not $self->isa("PPIx::Regexp::Structure::Main")) 221 258 479
Condition100%3/3
$self = $self->parent and not $self->isa("PPIx::Regexp::Structure::Main")
!ll&&!rl&&r
27231221
MC/DC100%2/2
$self = $self->parent and not $self->isa("PPIx::Regexp::Structure::Main")
$self = $self->parent not $self->isa("PPIx::Regexp::Structure::Main")
Truth table100%3/3
A and not(B)
A= $self = $self->parentB= not $self->isa("PPIx::Regexp::Structure::Main")
ABresult
0X0
100
111
497 and not $self->isa( 'PPIx::Regexp::Structure::Main' ) ) {
498 }
499 258 return $self;
500 }
501  
502 =head2 modifier_asserted
503  
504 $token->modifier_asserted( 'i' )
505 and print "Matched without regard to case.\n";
506  
507 This method returns true if the given modifier is in effect for the
508 element, and false otherwise.
509  
510 What it does is to walk backwards from the element until it finds a
511 modifier object that specifies the modifier, whether asserted or
512 negated. and returns the specified value. If nobody specifies the
513 modifier, it returns C<undef>.
514  
515 This method will not work reliably if called on tokenizer output.
516  
517 =cut
518  
519 6 ▶sub modifier_asserted {
Subroutine modifier_asserted: called CC=6 SCAR=18.3
Pod documented
520 6 my ( $self, $modifier ) = @_;
521  
522 6 ▶ defined $modifier
Branch: 1 branch
BranchTrueFalseTotal
defined $modifier or croak("Modifier must be defined") 6 0 6
523 or croak 'Modifier must be defined';
524  
525 6 my $elem = $self;
526  
527 6 ▶ while ( $elem ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem) 19 0 19
528 19 ▶ if ( $elem->can( '__ducktype_modifier_asserted' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->can("__ducktype_modifier_asserted")) 6 13 19
529 6 my $val;
530 6 ▶ defined( $val = $elem->__ducktype_modifier_asserted( $modifier ) )
Branch: 1 branch
BranchTrueFalseTotal
defined($val = $elem->__ducktype_modifier_asserted($modifier)) and return $val 6 0 6
531 and return $val;
532 }
533 13 ▶ if ( my $prev = $elem->sprevious_sibling() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $prev = $elem->sprevious_sibling) { } 5 8 13
534 5 $elem = $prev;
535 } else {
536 8 $elem = $elem->parent();
537 }
538 }
539  
540 0 return;
541 }
542  
543 =head2 next_element
544  
545 This method returns the next element, or nothing if there is none.
546  
547 Unlike L<next_sibling()|/next_sibling>, this will cross from the content
548 of a structure into the elements that define the structure, or vice
549 versa.
550  
551 =cut
552  
553 16 ▶sub next_element {
Subroutine next_element: called CC=2 SCAR=6.9
Pod documented
554 16 my ( $self ) = @_;
555 16 ▶ my $parent = $self->_parent()
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->_parent or return 15 1 16
556 or return;
557 15 my $inx = $self->__my_inx();
558 15 return ( $parent->elements() )[ $inx + 1 ];
559 }
560  
561 =head2 next_sibling
562  
563 This method returns the element's next sibling, or nothing if there is
564 none.
565  
566 =cut
567  
568 739 ▶sub next_sibling {
Subroutine next_sibling: called CC=2 SCAR=6.9
Pod documented
569 739 my ( $self ) = @_;
570 739 ▶ my ( $method, $inx ) = $self->__my_nav()
Branch: 1 branch
BranchTrueFalseTotal
() = $self->__my_nav or return 703 36 739
571 or return;
572 703 return $self->_parent()->$method( $inx + 1 );
573 }
574  
575 =head2 next_token
576  
577 This method returns the next token, or nothing if there is none.
578  
579 Unlike L<next_element()|/next_element>, this will walk the parse tree.
580  
581 =cut
582  
583 15 ▶sub next_token {
Subroutine next_token: called CC=3 SCAR=11.0
Pod documented
584 15 my ( $self ) = @_;
585 15 ▶ if ( my $next = $self->next_element() ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $next = $self->next_element) { } 11 4 15
elsif (my $parent = $self->parent) { } 3 1 4
586 11 return $next->first_token();
587 } elsif ( my $parent = $self->parent() ) {
588 3 return $parent->next_token();
589 } else {
590 1 return;
591 }
592 }
593  
594 =head2 parent
595  
596 This method returns the parent of the element, or undef if there is
597 none.
598  
599 =cut
600  
601 719 ▶sub parent {
Subroutine parent: called CC=1 SCAR=0.0
Pod documented
602 719 my ( $self ) = @_;
603 719 return $self->_parent();
604 }
605  
606 =head2 perl_version_introduced
607  
608 This method returns the version of Perl in which the element was
609 introduced. This will be at least 5.000. Before 5.006 I am relying on
610 the F<perldelta>, F<perlre>, and F<perlop> documentation, since I have
611 been unable to build earlier Perls. Since I have found no documentation
612 before 5.003, I assume that anything found in 5.003 is also in 5.000.
613  
614 Since this all depends on my ability to read and understand masses of
615 documentation, the results of this method should be viewed with caution,
616 if not downright skepticism.
617  
618 There are also cases which are ambiguous in various ways. For those see
619 the L<PPIx::Regexp|PPIx::Regexp> documentation, particularly
620 L<Changes in Syntax|PPIx::Regexp/Changes in Syntax>.
621  
622 Very occasionally, a construct will be removed and then added back. If
623 this happens, this method will return the B<lowest> version in which the
624 construct appeared. For the known instances of this, see
625 the L<PPIx::Regexp|PPIx::Regexp> documentation, particularly
626 L<Equivocation|PPIx::Regexp/Equivocation>.
627  
628 =cut
629  
630 0 ▶sub perl_version_introduced {
Subroutine perl_version_introduced: not called CC=1 SCAR=6.9
Pod documented
631 0 return MINIMUM_PERL;
632 }
633  
634 =head2 perl_version_removed
635  
636 This method returns the version of Perl in which the element was
637 removed. If the element is still valid the return is C<undef>.
638  
639 All the I<caveats> to
640 L<perl_version_introduced()|/perl_version_introduced> apply here also,
641 though perhaps less severely since although many features have been
642 introduced since 5.0, few have been removed.
643  
644 Very occasionally, a construct will be removed and then added back. If
645 this happens, this method will return the C<undef> if the construct is
646 present in the highest-numbered version of Perl (whether production or
647 development), or the version after the highest-numbered version in which
648 it appeared otherwise. For the known instances of this, see the
649 L<PPIx::Regexp|PPIx::Regexp> documentation, particularly
650 L<Equivocation|PPIx::Regexp/Equivocation>.
651  
652 =cut
653  
654 0 ▶sub perl_version_removed {
Subroutine perl_version_removed: not called CC=1 SCAR=6.9
Pod documented
655 0 return undef; ## no critic (ProhibitExplicitReturnUndef)
656 }
657  
658 =head2 previous_element
659  
660 This method returns the previous element, or nothing if there is none.
661  
662 Unlike L<previous_sibling()|/previous_sibling>, this will cross from
663 the content of a structure into the elements that define the structure,
664 or vice versa.
665  
666 =cut
667  
668 16 ▶sub previous_element {
Subroutine previous_element: called CC=3 SCAR=11.0
Pod documented
669 16 my ( $self ) = @_;
670 16 ▶ my $parent = $self->_parent()
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->_parent or return 15 1 16
671 or return;
672 15 ▶ my $inx = $self->__my_inx()
Branch: 1 branch
BranchTrueFalseTotal
my $inx = $self->__my_inx or return 12 3 15
673 or return;
674 12 return ( $parent->elements() )[ $inx - 1 ];
675 }
676  
677 =head2 previous_sibling
678  
679 This method returns the element's previous sibling, or nothing if there
680 is none.
681  
682 This method is analogous to the same-named L<PPI::Element|PPI::Element>
683 method, in that it will not cross from the content of a structure into
684 the elements that define the structure.
685  
686 =cut
687  
688 33 ▶sub previous_sibling {
Subroutine previous_sibling: called CC=3 SCAR=11.0
Pod documented
689 33 my ( $self ) = @_;
690 33 ▶ my ( $method, $inx ) = $self->__my_nav()
Branch: 1 branch
BranchTrueFalseTotal
() = $self->__my_nav or return 30 3 33
691 or return;
692 30 ▶ $inx or return;
Branch: 1 branch
BranchTrueFalseTotal
$inx or return 20 10 30
693 20 return $self->_parent()->$method( $inx - 1 );
694 }
695  
696 =head2 previous_token
697  
698 This method returns the previous token, or nothing if there is none.
699  
700 Unlike L<previous_element()|/previous_element>, this will walk the parse tree.
701  
702 =cut
703  
704 15 ▶sub previous_token {
Subroutine previous_token: called CC=3 SCAR=11.0
Pod documented
705 15 my ( $self ) = @_;
706 15 ▶ if ( my $previous = $self->previous_element() ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $previous = $self->previous_element) { } 11 4 15
elsif (my $parent = $self->parent) { } 3 1 4
707 11 return $previous->last_token();
708 } elsif ( my $parent = $self->parent() ) {
709 3 return $parent->previous_token();
710 } else {
711 1 return;
712 }
713 }
714  
715 =head2 raw_width
716  
717 my ( $raw_min, $raw_max ) = $self->raw_width();
718  
719 This public method returns the minimum and maximum width matched by the
720 element before taking into account such details as what the element
721 actually is and how it is quantified. Either or both elements can be
722 C<undef> if the width can not be determined, and the maximum can be
723 C<Inf>.
724  
725 This method was added in version 0.085_01.
726  
727 =cut
728  
729 # This implementation is appropriate to a structural element -- i.e. it
730 # returns C<( 0, 0 )>.
731  
732 99 ▶sub raw_width {
Subroutine raw_width: called CC=1 SCAR=0.0
Pod documented
733 99 return ( 0, 0 );
734 }
735  
736 =head2 remove_insignificant
737  
738 This method returns a new object manufactured from the invocant, but
739 containing only elements for which C<< $elem->significant() >> returns a
740 true value.
741  
742 If you call this method on a L<PPIx::Regexp::Node|PPIx::Regexp::Node>
743 you will get back a deep clone, but without the insignificant elements.
744  
745 If you call this method on any other L<PPIx::Regexp|PPIx::Regexp> class
746 you will get back either the invocant or nothing. This may change to a
747 clone of the invocant or nothing if unforeseen problems arise with
748 returning the invocant, or if objects become mutable (unlikely, but not
749 impossible.)
750  
751 =cut
752  
753 0 ▶sub remove_insignificant {
Subroutine remove_insignificant: not called CC=2 SCAR=17.9
Pod documented
754 0 my ( $self ) = @_;
755 0 ▶ $self->significant()
Branch: 1 branch
BranchTrueFalseTotal
$self->significant and return $self 0 0 0
756 and return $self;
757 0 return;
758 }
759  
760 =head2 requirements_for_perl
761  
762 say $token->requirements_for_perl();
763  
764 This method returns a string representing the Perl requirements for a
765 given module. This should only be used for informational purposes, as
766 the format of the string may be subject to change.
767  
768 At the moment, the returns may be:
769  
770 version <= $]
771 version <= $] < version
772 two or more of the above joined by '||'
773 ! $]
774  
775 The last means that, although all the components of the regular
776 expression can be compiled by B<some> version of Perl, there is no
777 version that will compile all of them.
778  
779 I reiterate: the returned string may be subject to change, maybe without
780 warning.
781  
782 This method was added in version 0.051_01.
783  
784 =cut
785  
786 10 ▶sub requirements_for_perl {
Subroutine requirements_for_perl: called CC=4 SCAR=13.9
Pod documented
787 10 my ( $self ) = @_;
788 10 my @req;
789 10 foreach my $r ( $self->__perl_requirements() ) {
790 push @req, defined $r->{removed} ?
791 11 ▶ "$r->{introduced} <= \$] < $r->{removed}" :
Branch: 1 branch
BranchTrueFalseTotal
defined $r->{'removed'} ? : 1 10 11
792 "$r->{introduced} <= \$]";
793 }
794 @req
795 10 ▶ or return '! $]';
Branch: 1 branch
BranchTrueFalseTotal
@req or return "! \$]" 10 0 10
796 10 return join ' || ', @req;
797 }
798  
799 =head2 scontent
800  
801 This method returns the significant content of the element. That is, if
802 called on the parse of C<'/ f u b a r /x'>, it returns C<'/fubar/x'>. If
803 the invocant contains no insignificant elements, it is the same as
804 L<content()|/content>. If called on an insignificant element, it returns
805 nothing -- that is, C<undef> in scalar context, and an empty list in
806 list context.
807  
808 This method was inspired by jb's question on Perl Monks about stripping
809 comments and white space from a regular expression:
810 L<https://perlmonks.org/?node_id=1207556>
811  
812 This method was added in version 0.053_01
813  
814 =cut
815  
816 0 ▶sub scontent {
Subroutine scontent: not called CC=1 SCAR=6.9
Pod documented
817 0 return;
818 }
819  
820 =head2 significant
821  
822 This method returns true if the element is significant and false
823 otherwise.
824  
825 =cut
826  
827 11430 ▶sub significant {
Subroutine significant: called CC=1 SCAR=0.0
Pod documented
828 11430 return 1;
829 }
830  
831 =head2 snext_element
832  
833 This method returns the next significant element, or nothing if
834 there is none.
835  
836 Unlike L<snext_sibling()|/snext_sibling>, this will cross from
837 the content of a structure into the elements that define the structure,
838 or vice versa.
839  
840 =cut
841  
842 1 ▶sub snext_element {
Subroutine snext_element: called CC=4 SCAR=14.2
Pod documented
843 1 my ( $self ) = @_;
844 1 my $inx = $self->__my_inx();
845 1 ▶ my $parent = $self->_parent()
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->_parent or return 1 0 1
846 or return;
847 1 my @elem = $parent->elements();
848 1 while ( 1 ) {
849 2 $inx++;
850 2 ▶ $elem[$inx]
Branch: 1 branch
BranchTrueFalseTotal
$elem[$inx] or last 2 0 2
851 or last;
852 2 ▶ $elem[$inx]->significant()
Branch: 1 branch
BranchTrueFalseTotal
$elem[$inx]->significant and return $elem[$inx] 1 1 2
853 and return $elem[$inx];
854 }
855 0 return;
856 }
857  
858 =head2 snext_sibling
859  
860 This method returns the element's next significant sibling, or nothing
861 if there is none.
862  
863 This method is analogous to the same-named L<PPI::Element|PPI::Element>
864 method, in that it will not cross from the content of a structure into
865 the elements that define the structure.
866  
867 =cut
868  
869 730 ▶sub snext_sibling {
Subroutine snext_sibling: called CC=3 SCAR=11.0
Pod documented
870 730 my ( $self ) = @_;
871 730 my $sib = $self;
872 730 ▶ while ( defined ( $sib = $sib->next_sibling() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($sib = $sib->next_sibling)) 434 300 734
873 434 ▶ $sib->significant() and return $sib;
Branch: 1 branch
BranchTrueFalseTotal
$sib->significant and return $sib 430 4 434
874 }
875 300 return;
876 }
877  
878 =head2 sprevious_element
879  
880 This method returns the previous significant element, or nothing if
881 there is none.
882  
883 Unlike L<sprevious_sibling()|/sprevious_sibling>, this will cross from
884 the content of a structure into the elements that define the structure,
885 or vice versa.
886  
887 =cut
888  
889 2 ▶sub sprevious_element {
Subroutine sprevious_element: called CC=5 SCAR=16.5
Pod documented
890 2 my ( $self ) = @_;
891 2 ▶ my $inx = $self->__my_inx()
Branch: 1 branch
BranchTrueFalseTotal
my $inx = $self->__my_inx or return 1 1 2
892 or return;
893 1 ▶ my $parent = $self->_parent()
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->_parent or return 1 0 1
894 or return;
895 1 my @elem = $parent->elements();
896 1 ▶ while ( $inx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inx) 2 0 2
897 2 ▶ $elem[--$inx]->significant()
Branch: 1 branch
BranchTrueFalseTotal
$elem[--$inx]->significant and return $elem[$inx] 1 1 2
898 and return $elem[$inx];
899 }
900 0 return;
901 }
902  
903 =head2 sprevious_sibling
904  
905 This method returns the element's previous significant sibling, or
906 nothing if there is none.
907  
908 This method is analogous to the same-named L<PPI::Element|PPI::Element>
909 method, in that it will not cross from the content of a structure into
910 the elements that define the structure.
911  
912 =cut
913  
914 28 ▶sub sprevious_sibling {
Subroutine sprevious_sibling: called CC=3 SCAR=11.0
Pod documented
915 28 my ( $self ) = @_;
916 28 my $sib = $self;
917 28 ▶ while ( defined ( $sib = $sib->previous_sibling() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($sib = $sib->previous_sibling)) 18 11 29
918 18 ▶ $sib->significant() and return $sib;
Branch: 1 branch
BranchTrueFalseTotal
$sib->significant and return $sib 17 1 18
919 }
920 11 return;
921 }
922  
923 =head2 statement
924  
925 This method returns the L<PPI::Statement|PPI::Statement> that contains
926 this element, or nothing if the statement can not be determined.
927  
928 In general this method will return something only under the following
929 conditions:
930  
931 =over
932  
933 =item * The element is contained in a L<PPIx::Regexp|PPIx::Regexp> object;
934  
935 =item * That object was initialized from a L<PPI::Element|PPI::Element>;
936  
937 =item * The L<PPI::Element|PPI::Element> is contained in a statement.
938  
939 =back
940  
941 =cut
942  
943 2 ▶sub statement {
Subroutine statement: called CC=5 SCAR=16.6
Pod documented
944 2 my ( $self ) = @_;
945 2 ▶ my $top = $self->top()
Branch: 1 branch
BranchTrueFalseTotal
my $top = $self->top or return 2 0 2
946 or return;
947 2 ▶ $top->can( 'source' )
Branch: 1 branch
BranchTrueFalseTotal
$top->can("source") or return 2 0 2
948 or return;
949 2 ▶ my $source = $top->source()
Branch: 1 branch
BranchTrueFalseTotal
my $source = $top->source or return 2 0 2
950 or return;
951 2 ▶ $source->can( 'statement' )
Branch: 1 branch
BranchTrueFalseTotal
$source->can("statement") or return 1 1 2
952 or return;
953 1 return $source->statement();
954 }
955  
956 =head2 tokens
957  
958 This method returns all tokens contained in the element.
959  
960 =cut
961  
962 119 ▶sub tokens {
Subroutine tokens: called CC=1 SCAR=0.0
Pod documented
963 119 my ( $self ) = @_;
964 119 return $self;
965 }
966  
967 =head2 top
968  
969 This method returns the top of the hierarchy.
970  
971 =cut
972  
973 36 ▶sub top {
Subroutine top: called CC=2 SCAR=6.9
Pod documented
974 36 my ( $self ) = @_;
975 36 my $kid = $self;
976 36 ▶ while ( defined ( my $parent = $kid->_parent() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $parent = $kid->_parent)) 64 36 100
977 64 $kid = $parent;
978 }
979 36 return $kid;
980 }
981  
982 =head2 unescaped_content
983  
984 This method returns the content of the element, unescaped.
985  
986 =cut
987  
988 0 ▶sub unescaped_content {
Subroutine unescaped_content: not called CC=1 SCAR=6.9
Pod documented
989 0 return;
990 }
991  
992 =head2 visual_column_number
993  
994 This method returns the visual column number (taking tabs into account)
995 of the first character in the element, or C<undef> if that can not be
996 determined.
997  
998 =cut
999  
1000 1 ▶sub visual_column_number {
Subroutine visual_column_number: called CC=2 SCAR=7.2
Pod documented
1001 1 my ( $self ) = @_;
1002 1 ▶ return ( $self->location() || [] )->[LOCATION_COLUMN];
Condition50%1/2
$self->location || []
l!l
10
MC/DC0%0/1
$self->location || []
$self->location
Truth table50%1/2
A
A= $self->location
Aresult
11
00
1003 }
1004  
1005 =head2 whitespace
1006  
1007 This method returns true if the element is whitespace and false
1008 otherwise.
1009  
1010 =cut
1011  
1012 2 ▶sub whitespace {
Subroutine whitespace: called CC=1 SCAR=0.0
Pod documented
1013 2 return;
1014 }
1015  
1016 =head2 width
1017  
1018 my ( $min, $max ) = $self->width();
1019  
1020 This method returns the minimum and maximum number of characters this
1021 element can match.
1022  
1023 Either element can be C<undef> if it cannot be determined. For example,
1024 for C</$foo/> both elements will be C<undef>. Recursions will return
1025 C<undef> because they can not be analyzed statically -- or at least I am
1026 not smart enough to do so. Back references B<may> return C<undef> if the
1027 referred-to group can not be uniquely determined.
1028  
1029 It is possible for C<$max> to be C<Inf>. For example, for C</x*/>
1030 C<$max> will be C<Inf>.
1031  
1032 Elements that do not actually match anything will return zeros.
1033  
1034 B<Note:> This method was added because I wanted better detection of
1035 variable-length look-behinds. Both it and L<raw_width()|/raw_width>
1036 (above) should be considered somewhat experimental.
1037  
1038 This method was added in version 0.085_01.
1039  
1040 =cut
1041  
1042 987 ▶sub width {
Subroutine width: called CC=1 SCAR=0.0
Pod documented
1043 987 return ( 0, 0 );
1044 }
1045  
1046 =head2 nav
1047  
1048 This method returns navigation information from the top of the hierarchy
1049 to this node. The return is a list of names of methods and references to
1050 their argument lists. The idea is that given C<$elem> which is somewhere
1051 under C<$top>,
1052  
1053 my @nav = $elem->nav();
1054 my $obj = $top;
1055 while ( @nav ) {
1056 my $method = shift @nav;
1057 my $args = shift @nav;
1058 $obj = $obj->$method( @{ $args } ) or die;
1059 }
1060 # At this point, $obj should contain the same object
1061 # as $elem.
1062  
1063 =cut
1064  
1065 33 ▶sub nav {
Subroutine nav: called CC=3 SCAR=11.0
Pod documented
1066 33 my ( $self ) = @_;
1067 33 ▶ __instance( $self, __PACKAGE__ ) or return;
Branch: 1 branch
BranchTrueFalseTotal
__instance($self, __PACKAGE__) or return 33 0 33
1068  
1069 # We do not use $self->parent() here because PPIx::Regexp overrides
1070 # this to return the (possibly) PPI object that initiated us.
1071 33 ▶ my $parent = $self->_parent() or return;
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->_parent or return 23 10 33
1072  
1073 23 return ( $parent->nav(), $parent->__nav( $self ) );
1074 }
1075  
1076 # Find our index among the parents children. If not found, just return.
1077 # Unlike __my_nav(), this just returns an index, which is appropriate
1078 # for ->element( $inx ), or would be if element() existed.
1079  
1080 33 ▶sub __my_inx {
Subroutine __my_inx: called CC=2 SCAR=6.9
1081 33 my ( $self ) = @_;
1082 33 ▶ my $parent = $self->_parent() or return;
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->_parent or return 32 1 33
1083 32 my $addr = refaddr( $self );
1084 32 my @elem = $parent->elements();
1085 32 ▶ return first { refaddr( $elem[$_] ) == $addr } 0 .. $#elem;
Subroutine __ANON__: called CC=1 SCAR=0.0
1086 }
1087  
1088 # Find our location and index among the parent's children. If not found,
1089 # just returns.
1090  
1091 {
1092 9 my %method_map = (
1093 children => 'child',
1094 );
1095  
1096 795 ▶ sub __my_nav {
Subroutine __my_nav: called CC=6 SCAR=18.2
1097 795 my ( $self ) = @_;
1098 795 ▶ my $parent = $self->_parent() or return;
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->_parent or return 756 39 795
1099 756 my $addr = refaddr( $self );
1100 756 foreach my $method ( qw{ children start type finish } ) {
1101 758 ▶ $parent->can( $method ) or next;
Branch: 1 branch
BranchTrueFalseTotal
$parent->can($method) or next 758 0 758
1102 758 my @elem = $parent->$method();
1103 1328 ▶ defined( my $inx = first { refaddr( $elem[$_] ) == $addr }
Subroutine __ANON__: called CC=1 SCAR=0.0
1104 758 ▶ 0 .. $#elem )
Branch: 1 branch
BranchTrueFalseTotal
defined(my $inx = &first(sub { builtin::refaddr($elem[$_]) == $addr; } , 0 .. $#elem)) or next 756 2 758
1105 or next;
1106 756 ▶ return ( $method_map{$method} || $method, $inx );
Condition66%2/3
$method_map{$method} || $method
l!l&&r!l&&!r
75420
MC/DC0%0/2
$method_map{$method} || $method
$method_map{$method} $method
Truth table66%2/3
A || B
A= $method_map{$method}B= $method
ABresult
1X1
011
000
1107 }
1108 0 return;
1109 }
1110 }
1111  
1112 {
1113 9 my %parent;
1114  
1115 # no-argument form returns the parent; one-argument sets it.
1116 12851 ▶ sub _parent {
Subroutine _parent: called CC=4 SCAR=13.9
1117 12851 my ( $self, @arg ) = @_;
1118 12851 my $addr = refaddr( $self );
1119 12851 ▶ if ( @arg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@arg) 10400 2451 12851
1120 10400 my $parent = shift @arg;
1121 10400 ▶ if ( defined $parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent) { } 3958 6442 10400
1122 3958 ▶ __instance( $parent, __PACKAGE__ ) or return;
Branch: 1 branch
BranchTrueFalseTotal
__instance($parent, __PACKAGE__) or return 3958 0 3958
1123 weaken(
1124 3958 $parent{$addr} = $parent );
1125 } else {
1126 6442 delete $parent{$addr};
1127 }
1128 }
1129 12851 return $parent{$addr};
1130 }
1131  
1132 2 ▶ sub __parent_keys {
Subroutine __parent_keys: called CC=1 SCAR=0.0
1133 2 return scalar keys %parent;
1134 }
1135  
1136 }
1137  
1138 # Bless into TOKEN_UNKNOWN, record error message, return 1.
1139 9 ▶sub __error {
Subroutine __error: called CC=2 SCAR=7.0
1140 2 my ( $self, $msg ) = @_;
1141 2 ▶ defined $msg
Branch: 1 branch
BranchTrueFalseTotal
defined $msg or $msg = 'Was ' . ref($self) 2 0 2
1142 or $msg = 'Was ' . ref $self;
1143 2 TOKEN_UNKNOWN->__PPIX_ELEM__rebless( $self, error => $msg );
1144 2 return 1;
1145 }
1146  
1147 # This huge kluge is required by
1148 # https://rt.perl.org/Ticket/Display.html?id=128213 which means the
1149 # deprecation will be done in at least two separate phases. It exists
1150 # for the use of PPIx::Regexp::Token::Literal->perl_version_removed, and
1151 # MUST NOT be called by any other code.
1152 # Note that the perldelta for 5.25.1 and 5.26.0 do not acknowledge tha
1153 # phased deprecation, and pretend that everything was done on the phase
1154 # 1 schedule. This appears to be deliberate per
1155 # https://rt.perl.org/Ticket/Display.html?id=131352
1156 0 ▶sub __following_literal_left_curly_disallowed_in {
Subroutine __following_literal_left_curly_disallowed_in: not called CC=1 SCAR=6.9
1157 0 return LITERAL_LEFT_CURLY_REMOVED_PHASE_1;
1158 }
1159  
1160 # Called by the lexer to record the capture number.
1161 972 ▶sub __PPIX_LEXER__record_capture_number {
Subroutine __PPIX_LEXER__record_capture_number: called CC=1 SCAR=0.0
1162 972 my ( undef, $number ) = @_; # Invocant unused
1163 972 return $number;
1164 }
1165  
1166 # Called by the lexer to rebless
1167 46 ▶sub __PPIX_ELEM__rebless {
Subroutine __PPIX_ELEM__rebless: called CC=2 SCAR=7.0
1168 46 my ( $class, $self, %arg ) = @_;
1169 46 ▶ $self ||= {};
Condition50%1/2
$self ||= {}
l!l
460
MC/DC0%0/1
$self ||= {}
$self
Truth table50%1/2
A
A= $self
Aresult
11
00
1170 46 bless $self, $class;
1171 46 delete $self->{error};
1172 46 return $self->__PPIX_ELEM__post_reblessing( %arg );
1173 }
1174  
1175 38 ▶sub __PPIX_ELEM__post_reblessing {
Subroutine __PPIX_ELEM__post_reblessing: called CC=1 SCAR=0.0
1176 38 return 0;
1177 }
1178  
1179 6442 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
1180 6442 $_[0]->_parent( undef );
1181 6442 return;
1182 }
1183  
1184 9 1;
1185  
1186 __END__
« Regexp/Token/CharClass/POSIX.pm ↑ Summary Regexp/Token/Whitespace.pm »