PPI/Lexer.pm

filter: Statementstmt 94.3% 420 / 445 Branchbran 88.0% 266 / 302 Conditioncond 78.1% 143 / 183 MC/DCmcdc 64.5% 71 / 110 Subroutinesub 100% 28 / 28 Podpod 83.3% 5 / 6 totaltotal 86.8% 933 / 1074 CC 217 SCAR 36.7
CC
217
Cov
89%
_continues
86.9
_statement
41.2
_curly
38.6
CRAP 39.2
« PPI/Token/Unknown.pm ↑ Summary PPI/Statement/Compound.pm »
1 package PPI::Lexer;
2  
3 =pod
4  
5 =head1 NAME
6  
7 PPI::Lexer - The PPI Lexer
8  
9 =head1 SYNOPSIS
10  
11 use PPI;
12
13 # Create a new Lexer
14 my $Lexer = PPI::Lexer->new;
15
16 # Build a PPI::Document object from a Token stream
17 my $Tokenizer = PPI::Tokenizer->load('My/Module.pm');
18 my $Document = $Lexer->lex_tokenizer($Tokenizer);
19
20 # Build a PPI::Document object for some raw source
21 my $source = "print 'Hello World!'; kill(Humans->all);";
22 $Document = $Lexer->lex_source($source);
23
24 # Build a PPI::Document object for a particular file name
25 $Document = $Lexer->lex_file('My/Module.pm');
26  
27 =head1 DESCRIPTION
28  
29 The is the L<PPI> Lexer. In the larger scheme of things, its job is to take
30 token streams, in a variety of forms, and "lex" them into nested structures.
31  
32 Pretty much everything in this module happens behind the scenes at this
33 point. In fact, at the moment you don't really need to instantiate the lexer
34 at all, the three main methods will auto-instantiate themselves a
35 C<PPI::Lexer> object as needed.
36  
37 All methods do a one-shot "lex this and give me a L<PPI::Document> object".
38  
39 In fact, if you are reading this, what you B<probably> want to do is to
40 just "load a document", in which case you can do this in a much more
41 direct and concise manner with one of the following.
42  
43 use PPI;
44
45 $Document = PPI::Document->load( $filename );
46 $Document = PPI::Document->new( $string );
47  
48 See L<PPI::Document> for more details.
49  
50 For more unusual tasks, by all means forge onwards.
51  
52 =head1 METHODS
53  
54 =cut
55  
56 63 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 63 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
58 63 ▶use Params::Util qw{_STRING _INSTANCE};
Subroutine BEGIN: called CC=1 SCAR=0.0
59 63 ▶use PPI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
60 63 ▶use PPI::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
61 63 ▶use PPI::Singletons '%_PARENT';
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 63 our $VERSION = '1.260'; # VERSION
64  
65 63 our $errstr = "";
66  
67 # Keyword -> Structure class maps
68 63 my %ROUND = (
69 # Conditions
70 'if' => 'PPI::Structure::Condition',
71 'elsif' => 'PPI::Structure::Condition',
72 'unless' => 'PPI::Structure::Condition',
73 'while' => 'PPI::Structure::Condition',
74 'until' => 'PPI::Structure::Condition',
75  
76 # For(each)
77 'for' => 'PPI::Structure::For',
78 'foreach' => 'PPI::Structure::For',
79 );
80  
81 # Opening brace to refining method
82 63 my %RESOLVE = (
83 '(' => '_round',
84 '[' => '_square',
85 '{' => '_curly',
86 );
87  
88 # Allows for experimental overriding of the tokenizer
89 63 our $X_TOKENIZER = "PPI::Tokenizer";
90 15927 ▶sub X_TOKENIZER { $X_TOKENIZER }
Subroutine X_TOKENIZER: called CC=1 SCAR=0.0
Pod undocumented
91  
92  
93  
94  
95  
96 #####################################################################
97 # Constructor
98  
99 =pod
100  
101 =head2 new
102  
103 The C<new> constructor creates a new C<PPI::Lexer> object. The object itself
104 is merely used to hold various buffers and state data during the lexing
105 process, and holds no significant data between -E<gt>lex_xxxxx calls.
106  
107 Returns a new C<PPI::Lexer> object
108  
109 =cut
110  
111 sub new {
112 15928 ▶ my $class = shift->_clear;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
113 15928 bless {
114 Tokenizer => undef, # Where we store the tokenizer for a run
115 buffer => [], # The input token buffer
116 delayed => [], # The "delayed insignificant tokens" buffer
117 }, $class;
118 }
119  
120  
121  
122  
123  
124 #####################################################################
125 # Main Lexing Methods
126  
127 =pod
128  
129 =head2 lex_file $filename
130  
131 The C<lex_file> method takes a filename as argument. It then loads the file,
132 creates a L<PPI::Tokenizer> for the content and lexes the token stream
133 produced by the tokenizer. Basically, a sort of all-in-one method for
134 getting a L<PPI::Document> object from a file name.
135  
136 Returns a L<PPI::Document> object, or C<undef> on error.
137  
138 =cut
139  
140 sub lex_file {
141 483 ▶ my $self = ref $_[0] ? shift : shift->new;
Subroutine lex_file: called CC=5 SCAR=16.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 1 482 483
142 483 my $file = _STRING(shift);
143 483 ▶ unless ( defined $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 1 482 483
144 1 return $self->_error("Did not pass a filename to PPI::Lexer::lex_file");
145 }
146  
147 # Create the Tokenizer
148 482 my $Tokenizer = eval {
149 482 X_TOKENIZER->new($file);
150 };
151 482 ▶ if ( _INSTANCE($@, 'PPI::Exception') ) {
Branch: 2 branches
BranchTrueFalseTotal
if (&_INSTANCE($@, 'PPI::Exception')) { } 0 482 482
elsif ($@) { } 0 482 482
152 0 return $self->_error( $@->message );
153 } elsif ( $@ ) {
154 0 return $self->_error( $errstr );
155 }
156  
157 482 $self->lex_tokenizer( $Tokenizer );
158 }
159  
160 =pod
161  
162 =head2 lex_source $string
163  
164 The C<lex_source> method takes a normal scalar string as argument. It
165 creates a L<PPI::Tokenizer> object for the string, and then lexes the
166 resulting token stream.
167  
168 Returns a L<PPI::Document> object, or C<undef> on error.
169  
170 =cut
171  
172 sub lex_source {
173 15445 ▶ my $self = ref $_[0] ? shift : shift->new;
Subroutine lex_source: called CC=6 SCAR=21.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 15445 15445
174 15445 my $source = shift;
175 15445 ▶ unless ( defined $source and not ref $source ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $source and not ref $source) 0 15445 15445
Condition33%1/3
defined $source and not ref $source
!ll&&!rl&&r
0015445
MC/DC0%0/2
defined $source and not ref $source
defined $source not ref $source
Truth table33%1/3
A and not(B)
A= defined $sourceB= not ref $source
ABresult
0X0
100
111
176 0 return $self->_error("Did not pass a string to PPI::Lexer::lex_source");
177 }
178  
179 # Create the Tokenizer and hand off to the next method
180 15445 my $Tokenizer = eval {
181 15445 X_TOKENIZER->new(\$source);
182 };
183 15445 ▶ if ( _INSTANCE($@, 'PPI::Exception') ) {
Branch: 2 branches
BranchTrueFalseTotal
if (&_INSTANCE($@, 'PPI::Exception')) { } 0 15445 15445
elsif ($@) { } 0 15445 15445
184 0 return $self->_error( $@->message );
185 } elsif ( $@ ) {
186 0 return $self->_error( $errstr );
187 }
188  
189 15445 $self->lex_tokenizer( $Tokenizer );
190 }
191  
192 =pod
193  
194 =head2 lex_tokenizer $Tokenizer
195  
196 The C<lex_tokenizer> takes as argument a L<PPI::Tokenizer> object. It
197 lexes the token stream from the tokenizer into a L<PPI::Document> object.
198  
199 Returns a L<PPI::Document> object, or C<undef> on error.
200  
201 =cut
202  
203 sub lex_tokenizer {
204 15927 ▶ my $self = ref $_[0] ? shift : shift->new;
Subroutine lex_tokenizer: called CC=5 SCAR=16.4
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 15927 0 15927
205 15927 my $Tokenizer = _INSTANCE(shift, 'PPI::Tokenizer');
206 15927 ▶ return $self->_error(
Branch: 1 branch
BranchTrueFalseTotal
unless $Tokenizer 0 15927 15927
207 "Did not pass a PPI::Tokenizer object to PPI::Lexer::lex_tokenizer"
208 ) unless $Tokenizer;
209  
210 # Create the empty document
211 15927 my $Document = PPI::Document->new;
212  
213 # Lex the token stream into the document
214 15927 $self->{Tokenizer} = $Tokenizer;
215 15927 ▶ if ( !eval { $self->_lex_document($Document); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $self->_lex_document($Document); 1 } }) 1 15926 15927
216 # If an error occurs DESTROY the partially built document.
217 1 undef $Document;
218 1 ▶ if ( _INSTANCE($@, 'PPI::Exception') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_INSTANCE($@, 'PPI::Exception')) { } 1 0 1
219 1 return $self->_error( $@->message );
220 } else {
221 0 return $self->_error( $errstr );
222 }
223 }
224  
225 15926 return $Document;
226 }
227  
228  
229  
230  
231  
232 #####################################################################
233 # Lex Methods - Document Object
234  
235 sub _lex_document {
236 15927 ▶ my ($self, $Document) = @_;
Subroutine _lex_document: called CC=13 SCAR=26.6
237 # my $self = shift;
238 # my $Document = _INSTANCE(shift, 'PPI::Document') or return undef;
239  
240 # Start the processing loop
241 15927 my $Token;
242 15927 ▶ while ( ref($Token = $self->_get_token) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($Token = $self->_get_token)) 50637 15926 66563
243 # Add insignificant tokens directly beneath us
244 50637 ▶ unless ( $Token->significant ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Token->significant) 20252 30385 50637
245 20252 $self->_add_element( $Document, $Token );
246 20252 next;
247 }
248  
249 30385 ▶ if ( $Token->content eq ';' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Token->content eq ";") 256 30129 30385
250 # It's a semi-colon on it's own.
251 # We call this a null statement.
252 256 $self->_add_element(
253 $Document,
254 PPI::Statement::Null->new($Token),
255 );
256 256 next;
257 }
258  
259 # Handle anything other than a structural element
260 30129 ▶ unless ( ref $Token eq 'PPI::Token::Structure' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $Token eq "PPI::Token::Structure") 27518 2611 30129
261 # Determine the class for the Statement, and create it
262 27518 my $Statement = $self->_statement($Document, $Token)->new($Token);
263  
264 # Move the lexing down into the statement
265 27518 $self->_add_delayed( $Document );
266 27518 $self->_add_element( $Document, $Statement );
267 27518 $self->_lex_statement( $Statement );
268  
269 27518 next;
270 }
271  
272 # Is this the opening of a structure?
273 2611 ▶ if ( $Token->__LEXER__opens ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Token->__LEXER__opens) 947 1664 2611
274 # This should actually have a Statement instead
275 947 $self->_rollback( $Token );
276 947 my $Statement = PPI::Statement->new;
277 947 $self->_add_element( $Document, $Statement );
278 947 $self->_lex_statement( $Statement );
279 947 next;
280 }
281  
282 # Is this the close of a structure.
283 1664 ▶ if ( $Token->__LEXER__closes ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Token->__LEXER__closes) 1664 0 1664
284 # Because we are at the top of the tree, this is an error.
285 # This means either a mis-parsing, or a mistake in the code.
286 # To handle this, we create a "Naked Close" statement
287 1664 $self->_add_element( $Document,
288 PPI::Statement::UnmatchedBrace->new($Token)
289 );
290 1664 next;
291 }
292  
293 # Shouldn't be able to get here
294 0 PPI::Exception->throw('Lexer reached an illegal state');
295 }
296  
297 # Did we leave the main loop because of a Tokenizer error?
298 15926 ▶ unless ( defined $Token ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Token) 0 15926 15926
299 0 ▶ my $errstr = $self->{Tokenizer} ? $self->{Tokenizer}->errstr : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'Tokenizer'} ? : 0 0 0
300 0 ▶ $errstr ||= 'Unknown Tokenizer Error';
Condition0%0/2
$errstr ||= "Unknown Tokenizer Error"
l!l
00
MC/DC0%0/1
$errstr ||= "Unknown Tokenizer Error"
$errstr
Truth table0%0/2
A
A= $errstr
Aresult
11
00
301 0 PPI::Exception->throw($errstr);
302 }
303  
304 # No error, it's just the end of file.
305 # Add any insignificant trailing tokens.
306 15926 $self->_add_delayed( $Document );
307  
308 # If the Tokenizer has any v6 blocks to attach, do so now.
309 # Checking once at the end is faster than adding a special
310 # case check for every statement parsed.
311 15926 my $perl6 = $self->{Tokenizer}->{'perl6'};
312 15926 ▶ if ( @$perl6 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$perl6) 2 15924 15926
313 2 my $includes = $Document->find( 'PPI::Statement::Include::Perl6' );
314 2 foreach my $include ( @$includes ) {
315 2 ▶ unless ( @$perl6 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$perl6) 0 2 2
316 0 PPI::Exception->throw('Failed to find a perl6 section');
317 }
318 2 $include->{perl6} = shift @$perl6;
319 }
320 }
321  
322 15926 return 1;
323 }
324  
325  
326  
327  
328  
329 #####################################################################
330 # Lex Methods - Statement Object
331  
332 # Keyword -> Statement Subclass
333 63 my %STATEMENT_CLASSES = (
334 # Things that affect the timing of execution
335 'BEGIN' => 'PPI::Statement::Scheduled',
336 'CHECK' => 'PPI::Statement::Scheduled',
337 'UNITCHECK' => 'PPI::Statement::Scheduled',
338 'INIT' => 'PPI::Statement::Scheduled',
339 'END' => 'PPI::Statement::Scheduled',
340  
341 # Special subroutines for which 'sub' is optional
342 'AUTOLOAD' => 'PPI::Statement::Sub',
343 'DESTROY' => 'PPI::Statement::Sub',
344  
345 # Loading and context statement
346 'package' => 'PPI::Statement::Package',
347 # 'use' => 'PPI::Statement::Include',
348 'no' => 'PPI::Statement::Include',
349 'require' => 'PPI::Statement::Include',
350  
351 # Various declarations
352 'my' => 'PPI::Statement::Variable',
353 'local' => 'PPI::Statement::Variable',
354 'our' => 'PPI::Statement::Variable',
355 'state' => 'PPI::Statement::Variable',
356 # Statements starting with 'sub' could be any one of...
357 # 'sub' => 'PPI::Statement::Sub',
358 # 'sub' => 'PPI::Statement::Scheduled',
359 # 'sub' => 'PPI::Statement',
360  
361 # Compound statement
362 'if' => 'PPI::Statement::Compound',
363 'unless' => 'PPI::Statement::Compound',
364 'for' => 'PPI::Statement::Compound',
365 'foreach' => 'PPI::Statement::Compound',
366 'while' => 'PPI::Statement::Compound',
367 'until' => 'PPI::Statement::Compound',
368  
369 # Switch statement
370 'given' => 'PPI::Statement::Given',
371 'when' => 'PPI::Statement::When',
372 'default' => 'PPI::Statement::When',
373  
374 # Various ways of breaking out of scope
375 'redo' => 'PPI::Statement::Break',
376 'next' => 'PPI::Statement::Break',
377 'last' => 'PPI::Statement::Break',
378 'return' => 'PPI::Statement::Break',
379 'goto' => 'PPI::Statement::Break',
380  
381 # Special sections of the file
382 '__DATA__' => 'PPI::Statement::Data',
383 '__END__' => 'PPI::Statement::End',
384 );
385  
386 sub _statement {
387 52476 ▶ my ($self, $Parent, $Token) = @_;
Subroutine _statement: called CC=41 SCAR=37.2
388 # my $self = shift;
389 # my $Parent = _INSTANCE(shift, 'PPI::Node') or die "Bad param 1";
390 # my $Token = _INSTANCE(shift, 'PPI::Token') or die "Bad param 2";
391  
392 # Check for things like ( parent => ... )
393 52476 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($Parent->isa("PPI::Structure::List") or $Parent->isa("PPI::Structure::Constructor")) 7541 44935 52476
Condition100%3/3
$Parent->isa("PPI::Structure::List") or $Parent->isa("PPI::Structure::Constructor")
l!l&&r!l&&!r
5384215744935
MC/DC100%2/2
$Parent->isa("PPI::Structure::List") or $Parent->isa("PPI::Structure::Constructor")
$Parent->isa("PPI::Structure::List") $Parent->isa("PPI::Structure::Constructor")
Truth table100%3/3
A or B
A= $Parent->isa("PPI::Structure::List")B= $Parent->isa("PPI::Structure::Constructor")
ABresult
1X1
011
000
394 $Parent->isa('PPI::Structure::List')
395 or
396 $Parent->isa('PPI::Structure::Constructor')
397 ) {
398 7541 ▶ if ( $Token->isa('PPI::Token::Word') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Token->isa("PPI::Token::Word")) 1698 5843 7541
399 # Is the next significant token a =>
400 # Read ahead to the next significant token
401 1698 my $Next;
402 1698 ▶ while ( $Next = $self->_get_token ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Next = $self->_get_token) 2321 44 2365
403 2321 ▶ unless ( $Next->significant ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Next->significant) 667 1654 2321
404 667 push @{$self->{delayed}}, $Next;
405 # $self->_delay_element( $Next );
406 667 next;
407 }
408  
409 # Got the next token
410 1654 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($Next->isa('PPI::Token::Operator') and $Next->content eq '=>') { } 886 768 1654
Condition100%3/3
$Next->isa("PPI::Token::Operator") and $Next->content eq "=>"
!ll&&!rl&&r
532236886
MC/DC100%2/2
$Next->isa("PPI::Token::Operator") and $Next->content eq "=>"
$Next->isa("PPI::Token::Operator") $Next->content eq "=>"
Truth table100%3/3
A and B
A= $Next->isa("PPI::Token::Operator")B= $Next->content eq "=>"
ABresult
0X0
100
111
411 $Next->isa('PPI::Token::Operator')
412 and
413 $Next->content eq '=>'
414 ) {
415 # Is an ordinary expression
416 886 $self->_rollback( $Next );
417 886 return 'PPI::Statement::Expression';
418 } else {
419 768 last;
420 }
421 }
422  
423 # Rollback and continue
424 812 $self->_rollback( $Next );
425 }
426 }
427  
428 51590 my $is_lexsub = 0;
429  
430 # Is it a token in our known classes list
431 51590 my $class = $STATEMENT_CLASSES{$Token->content};
432 51590 ▶ if ( $class ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class) 9571 42019 51590
433 # Is the next significant token a =>
434 # Read ahead to the next significant token
435 9571 my $Next;
436 9571 ▶ while ( $Next = $self->_get_token ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Next = $self->_get_token) 18782 47 18829
437 18782 ▶ if ( !$Next->significant ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Next->significant) 9258 9524 18782
438 9258 push @{$self->{delayed}}, $Next;
439 9258 next;
440 }
441  
442 # Lexical subroutine
443 9524 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($Token->content =~ /^(?:my|our|state)$/ and $Next->isa("PPI::Token::Word") and $Next->content eq "sub") 7 9517 9524
Condition83%5/6
$Token->content =~ /^(?:my|our|state)$/ and $Next->isa("PPI::Token::Word") and $Next->content eq "sub"
!ll&&!rl&&r
951707
$Token->content =~ /^(?:my|our|state)$/ and $Next->isa("PPI::Token::Word")
!ll&&!rl&&r
659629217
MC/DC66%2/3
$Token->content =~ /^(?:my|our|state)$/ and $Next->isa("PPI::Token::Word") and $Next->content eq "sub"
$Token->content =~ /^(?:my|our|state)$/ $Next->isa("PPI::Token::Word") $Next->content eq "sub"
Truth table75%3/4
A and B and C
A= $Token->content =~ /^(?:my|our|state)$/B= $Next->isa("PPI::Token::Word")C= $Next->content eq "sub"
ABCresult
0XX0
10X0
1100
1111
444 $Token->content =~ /^(?:my|our|state)$/
445 and $Next->isa( 'PPI::Token::Word' ) and $Next->content eq 'sub'
446 ) {
447 # This should be PPI::Statement::Sub rather than PPI::Statement::Variable
448 7 $class = undef;
449 7 $is_lexsub = 1;
450 7 last;
451 }
452  
453 last if
454 9517 ▶ !$Next->isa( 'PPI::Token::Operator' ) or $Next->content ne '=>';
Branch: 1 branch
BranchTrueFalseTotal
if not $Next->isa("PPI::Token::Operator") or $Next->content ne "=>" 9496 21 9517
Condition100%3/3
not $Next->isa("PPI::Token::Operator") or $Next->content ne "=>"
l!l&&r!l&&!r
94801621
MC/DC100%2/2
not $Next->isa("PPI::Token::Operator") or $Next->content ne "=>"
not $Next->isa("PPI::Token::Operator") $Next->content ne "=>"
Truth table100%3/3
not(A) or B
A= not $Next->isa("PPI::Token::Operator")B= $Next->content ne "=>"
ABresult
1X1
011
000
455  
456 # Got the next token
457 # Is an ordinary expression
458 21 $self->_rollback( $Next );
459 21 return 'PPI::Statement';
460 }
461  
462 # Rollback and continue
463 9550 $self->_rollback( $Next );
464 }
465  
466 # Handle potential barewords for subscripts
467 51569 ▶ if ( $Parent->isa('PPI::Structure::Subscript') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Parent->isa("PPI::Structure::Subscript")) 3807 47762 51569
468 # Fast obvious case, just an expression
469 3807 ▶ unless ( $class and $class->isa('PPI::Statement::Expression') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class and $class->isa("PPI::Statement::Expression")) 3684 123 3807
Condition100%3/3
$class and $class->isa("PPI::Statement::Expression")
!ll&&!rl&&r
365430123
MC/DC100%2/2
$class and $class->isa("PPI::Statement::Expression")
$class $class->isa("PPI::Statement::Expression")
Truth table100%3/3
A and B
A= $classB= $class->isa("PPI::Statement::Expression")
ABresult
0X0
100
111
470 3684 return 'PPI::Statement::Expression';
471 }
472  
473 # This is something like "my" or "our" etc... more subtle.
474 # Check if the next token is a closing curly brace.
475 # This means we are something like $h{my}
476 123 my $Next;
477 123 ▶ while ( $Next = $self->_get_token ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Next = $self->_get_token) 119 4 123
478 119 ▶ unless ( $Next->significant ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Next->significant) 0 119 119
479 0 push @{$self->{delayed}}, $Next;
480 # $self->_delay_element( $Next );
481 0 next;
482 }
483  
484 # Found the next significant token.
485 # Is it a closing curly brace?
486 119 ▶ if ( $Next->content eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Next->content eq '}') { } 119 0 119
487 119 $self->_rollback( $Next );
488 119 return 'PPI::Statement::Expression';
489 } else {
490 0 $self->_rollback( $Next );
491 0 return $class;
492 }
493 }
494  
495 # End of file... this means it is something like $h{our
496 # which is probably going to be $h{our} ... I think
497 4 $self->_rollback( $Next );
498 4 return 'PPI::Statement::Expression';
499 }
500  
501 # If it's a token in our list, use that class
502 47762 ▶ return $class if $class;
Branch: 1 branch
BranchTrueFalseTotal
if $class 9390 38372 47762
503  
504 # Handle the more in-depth sub detection
505 38372 ▶ if ( $is_lexsub || $Token->content eq 'sub' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_lexsub or $Token->content eq "sub") 3291 35081 38372
Condition100%3/3
$is_lexsub or $Token->content eq "sub"
l!l&&r!l&&!r
7328435081
MC/DC100%2/2
$is_lexsub or $Token->content eq "sub"
$is_lexsub $Token->content eq "sub"
Truth table100%3/3
A or B
A= $is_lexsubB= $Token->content eq "sub"
ABresult
1X1
011
000
506 # Read ahead to the next significant token
507 3291 my $Next;
508 3291 ▶ while ( $Next = $self->_get_token ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Next = $self->_get_token) 6523 24 6547
509 6523 ▶ unless ( $Next->significant ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Next->significant) 3256 3267 6523
510 3256 push @{$self->{delayed}}, $Next;
511 # $self->_delay_element( $Next );
512 3256 next;
513 }
514  
515 # Got the next significant token
516 3267 my $sclass = $STATEMENT_CLASSES{$Next->content};
517 3267 ▶ if ( $sclass and $sclass eq 'PPI::Statement::Scheduled' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sclass and $sclass eq "PPI::Statement::Scheduled") 28 3239 3267
Condition100%3/3
$sclass and $sclass eq "PPI::Statement::Scheduled"
!ll&&!rl&&r
302921028
MC/DC100%2/2
$sclass and $sclass eq "PPI::Statement::Scheduled"
$sclass $sclass eq "PPI::Statement::Scheduled"
Truth table100%3/3
A and B
A= $sclassB= $sclass eq "PPI::Statement::Scheduled"
ABresult
0X0
100
111
518 28 $self->_rollback( $Next );
519 28 return 'PPI::Statement::Scheduled';
520 }
521 3239 ▶ if ( $Next->isa('PPI::Token::Word') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Next->isa("PPI::Token::Word")) 3110 129 3239
522 3110 $self->_rollback( $Next );
523 3110 return 'PPI::Statement::Sub';
524 }
525  
526 ### Comment out these two, as they would return PPI::Statement anyway
527 # if ( $content eq '{' ) {
528 # Anonymous sub at start of statement
529 # return 'PPI::Statement';
530 # }
531 #
532 # if ( $Next->isa('PPI::Token::Prototype') ) {
533 # Anonymous sub at start of statement
534 # return 'PPI::Statement';
535 # }
536  
537 # PPI::Statement is the safest fall-through
538 129 $self->_rollback( $Next );
539 129 return 'PPI::Statement';
540 }
541  
542 # End of file... PPI::Statement::Sub is the most likely
543 24 $self->_rollback( $Next );
544 24 return 'PPI::Statement::Sub';
545 }
546  
547 35081 ▶ if ( $Token->content eq 'use' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Token->content eq "use") 2189 32892 35081
548 # Add a special case for "use v6" lines.
549 2189 my $Next;
550 2189 ▶ while ( $Next = $self->_get_token ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Next = $self->_get_token) 4373 2 4375
551 4373 ▶ unless ( $Next->significant ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Next->significant) 2186 2187 4373
552 2186 push @{$self->{delayed}}, $Next;
553 # $self->_delay_element( $Next );
554 2186 next;
555 }
556  
557 # Found the next significant token.
558 2187 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($Next->isa('PPI::Token::Operator') and $Next->content eq '=>') { } 1 2186 2187
elsif ($Next->content eq 'v6') { } 2 2184 2186
Condition66%2/3
$Next->isa("PPI::Token::Operator") and $Next->content eq "=>"
!ll&&!rl&&r
218601
MC/DC50%1/2
$Next->isa("PPI::Token::Operator") and $Next->content eq "=>"
$Next->isa("PPI::Token::Operator") $Next->content eq "=>"
Truth table66%2/3
A and B
A= $Next->isa("PPI::Token::Operator")B= $Next->content eq "=>"
ABresult
0X0
100
111
559 $Next->isa('PPI::Token::Operator')
560 and
561 $Next->content eq '=>'
562 ) {
563 # Is an ordinary expression
564 1 $self->_rollback( $Next );
565 1 return 'PPI::Statement';
566 # Is it a v6 use?
567 } elsif ( $Next->content eq 'v6' ) {
568 2 $self->_rollback( $Next );
569 2 return 'PPI::Statement::Include::Perl6';
570 } else {
571 2184 $self->_rollback( $Next );
572 2184 return 'PPI::Statement::Include';
573 }
574 }
575  
576 # End of file... this means it is an incomplete use
577 # line, just treat it as a normal include.
578 2 $self->_rollback( $Next );
579 2 return 'PPI::Statement::Include';
580 }
581  
582 # If our parent is a Condition, we are an Expression
583 32892 ▶ if ( $Parent->isa('PPI::Structure::Condition') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Parent->isa("PPI::Structure::Condition")) 1217 31675 32892
584 1217 return 'PPI::Statement::Expression';
585 }
586  
587 # If our parent is a List, we are also an expression
588 31675 ▶ if ( $Parent->isa('PPI::Structure::List') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Parent->isa("PPI::Structure::List")) 5057 26618 31675
589 5057 return 'PPI::Statement::Expression';
590 }
591  
592 # Switch statements use expressions, as well.
593 26618 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($Parent->isa("PPI::Structure::Given") or $Parent->isa("PPI::Structure::When")) 6 26612 26618
Condition100%3/3
$Parent->isa("PPI::Structure::Given") or $Parent->isa("PPI::Structure::When")
l!l&&r!l&&!r
3326612
MC/DC100%2/2
$Parent->isa("PPI::Structure::Given") or $Parent->isa("PPI::Structure::When")
$Parent->isa("PPI::Structure::Given") $Parent->isa("PPI::Structure::When")
Truth table100%3/3
A or B
A= $Parent->isa("PPI::Structure::Given")B= $Parent->isa("PPI::Structure::When")
ABresult
1X1
011
000
594 $Parent->isa('PPI::Structure::Given')
595 or
596 $Parent->isa('PPI::Structure::When')
597 ) {
598 6 return 'PPI::Statement::Expression';
599 }
600  
601 26612 ▶ if ( _INSTANCE($Token, 'PPI::Token::Label') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_INSTANCE($Token, "PPI::Token::Label")) 347 26265 26612
602 347 return 'PPI::Statement::Compound';
603 }
604  
605 # Beyond that, I have no idea for the moment.
606 # Just keep adding more conditions above this.
607 26265 return 'PPI::Statement';
608 }
609  
610 sub _lex_statement {
611 53861 ▶ my ($self, $Statement) = @_;
Subroutine _lex_statement: called CC=11 SCAR=24.0
612 # my $self = shift;
613 # my $Statement = _INSTANCE(shift, 'PPI::Statement') or die "Bad param 1";
614  
615 # Handle some special statements
616 53861 ▶ if ( $Statement->isa('PPI::Statement::End') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Statement->isa("PPI::Statement::End")) 8 53853 53861
617 8 return $self->_lex_end( $Statement );
618 }
619  
620 # Begin processing tokens
621 53853 my $Token;
622 53853 ▶ while ( ref( $Token = $self->_get_token ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($Token = $self->_get_token)) 240779 10106 250885
623 # Delay whitespace and comment tokens
624 240779 ▶ unless ( $Token->significant ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Token->significant) 86399 154380 240779
625 86399 push @{$self->{delayed}}, $Token;
626 # $self->_delay_element( $Token );
627 86399 next;
628 }
629  
630 # Structual closes, and __DATA__ and __END__ tags implicitly
631 # end every type of statement
632 154380 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($Token->__LEXER__closes or $Token->isa("PPI::Token::Separator")) 17139 137241 154380
Condition66%2/3
$Token->__LEXER__closes or $Token->isa("PPI::Token::Separator")
l!l&&r!l&&!r
171390137241
MC/DC50%1/2
$Token->__LEXER__closes or $Token->isa("PPI::Token::Separator")
$Token->__LEXER__closes $Token->isa("PPI::Token::Separator")
Truth table66%2/3
A or B
A= $Token->__LEXER__closesB= $Token->isa("PPI::Token::Separator")
ABresult
1X1
011
000
633 $Token->__LEXER__closes
634 or
635 $Token->isa('PPI::Token::Separator')
636 ) {
637 # Rollback and end the statement
638 17139 return $self->_rollback( $Token );
639 }
640  
641 # Normal statements never implicitly end
642 137241 ▶ unless ( $Statement->__LEXER__normal ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Statement->__LEXER__normal) 24458 112783 137241
643 # Have we hit an implicit end to the statement
644 24458 ▶ unless ( $self->_continues( $Statement, $Token ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_continues($Statement, $Token)) 4291 20167 24458
645 # Rollback and finish the statement
646 4291 return $self->_rollback( $Token );
647 }
648 }
649  
650 # Any normal character just gets added
651 132950 ▶ unless ( $Token->isa('PPI::Token::Structure') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Token->isa("PPI::Token::Structure")) 89137 43813 132950
652 89137 $self->_add_element( $Statement, $Token );
653 89137 next;
654 }
655  
656 # Handle normal statement terminators
657 43813 ▶ if ( $Token->content eq ';' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Token->content eq ";") 22317 21496 43813
658 22317 $self->_add_element( $Statement, $Token );
659 22317 return 1;
660 }
661  
662 # Which leaves us with a new structure
663  
664 # Determine the class for the structure and create it
665 21496 my $method = $RESOLVE{$Token->content};
666 21496 my $Structure = $self->$method($Statement)->new($Token);
667  
668 # Move the lexing down into the Structure
669 21496 $self->_add_delayed( $Statement );
670 21496 $self->_add_element( $Statement, $Structure );
671 21496 $self->_lex_structure( $Structure );
672 }
673  
674 # Was it an error in the tokenizer?
675 10106 ▶ unless ( defined $Token ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Token) 0 10106 10106
676 0 PPI::Exception->throw;
677 }
678  
679 # No, it's just the end of the file...
680 # Roll back any insignificant tokens, they'll get added at the Document level
681 10106 $self->_rollback;
682 }
683  
684 sub _lex_end {
685 8 ▶ my ($self, $Statement) = @_;
Subroutine _lex_end: called CC=3 SCAR=11.1
686 # my $self = shift;
687 # my $Statement = _INSTANCE(shift, 'PPI::Statement::End') or die "Bad param 1";
688  
689 # End of the file, EVERYTHING is ours
690 8 my $Token;
691 8 ▶ while ( $Token = $self->_get_token ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Token = $self->_get_token) 15 8 23
692 # Inlined $Statement->__add_element($Token);
693 Scalar::Util::weaken(
694 15 $_PARENT{Scalar::Util::refaddr $Token} = $Statement
695 );
696 15 push @{$Statement->{children}}, $Token;
697 }
698  
699 # Was it an error in the tokenizer?
700 8 ▶ unless ( defined $Token ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Token) 0 8 8
701 0 PPI::Exception->throw;
702 }
703  
704 # No, it's just the end of the file...
705 # Roll back any insignificant tokens, they get added at the Document level
706 8 $self->_rollback;
707 }
708  
709 # For many statements, it can be difficult to determine the end-point.
710 # This method takes a statement and the next significant token, and attempts
711 # to determine if the there is a statement boundary between the two, or if
712 # the statement can continue with the token.
713 sub _continues {
714 24458 ▶ my ($self, $Statement, $Token) = @_;
Subroutine _continues: called CC=64 SCAR=44.7
715 # my $self = shift;
716 # my $Statement = _INSTANCE(shift, 'PPI::Statement') or die "Bad param 1";
717 # my $Token = _INSTANCE(shift, 'PPI::Token') or die "Bad param 2";
718  
719 # Handle the simple block case
720 # { print 1; }
721 24458 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($Statement->schildren == 1 and $Statement->schild(0)->isa("PPI::Structure::Block")) 46 24412 24458
Condition100%3/3
$Statement->schildren == 1 and $Statement->schild(0)->isa("PPI::Structure::Block")
!ll&&!rl&&r
16800761246
MC/DC100%2/2
$Statement->schildren == 1 and $Statement->schild(0)->isa("PPI::Structure::Block")
$Statement->schildren == 1 $Statement->schild(0)->isa("PPI::Structure::Block")
Truth table100%3/3
A and B
A= $Statement->schildren == 1B= $Statement->schild(0)->isa("PPI::Structure::Block")
ABresult
0X0
100
111
722 $Statement->schildren == 1
723 and
724 $Statement->schild(0)->isa('PPI::Structure::Block')
725 ) {
726 46 return '';
727 }
728  
729 # Alrighty then, there are six implied-end statement types:
730 # ::Scheduled blocks, ::Sub declarations, ::Compound, ::Given, ::When,
731 # and ::Package statements.
732 24412 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if ref !($Statement =~ /\b(?:Scheduled|Sub|Compound|Given|When|Package)$/) 0 24412 24412
733 if ref $Statement !~ /\b(?:Scheduled|Sub|Compound|Given|When|Package)$/;
734  
735 # Of these six, ::Scheduled, ::Sub, ::Given, and ::When follow the same
736 # simple rule and can be handled first. The block form of ::Package
737 # follows the rule, too. (The non-block form of ::Package
738 # requires a statement terminator, and thus doesn't need to have
739 # an implied end detected.)
740 24412 my @part = $Statement->schildren;
741 24412 my $LastChild = $part[-1];
742 # If the last significant element of the statement is a block,
743 # then an implied-end statement is done, no questions asked.
744 24412 ▶ return !$LastChild->isa('PPI::Structure::Block')
Branch: 1 branch
BranchTrueFalseTotal
unless $Statement->isa("PPI::Statement::Compound") 19035 5377 24412
745 if !$Statement->isa('PPI::Statement::Compound');
746  
747 # Now we get to compound statements, which kind of suck (to lex).
748 # However, of them all, the 'if' type, which includes unless, are
749 # relatively easy to handle compared to the others.
750 5377 my $type = $Statement->type;
751 5377 ▶ if ( $type eq 'if' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "if") 3374 2003 5377
752 # This should be one of the following
753 # if (EXPR) BLOCK
754 # if (EXPR) BLOCK else BLOCK
755 # if (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK
756  
757 # We only implicitly end on a block
758 3374 ▶ unless ( $LastChild->isa('PPI::Structure::Block') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($LastChild->isa("PPI::Structure::Block")) 2332 1042 3374
759 # if (EXPR) ...
760 # if (EXPR) BLOCK else ...
761 # if (EXPR) BLOCK elsif (EXPR) BLOCK ...
762 2332 return 1;
763 }
764  
765 # If the token before the block is an 'else',
766 # it's over, no matter what.
767 1042 my $NextLast = $Statement->schild(-2);
768 1042 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($NextLast and $NextLast->isa("PPI::Token") and $NextLast->isa("PPI::Token::Word") and $NextLast->content eq "else") 77 965 1042
Condition66%6/9
$NextLast and $NextLast->isa("PPI::Token") and $NextLast->isa("PPI::Token::Word") and $NextLast->content eq "else"
!ll&&!rl&&r
965077
$NextLast and $NextLast->isa("PPI::Token") and $NextLast->isa("PPI::Token::Word")
!ll&&!rl&&r
965077
$NextLast and $NextLast->isa("PPI::Token")
!ll&&!rl&&r
096577
MC/DC25%1/4
$NextLast and $NextLast->isa("PPI::Token") and $NextLast->isa("PPI::Token::Word") and $NextLast->content eq "else"
$NextLast $NextLast->isa("PPI::Token") $NextLast->isa("PPI::Token::Word") $NextLast->content eq "else"
Truth table40%2/5
A and B and C and D
A= $NextLastB= $NextLast->isa("PPI::Token")C= $NextLast->isa("PPI::Token::Word")D= $NextLast->content eq "else"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
769 $NextLast
770 and
771 $NextLast->isa('PPI::Token')
772 and
773 $NextLast->isa('PPI::Token::Word')
774 and
775 $NextLast->content eq 'else'
776 ) {
777 77 return '';
778 }
779  
780 # Otherwise, we continue for 'elsif' or 'else' only.
781 965 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($Token->isa("PPI::Token::Word") and $Token->content eq "else" || $Token->content eq "elsif") 301 664 965
Condition100%6/6
$Token->isa("PPI::Token::Word") and $Token->content eq "else" || $Token->content eq "elsif"
!ll&&!rl&&r
202561202
$Token->content eq "else" or $Token->content eq "elsif"
l!l&&r!l&&!r
152149462
MC/DC66%2/3
$Token->isa("PPI::Token::Word") and $Token->content eq "else" || $Token->content eq "elsif"
$Token->isa("PPI::Token::Word") $Token->content eq "else" $Token->content eq "elsif"
Truth table75%3/4
A and B or C
A= $Token->isa("PPI::Token::Word")B= $Token->content eq "else"C= $Token->content eq "elsif"
ABCresult
0XX0
1000
11X1
1011
782 $Token->isa('PPI::Token::Word')
783 and (
784 $Token->content eq 'else'
785 or
786 $Token->content eq 'elsif'
787 )
788 ) {
789 301 return 1;
790 }
791  
792 664 return '';
793 }
794  
795 2003 ▶ if ( $type eq 'label' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "label") 325 1678 2003
796 # We only have the label so far, could be any of
797 # LABEL while (EXPR) BLOCK
798 # LABEL while (EXPR) BLOCK continue BLOCK
799 # LABEL for (EXPR; EXPR; EXPR) BLOCK
800 # LABEL foreach VAR (LIST) BLOCK
801 # LABEL foreach VAR (LIST) BLOCK continue BLOCK
802 # LABEL BLOCK continue BLOCK
803  
804 # Handle cases with a word after the label
805 325 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($Token->isa("PPI::Token::Word") and $Token->content =~ /^(?:while|until|for|foreach)$/) 38 287 325
Condition100%3/3
$Token->isa("PPI::Token::Word") and $Token->content =~ /^(?:while|until|for|foreach)$/
!ll&&!rl&&r
279838
MC/DC100%2/2
$Token->isa("PPI::Token::Word") and $Token->content =~ /^(?:while|until|for|foreach)$/
$Token->isa("PPI::Token::Word") $Token->content =~ /^(?:while|until|for|foreach)$/
Truth table100%3/3
A and B
A= $Token->isa("PPI::Token::Word")B= $Token->content =~ /^(?:while|until|for|foreach)$/
ABresult
0X0
100
111
806 $Token->isa('PPI::Token::Word')
807 and
808 $Token->content =~ /^(?:while|until|for|foreach)$/
809 ) {
810 38 return 1;
811 }
812  
813 # Handle labelled blocks
814 287 ▶ if ( $Token->isa('PPI::Token::Structure') && $Token->content eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Token->isa("PPI::Token::Structure") and $Token->content eq "{") 209 78 287
Condition100%3/3
$Token->isa("PPI::Token::Structure") and $Token->content eq "{"
!ll&&!rl&&r
771209
MC/DC100%2/2
$Token->isa("PPI::Token::Structure") and $Token->content eq "{"
$Token->isa("PPI::Token::Structure") $Token->content eq "{"
Truth table100%3/3
A and B
A= $Token->isa("PPI::Token::Structure")B= $Token->content eq "{"
ABresult
0X0
100
111
815 209 return 1;
816 }
817  
818 78 return '';
819 }
820  
821 # Handle the common "after round braces" case
822 1678 ▶ if ( $LastChild->isa('PPI::Structure') and $LastChild->braces eq '()' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($LastChild->isa("PPI::Structure") and $LastChild->braces eq "()") 372 1306 1678
Condition100%3/3
$LastChild->isa("PPI::Structure") and $LastChild->braces eq "()"
!ll&&!rl&&r
875431372
MC/DC100%2/2
$LastChild->isa("PPI::Structure") and $LastChild->braces eq "()"
$LastChild->isa("PPI::Structure") $LastChild->braces eq "()"
Truth table100%3/3
A and B
A= $LastChild->isa("PPI::Structure")B= $LastChild->braces eq "()"
ABresult
0X0
100
111
823 # LABEL while (EXPR) ...
824 # LABEL while (EXPR) ...
825 # LABEL for (EXPR; EXPR; EXPR) ...
826 # LABEL for VAR (LIST) ...
827 # LABEL foreach VAR (LIST) ...
828 # Only a block will do
829 372 ▶ return $Token->isa('PPI::Token::Structure') && $Token->content eq '{';
Condition33%1/3
$Token->isa('PPI::Token::Structure') && $Token->content eq '{'
!ll&&!rl&&r
00372
MC/DC0%0/2
$Token->isa('PPI::Token::Structure') && $Token->content eq '{'
$Token->isa('PPI::Token::Structure') $Token->content eq '{'
Truth table33%1/3
A && B
A= $Token->isa('PPI::Token::Structure')B= $Token->content eq '{'
ABresult
0X0
100
111
830 }
831  
832 1306 ▶ if ( $type eq 'for' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "for") 141 1165 1306
833 # LABEL for (EXPR; EXPR; EXPR) BLOCK
834 141 ▶ if (
Branch: 3 branches
BranchTrueFalseTotal
if ($LastChild->isa('PPI::Token::Word') and $LastChild->content =~ /^for(?:each)?\z/) { } 128 13 141
elsif ($LastChild->isa('PPI::Structure::Block')) { } 13 0 13
elsif ($LastChild->isa('PPI::Token::QuoteLike::Words')) { } 0 0 0
Condition66%2/3
$LastChild->isa("PPI::Token::Word") and $LastChild->content =~ /^for(?:each)?\z/
!ll&&!rl&&r
130128
MC/DC50%1/2
$LastChild->isa("PPI::Token::Word") and $LastChild->content =~ /^for(?:each)?\z/
$LastChild->isa("PPI::Token::Word") $LastChild->content =~ /^for(?:each)?\z/
Truth table66%2/3
A and B
A= $LastChild->isa("PPI::Token::Word")B= $LastChild->content =~ /^for(?:each)?\z/
ABresult
0X0
100
111
835 $LastChild->isa('PPI::Token::Word')
836 and
837 $LastChild->content =~ /^for(?:each)?\z/
838 ) {
839 # LABEL for ...
840 128 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($Token->isa("PPI::Token::Structure") and $Token->content eq "(" or $Token->isa("PPI::Token::QuoteLike::Words")) 21 107 128
Condition83%5/6
$Token->isa("PPI::Token::Structure") and $Token->content eq "(" or $Token->isa("PPI::Token::QuoteLike::Words")
l!l&&r!l&&!r
183107
$Token->isa("PPI::Token::Structure") and $Token->content eq "("
!ll&&!rl&&r
110018
MC/DC66%2/3
$Token->isa("PPI::Token::Structure") and $Token->content eq "(" or $Token->isa("PPI::Token::QuoteLike::Words")
$Token->isa("PPI::Token::Structure") $Token->content eq "(" $Token->isa("PPI::Token::QuoteLike::Words")
Truth table60%3/5
A and B or C
A= $Token->isa("PPI::Token::Structure")B= $Token->content eq "("C= $Token->isa("PPI::Token::QuoteLike::Words")
ABCresult
11X1
0X11
1011
0X00
1000
841 (
842 $Token->isa('PPI::Token::Structure')
843 and
844 $Token->content eq '('
845 )
846 or
847 $Token->isa('PPI::Token::QuoteLike::Words')
848 ) {
849 21 return 1;
850 }
851  
852 107 ▶ if ( $LastChild->isa('PPI::Token::QuoteLike::Words') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($LastChild->isa("PPI::Token::QuoteLike::Words")) 0 107 107
853 # LABEL for VAR QW{} ...
854 # LABEL foreach VAR QW{} ...
855 # Only a block will do
856 0 ▶ return $Token->isa('PPI::Token::Structure') && $Token->content eq '{';
Condition0%0/3
$Token->isa('PPI::Token::Structure') && $Token->content eq '{'
!ll&&!rl&&r
000
MC/DC0%0/2
$Token->isa('PPI::Token::Structure') && $Token->content eq '{'
$Token->isa('PPI::Token::Structure') $Token->content eq '{'
Truth table0%0/3
A && B
A= $Token->isa('PPI::Token::Structure')B= $Token->content eq '{'
ABresult
0X0
100
111
857 }
858  
859 # In this case, we can also behave like a foreach
860 107 $type = 'foreach';
861  
862 } elsif ( $LastChild->isa('PPI::Structure::Block') ) {
863 # LABEL for (EXPR; EXPR; EXPR) BLOCK
864 # That's it, nothing can continue
865 13 return '';
866  
867 } elsif ( $LastChild->isa('PPI::Token::QuoteLike::Words') ) {
868 # LABEL for VAR QW{} ...
869 # LABEL foreach VAR QW{} ...
870 # Only a block will do
871 0 ▶ return $Token->isa('PPI::Token::Structure') && $Token->content eq '{';
Condition0%0/3
$Token->isa('PPI::Token::Structure') && $Token->content eq '{'
!ll&&!rl&&r
000
MC/DC0%0/2
$Token->isa('PPI::Token::Structure') && $Token->content eq '{'
$Token->isa('PPI::Token::Structure') $Token->content eq '{'
Truth table0%0/3
A && B
A= $Token->isa('PPI::Token::Structure')B= $Token->content eq '{'
ABresult
0X0
100
111
872 }
873 }
874  
875 # Handle the common continue case
876 1272 ▶ if ( $LastChild->isa('PPI::Token::Word') and $LastChild->content eq 'continue' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($LastChild->isa("PPI::Token::Word") and $LastChild->content eq "continue") 6 1266 1272
Condition100%3/3
$LastChild->isa("PPI::Token::Word") and $LastChild->content eq "continue"
!ll&&!rl&&r
6506166
MC/DC100%2/2
$LastChild->isa("PPI::Token::Word") and $LastChild->content eq "continue"
$LastChild->isa("PPI::Token::Word") $LastChild->content eq "continue"
Truth table100%3/3
A and B
A= $LastChild->isa("PPI::Token::Word")B= $LastChild->content eq "continue"
ABresult
0X0
100
111
877 # LABEL while (EXPR) BLOCK continue ...
878 # LABEL foreach VAR (LIST) BLOCK continue ...
879 # LABEL BLOCK continue ...
880 # Only a block will do
881 6 ▶ return $Token->isa('PPI::Token::Structure') && $Token->content eq '{';
Condition33%1/3
$Token->isa('PPI::Token::Structure') && $Token->content eq '{'
!ll&&!rl&&r
006
MC/DC0%0/2
$Token->isa('PPI::Token::Structure') && $Token->content eq '{'
$Token->isa('PPI::Token::Structure') $Token->content eq '{'
Truth table33%1/3
A && B
A= $Token->isa('PPI::Token::Structure')B= $Token->content eq '{'
ABresult
0X0
100
111
882 }
883  
884 # Handle the common continuable block case
885 1266 ▶ if ( $LastChild->isa('PPI::Structure::Block') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($LastChild->isa("PPI::Structure::Block")) 418 848 1266
886 # LABEL while (EXPR) BLOCK
887 # LABEL while (EXPR) BLOCK ...
888 # LABEL for (EXPR; EXPR; EXPR) BLOCK
889 # LABEL foreach VAR (LIST) BLOCK
890 # LABEL foreach VAR (LIST) BLOCK ...
891 # LABEL BLOCK ...
892 # Is this the block for a continue?
893 418 ▶ if ( _INSTANCE($part[-2], 'PPI::Token::Word') and $part[-2]->content eq 'continue' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_INSTANCE($part[-2], "PPI::Token::Word") and $part[-2]->content eq "continue") 6 412 418
Condition66%2/3
&_INSTANCE($part[-2], "PPI::Token::Word") and $part[-2]->content eq "continue"
!ll&&!rl&&r
41206
MC/DC50%1/2
&_INSTANCE($part[-2], "PPI::Token::Word") and $part[-2]->content eq "continue"
&_INSTANCE($part[-2], "PPI::Token::Word") $part[-2]->content eq "continue"
Truth table66%2/3
A and B
A= &_INSTANCE($part[-2], "PPI::Token::Word")B= $part[-2]->content eq "continue"
ABresult
0X0
100
111
894 # LABEL while (EXPR) BLOCK continue BLOCK
895 # LABEL foreach VAR (LIST) BLOCK continue BLOCK
896 # LABEL BLOCK continue BLOCK
897 # That's it, nothing can continue this
898 6 return '';
899 }
900  
901 # Only a continue will do
902 412 ▶ return $Token->isa('PPI::Token::Word') && $Token->content eq 'continue';
Condition100%3/3
$Token->isa('PPI::Token::Word') && $Token->content eq 'continue'
!ll&&!rl&&r
2062006
MC/DC100%2/2
$Token->isa('PPI::Token::Word') && $Token->content eq 'continue'
$Token->isa('PPI::Token::Word') $Token->content eq 'continue'
Truth table100%3/3
A && B
A= $Token->isa('PPI::Token::Word')B= $Token->content eq 'continue'
ABresult
0X0
100
111
903 }
904  
905 848 ▶ if ( $type eq 'block' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "block") 0 848 848
906 # LABEL BLOCK continue BLOCK
907 # Every possible case is covered in the common cases above
908 }
909  
910 848 ▶ if ( $type eq 'while' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "while") 149 699 848
911 # LABEL while (EXPR) BLOCK
912 # LABEL while (EXPR) BLOCK continue BLOCK
913 # LABEL until (EXPR) BLOCK
914 # LABEL until (EXPR) BLOCK continue BLOCK
915 # The only case not covered is the while ...
916 149 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($LastChild->isa("PPI::Token::Word") and $LastChild->content eq "while" || $LastChild->content eq "until") 149 0 149
Condition66%4/6
$LastChild->isa("PPI::Token::Word") and $LastChild->content eq "while" || $LastChild->content eq "until"
!ll&&!rl&&r
033116
$LastChild->content eq "while" or $LastChild->content eq "until"
l!l&&r!l&&!r
14180
MC/DC0%0/3
$LastChild->isa("PPI::Token::Word") and $LastChild->content eq "while" || $LastChild->content eq "until"
$LastChild->isa("PPI::Token::Word") $LastChild->content eq "while" $LastChild->content eq "until"
Truth table25%1/4
A and B or C
A= $LastChild->isa("PPI::Token::Word")B= $LastChild->content eq "while"C= $LastChild->content eq "until"
ABCresult
0XX0
1000
11X1
1011
917 $LastChild->isa('PPI::Token::Word')
918 and (
919 $LastChild->content eq 'while'
920 or
921 $LastChild->content eq 'until'
922 )
923 ) {
924 # LABEL while ...
925 # LABEL until ...
926 # Only a condition structure will do
927 149 ▶ return $Token->isa('PPI::Token::Structure') && $Token->content eq '(';
Condition33%1/3
$Token->isa('PPI::Token::Structure') && $Token->content eq '('
!ll&&!rl&&r
00149
MC/DC0%0/2
$Token->isa('PPI::Token::Structure') && $Token->content eq '('
$Token->isa('PPI::Token::Structure') $Token->content eq '('
Truth table33%1/3
A && B
A= $Token->isa('PPI::Token::Structure')B= $Token->content eq '('
ABresult
0X0
100
111
928 }
929 }
930  
931 699 ▶ if ( $type eq 'foreach' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "foreach") 699 0 699
932 # LABEL foreach VAR (LIST) BLOCK
933 # LABEL foreach VAR (LIST) BLOCK continue BLOCK
934 # The only two cases that have not been covered already are
935 # 'foreach ...' and 'foreach VAR ...'
936  
937 699 ▶ if ( $LastChild->isa('PPI::Token::Symbol') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($LastChild->isa("PPI::Token::Symbol")) 207 492 699
938 # LABEL foreach my $scalar ...
939 # Open round brace, or a quotewords
940 207 ▶ return 1 if $Token->isa('PPI::Token::Structure') && $Token->content eq '(';
Branch: 1 branch
BranchTrueFalseTotal
if $Token->isa("PPI::Token::Structure") and $Token->content eq "(" 191 16 207
Condition66%2/3
$Token->isa("PPI::Token::Structure") and $Token->content eq "("
!ll&&!rl&&r
160191
MC/DC50%1/2
$Token->isa("PPI::Token::Structure") and $Token->content eq "("
$Token->isa("PPI::Token::Structure") $Token->content eq "("
Truth table66%2/3
A and B
A= $Token->isa("PPI::Token::Structure")B= $Token->content eq "("
ABresult
0X0
100
111
941 16 ▶ return 1 if $Token->isa('PPI::Token::QuoteLike::Words');
Branch: 1 branch
BranchTrueFalseTotal
if $Token->isa("PPI::Token::QuoteLike::Words") 16 0 16
942 0 return '';
943 }
944  
945 492 ▶ if ( $LastChild->content eq 'foreach' or $LastChild->content eq 'for' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($LastChild->content eq "foreach" or $LastChild->content eq "for") 278 214 492
Condition100%3/3
$LastChild->content eq "foreach" or $LastChild->content eq "for"
l!l&&r!l&&!r
171107214
MC/DC100%2/2
$LastChild->content eq "foreach" or $LastChild->content eq "for"
$LastChild->content eq "foreach" $LastChild->content eq "for"
Truth table100%3/3
A or B
A= $LastChild->content eq "foreach"B= $LastChild->content eq "for"
ABresult
1X1
011
000
946 # There are three possibilities here
947 278 ▶ if (
Branch: 4 branches
BranchTrueFalseTotal
if ($Token->isa('PPI::Token::Word') and ($STATEMENT_CLASSES{$Token->content} || '') eq 'PPI::Statement::Variable') { } 193 85 278
elsif ($Token->content =~ /^\$/) { } 34 51 85
elsif ($Token->isa('PPI::Token::Structure') and $Token->content eq '(') { } 42 9 51
elsif ($Token->isa('PPI::Token::QuoteLike::Words')) { } 6 3 9
Condition100%5/5
$Token->isa("PPI::Token::Word") and ($STATEMENT_CLASSES{$Token->content} || "") eq "PPI::Statement::Variable"
!ll&&!rl&&r
832193
$STATEMENT_CLASSES{$Token->content} || ''
l!l
1932
MC/DC100%2/2
$Token->isa("PPI::Token::Word") and ($STATEMENT_CLASSES{$Token->content} || "") eq "PPI::Statement::Variable"
$Token->isa("PPI::Token::Word") $STATEMENT_CLASSES{$Token->content}
Truth table100%3/3
A and B
A= $Token->isa("PPI::Token::Word")B= $STATEMENT_CLASSES{$Token->content}
ABresult
0X0
100
111
948 $Token->isa('PPI::Token::Word')
949 and (
950 ($STATEMENT_CLASSES{ $Token->content } || '')
951 eq
952 'PPI::Statement::Variable'
953 )
954 ) {
955 # VAR == 'my ...'
956 193 return 1;
957 } elsif ( $Token->content =~ /^\$/ ) {
958 # VAR == '$scalar'
959 34 return 1;
960 ▶ } elsif ( $Token->isa('PPI::Token::Structure') and $Token->content eq '(' ) {
Condition66%2/3
$Token->isa("PPI::Token::Structure") and $Token->content eq "("
!ll&&!rl&&r
9042
MC/DC50%1/2
$Token->isa("PPI::Token::Structure") and $Token->content eq "("
$Token->isa("PPI::Token::Structure") $Token->content eq "("
Truth table66%2/3
A and B
A= $Token->isa("PPI::Token::Structure")B= $Token->content eq "("
ABresult
0X0
100
111
961 42 return 1;
962 } elsif ( $Token->isa('PPI::Token::QuoteLike::Words') ) {
963 6 return 1;
964 } else {
965 3 return '';
966 }
967 }
968  
969 214 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (($STATEMENT_CLASSES{$LastChild->content} || "") eq "PPI::Statement::Variable") 189 25 214
Condition100%2/2
$STATEMENT_CLASSES{$LastChild->content} || ''
l!l
18925
MC/DC100%1/1
$STATEMENT_CLASSES{$LastChild->content} || ''
$STATEMENT_CLASSES{$LastChild->content}
Truth table100%2/2
A
A= $STATEMENT_CLASSES{$LastChild->content}
Aresult
11
00
970 ($STATEMENT_CLASSES{ $LastChild->content } || '')
971 eq
972 'PPI::Statement::Variable'
973 ) {
974 # LABEL foreach my ...
975 # Only a scalar will do
976 189 return $Token->content =~ /^\$/;
977 }
978  
979 # Handle the rare for my $foo qw{bar} ... case
980 25 ▶ if ( $LastChild->isa('PPI::Token::QuoteLike::Words') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($LastChild->isa("PPI::Token::QuoteLike::Words")) 25 0 25
981 # LABEL for VAR QW ...
982 # LABEL foreach VAR QW ...
983 # Only a block will do
984 25 ▶ return $Token->isa('PPI::Token::Structure') && $Token->content eq '{';
Condition33%1/3
$Token->isa('PPI::Token::Structure') && $Token->content eq '{'
!ll&&!rl&&r
0025
MC/DC0%0/2
$Token->isa('PPI::Token::Structure') && $Token->content eq '{'
$Token->isa('PPI::Token::Structure') $Token->content eq '{'
Truth table33%1/3
A && B
A= $Token->isa('PPI::Token::Structure')B= $Token->content eq '{'
ABresult
0X0
100
111
985 }
986 }
987  
988 # Something we don't know about... what could it be
989 0 PPI::Exception->throw("Illegal state in '$type' compound statement");
990 }
991  
992  
993  
994  
995  
996 #####################################################################
997 # Lex Methods - Structure Object
998  
999 # Given a parent element, and a ( token to open a structure, determine
1000 # the class that the structure should be.
1001 sub _round {
1002 7850 ▶ my ($self, $Parent) = @_;
Subroutine _round: called CC=9 SCAR=22.0
1003 # my $self = shift;
1004 # my $Parent = _INSTANCE(shift, 'PPI::Node') or die "Bad param 1";
1005  
1006 # Get the last significant element in the parent
1007 7850 my $Element = $Parent->schild(-1);
1008 7850 ▶ if ( _INSTANCE($Element, 'PPI::Token::Word') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_INSTANCE($Element, "PPI::Token::Word")) 6328 1522 7850
1009 # Can it be determined because it is a keyword?
1010 6328 my $rclass = $ROUND{$Element->content};
1011 6328 ▶ return $rclass if $rclass;
Branch: 1 branch
BranchTrueFalseTotal
if $rclass 1308 5020 6328
1012 }
1013  
1014 # If we are part of a for or foreach statement, we are a ForLoop
1015 6542 ▶ if ( $Parent->isa('PPI::Statement::Compound') ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($Parent->isa('PPI::Statement::Compound')) { } 191 6351 6542
elsif ($Parent->isa('PPI::Statement::Given')) { } 3 6348 6351
elsif ($Parent->isa('PPI::Statement::When')) { } 3 6345 6348
1016 191 ▶ if ( $Parent->type =~ /^for(?:each)?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Parent->type =~ /^for(?:each)?$/) 191 0 191
1017 191 return 'PPI::Structure::For';
1018 }
1019 } elsif ( $Parent->isa('PPI::Statement::Given') ) {
1020 3 return 'PPI::Structure::Given';
1021 } elsif ( $Parent->isa('PPI::Statement::When') ) {
1022 3 return 'PPI::Structure::When';
1023 }
1024  
1025 # Otherwise, it must be a list
1026  
1027 # If the previous element is -> then we mark it as a dereference
1028 6345 ▶ if ( _INSTANCE($Element, 'PPI::Token::Operator') and $Element->content eq '->' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_INSTANCE($Element, "PPI::Token::Operator") and $Element->content eq "->") 6 6339 6345
Condition100%3/3
&_INSTANCE($Element, "PPI::Token::Operator") and $Element->content eq "->"
!ll&&!rl&&r
57066336
MC/DC100%2/2
&_INSTANCE($Element, "PPI::Token::Operator") and $Element->content eq "->"
&_INSTANCE($Element, "PPI::Token::Operator") $Element->content eq "->"
Truth table100%3/3
A and B
A= &_INSTANCE($Element, "PPI::Token::Operator")B= $Element->content eq "->"
ABresult
0X0
100
111
1029 6 $Element->{_dereference} = 1;
1030 }
1031  
1032 'PPI::Structure::List'
1033 6345 }
1034  
1035 # Given a parent element, and a [ token to open a structure, determine
1036 # the class that the structure should be.
1037 sub _square {
1038 2776 ▶ my ($self, $Parent) = @_;
Subroutine _square: called CC=12 SCAR=24.8
1039 # my $self = shift;
1040 # my $Parent = _INSTANCE(shift, 'PPI::Node') or die "Bad param 1";
1041  
1042 # Get the last significant element in the parent
1043 2776 my $Element = $Parent->schild(-1);
1044  
1045 # Is this a subscript, like $foo[1] or $foo{expr}
1046
1047 2776 ▶ if ( $Element ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Element) 2537 239 2776
1048 2537 ▶ if ( $Element->isa('PPI::Token::Operator') and $Element->content eq '->' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Element->isa("PPI::Token::Operator") and $Element->content eq "->") 392 2145 2537
Condition100%3/3
$Element->isa("PPI::Token::Operator") and $Element->content eq "->"
!ll&&!rl&&r
11121033392
MC/DC100%2/2
$Element->isa("PPI::Token::Operator") and $Element->content eq "->"
$Element->isa("PPI::Token::Operator") $Element->content eq "->"
Truth table100%3/3
A and B
A= $Element->isa("PPI::Token::Operator")B= $Element->content eq "->"
ABresult
0X0
100
111
1049 # $foo->[]
1050 392 $Element->{_dereference} = 1;
1051 392 return 'PPI::Structure::Subscript';
1052 }
1053 2145 ▶ if ( $Element->isa('PPI::Structure::Subscript') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Element->isa("PPI::Structure::Subscript")) 21 2124 2145
1054 # $foo{}[]
1055 21 return 'PPI::Structure::Subscript';
1056 }
1057 2124 ▶ if ( $Element->isa('PPI::Token::Symbol') and $Element->content =~ /^(?:\$|\@)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Element->isa("PPI::Token::Symbol") and $Element->content =~ /^(?:\$|\@)/) 738 1386 2124
Condition100%3/3
$Element->isa("PPI::Token::Symbol") and $Element->content =~ /^(?:\$|\@)/
!ll&&!rl&&r
136224738
MC/DC100%2/2
$Element->isa("PPI::Token::Symbol") and $Element->content =~ /^(?:\$|\@)/
$Element->isa("PPI::Token::Symbol") $Element->content =~ /^(?:\$|\@)/
Truth table100%3/3
A and B
A= $Element->isa("PPI::Token::Symbol")B= $Element->content =~ /^(?:\$|\@)/
ABresult
0X0
100
111
1058 # $foo[], @foo[]
1059 738 return 'PPI::Structure::Subscript';
1060 }
1061 1386 ▶ if ( $Element->isa('PPI::Token::Cast') and $Element->content =~ /^(?:\@|\%)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Element->isa("PPI::Token::Cast") and $Element->content =~ /^(?:\@|\%)/) 46 1340 1386
Condition100%3/3
$Element->isa("PPI::Token::Cast") and $Element->content =~ /^(?:\@|\%)/
!ll&&!rl&&r
1332846
MC/DC100%2/2
$Element->isa("PPI::Token::Cast") and $Element->content =~ /^(?:\@|\%)/
$Element->isa("PPI::Token::Cast") $Element->content =~ /^(?:\@|\%)/
Truth table100%3/3
A and B
A= $Element->isa("PPI::Token::Cast")B= $Element->content =~ /^(?:\@|\%)/
ABresult
0X0
100
111
1062 46 my $prior = $Parent->schild(-2);
1063 46 ▶ if ( $prior and $prior->isa('PPI::Token::Operator') and $prior->content eq '->' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prior and $prior->isa("PPI::Token::Operator") and $prior->content eq "->") 2 44 46
Condition100%6/6
$prior and $prior->isa("PPI::Token::Operator") and $prior->content eq "->"
!ll&&!rl&&r
4222
$prior and $prior->isa("PPI::Token::Operator")
!ll&&!rl&&r
29134
MC/DC100%3/3
$prior and $prior->isa("PPI::Token::Operator") and $prior->content eq "->"
$prior $prior->isa("PPI::Token::Operator") $prior->content eq "->"
Truth table100%4/4
A and B and C
A= $priorB= $prior->isa("PPI::Token::Operator")C= $prior->content eq "->"
ABCresult
0XX0
10X0
1100
1111
1064 # Postfix dereference: ->@[...] ->%[...]
1065 2 return 'PPI::Structure::Subscript';
1066 }
1067 }
1068 # FIXME - More cases to catch
1069 }
1070  
1071 # Otherwise, we assume that it's an anonymous arrayref constructor
1072 1623 'PPI::Structure::Constructor';
1073 }
1074  
1075 # Keyword -> Structure class maps
1076 63 my %CURLY_CLASSES = (
1077 # Blocks
1078 'sub' => 'PPI::Structure::Block',
1079 'grep' => 'PPI::Structure::Block',
1080 'map' => 'PPI::Structure::Block',
1081 'sort' => 'PPI::Structure::Block',
1082 'do' => 'PPI::Structure::Block',
1083 # rely on 'continue' + block being handled elsewhere
1084 # rely on 'eval' + block being handled elsewhere
1085  
1086 # Hash constructors
1087 'scalar' => 'PPI::Structure::Constructor',
1088 '=' => 'PPI::Structure::Constructor',
1089 '||=' => 'PPI::Structure::Constructor',
1090 '&&=' => 'PPI::Structure::Constructor',
1091 '//=' => 'PPI::Structure::Constructor',
1092 '||' => 'PPI::Structure::Constructor',
1093 '&&' => 'PPI::Structure::Constructor',
1094 '//' => 'PPI::Structure::Constructor',
1095 '?' => 'PPI::Structure::Constructor',
1096 ':' => 'PPI::Structure::Constructor',
1097 ',' => 'PPI::Structure::Constructor',
1098 '=>' => 'PPI::Structure::Constructor',
1099 '+' => 'PPI::Structure::Constructor', # per perlref
1100 'return' => 'PPI::Structure::Constructor', # per perlref
1101 'bless' => 'PPI::Structure::Constructor', # pragmatic --
1102 # perlfunc says first arg is a reference, and
1103 # bless {; ... } fails to compile.
1104 );
1105  
1106 63 my @CURLY_LOOKAHEAD_CLASSES = (
1107 {}, # not used
1108 {
1109 ';' => 'PPI::Structure::Block', # per perlref
1110 '}' => 'PPI::Structure::Constructor',
1111 },
1112 {
1113 '=>' => 'PPI::Structure::Constructor',
1114 },
1115 );
1116  
1117  
1118 # Given a parent element, and a { token to open a structure, determine
1119 # the class that the structure should be.
1120 sub _curly {
1121 10870 ▶ my ($self, $Parent) = @_;
Subroutine _curly: called CC=38 SCAR=36.5
1122 # my $self = shift;
1123 # my $Parent = _INSTANCE(shift, 'PPI::Node') or die "Bad param 1";
1124  
1125 # Get the last significant element in the parent
1126 10870 my $Element = $Parent->schild(-1);
1127 10870 ▶ my $content = $Element ? $Element->content : '';
Branch: 1 branch
BranchTrueFalseTotal
$Element ? : 10251 619 10870
1128  
1129 # Is this a subscript, like $foo[1] or $foo{expr}
1130 10870 ▶ if ( $Element ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Element) 10251 619 10870
1131 10251 ▶ if ( $content eq '->' and $Element->isa('PPI::Token::Operator') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content eq "->" and $Element->isa("PPI::Token::Operator")) 2046 8205 10251
Condition66%2/3
$content eq "->" and $Element->isa("PPI::Token::Operator")
!ll&&!rl&&r
820502046
MC/DC50%1/2
$content eq "->" and $Element->isa("PPI::Token::Operator")
$content eq "->" $Element->isa("PPI::Token::Operator")
Truth table66%2/3
A and B
A= $content eq "->"B= $Element->isa("PPI::Token::Operator")
ABresult
0X0
100
111
1132 # $foo->{}
1133 2046 $Element->{_dereference} = 1;
1134 2046 return 'PPI::Structure::Subscript';
1135 }
1136 8205 ▶ if ( $Element->isa('PPI::Structure::Subscript') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Element->isa("PPI::Structure::Subscript")) 73 8132 8205
1137 # $foo[]{}
1138 73 return 'PPI::Structure::Subscript';
1139 }
1140 8132 ▶ if ( $content =~ /^(?:\$|\@)/ and $Element->isa('PPI::Token::Symbol') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /^(?:\$|\@)/ and $Element->isa("PPI::Token::Symbol")) 538 7594 8132
Condition100%3/3
$content =~ /^(?:\$|\@)/ and $Element->isa("PPI::Token::Symbol")
!ll&&!rl&&r
7313281538
MC/DC100%2/2
$content =~ /^(?:\$|\@)/ and $Element->isa("PPI::Token::Symbol")
$content =~ /^(?:\$|\@)/ $Element->isa("PPI::Token::Symbol")
Truth table100%3/3
A and B
A= $content =~ /^(?:\$|\@)/B= $Element->isa("PPI::Token::Symbol")
ABresult
0X0
100
111
1141 # $foo{}, @foo{}
1142 538 return 'PPI::Structure::Subscript';
1143 }
1144 7594 ▶ if ( $Element->isa('PPI::Token::Cast') and $Element->content =~ /^(?:\@|\%|\*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Element->isa("PPI::Token::Cast") and $Element->content =~ /^(?:\@|\%|\*)/) 293 7301 7594
Condition100%3/3
$Element->isa("PPI::Token::Cast") and $Element->content =~ /^(?:\@|\%|\*)/
!ll&&!rl&&r
723566293
MC/DC100%2/2
$Element->isa("PPI::Token::Cast") and $Element->content =~ /^(?:\@|\%|\*)/
$Element->isa("PPI::Token::Cast") $Element->content =~ /^(?:\@|\%|\*)/
Truth table100%3/3
A and B
A= $Element->isa("PPI::Token::Cast")B= $Element->content =~ /^(?:\@|\%|\*)/
ABresult
0X0
100
111
1145 293 my $prior = $Parent->schild(-2);
1146 293 ▶ if ( $prior and $prior->isa('PPI::Token::Operator') and $prior->content eq '->' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prior and $prior->isa("PPI::Token::Operator") and $prior->content eq "->") 3 290 293
Condition100%6/6
$prior and $prior->isa("PPI::Token::Operator") and $prior->content eq "->"
!ll&&!rl&&r
226643
$prior and $prior->isa("PPI::Token::Operator")
!ll&&!rl&&r
8813867
MC/DC100%3/3
$prior and $prior->isa("PPI::Token::Operator") and $prior->content eq "->"
$prior $prior->isa("PPI::Token::Operator") $prior->content eq "->"
Truth table100%4/4
A and B and C
A= $priorB= $prior->isa("PPI::Token::Operator")C= $prior->content eq "->"
ABCresult
0XX0
10X0
1100
1111
1147 # Postfix dereference: ->@{...} ->%{...} ->*{...}
1148 3 return 'PPI::Structure::Subscript';
1149 }
1150 }
1151 7591 ▶ if ( $Element->isa('PPI::Structure::Block') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Element->isa("PPI::Structure::Block")) 5 7586 7591
1152 # deference - ${$hash_ref}{foo}
1153 # or even ${burfle}{foo}
1154 # hash slice - @{$hash_ref}{'foo', 'bar'}
1155 5 ▶ if ( my $prior = $Parent->schild(-2) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $prior = $Parent->schild(-2)) 5 0 5
1156 5 my $prior_content = $prior->content();
1157 5 ▶ $prior->isa( 'PPI::Token::Cast' )
Branch: 1 branch
BranchTrueFalseTotal
$prior->isa("PPI::Token::Cast") and $prior_content eq "\@" || $prior_content eq "\$" and return "PPI::Structure::Subscript" 2 3 5
Condition66%4/6
$prior->isa("PPI::Token::Cast") and $prior_content eq "\@" || $prior_content eq "\$"
!ll&&!rl&&r
302
$prior_content eq "\@" or $prior_content eq "\$"
l!l&&r!l&&!r
110
MC/DC33%1/3
$prior->isa("PPI::Token::Cast") and $prior_content eq "\@" || $prior_content eq "\$"
$prior->isa("PPI::Token::Cast") $prior_content eq "\@" $prior_content eq "\$"
Truth table50%2/4
A and B or C
A= $prior->isa("PPI::Token::Cast")B= $prior_content eq "\@"C= $prior_content eq "\$"
ABCresult
0XX0
1000
11X1
1011
1158 and ( $prior_content eq '@' ||
1159 $prior_content eq '$' )
1160 and return 'PPI::Structure::Subscript';
1161 }
1162 }
1163  
1164 # Are we the last argument of sub?
1165 # E.g.: 'sub foo {}', 'sub foo ($) {}'
1166 7589 ▶ return 'PPI::Structure::Block' if $Parent->isa('PPI::Statement::Sub');
Branch: 1 branch
BranchTrueFalseTotal
if $Parent->isa("PPI::Statement::Sub") 2290 5299 7589
1167  
1168 # Are we the second or third argument of package?
1169 # E.g.: 'package Foo {}' or 'package Foo v1.2.3 {}'
1170 5299 ▶ return 'PPI::Structure::Block'
Branch: 1 branch
BranchTrueFalseTotal
if $Parent->isa("PPI::Statement::Package") 1293 4006 5299
1171 if $Parent->isa('PPI::Statement::Package');
1172  
1173 4006 ▶ if ( $CURLY_CLASSES{$content} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CURLY_CLASSES{$content}) 823 3183 4006
1174 # Known type
1175 823 return $CURLY_CLASSES{$content};
1176 }
1177 }
1178  
1179 # Are we in a compound statement
1180 3802 ▶ if ( $Parent->isa('PPI::Statement::Compound') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Parent->isa("PPI::Statement::Compound")) 1854 1948 3802
1181 # We will only encounter blocks in compound statements
1182 1854 return 'PPI::Structure::Block';
1183 }
1184  
1185 # Are we the second or third argument of use
1186 1948 ▶ if ( $Parent->isa('PPI::Statement::Include') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Parent->isa("PPI::Statement::Include")) 53 1895 1948
1187 53 ▶ if ( $Parent->schildren == 2 ||
Branch: 1 branch
BranchTrueFalseTotal
if ($Parent->schildren == 2 or $Parent->schildren == 3 and $Parent->schild(2)->isa("PPI::Token::Number")) 53 0 53
Condition50%3/6
$Parent->schildren == 2 or $Parent->schildren == 3 and $Parent->schild(2)->isa("PPI::Token::Number")
l!l&&r!l&&!r
5210
$Parent->schildren == 3 and $Parent->schild(2)->isa("PPI::Token::Number")
!ll&&!rl&&r
001
MC/DC0%0/3
$Parent->schildren == 2 or $Parent->schildren == 3 and $Parent->schild(2)->isa("PPI::Token::Number")
$Parent->schildren == 2 $Parent->schildren == 3 $Parent->schild(2)->isa("PPI::Token::Number")
Truth table50%2/4
A or B and C
A= $Parent->schildren == 2B= $Parent->schildren == 3C= $Parent->schild(2)->isa("PPI::Token::Number")
ABCresult
1XX1
0111
00X0
0100
1188 $Parent->schildren == 3 &&
1189 $Parent->schild(2)->isa('PPI::Token::Number')
1190 ) {
1191 # This is something like use constant { ... };
1192 53 return 'PPI::Structure::Constructor';
1193 }
1194 }
1195  
1196 # Unless we are at the start of the statement, everything else should be a block
1197 ### FIXME This is possibly a bad choice, but will have to do for now.
1198 1895 ▶ return 'PPI::Structure::Block' if $Element;
Branch: 1 branch
BranchTrueFalseTotal
if $Element 1276 619 1895
1199  
1200 619 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($Parent->isa("PPI::Statement") and &_INSTANCE(scalar $Parent->parent, "PPI::Structure::List")) 165 454 619
Condition66%2/3
$Parent->isa("PPI::Statement") and &_INSTANCE(scalar $Parent->parent, "PPI::Structure::List")
!ll&&!rl&&r
0454165
MC/DC50%1/2
$Parent->isa("PPI::Statement") and &_INSTANCE(scalar $Parent->parent, "PPI::Structure::List")
$Parent->isa("PPI::Statement") &_INSTANCE(scalar $Parent->parent, "PPI::Structure::List")
Truth table66%2/3
A and B
A= $Parent->isa("PPI::Statement")B= &_INSTANCE(scalar $Parent->parent, "PPI::Structure::List")
ABresult
0X0
100
111
1201 $Parent->isa('PPI::Statement')
1202 and
1203 _INSTANCE($Parent->parent, 'PPI::Structure::List')
1204 ) {
1205 165 my $function = $Parent->parent->parent->schild(-2);
1206  
1207 # Special case: Are we the param of a core function
1208 # i.e. map({ $_ => 1 } @foo)
1209 165 ▶ return 'PPI::Structure::Block'
Branch: 1 branch
BranchTrueFalseTotal
if $function and $function->content =~ /^(?:map|grep|sort|eval|do)$/ 94 71 165
Condition100%3/3
$function and $function->content =~ /^(?:map|grep|sort|eval|do)$/
!ll&&!rl&&r
165594
MC/DC100%2/2
$function and $function->content =~ /^(?:map|grep|sort|eval|do)$/
$function $function->content =~ /^(?:map|grep|sort|eval|do)$/
Truth table100%3/3
A and B
A= $functionB= $function->content =~ /^(?:map|grep|sort|eval|do)$/
ABresult
0X0
100
111
1210 if $function and $function->content =~ /^(?:map|grep|sort|eval|do)$/;
1211  
1212 # If not part of a block print, list-embedded curlies are most likely constructors
1213 71 ▶ return 'PPI::Structure::Constructor'
Branch: 1 branch
BranchTrueFalseTotal
unless $function and $function->content =~ /^(?:print|say)$/ 65 6 71
Condition100%3/3
$function and $function->content =~ /^(?:print|say)$/
!ll&&!rl&&r
16496
MC/DC100%2/2
$function and $function->content =~ /^(?:print|say)$/
$function $function->content =~ /^(?:print|say)$/
Truth table100%3/3
A and B
A= $functionB= $function->content =~ /^(?:print|say)$/
ABresult
0X0
100
111
1214 if not $function or $function->content !~ /^(?:print|say)$/;
1215 }
1216  
1217 # We need to scan ahead.
1218 460 my $Next;
1219 460 my $position = 0;
1220 460 my @delayed;
1221 460 ▶ while ( $Next = $self->_get_token ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Next = $self->_get_token) 1112 84 1196
1222 1112 ▶ unless ( $Next->significant ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Next->significant) 187 925 1112
1223 187 push @delayed, $Next;
1224 187 next;
1225 }
1226  
1227 # If we are off the end of the lookahead array,
1228 925 ▶ if ( ++$position >= @CURLY_LOOKAHEAD_CLASSES ) {
Branch: 2 branches
BranchTrueFalseTotal
if (++$position >= @CURLY_LOOKAHEAD_CLASSES) { } 108 817 925
elsif (my $class = $CURLY_LOOKAHEAD_CLASSES[$position]{$Next->content}) { } 268 549 817
1229 # default to block.
1230 108 $self->_buffer( splice(@delayed), $Next );
1231 108 last;
1232 # If the content at this position is known
1233 } elsif ( my $class = $CURLY_LOOKAHEAD_CLASSES[$position]
1234 {$Next->content} ) {
1235 # return the associated class.
1236 268 $self->_buffer( splice(@delayed), $Next );
1237 268 return $class;
1238 }
1239  
1240 # Delay and continue
1241 549 push @delayed, $Next;
1242 }
1243  
1244 # Hit the end of the document, or bailed out, go with block
1245 192 $self->_buffer( splice(@delayed) );
1246 192 ▶ if ( ref $Parent eq 'PPI::Statement' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $Parent eq "PPI::Statement") 192 0 192
1247 192 bless $Parent, 'PPI::Statement::Compound';
1248 }
1249 192 return 'PPI::Structure::Block';
1250 }
1251  
1252  
1253 sub _lex_structure {
1254 21496 ▶ my ($self, $Structure) = @_;
Subroutine _lex_structure: called CC=10 SCAR=23.0
1255 # my $self = shift;
1256 # my $Structure = _INSTANCE(shift, 'PPI::Structure') or die "Bad param 1";
1257  
1258 # Start the processing loop
1259 21496 my $Token;
1260 21496 ▶ while ( ref($Token = $self->_get_token) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($Token = $self->_get_token)) 87204 1467 88671
1261 # Is this a direct type token
1262 87204 ▶ unless ( $Token->significant ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Token->significant) 41723 45481 87204
1263 41723 push @{$self->{delayed}}, $Token;
1264 # $self->_delay_element( $Token );
1265 41723 next;
1266 }
1267  
1268 # Anything other than a Structure starts a Statement
1269 45481 ▶ unless ( $Token->isa('PPI::Token::Structure') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Token->isa("PPI::Token::Structure")) 24958 20523 45481
1270 # Because _statement may well delay and rollback itself,
1271 # we need to add the delayed tokens early
1272 24958 $self->_add_delayed( $Structure );
1273  
1274 # Determine the class for the Statement and create it
1275 24958 my $Statement = $self->_statement($Structure, $Token)->new($Token);
1276  
1277 # Move the lexing down into the Statement
1278 24958 $self->_add_element( $Structure, $Statement );
1279 24958 $self->_lex_statement( $Statement );
1280  
1281 24958 next;
1282 }
1283  
1284 # Is this the opening of another structure directly inside us?
1285 20523 ▶ if ( $Token->__LEXER__opens ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Token->__LEXER__opens) 438 20085 20523
1286 # Rollback the Token, and recurse into the statement
1287 438 $self->_rollback( $Token );
1288 438 my $Statement = PPI::Statement->new;
1289 438 $self->_add_element( $Structure, $Statement );
1290 438 $self->_lex_statement( $Statement );
1291 438 next;
1292 }
1293  
1294 # Is this the close of a structure ( which would be an error )
1295 20085 ▶ if ( $Token->__LEXER__closes ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Token->__LEXER__closes) 20029 56 20085
1296 # Is this OUR closing structure
1297 20029 ▶ if ( $Token->content eq $Structure->start->__LEXER__opposite ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Token->content eq $Structure->start->__LEXER__opposite) 19421 608 20029
1298 # Add any delayed tokens, and the finishing token (the ugly way)
1299 19421 $self->_add_delayed( $Structure );
1300 19421 $Structure->{finish} = $Token;
1301 Scalar::Util::weaken(
1302 19421 $_PARENT{Scalar::Util::refaddr $Token} = $Structure
1303 );
1304  
1305 # Confirm that ForLoop structures are actually so, and
1306 # aren't really a list.
1307 19421 ▶ if ( $Structure->isa('PPI::Structure::For') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Structure->isa("PPI::Structure::For")) 229 19192 19421
1308 229 ▶ if ( 2 > scalar grep {
Branch: 1 branch
BranchTrueFalseTotal
if (2 > scalar grep({$_->isa("PPI::Statement");} $Structure->children)) 208 21 229
1309 590 $_->isa('PPI::Statement')
1310 } $Structure->children ) {
1311 208 bless($Structure, 'PPI::Structure::List');
1312 }
1313 }
1314 19421 return 1;
1315 }
1316  
1317 # Unmatched closing brace.
1318 # Either they typed the wrong thing, or haven't put
1319 # one at all. Either way it's an error we need to
1320 # somehow handle gracefully. For now, we'll treat it
1321 # as implicitly ending the structure. This causes the
1322 # least damage across the various reasons why this
1323 # might have happened.
1324 608 return $self->_rollback( $Token );
1325 }
1326  
1327 # It's a semi-colon on it's own, just inside the block.
1328 # This is a null statement.
1329 $self->_add_element(
1330 56 $Structure,
1331 PPI::Statement::Null->new($Token),
1332 );
1333 }
1334  
1335 # Is this an error
1336 1467 ▶ unless ( defined $Token ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Token) 0 1467 1467
1337 0 PPI::Exception->throw;
1338 }
1339  
1340 # No, it's just the end of file.
1341 # Add any insignificant trailing tokens.
1342 1467 $self->_add_delayed( $Structure );
1343 }
1344  
1345  
1346  
1347  
1348  
1349 #####################################################################
1350 # Support Methods
1351  
1352 # Get the next token for processing, handling buffering
1353 sub _get_token {
1354 439578 ▶ shift(@{$_[0]->{buffer}}) or $_[0]->{Tokenizer}->get_token;
Subroutine _get_token: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
shift @{$_[0]{"buffer"};} or $_[0]{"Tokenizer"}->get_token 363487 76091 439578
1355 }
1356  
1357 # Old long version of the above
1358 # my $self = shift;
1359 # # First from the buffer
1360 # if ( @{$self->{buffer}} ) {
1361 # return shift @{$self->{buffer}};
1362 # }
1363 #
1364 # # Then from the Tokenizer
1365 # $self->{Tokenizer}->get_token;
1366 # }
1367  
1368 # Delay the addition of insignificant elements.
1369 # This ended up being inlined.
1370 # sub _delay_element {
1371 # my $self = shift;
1372 # my $Element = _INSTANCE(shift, 'PPI::Element') or die "Bad param 1";
1373 # push @{ $_[0]->{delayed} }, $_[1];
1374 # }
1375  
1376 # Add an Element to a Node, including any delayed Elements
1377 sub _add_element {
1378 209039 ▶ my ($self, $Parent, $Element) = @_;
Subroutine _add_element: called CC=7 SCAR=20.9
1379 # my $self = shift;
1380 # my $Parent = _INSTANCE(shift, 'PPI::Node') or die "Bad param 1";
1381 # my $Element = _INSTANCE(shift, 'PPI::Element') or die "Bad param 2";
1382  
1383 # Handle a special case, where a statement is not fully resolved
1384 209039 ▶ if ( ref $Parent eq 'PPI::Statement'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $Parent eq "PPI::Statement" and my $first = $Parent->schild(0)) 56714 152325 209039
Condition100%3/3
ref $Parent eq "PPI::Statement" and my $first = $Parent->schild(0)
!ll&&!rl&&r
151132119356714
MC/DC100%2/2
ref $Parent eq "PPI::Statement" and my $first = $Parent->schild(0)
ref $Parent eq "PPI::Statement" my $first = $Parent->schild(0)
Truth table100%3/3
A and B
A= ref $Parent eq "PPI::Statement"B= my $first = $Parent->schild(0)
ABresult
0X0
100
111
1385 and my $first = $Parent->schild(0) ) {
1386 56714 ▶ if ( $first->isa('PPI::Token::Label')
Branch: 1 branch
BranchTrueFalseTotal
if ($first->isa("PPI::Token::Label") and not my $second = $Parent->schild(1)) 0 56714 56714
Condition33%1/3
$first->isa("PPI::Token::Label") and not my $second = $Parent->schild(1)
!ll&&!rl&&r
5671400
MC/DC0%0/2
$first->isa("PPI::Token::Label") and not my $second = $Parent->schild(1)
$first->isa("PPI::Token::Label") not my $second = $Parent->schild(1)
Truth table33%1/3
A and not(B)
A= $first->isa("PPI::Token::Label")B= not my $second = $Parent->schild(1)
ABresult
0X0
100
111
1387 and !(my $second = $Parent->schild(1)) ) {
1388 0 my $new_class = $STATEMENT_CLASSES{$second->content};
1389 # It's a labelled statement
1390 0 ▶ bless $Parent, $new_class if $new_class;
Branch: 1 branch
BranchTrueFalseTotal
if $new_class 0 0 0
1391 }
1392 }
1393  
1394 # Add first the delayed, from the front, then the passed element
1395 209039 foreach my $el ( @{$self->{delayed}} ) {
1396 Scalar::Util::weaken(
1397 56311 $_PARENT{Scalar::Util::refaddr $el} = $Parent
1398 );
1399 # Inlined $Parent->__add_element($el);
1400 }
1401 Scalar::Util::weaken(
1402 209039 $_PARENT{Scalar::Util::refaddr $Element} = $Parent
1403 );
1404 209039 push @{$Parent->{children}}, @{$self->{delayed}}, $Element;
1405  
1406 # Clear the delayed elements
1407 209039 $self->{delayed} = [];
1408 }
1409  
1410 # Specifically just add any delayed tokens, if any.
1411 sub _add_delayed {
1412 110786 ▶ my ($self, $Parent) = @_;
Subroutine _add_delayed: called CC=2 SCAR=6.9
1413 # my $self = shift;
1414 # my $Parent = _INSTANCE(shift, 'PPI::Node') or die "Bad param 1";
1415  
1416 # Add any delayed
1417 110786 foreach my $el ( @{$self->{delayed}} ) {
1418 Scalar::Util::weaken(
1419 52373 $_PARENT{Scalar::Util::refaddr $el} = $Parent
1420 );
1421 # Inlined $Parent->__add_element($el);
1422 }
1423 110786 push @{$Parent->{children}}, @{$self->{delayed}};
1424  
1425 # Clear the delayed elements
1426 110786 $self->{delayed} = [];
1427 }
1428  
1429 # Rollback the delayed tokens, plus any passed. Once all the tokens
1430 # have been moved back on to the buffer, the order should be.
1431 # <--- @{$self->{delayed}}, @_, @{$self->{buffer}} <----
1432 sub _rollback {
1433 50409 ▶ my $self = shift;
Subroutine _rollback: called CC=3 SCAR=11.0
1434  
1435 # First, put any passed objects back
1436 50409 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 40295 10114 50409
1437 40295 unshift @{$self->{buffer}}, splice @_;
1438 }
1439  
1440 # Then, put back anything delayed
1441 50409 ▶ if ( @{$self->{delayed}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"delayed"};}) 28191 22218 50409
1442 28191 unshift @{$self->{buffer}}, splice @{$self->{delayed}};
1443 }
1444  
1445 50409 1;
1446 }
1447  
1448 # Partial rollback, just return a single list to the buffer
1449 sub _buffer {
1450 568 ▶ my $self = shift;
Subroutine _buffer: called CC=2 SCAR=6.9
1451  
1452 # Put any passed objects back
1453 568 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 447 121 568
1454 447 unshift @{$self->{buffer}}, splice @_;
1455 }
1456  
1457 568 1;
1458 }
1459  
1460  
1461  
1462  
1463  
1464 #####################################################################
1465 # Error Handling
1466  
1467 # Set the error message
1468 sub _error {
1469 2 ▶ $errstr = $_[1];
Subroutine _error: called CC=1 SCAR=0.0
1470 2 undef;
1471 }
1472  
1473 # Clear the error message.
1474 # Returns the object as a convenience.
1475 sub _clear {
1476 15929 ▶ $errstr = '';
Subroutine _clear: called CC=1 SCAR=0.0
1477 15929 $_[0];
1478 }
1479  
1480 =pod
1481  
1482 =head2 errstr
1483  
1484 For any error that occurs, you can use the C<errstr>, as either
1485 a static or object method, to access the error message.
1486  
1487 If no error occurs for any particular action, C<errstr> will return false.
1488  
1489 =cut
1490  
1491 sub errstr {
1492 2 ▶ $errstr;
Subroutine errstr: called CC=1 SCAR=0.0
Pod documented
1493 }
1494  
1495  
1496  
1497  
1498  
1499 #####################################################################
1500 # PDOM Extensions
1501 #
1502 # This is something of a future expansion... ignore it for now :)
1503 #
1504 # use PPI::Statement::Sub ();
1505 #
1506 # sub PPI::Statement::Sub::__LEXER__normal { '' }
1507  
1508 63 1;
1509  
1510 =pod
1511  
1512 =head1 TO DO
1513  
1514 - Add optional support for some of the more common source filters
1515  
1516 - Some additional checks for blessing things into various Statement
1517 and Structure subclasses.
1518  
1519 =head1 SUPPORT
1520  
1521 See the L<support section|PPI/SUPPORT> in the main module.
1522  
1523 =head1 AUTHOR
1524  
1525 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
1526  
1527 =head1 COPYRIGHT
1528  
1529 Copyright 2001 - 2011 Adam Kennedy.
1530  
1531 This program is free software; you can redistribute
1532 it and/or modify it under the same terms as Perl itself.
1533  
1534 The full text of the license can be found in the
1535 LICENSE file included with this module.
1536  
1537 =cut
« PPI/Token/Unknown.pm ↑ Summary PPI/Statement/Compound.pm »