← 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:12 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Structure.pm
StatementsExecuted 198598 statements in 567ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1157811144ms735msPPI::Structure::::tokensPPI::Structure::tokens (recurses: max depth 6, inclusive time 664ms)
57891171.9ms139msPPI::Structure::::newPPI::Structure::new
623233271.5ms71.5msPPI::Structure::::startPPI::Structure::start
565342166.5ms66.5msPPI::Structure::::finishPPI::Structure::finish
22444440.6ms116msPPI::Structure::::contentPPI::Structure::content (recurses: max depth 5, inclusive time 46.0ms)
284112.27ms2.43msPPI::Structure::::bracesPPI::Structure::braces
111247┬Ás321┬ÁsPPI::Structure::::BEGIN@109PPI::Structure::BEGIN@109
2322218┬Ás484┬ÁsPPI::Structure::::locationPPI::Structure::location
111195┬Ás272┬ÁsPPI::Structure::::BEGIN@107PPI::Structure::BEGIN@107
111166┬Ás239┬ÁsPPI::Structure::::BEGIN@104PPI::Structure::BEGIN@104
111163┬Ás237┬ÁsPPI::Structure::::BEGIN@105PPI::Structure::BEGIN@105
111156┬Ás242┬ÁsPPI::Structure::::BEGIN@108PPI::Structure::BEGIN@108
111150┬Ás220┬ÁsPPI::Structure::::BEGIN@110PPI::Structure::BEGIN@110
111145┬Ás213┬ÁsPPI::Structure::::BEGIN@106PPI::Structure::BEGIN@106
111144┬Ás217┬ÁsPPI::Structure::::BEGIN@111PPI::Structure::BEGIN@111
111143┬Ás214┬ÁsPPI::Structure::::BEGIN@112PPI::Structure::BEGIN@112
231196┬Ás108┬ÁsPPI::Structure::::first_elementPPI::Structure::first_element
11113┬Ás25┬ÁsPPI::Structure::::BEGIN@91PPI::Structure::BEGIN@91
1119┬Ás9┬ÁsPPI::Structure::::BEGIN@98PPI::Structure::BEGIN@98
1119┬Ás48┬ÁsPPI::Structure::::BEGIN@97PPI::Structure::BEGIN@97
1117┬Ás29┬ÁsPPI::Structure::::BEGIN@93PPI::Structure::BEGIN@93
1113┬Ás3┬ÁsPPI::Structure::::BEGIN@92PPI::Structure::BEGIN@92
1113┬Ás3┬ÁsPPI::Structure::::BEGIN@95PPI::Structure::BEGIN@95
1113┬Ás3┬ÁsPPI::Structure::::BEGIN@94PPI::Structure::BEGIN@94
0000s0sPPI::Structure::::_completePPI::Structure::_complete
0000s0sPPI::Structure::::completePPI::Structure::complete
0000s0sPPI::Structure::::elementsPPI::Structure::elements
0000s0sPPI::Structure::::insert_afterPPI::Structure::insert_after
0000s0sPPI::Structure::::insert_beforePPI::Structure::insert_before
0000s0sPPI::Structure::::last_elementPPI::Structure::last_element
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package PPI::Structure;
2
3=pod
4
5=head1 NAME
6
7PPI::Structure - The base class for Perl braced structures
8
9=head1 INHERITANCE
10
11 PPI::Structure
12 isa PPI::Node
13 isa PPI::Element
14
15=head1 DESCRIPTION
16
17PPI::Structure is the root class for all Perl bracing structures. This
18covers all forms of C< [ ... ] >, C< { ... } >, and C< ( ... ) > brace
19types, and includes cases where only one half of the pair exist.
20
21The class PPI::Structure itself is full abstract and no objects of that
22type should actually exist in the tree.
23
24=head2 Elements vs Children
25
26A B<PPI::Structure> has an unusual existance. Unlike a L<PPI::Document>
27or L<PPI::Statement>, which both simply contain other elements, a
28structure B<both> contains and consists of content.
29
30That is, the brace tokens are B<not> considered to be "children" of the
31structure, but are part of it.
32
33In practice, this will mean that while the -E<gt>elements and -E<gt>tokens
34methods (and related) B<will> return a list with the brace tokens at either
35end, the -E<gt>children method explicitly will B<not> return the brace.
36
37=head1 STRUCTURE CLASSES
38
39Excluding the transient L<PPI::Structure::Unknown> that exists briefly
40inside the parser, there are eight types of structure.
41
42=head2 L<PPI::Structure::List>
43
44This covers all round braces used for function arguments, in C<foreach>
45loops, literal lists, and braces used for precedence-ordering purposes.
46
47=head2 L<PPI::Structure::For>
48
49Although B<not> used for the C<foreach> loop list, this B<is> used for
50the special case of the round-brace three-part semicolon-seperated C<for>
51loop expression (the traditional C style for loop).
52
53=head2 L<PPI::Structure::Given>
54
55This is for the expression being matched in switch statements.
56
57=head2 L<PPI::Structure::When>
58
59This is for the matching expression in "when" statements.
60
61=head2 L<PPI::Structure::Condition>
62
63This round-brace structure covers boolean conditional braces, such as
64for C<if> and C<while> blocks.
65
66=head2 L<PPI::Structure::Block>
67
68This curly-brace and common structure is used for all form of code
69blocks. This includes those for C<if>, C<do> and similar, as well
70as C<grep>, C<map>, C<sort>, C<sub> and (labelled or anonymous)
71scoping blocks.
72
73=head2 L<PPI::Structure::Constructor>
74
75This class covers brace structures used for the construction of
76anonymous C<ARRAY> and C<HASH> references.
77
78=head2 L<PPI::Structure::Subscript>
79
80This class covers square-braces and curly-braces used after a
81-E<gt> pointer to access the subscript of an C<ARRAY> or C<HASH>.
82
83=head1 METHODS
84
85C<PPI::Structure> itself has very few methods. Most of the time, you will be
86working with the more generic L<PPI::Element> or L<PPI::Node> methods, or one
87of the methods that are subclass-specific.
88
89=cut
90
91219┬Ás238┬Ás
# spent 25┬Ás (13+12) within PPI::Structure::BEGIN@91 which was called: # once (13┬Ás+12┬Ás) by PPI::BEGIN@22 at line 91
use strict;
# spent 25┬Ás making 1 call to PPI::Structure::BEGIN@91 # spent 12┬Ás making 1 call to strict::import
92218┬Ás13┬Ás
# spent 3┬Ás within PPI::Structure::BEGIN@92 which was called: # once (3┬Ás+0s) by PPI::BEGIN@22 at line 92
use Scalar::Util ();
# spent 3┬Ás making 1 call to PPI::Structure::BEGIN@92
93218┬Ás252┬Ás
# spent 29┬Ás (7+23) within PPI::Structure::BEGIN@93 which was called: # once (7┬Ás+23┬Ás) by PPI::BEGIN@22 at line 93
use Params::Util qw{_INSTANCE};
# spent 29┬Ás making 1 call to PPI::Structure::BEGIN@93 # spent 23┬Ás making 1 call to Exporter::import
94215┬Ás13┬Ás
# spent 3┬Ás within PPI::Structure::BEGIN@94 which was called: # once (3┬Ás+0s) by PPI::BEGIN@22 at line 94
use PPI::Node ();
# spent 3┬Ás making 1 call to PPI::Structure::BEGIN@94
95224┬Ás13┬Ás
# spent 3┬Ás within PPI::Structure::BEGIN@95 which was called: # once (3┬Ás+0s) by PPI::BEGIN@22 at line 95
use PPI::Exception ();
# spent 3┬Ás making 1 call to PPI::Structure::BEGIN@95
96
97233┬Ás286┬Ás
# spent 48┬Ás (9+39) within PPI::Structure::BEGIN@97 which was called: # once (9┬Ás+39┬Ás) by PPI::BEGIN@22 at line 97
use vars qw{$VERSION @ISA *_PARENT};
# spent 48┬Ás making 1 call to PPI::Structure::BEGIN@97 # spent 39┬Ás making 1 call to vars::import
98
# spent 9┬Ás within PPI::Structure::BEGIN@98 which was called: # once (9┬Ás+0s) by PPI::BEGIN@22 at line 102
BEGIN {
991300ns $VERSION = '1.215';
10015┬Ás @ISA = 'PPI::Node';
10114┬Ás *_PARENT = *PPI::Element::_PARENT;
102114┬Ás19┬Ás}
# spent 9┬Ás making 1 call to PPI::Structure::BEGIN@98
103
1042106┬Ás1239┬Ás
# spent 239┬Ás (166+73) within PPI::Structure::BEGIN@104 which was called: # once (166┬Ás+73┬Ás) by PPI::BEGIN@22 at line 104
use PPI::Structure::Block ();
# spent 239┬Ás making 1 call to PPI::Structure::BEGIN@104
105293┬Ás1237┬Ás
# spent 237┬Ás (163+74) within PPI::Structure::BEGIN@105 which was called: # once (163┬Ás+74┬Ás) by PPI::BEGIN@22 at line 105
use PPI::Structure::Condition ();
# spent 237┬Ás making 1 call to PPI::Structure::BEGIN@105
106288┬Ás1213┬Ás
# spent 213┬Ás (145+68) within PPI::Structure::BEGIN@106 which was called: # once (145┬Ás+68┬Ás) by PPI::BEGIN@22 at line 106
use PPI::Structure::Constructor ();
# spent 213┬Ás making 1 call to PPI::Structure::BEGIN@106
107286┬Ás1272┬Ás
# spent 272┬Ás (195+77) within PPI::Structure::BEGIN@107 which was called: # once (195┬Ás+77┬Ás) by PPI::BEGIN@22 at line 107
use PPI::Structure::For ();
# spent 272┬Ás making 1 call to PPI::Structure::BEGIN@107
108293┬Ás1242┬Ás
# spent 242┬Ás (156+86) within PPI::Structure::BEGIN@108 which was called: # once (156┬Ás+86┬Ás) by PPI::BEGIN@22 at line 108
use PPI::Structure::Given ();
# spent 242┬Ás making 1 call to PPI::Structure::BEGIN@108
109289┬Ás1321┬Ás
# spent 321┬Ás (247+74) within PPI::Structure::BEGIN@109 which was called: # once (247┬Ás+74┬Ás) by PPI::BEGIN@22 at line 109
use PPI::Structure::List ();
# spent 321┬Ás making 1 call to PPI::Structure::BEGIN@109
110292┬Ás1220┬Ás
# spent 220┬Ás (150+71) within PPI::Structure::BEGIN@110 which was called: # once (150┬Ás+71┬Ás) by PPI::BEGIN@22 at line 110
use PPI::Structure::Subscript ();
# spent 220┬Ás making 1 call to PPI::Structure::BEGIN@110
111291┬Ás1217┬Ás
# spent 217┬Ás (144+73) within PPI::Structure::BEGIN@111 which was called: # once (144┬Ás+73┬Ás) by PPI::BEGIN@22 at line 111
use PPI::Structure::Unknown ();
# spent 217┬Ás making 1 call to PPI::Structure::BEGIN@111
1122613┬Ás1214┬Ás
# spent 214┬Ás (143+71) within PPI::Structure::BEGIN@112 which was called: # once (143┬Ás+71┬Ás) by PPI::BEGIN@22 at line 112
use PPI::Structure::When ();
# spent 214┬Ás making 1 call to PPI::Structure::BEGIN@112
113
- -
118#####################################################################
119# Constructor
120
121
# spent 139ms (71.9+67.6) within PPI::Structure::new which was called 5789 times, avg 24┬Ás/call: # 5789 times (71.9ms+67.6ms) by PPI::Lexer::_lex_statement at line 650 of PPI/Lexer.pm, avg 24┬Ás/call
sub new {
12257891.82ms my $class = shift;
123578912.8ms578955.8ms my $Token = PPI::Token::__LEXER__opens($_[0]) ? shift : return undef;
# spent 55.8ms making 5789 calls to PPI::Token::__LEXER__opens, avg 10┬Ás/call
124
125 # Create the object
126578912.3ms my $self = bless {
127 children => [],
128 start => $Token,
129 }, $class;
130
131 # Set the start braces parent link
132578937.9ms1157811.8ms Scalar::Util::weaken(
# spent 6.88ms making 5789 calls to Scalar::Util::weaken, avg 1┬Ás/call # spent 4.95ms making 5789 calls to Scalar::Util::refaddr, avg 854ns/call
133 $_PARENT{Scalar::Util::refaddr $Token} = $self
134 );
135
136578911.6ms $self;
137}
138
- -
143#####################################################################
144# PPI::Structure API methods
145
146=pod
147
148=head2 start
149
150For lack of better terminology (like "open" and "close") that has not
151already in use for some other more important purpose, the two individual
152braces for the structure are known within PPI as the "start" and "finish"
153braces (at least for method purposes).
154
155The C<start> method returns the start brace for the structure (i.e. the
156opening brace).
157
158Returns the brace as a L<PPI::Token::Structure> or C<undef> if the
159structure does not have a starting brace.
160
161Under normal parsing circumstances this should never occur, but may happen
162due to manipulation of the PDOM tree.
163
164=cut
165
16662323168ms
# spent 71.5ms within PPI::Structure::start which was called 62323 times, avg 1┬Ás/call: # 45436 times (50.8ms+0s) by PPI::Node::find at line 395 of PPI/Node.pm, avg 1┬Ás/call # 11098 times (12.6ms+0s) by PPI::Node::find_first at line 452 of PPI/Node.pm, avg 1┬Ás/call # 5789 times (8.13ms+0s) by PPI::Lexer::_lex_structure at line 1356 of PPI/Lexer.pm, avg 1┬Ás/call
sub start { $_[0]->{start} }
167
168=pod
169
170=head2 finish
171
172The C<finish> method returns the finish brace for the structure (i.e. the
173closing brace).
174
175Returns the brace as a L<PPI::Token::Structure> or C<undef> if the
176structure does not have a finishing brace. This can be quite common if
177the document is not complete (for example, from an editor where the user
178may be halfway through typeing a subroutine).
179
180=cut
181
18256534134ms
# spent 66.5ms within PPI::Structure::finish which was called 56534 times, avg 1┬Ás/call: # 45436 times (53.3ms+0s) by PPI::Node::find at line 393 of PPI/Node.pm, avg 1┬Ás/call # 11098 times (13.2ms+0s) by PPI::Node::find_first at line 450 of PPI/Node.pm, avg 1┬Ás/call
sub finish { $_[0]->{finish} }
183
184=pod
185
186=head2 braces
187
188The C<braces> method is a utility method which returns the brace type,
189regardless of whether has both braces defined, or just the starting
190brace, or just the ending brace.
191
192Returns on of the three strings C<'[]'>, C<'{}'>, or C<'()'>, or C<undef>
193on error (primarily not having a start brace, as mentioned above).
194
195=cut
196
197
# spent 2.43ms (2.27+162┬Ás) within PPI::Structure::braces which was called 284 times, avg 9┬Ás/call: # 284 times (2.27ms+162┬Ás) by PPI::Lexer::_continues at line 805 of PPI/Lexer.pm, avg 9┬Ás/call
sub braces {
1982841.04ms284162┬Ás my $self = $_[0]->{start} ? shift : return undef;
# spent 162┬Ás making 284 calls to PPI::Util::TRUE, avg 571ns/call
199 return {
2002841.58ms '[' => '[]',
201 '(' => '()',
202 '{' => '{}',
203 }->{ $self->{start}->{content} };
204}
205
206=pod
207
208=head1 complete
209
210The C<complete> method is a convenience method that returns true if
211the both braces are defined for the structure, or false if only one
212brace is defined.
213
214Unlike the top level C<complete> method which checks for completeness
215in depth, the structure complete method ONLY confirms completeness
216for the braces, and does not recurse downwards.
217
218=cut
219
220sub complete {
221 !! ($_[0]->{start} and $_[0]->{finish});
222}
223
- -
228#####################################################################
229# PPI::Node overloaded methods
230
231# For us, the "elements" concept includes the brace tokens
232sub elements {
233 my $self = shift;
234
235 if ( wantarray ) {
236 # Return a list in array context
237 return ( $self->{start} || (), @{$self->{children}}, $self->{finish} || () );
238 } else {
239 # Return the number of elements in scalar context.
240 # This is memory-cheaper than creating another big array
241 return scalar(@{$self->{children}})
242 + ($self->{start} ? 1 : 0)
243 + ($self->{finish} ? 1 : 0);
244 }
245}
246
247# For us, the first element is probably the opening brace
248
# spent 108┬Ás (96+12) within PPI::Structure::first_element which was called 23 times, avg 5┬Ás/call: # 23 times (96┬Ás+12┬Ás) by PPI::Structure::location at line 264, avg 5┬Ás/call
sub first_element {
249 # Technically, if we have no children and no opening brace,
250 # then the first element is the closing brace.
25123126┬Ás2312┬Ás $_[0]->{start} or $_[0]->{children}->[0] or $_[0]->{finish};
# spent 12┬Ás making 23 calls to PPI::Util::TRUE, avg 513ns/call
252}
253
254# For us, the last element is probably the closing brace
255sub last_element {
256 # Technically, if we have no children and no closing brace,
257 # then the last element is the opening brace
258 $_[0]->{finish} or $_[0]->{children}->[-1] or $_[0]->{start};
259}
260
261# Location is same as the start token, if any
262
# spent 484┬Ás (218+266) within PPI::Structure::location which was called 23 times, avg 21┬Ás/call: # 15 times (140┬Ás+164┬Ás) by PPI::Element::logical_line_number at line 932 of PPI/Element.pm, avg 20┬Ás/call # 8 times (78┬Ás+102┬Ás) by PPI::Node::location at line 685 of PPI/Node.pm, avg 23┬Ás/call
sub location {
263239┬Ás my $self = shift;
26423109┬Ás46121┬Ás my $first = $self->first_element or return undef;
# spent 108┬Ás making 23 calls to PPI::Structure::first_element, avg 5┬Ás/call # spent 13┬Ás making 23 calls to PPI::Util::TRUE, avg 548ns/call
2652385┬Ás23145┬Ás $first->location;
# spent 145┬Ás making 23 calls to PPI::Element::location, avg 6┬Ás/call
266}
267
- -
272#####################################################################
273# PPI::Element overloaded methods
274
275# Get the full set of tokens, including start and finish
276
# spent 735ms (144+591) within PPI::Structure::tokens which was called 11578 times, avg 64┬Ás/call: # 11578 times (144ms+591ms) by PPI::Node::tokens at line 666 of PPI/Node.pm, avg 64┬Ás/call
sub tokens {
277115782.52ms my $self = shift;
27811578109ms3473413.2ms my @tokens = (
# spent 13.2ms making 23156 calls to PPI::Util::TRUE, avg 569ns/call # spent 1.24s making 11578 calls to PPI::Node::tokens, avg 107┬Ás/call, recursion: max depth 14, sum of overlapping time 1.24s
279 $self->{start} || (),
280 $self->SUPER::tokens(@_),
281 $self->{finish} || (),
282 );
2831157837.2ms @tokens;
284}
285
286# Like the token method ->content, get our merged contents.
287# This will recurse downwards through everything
288### Reimplement this using List::Utils stuff
289
# spent 116ms (40.6+75.0) within PPI::Structure::content which was called 2244 times, avg 51┬Ás/call: # 945 times (16.3ms+22.8ms) by Perl::Critic::Policy::Variables::ProhibitConditionalDeclarations::_is_conditional at line 50 of Perl/Critic/Policy/Variables/ProhibitConditionalDeclarations.pm, avg 41┬Ás/call # 724 times (11.8ms+-11.7ms) by PPI::Node::content at line 671 of PPI/Node.pm, avg 110ns/call # 568 times (12.0ms+58.2ms) by PPI::Lexer::_curly at line 1190 of PPI/Lexer.pm, avg 124┬Ás/call # 7 times (435┬Ás+5.75ms) by PPI::Statement::Compound::type at line 202 of PPI/Statement/Compound.pm, avg 883┬Ás/call
sub content {
2902244501┬Ás my $self = shift;
29122449.99ms44884.24ms my $content = $self->{start} ? $self->{start}->content : '';
# spent 2.97ms making 2244 calls to PPI::Token::content, avg 1┬Ás/call # spent 1.27ms making 2244 calls to PPI::Util::TRUE, avg 564ns/call
29222441.90ms foreach my $child ( @{$self->{children}} ) {
29341488.75ms414881.8ms $content .= $child->content;
# spent 110ms making 1929 calls to PPI::Node::content, avg 57┬Ás/call, recursion: max depth 5, sum of overlapping time 30.8ms # spent 3.02ms making 2219 calls to PPI::Token::content, avg 1┬Ás/call
294 }
29522449.33ms44884.18ms $content .= $self->{finish}->content if $self->{finish};
# spent 2.87ms making 2244 calls to PPI::Token::content, avg 1┬Ás/call # spent 1.31ms making 2244 calls to PPI::Util::TRUE, avg 586ns/call
29622444.83ms $content;
297}
298
299# Is the structure completed
300sub _complete {
301 !! ( defined $_[0]->{finish} );
302}
303
304# You can insert either another structure, or a token
305sub insert_before {
306 my $self = shift;
307 my $Element = _INSTANCE(shift, 'PPI::Element') or return undef;
308 if ( $Element->isa('PPI::Structure') ) {
309 return $self->__insert_before($Element);
310 } elsif ( $Element->isa('PPI::Token') ) {
311 return $self->__insert_before($Element);
312 }
313 '';
314}
315
316# As above, you can insert either another structure, or a token
317sub insert_after {
318 my $self = shift;
319 my $Element = _INSTANCE(shift, 'PPI::Element') or return undef;
320 if ( $Element->isa('PPI::Structure') ) {
321 return $self->__insert_after($Element);
322 } elsif ( $Element->isa('PPI::Token') ) {
323 return $self->__insert_after($Element);
324 }
325 '';
326}
327
32812┬Ás1;
329
330=pod
331
332=head1 SUPPORT
333
334See the L<support section|PPI/SUPPORT> in the main module.
335
336=head1 AUTHOR
337
338Adam Kennedy E<lt>adamk@cpan.orgE<gt>
339
340=head1 COPYRIGHT
341
342Copyright 2001 - 2011 Adam Kennedy.
343
344This program is free software; you can redistribute
345it and/or modify it under the same terms as Perl itself.
346
347The full text of the license can be found in the
348LICENSE file included with this module.
349
350=cut