← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:11 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Statement.pm
StatementsExecuted 114591 statements in 377ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1053851179ms265msPPI::Statement::::newPPI::Statement::new
304151126.7ms26.7msPPI::Statement::::__LEXER__normalPPI::Statement::__LEXER__normal
1113.65ms3.71msPPI::Statement::::BEGIN@166PPI::Statement::BEGIN@166
1111.51ms1.85msPPI::Statement::::BEGIN@167PPI::Statement::BEGIN@167
111524µs632µsPPI::Statement::::BEGIN@175PPI::Statement::BEGIN@175
111440µs523µsPPI::Statement::::BEGIN@163PPI::Statement::BEGIN@163
111240µs793µsPPI::Statement::::BEGIN@170PPI::Statement::BEGIN@170
111233µs304µsPPI::Statement::::BEGIN@176PPI::Statement::BEGIN@176
111232µs300µsPPI::Statement::::BEGIN@169PPI::Statement::BEGIN@169
111208µs276µsPPI::Statement::::BEGIN@172PPI::Statement::BEGIN@172
111174µs242µsPPI::Statement::::BEGIN@165PPI::Statement::BEGIN@165
111164µs237µsPPI::Statement::::BEGIN@168PPI::Statement::BEGIN@168
111163µs234µsPPI::Statement::::BEGIN@164PPI::Statement::BEGIN@164
111159µs227µsPPI::Statement::::BEGIN@173PPI::Statement::BEGIN@173
111156µs223µsPPI::Statement::::BEGIN@162PPI::Statement::BEGIN@162
111152µs219µsPPI::Statement::::BEGIN@174PPI::Statement::BEGIN@174
11113µs13µsPPI::Statement::::BEGIN@156PPI::Statement::BEGIN@156
11112µs24µsPPI::Statement::::BEGIN@149PPI::Statement::BEGIN@149
11110µs39µsPPI::Statement::::BEGIN@151PPI::Statement::BEGIN@151
1116µs43µsPPI::Statement::::BEGIN@155PPI::Statement::BEGIN@155
1113µs3µsPPI::Statement::::BEGIN@171PPI::Statement::BEGIN@171
1113µs3µsPPI::Statement::::BEGIN@150PPI::Statement::BEGIN@150
1113µs3µsPPI::Statement::::BEGIN@152PPI::Statement::BEGIN@152
1113µs3µsPPI::Statement::::BEGIN@153PPI::Statement::BEGIN@153
0000s0sPPI::Statement::::_completePPI::Statement::_complete
0000s0sPPI::Statement::::insert_afterPPI::Statement::insert_after
0000s0sPPI::Statement::::insert_beforePPI::Statement::insert_before
0000s0sPPI::Statement::::labelPPI::Statement::label
0000s0sPPI::Statement::::specializedPPI::Statement::specialized
0000s0sPPI::Statement::::stablePPI::Statement::stable
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package PPI::Statement;
2
3=pod
4
5=head1 NAME
6
7PPI::Statement - The base class for Perl statements
8
9=head1 INHERITANCE
10
11 PPI::Statement
12 isa PPI::Node
13 isa PPI::Element
14
15=head1 DESCRIPTION
16
17PPI::Statement is the root class for all Perl statements. This includes (from
18L<perlsyn>) "Declarations", "Simple Statements" and "Compound Statements".
19
20The class PPI::Statement itself represents a "Simple Statement" as defined
21in the L<perlsyn> manpage.
22
23=head1 STATEMENT CLASSES
24
25Please note that unless documented themselves, these classes are yet to be
26frozen/finalised. Names may change slightly or be added or removed.
27
28=head2 L<PPI::Statement::Scheduled>
29
30This covers all "scheduled" blocks, chunks of code that are executed separately
31from the main body of the code, at a particular time. This includes all
32C<BEGIN>, C<CHECK>, C<UNITCHECK>, C<INIT> and C<END> blocks.
33
34=head2 L<PPI::Statement::Package>
35
36A package declaration, as defined in L<perlfunc|perlfunc/package>.
37
38=head2 L<PPI::Statement::Include>
39
40A statement that loads or unloads another module.
41
42This includes 'use', 'no', and 'require' statements.
43
44=head2 L<PPI::Statement::Sub>
45
46A named subroutine declaration, or forward declaration
47
48=head2 L<PPI::Statement::Variable>
49
50A variable declaration statement. This could be either a straight
51declaration or also be an expression.
52
53This includes all 'my', 'state', 'local' and 'our' statements.
54
55=head2 L<PPI::Statement::Compound>
56
57This covers the whole family of 'compound' statements, as described in
58L<perlsyn|perlsyn>.
59
60This includes all statements starting with 'if', 'unless', 'for', 'foreach'
61and 'while'. Note that this does NOT include 'do', as it is treated
62differently.
63
64All compound statements have implicit ends. That is, they do not end with
65a ';' statement terminator.
66
67=head2 L<PPI::Statement::Break>
68
69A statement that breaks out of a structure.
70
71This includes all of 'redo', 'next', 'last' and 'return' statements.
72
73=head2 L<PPI::Statement::Given>
74
75The kind of statement introduced in Perl 5.10 that starts with 'given'. This
76has an implicit end.
77
78=head2 L<PPI::Statement::When>
79
80The kind of statement introduced in Perl 5.10 that starts with 'when' or
81'default'. This also has an implicit end.
82
83=head2 L<PPI::Statement::Data>
84
85A special statement which encompasses an entire C<__DATA__> block, including
86the initial C<'__DATA__'> token itself and the entire contents.
87
88=head2 L<PPI::Statement::End>
89
90A special statement which encompasses an entire __END__ block, including
91the initial '__END__' token itself and the entire contents, including any
92parsed PPI::Token::POD that may occur in it.
93
94=head2 L<PPI::Statement::Expression>
95
96L<PPI::Statement::Expression> is a little more speculative, and is intended
97to help represent the special rules relating to "expressions" such as in:
98
99 # Several examples of expression statements
100
101 # Boolean conditions
102 if ( expression ) { ... }
103
104 # Lists, such as for arguments
105 Foo->bar( expression )
106
107=head2 L<PPI::Statement::Null>
108
109A null statement is a special case for where we encounter two consecutive
110statement terminators. ( ;; )
111
112The second terminator is given an entire statement of its own, but one
113that serves no purpose. Hence a 'null' statement.
114
115Theoretically, assuming a correct parsing of a perl file, all null statements
116are superfluous and should be able to be removed without damage to the file.
117
118But don't do that, in case PPI has parsed something wrong.
119
120=head2 L<PPI::Statement::UnmatchedBrace>
121
122Because L<PPI> is intended for use when parsing incorrect or incomplete code,
123the problem arises of what to do with a stray closing brace.
124
125Rather than die, it is allocated its own "unmatched brace" statement,
126which really means "unmatched closing brace". An unmatched open brace at the
127end of a file would become a structure with no contents and no closing brace.
128
129If the document loaded is intended to be correct and valid, finding a
130L<PPI::Statement::UnmatchedBrace> in the PDOM is generally indicative of a
131misparse.
132
133=head2 L<PPI::Statement::Unknown>
134
135This is used temporarily mid-parsing to hold statements for which the lexer
136cannot yet determine what class it should be, usually because there are
137insufficient clues, or it might be more than one thing.
138
139You should never encounter these in a fully parsed PDOM tree.
140
141=head1 METHODS
142
143C<PPI::Statement> itself has very few methods. Most of the time, you will be
144working with the more generic L<PPI::Element> or L<PPI::Node> methods, or one
145of the methods that are subclass-specific.
146
147=cut
148
149222µs236µs
# spent 24µs (12+12) within PPI::Statement::BEGIN@149 which was called: # once (12µs+12µs) by PPI::BEGIN@21 at line 149
use strict;
# spent 24µs making 1 call to PPI::Statement::BEGIN@149 # spent 12µs making 1 call to strict::import
150218µs13µs
# spent 3µs within PPI::Statement::BEGIN@150 which was called: # once (3µs+0s) by PPI::BEGIN@21 at line 150
use Scalar::Util ();
# spent 3µs making 1 call to PPI::Statement::BEGIN@150
151220µs269µs
# spent 39µs (10+30) within PPI::Statement::BEGIN@151 which was called: # once (10µs+30µs) by PPI::BEGIN@21 at line 151
use Params::Util qw{_INSTANCE};
# spent 39µs making 1 call to PPI::Statement::BEGIN@151 # spent 30µs making 1 call to Exporter::import
152215µs13µs
# spent 3µs within PPI::Statement::BEGIN@152 which was called: # once (3µs+0s) by PPI::BEGIN@21 at line 152
use PPI::Node ();
# spent 3µs making 1 call to PPI::Statement::BEGIN@152
153221µs13µs
# spent 3µs within PPI::Statement::BEGIN@153 which was called: # once (3µs+0s) by PPI::BEGIN@21 at line 153
use PPI::Exception ();
# spent 3µs making 1 call to PPI::Statement::BEGIN@153
154
155232µs280µs
# spent 43µs (6+37) within PPI::Statement::BEGIN@155 which was called: # once (6µs+37µs) by PPI::BEGIN@21 at line 155
use vars qw{$VERSION @ISA *_PARENT};
# spent 43µs making 1 call to PPI::Statement::BEGIN@155 # spent 37µs making 1 call to vars::import
156
# spent 13µs within PPI::Statement::BEGIN@156 which was called: # once (13µs+0s) by PPI::BEGIN@21 at line 160
BEGIN {
1571300ns $VERSION = '1.215';
15819µs @ISA = 'PPI::Node';
15914µs *_PARENT = *PPI::Element::_PARENT;
160114µs113µs}
# spent 13µs making 1 call to PPI::Statement::BEGIN@156
161
162294µs1223µs
# spent 223µs (156+67) within PPI::Statement::BEGIN@162 which was called: # once (156µs+67µs) by PPI::BEGIN@21 at line 162
use PPI::Statement::Break ();
# spent 223µs making 1 call to PPI::Statement::BEGIN@162
163296µs1523µs
# spent 523µs (440+83) within PPI::Statement::BEGIN@163 which was called: # once (440µs+83µs) by PPI::BEGIN@21 at line 163
use PPI::Statement::Compound ();
# spent 523µs making 1 call to PPI::Statement::BEGIN@163
164289µs1234µs
# spent 234µs (163+71) within PPI::Statement::BEGIN@164 which was called: # once (163µs+71µs) by PPI::BEGIN@21 at line 164
use PPI::Statement::Data ();
# spent 234µs making 1 call to PPI::Statement::BEGIN@164
1652101µs1242µs
# spent 242µs (174+68) within PPI::Statement::BEGIN@165 which was called: # once (174µs+68µs) by PPI::BEGIN@21 at line 165
use PPI::Statement::End ();
# spent 242µs making 1 call to PPI::Statement::BEGIN@165
166296µs13.71ms
# spent 3.71ms (3.65+67µs) within PPI::Statement::BEGIN@166 which was called: # once (3.65ms+67µs) by PPI::BEGIN@21 at line 166
use PPI::Statement::Expression ();
# spent 3.71ms making 1 call to PPI::Statement::BEGIN@166
16721.05ms11.85ms
# spent 1.85ms (1.51+340µs) within PPI::Statement::BEGIN@167 which was called: # once (1.51ms+340µs) by PPI::BEGIN@21 at line 167
use PPI::Statement::Include ();
# spent 1.85ms making 1 call to PPI::Statement::BEGIN@167
168294µs1237µs
# spent 237µs (164+73) within PPI::Statement::BEGIN@168 which was called: # once (164µs+73µs) by PPI::BEGIN@21 at line 168
use PPI::Statement::Null ();
# spent 237µs making 1 call to PPI::Statement::BEGIN@168
169298µs1300µs
# spent 300µs (232+68) within PPI::Statement::BEGIN@169 which was called: # once (232µs+68µs) by PPI::BEGIN@21 at line 169
use PPI::Statement::Package ();
# spent 300µs making 1 call to PPI::Statement::BEGIN@169
170295µs1793µs
# spent 793µs (240+554) within PPI::Statement::BEGIN@170 which was called: # once (240µs+554µs) by PPI::BEGIN@21 at line 170
use PPI::Statement::Scheduled ();
# spent 793µs making 1 call to PPI::Statement::BEGIN@170
171219µs13µs
# spent 3µs within PPI::Statement::BEGIN@171 which was called: # once (3µs+0s) by PPI::BEGIN@21 at line 171
use PPI::Statement::Sub ();
# spent 3µs making 1 call to PPI::Statement::BEGIN@171
172291µs1276µs
# spent 276µs (208+68) within PPI::Statement::BEGIN@172 which was called: # once (208µs+68µs) by PPI::BEGIN@21 at line 172
use PPI::Statement::Given ();
# spent 276µs making 1 call to PPI::Statement::BEGIN@172
173293µs1227µs
# spent 227µs (159+67) within PPI::Statement::BEGIN@173 which was called: # once (159µs+67µs) by PPI::BEGIN@21 at line 173
use PPI::Statement::UnmatchedBrace ();
# spent 227µs making 1 call to PPI::Statement::BEGIN@173
174287µs1219µs
# spent 219µs (152+66) within PPI::Statement::BEGIN@174 which was called: # once (152µs+66µs) by PPI::BEGIN@21 at line 174
use PPI::Statement::Unknown ();
# spent 219µs making 1 call to PPI::Statement::BEGIN@174
175292µs1632µs
# spent 632µs (524+108) within PPI::Statement::BEGIN@175 which was called: # once (524µs+108µs) by PPI::BEGIN@21 at line 175
use PPI::Statement::Variable ();
# spent 632µs making 1 call to PPI::Statement::BEGIN@175
1762463µs1304µs
# spent 304µs (233+71) within PPI::Statement::BEGIN@176 which was called: # once (233µs+71µs) by PPI::BEGIN@21 at line 176
use PPI::Statement::When ();
# spent 304µs making 1 call to PPI::Statement::BEGIN@176
177
178# "Normal" statements end at a statement terminator ;
179# Some are not, and need the more rigorous _continues to see
180# if we are at an implicit statement boundary.
1813041585.0ms
# spent 26.7ms within PPI::Statement::__LEXER__normal which was called 30415 times, avg 879ns/call: # 30415 times (26.7ms+0s) by PPI::Lexer::_lex_statement at line 626 of PPI/Lexer.pm, avg 879ns/call
sub __LEXER__normal { 1 }
182
- -
187#####################################################################
188# Constructor
189
190
# spent 265ms (179+86.4) within PPI::Statement::new which was called 10538 times, avg 25µs/call: # 7432 times (122ms+63.5ms) by PPI::Lexer::_lex_structure at line 1334 of PPI/Lexer.pm, avg 25µs/call # 3018 times (56.0ms+22.8ms) by PPI::Lexer::_lex_document at line 290 of PPI/Lexer.pm, avg 26µs/call # 81 times (450µs+65µs) by PPI::Lexer::_lex_structure at line 1347 of PPI/Lexer.pm, avg 6µs/call # 6 times (44µs+7µs) by PPI::Lexer::_lex_document at line 304 of PPI/Lexer.pm, avg 9µs/call # once (96µs+7µs) by PPI::Lexer::_lex_structure at line 1389 of PPI/Lexer.pm
sub new {
191105382.89ms my $class = shift;
192105381.30ms if ( ref $class ) {
193 PPI::Exception->throw;
194 }
195
196 # Create the object
1971053817.9ms my $self = bless {
198 children => [],
199 }, $class;
200
201 # If we have been passed what should be an initial token, add it
202105381.35ms my $token = shift;
20310538117ms3144074.7ms if ( _INSTANCE($token, 'PPI::Token') ) {
# spent 60.4ms making 10538 calls to Params::Util::_INSTANCE, avg 6µs/call # spent 7.69ms making 10451 calls to UNIVERSAL::isa, avg 736ns/call # spent 6.54ms making 10451 calls to PPI::Util::TRUE, avg 626ns/call
204 # Inlined $self->__add_element(shift);
2051045195.8ms2090219.4ms Scalar::Util::weaken(
# spent 11.9ms making 10451 calls to Scalar::Util::weaken, avg 1µs/call # spent 7.47ms making 10451 calls to Scalar::Util::refaddr, avg 715ns/call
206 $_PARENT{Scalar::Util::refaddr $token} = $self
207 );
2081045110.1ms push @{$self->{children}}, $token;
209 }
210
2111053843.3ms $self;
212}
213
214=pod
215
216=head2 label
217
218One factor common to most statements is their ability to be labeled.
219
220The C<label> method returns the label for a statement, if one has been
221defined, but without the trailing colon. Take the following example
222
223 MYLABEL: while ( 1 .. 10 ) { last MYLABEL if $_ > 5 }
224
225For the above statement, the C<label> method would return 'MYLABEL'.
226
227Returns false if the statement does not have a label.
228
229=cut
230
231sub label {
232 my $first = shift->schild(1) or return '';
233 $first->isa('PPI::Token::Label')
234 ? substr($first, 0, length($first) - 1)
235 : '';
236}
237
238=pod
239
240=head2 specialized
241
242Answer whether this is a plain statement or one that has more
243significance.
244
245Returns true if the statement is a subclass of this one, false
246otherwise.
247
248=begin testing specialized 22
249
250my $Document = PPI::Document->new(\<<'END_PERL');
251package Foo;
252use strict;
253;
254while (1) { last; }
255BEGIN { }
256sub foo { }
257state $x;
258$x = 5;
259END_PERL
260
261isa_ok( $Document, 'PPI::Document' );
262
263my $statements = $Document->find('Statement');
264is( scalar @{$statements}, 10, 'Found the 10 test statements' );
265
266isa_ok( $statements->[0], 'PPI::Statement::Package', 'Statement 1: isa Package' );
267ok( $statements->[0]->specialized, 'Statement 1: is specialized' );
268isa_ok( $statements->[1], 'PPI::Statement::Include', 'Statement 2: isa Include' );
269ok( $statements->[1]->specialized, 'Statement 2: is specialized' );
270isa_ok( $statements->[2], 'PPI::Statement::Null', 'Statement 3: isa Null' );
271ok( $statements->[2]->specialized, 'Statement 3: is specialized' );
272isa_ok( $statements->[3], 'PPI::Statement::Compound', 'Statement 4: isa Compound' );
273ok( $statements->[3]->specialized, 'Statement 4: is specialized' );
274isa_ok( $statements->[4], 'PPI::Statement::Expression', 'Statement 5: isa Expression' );
275ok( $statements->[4]->specialized, 'Statement 5: is specialized' );
276isa_ok( $statements->[5], 'PPI::Statement::Break', 'Statement 6: isa Break' );
277ok( $statements->[5]->specialized, 'Statement 6: is specialized' );
278isa_ok( $statements->[6], 'PPI::Statement::Scheduled', 'Statement 7: isa Scheduled' );
279ok( $statements->[6]->specialized, 'Statement 7: is specialized' );
280isa_ok( $statements->[7], 'PPI::Statement::Sub', 'Statement 8: isa Sub' );
281ok( $statements->[7]->specialized, 'Statement 8: is specialized' );
282isa_ok( $statements->[8], 'PPI::Statement::Variable', 'Statement 9: isa Variable' );
283ok( $statements->[8]->specialized, 'Statement 9: is specialized' );
284is( ref $statements->[9], 'PPI::Statement', 'Statement 10: is a simple Statement' );
285ok( ! $statements->[9]->specialized, 'Statement 10: is not specialized' );
286
287=end testing
288
289=cut
290
291# Yes, this is doing precisely what it's intending to prevent
292# client code from doing. However, since it's here, if the
293# implementation changes, code outside PPI doesn't care.
294sub specialized {
295 __PACKAGE__ ne ref $_[0];
296}
297
298=pod
299
300=head2 stable
301
302Much like the L<PPI::Document> method of the same name, the ->stable
303method converts a statement to source and back again, to determine if
304a modified statement is still legal, and won't be interpreted in a
305different way.
306
307Returns true if the statement is stable, false if not, or C<undef> on
308error.
309
310=cut
311
312sub stable {
313 die "The ->stable method has not yet been implemented";
314}
315
- -
320#####################################################################
321# PPI::Element Methods
322
323# Is the statement complete.
324# By default for a statement, we need a semi-colon at the end.
325sub _complete {
326 my $self = shift;
327 my $semi = $self->schild(-1);
328 return !! (
329 defined $semi
330 and
331 $semi->isa('PPI::Token::Structure')
332 and
333 $semi->content eq ';'
334 );
335}
336
337# You can insert either a statement or a non-significant token.
338sub insert_before {
339 my $self = shift;
340 my $Element = _INSTANCE(shift, 'PPI::Element') or return undef;
341 if ( $Element->isa('PPI::Statement') ) {
342 return $self->__insert_before($Element);
343 } elsif ( $Element->isa('PPI::Token') and ! $Element->significant ) {
344 return $self->__insert_before($Element);
345 }
346 '';
347}
348
349# As above, you can insert a statement, or a non-significant token
350sub insert_after {
351 my $self = shift;
352 my $Element = _INSTANCE(shift, 'PPI::Element') or return undef;
353 if ( $Element->isa('PPI::Statement') ) {
354 return $self->__insert_after($Element);
355 } elsif ( $Element->isa('PPI::Token') and ! $Element->significant ) {
356 return $self->__insert_after($Element);
357 }
358 '';
359}
360
36112µs1;
362
363=pod
364
365=head1 TO DO
366
367- Complete, freeze and document the remaining classes
368
369=head1 SUPPORT
370
371See the L<support section|PPI/SUPPORT> in the main module.
372
373=head1 AUTHOR
374
375Adam Kennedy E<lt>adamk@cpan.orgE<gt>
376
377=head1 COPYRIGHT
378
379Copyright 2001 - 2011 Adam Kennedy.
380
381This program is free software; you can redistribute
382it and/or modify it under the same terms as Perl itself.
383
384The full text of the license can be found in the
385LICENSE file included with this module.
386
387=cut