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

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Token/Unknown.pm
StatementsExecuted 58731 statements in 95.8ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
81801183.0ms201msPPI::Token::Unknown::::__TOKENIZER__on_charPPI::Token::Unknown::__TOKENIZER__on_char
88441418.85ms8.85msPPI::Token::Unknown::::CORE:matchPPI::Token::Unknown::CORE:match (opcode)
2511345µs1.04msPPI::Token::Unknown::::__TOKENIZER__is_an_attributePPI::Token::Unknown::__TOKENIZER__is_an_attribute
10831280µs280µsPPI::Token::Unknown::::CORE:regcompPPI::Token::Unknown::CORE:regcomp (opcode)
11114µs16µsPPI::Token::Unknown::::BEGIN@35PPI::Token::Unknown::BEGIN@35
11111µs22µsPPI::Token::Unknown::::BEGIN@30PPI::Token::Unknown::BEGIN@30
1116µs45µsPPI::Token::Unknown::::BEGIN@34PPI::Token::Unknown::BEGIN@34
1113µs3µsPPI::Token::Unknown::::BEGIN@31PPI::Token::Unknown::BEGIN@31
1112µs2µsPPI::Token::Unknown::::BEGIN@32PPI::Token::Unknown::BEGIN@32
1112µs2µsPPI::Token::Unknown::::CORE:qrPPI::Token::Unknown::CORE:qr (opcode)
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package PPI::Token::Unknown;
2
3=pod
4
5=head1 NAME
6
7PPI::Token::Unknown - Token of unknown or as-yet undetermined type
8
9=head1 INHERITANCE
10
11 PPI::Token::Unknown
12 isa PPI::Token
13 isa PPI::Element
14
15=head1 DESCRIPTION
16
17Object of the type C<PPI::Token::Unknown> exist primarily inside the
18tokenizer, where they are temporarily brought into existing for a very
19short time to represent a token that could be one of a number of types.
20
21Generally, they only exist for a character or two, after which they are
22resolved and converted into the correct type. For an object of this type
23to survive the parsing process is considered a major bug.
24
25Please report any C<PPI::Token::Unknown> you encounter in a L<PPI::Document>
26object as a bug.
27
28=cut
29
30218µs233µs
# spent 22µs (11+11) within PPI::Token::Unknown::BEGIN@30 which was called: # once (11µs+11µs) by PPI::Token::Magic::BEGIN@46 at line 30
use strict;
# spent 22µs making 1 call to PPI::Token::Unknown::BEGIN@30 # spent 11µs making 1 call to strict::import
31215µs13µs
# spent 3µs within PPI::Token::Unknown::BEGIN@31 which was called: # once (3µs+0s) by PPI::Token::Magic::BEGIN@46 at line 31
use PPI::Token ();
# spent 3µs making 1 call to PPI::Token::Unknown::BEGIN@31
32221µs12µs
# spent 2µs within PPI::Token::Unknown::BEGIN@32 which was called: # once (2µs+0s) by PPI::Token::Magic::BEGIN@46 at line 32
use PPI::Exception ();
# spent 2µs making 1 call to PPI::Token::Unknown::BEGIN@32
33
34252µs283µs
# spent 45µs (6+39) within PPI::Token::Unknown::BEGIN@34 which was called: # once (6µs+39µs) by PPI::Token::Magic::BEGIN@46 at line 34
use vars qw{$VERSION @ISA $CURLY_SYMBOL};
# spent 45µs making 1 call to PPI::Token::Unknown::BEGIN@34 # spent 39µs making 1 call to vars::import
35
# spent 16µs (14+2) within PPI::Token::Unknown::BEGIN@35 which was called: # once (14µs+2µs) by PPI::Token::Magic::BEGIN@46 at line 39
BEGIN {
361300ns $VERSION = '1.215';
3715µs @ISA = 'PPI::Token';
3819µs12µs $CURLY_SYMBOL = qr{^\^[[:upper:]_]\w+\}};
# spent 2µs making 1 call to PPI::Token::Unknown::CORE:qr
391948µs116µs}
# spent 16µs making 1 call to PPI::Token::Unknown::BEGIN@35
40
- -
45#####################################################################
46# Tokenizer Methods
47
48
# spent 201ms (83.0+118) within PPI::Token::Unknown::__TOKENIZER__on_char which was called 8180 times, avg 25µs/call: # 8180 times (83.0ms+118ms) by PPI::Tokenizer::_process_next_char at line 554 of PPI/Tokenizer.pm, avg 25µs/call
sub __TOKENIZER__on_char {
4981801.45ms my $t = $_[1]; # Tokenizer object
5081804.02ms my $c = $t->{token}->{content}; # Current token
5181803.54ms my $char = substr( $t->{line}, $t->{line_cursor}, 1 ); # Current character
52
53 # Now, we split on the different values of the current content
5481803.65ms if ( $c eq '*' ) {
5529µs23µs if ( $char =~ /(?:(?!\d)\w|\:)/ ) {
# spent 3µs making 2 calls to PPI::Token::Unknown::CORE:match, avg 1µs/call
56 # Symbol (unless the thing before it is a number
5723µs220µs my $tokens = $t->_previous_significant_tokens(1);
# spent 20µs making 2 calls to PPI::Tokenizer::_previous_significant_tokens, avg 10µs/call
582600ns my $p0 = $tokens->[0];
59219µs45µs if ( $p0 and ! $p0->isa('PPI::Token::Number') ) {
# spent 4µs making 2 calls to UNIVERSAL::isa, avg 2µs/call # spent 2µs making 2 calls to PPI::Util::TRUE, avg 750ns/call
6024µs220µs $t->{class} = $t->{token}->set_class( 'Symbol' );
# spent 20µs making 2 calls to PPI::Token::set_class, avg 10µs/call
6125µs return 1;
62 }
63 }
64
65 if ( $char eq '{' ) {
66 # Get rest of line
67 my $rest = substr( $t->{line}, $t->{line_cursor} + 1 );
68 if ( $rest =~ m/$CURLY_SYMBOL/ ) {
69 # control-character symbol (e.g. *{^_Foo})
70 $t->{class} = $t->{token}->set_class( 'Magic' );
71 return 1;
72 } else {
73 # Obvious GLOB cast
74 $t->{class} = $t->{token}->set_class( 'Cast' );
75 return $t->_finalize_token->__TOKENIZER__on_char( $t );
76 }
77 }
78
79 if ( $char eq '$' ) {
80 # Operator/operand-sensitive, multiple or GLOB cast
81 my $_class = undef;
82 my $tokens = $t->_previous_significant_tokens(1);
83 my $p0 = $tokens->[0];
84 if ( $p0 ) {
85 # Is it a token or a number
86 if ( $p0->isa('PPI::Token::Symbol') ) {
87 $_class = 'Operator';
88 } elsif ( $p0->isa('PPI::Token::Number') ) {
89 $_class = 'Operator';
90 } elsif (
91 $p0->isa('PPI::Token::Structure')
92 and
93 $p0->content =~ /^(?:\)|\])$/
94 ) {
95 $_class = 'Operator';
96 } else {
97 ### This is pretty weak, there's
98 ### room for a dozen more tests
99 ### before going with a default.
100 ### Or even better, a proper
101 ### operator/operand method :(
102 $_class = 'Cast';
103 }
104 } else {
105 # Nothing before it, must be glob cast
106 $_class = 'Cast';
107 }
108
109 # Set class and rerun
110 $t->{class} = $t->{token}->set_class( $_class );
111 return $t->_finalize_token->__TOKENIZER__on_char( $t );
112 }
113
114 if ( $char eq '*' || $char eq '=' ) {
115 # Power operator '**' or mult-assign '*='
116 $t->{class} = $t->{token}->set_class( 'Operator' );
117 return 1;
118 }
119
120 $t->{class} = $t->{token}->set_class( 'Operator' );
121 return $t->_finalize_token->__TOKENIZER__on_char( $t );
122
- -
125 } elsif ( $c eq '$' ) {
126683725.7ms68377.28ms if ( $char =~ /[a-z_]/i ) {
# spent 7.28ms making 6837 calls to PPI::Token::Unknown::CORE:match, avg 1µs/call
127 # Symbol
128680212.5ms680287.5ms $t->{class} = $t->{token}->set_class( 'Symbol' );
# spent 87.5ms making 6802 calls to PPI::Token::set_class, avg 13µs/call
129680230.7ms return 1;
130 }
131
1323528µs if ( $PPI::Token::Magic::magic{ $c . $char } ) {
133 # Magic variable
1343464µs34319µs $t->{class} = $t->{token}->set_class( 'Magic' );
# spent 319µs making 34 calls to PPI::Token::set_class, avg 9µs/call
1353465µs return 1;
136 }
137
1381600ns if ( $char eq '{' ) {
139 # Get rest of line
14011µs my $rest = substr( $t->{line}, $t->{line_cursor} + 1 );
14119µs22µs if ( $rest =~ m/$CURLY_SYMBOL/ ) {
# spent 1µs making 1 call to PPI::Token::Unknown::CORE:regcomp # spent 700ns making 1 call to PPI::Token::Unknown::CORE:match
142 # control-character symbol (e.g. ${^MATCH})
143 $t->{class} = $t->{token}->set_class( 'Magic' );
144 return 1;
145 }
146 }
147
148 # Must be a cast
14912µs18µs $t->{class} = $t->{token}->set_class( 'Cast' );
# spent 8µs making 1 call to PPI::Token::set_class
15014µs222µs return $t->_finalize_token->__TOKENIZER__on_char( $t );
# spent 19µs making 1 call to PPI::Token::Whitespace::__TOKENIZER__on_char # spent 2µs making 1 call to PPI::Tokenizer::_finalize_token
151
- -
154 } elsif ( $c eq '@' ) {
1558882.78ms888890µs if ( $char =~ /[\w:]/ ) {
# spent 890µs making 888 calls to PPI::Token::Unknown::CORE:match, avg 1µs/call
156 # Symbol
1578031.55ms8037.07ms $t->{class} = $t->{token}->set_class( 'Symbol' );
# spent 7.07ms making 803 calls to PPI::Token::set_class, avg 9µs/call
1588031.57ms return 1;
159 }
160
1618576µs if ( $PPI::Token::Magic::magic{ $c . $char } ) {
162 # Magic variable
163 $t->{class} = $t->{token}->set_class( 'Magic' );
164 return 1;
165 }
166
1678551µs if ( $char eq '{' ) {
168 # Get rest of line
1698573µs my $rest = substr( $t->{line}, $t->{line_cursor} + 1 );
17085671µs170290µs if ( $rest =~ m/$CURLY_SYMBOL/ ) {
# spent 233µs making 85 calls to PPI::Token::Unknown::CORE:regcomp, avg 3µs/call # spent 57µs making 85 calls to PPI::Token::Unknown::CORE:match, avg 674ns/call
171 # control-character symbol (e.g. @{^_Foo})
172 $t->{class} = $t->{token}->set_class( 'Magic' );
173 return 1;
174 }
175 }
176
177 # Must be a cast
17885188µs85792µs $t->{class} = $t->{token}->set_class( 'Cast' );
# spent 792µs making 85 calls to PPI::Token::set_class, avg 9µs/call
17985358µs1702.00ms return $t->_finalize_token->__TOKENIZER__on_char( $t );
# spent 1.79ms making 85 calls to PPI::Token::Whitespace::__TOKENIZER__on_char, avg 21µs/call # spent 215µs making 85 calls to PPI::Tokenizer::_finalize_token, avg 3µs/call
180
- -
183 } elsif ( $c eq '%' ) {
184 # Is it a number?
185142436µs14299µs if ( $char =~ /\d/ ) {
# spent 99µs making 142 calls to PPI::Token::Unknown::CORE:match, avg 695ns/call
186 # This is %2 (modulus number)
187 $t->{class} = $t->{token}->set_class( 'Operator' );
188 return $t->_finalize_token->__TOKENIZER__on_char( $t );
189 }
190
191 # Is it a magic variable?
192142129µs if ( $char eq '^' || $PPI::Token::Magic::magic{ $c . $char } ) {
193 $t->{class} = $t->{token}->set_class( 'Magic' );
194 return 1;
195 }
196
197 # Is it a symbol?
198142378µs142120µs if ( $char =~ /[\w:]/ ) {
# spent 120µs making 142 calls to PPI::Token::Unknown::CORE:match, avg 843ns/call
199119277µs1191.15ms $t->{class} = $t->{token}->set_class( 'Symbol' );
# spent 1.15ms making 119 calls to PPI::Token::set_class, avg 10µs/call
200119247µs return 1;
201 }
202
2032310µs if ( $char eq '{' ) {
204 # Get rest of line
2052221µs my $rest = substr( $t->{line}, $t->{line_cursor} + 1 );
20622157µs4461µs if ( $rest =~ m/$CURLY_SYMBOL/ ) {
# spent 46µs making 22 calls to PPI::Token::Unknown::CORE:regcomp, avg 2µs/call # spent 15µs making 22 calls to PPI::Token::Unknown::CORE:match, avg 677ns/call
207 # control-character symbol (e.g. @{^_Foo})
208 $t->{class} = $t->{token}->set_class( 'Magic' );
209 return 1;
210 }
211 }
212
2132358µs2317µs if ( $char =~ /[\$@%*{]/ ) {
# spent 17µs making 23 calls to PPI::Token::Unknown::CORE:match, avg 752ns/call
214 # It's a cast
2152246µs22183µs $t->{class} = $t->{token}->set_class( 'Cast' );
# spent 183µs making 22 calls to PPI::Token::set_class, avg 8µs/call
2162295µs44483µs return $t->_finalize_token->__TOKENIZER__on_char( $t );
# spent 429µs making 22 calls to PPI::Token::Whitespace::__TOKENIZER__on_char, avg 20µs/call # spent 54µs making 22 calls to PPI::Tokenizer::_finalize_token, avg 2µs/call
217
218 }
219
220 # Probably the mod operator
22112µs18µs $t->{class} = $t->{token}->set_class( 'Operator' );
# spent 8µs making 1 call to PPI::Token::set_class
22213µs112µs return $t->{class}->__TOKENIZER__on_char( $t );
# spent 12µs making 1 call to PPI::Token::Operator::__TOKENIZER__on_char
223
- -
226 } elsif ( $c eq '&' ) {
227 # Is it a number?
228167493µs167118µs if ( $char =~ /\d/ ) {
# spent 118µs making 167 calls to PPI::Token::Unknown::CORE:match, avg 707ns/call
229 # This is &2 (bitwise-and number)
230 $t->{class} = $t->{token}->set_class( 'Operator' );
231 return $t->_finalize_token->__TOKENIZER__on_char( $t );
232 }
233
234 # Is it a symbol
235167360µs16787µs if ( $char =~ /[\w:]/ ) {
# spent 87µs making 167 calls to PPI::Token::Unknown::CORE:match, avg 522ns/call
2362857µs28263µs $t->{class} = $t->{token}->set_class( 'Symbol' );
# spent 263µs making 28 calls to PPI::Token::set_class, avg 9µs/call
2372856µs return 1;
238 }
239
240139246µs13949µs if ( $char =~ /[\$@%{]/ ) {
# spent 49µs making 139 calls to PPI::Token::Unknown::CORE:match, avg 351ns/call
241 # The ampersand is a cast
242 $t->{class} = $t->{token}->set_class( 'Cast' );
243 return $t->_finalize_token->__TOKENIZER__on_char( $t );
244 }
245
246 # Probably the binary and operator
247139301µs1395.50ms $t->{class} = $t->{token}->set_class( 'Operator' );
# spent 5.50ms making 139 calls to PPI::Token::set_class, avg 40µs/call
248139479µs139396µs return $t->{class}->__TOKENIZER__on_char( $t );
# spent 396µs making 139 calls to PPI::Token::Operator::__TOKENIZER__on_char, avg 3µs/call
249
- -
252 } elsif ( $c eq '-' ) {
253119326µs11978µs if ( $char =~ /\d/o ) {
# spent 78µs making 119 calls to PPI::Token::Unknown::CORE:match, avg 660ns/call
254 # Number
255919µs978µs $t->{class} = $t->{token}->set_class( 'Number' );
# spent 78µs making 9 calls to PPI::Token::set_class, avg 9µs/call
256918µs return 1;
257 }
258
25911031µs if ( $char eq '.' ) {
260 # Number::Float
261 $t->{class} = $t->{token}->set_class( 'Number::Float' );
262 return 1;
263 }
264
265110205µs11042µs if ( $char =~ /[a-zA-Z]/ ) {
# spent 42µs making 110 calls to PPI::Token::Unknown::CORE:match, avg 382ns/call
26623µs216µs $t->{class} = $t->{token}->set_class( 'DashedWord' );
# spent 16µs making 2 calls to PPI::Token::set_class, avg 8µs/call
26724µs return 1;
268 }
269
270 # The numeric negative operator
271108222µs108952µs $t->{class} = $t->{token}->set_class( 'Operator' );
# spent 952µs making 108 calls to PPI::Token::set_class, avg 9µs/call
272108372µs108319µs return $t->{class}->__TOKENIZER__on_char( $t );
# spent 319µs making 108 calls to PPI::Token::Operator::__TOKENIZER__on_char, avg 3µs/call
273
- -
276 } elsif ( $c eq ':' ) {
277258µs if ( $char eq ':' ) {
278 # ::foo style bareword
279 $t->{class} = $t->{token}->set_class( 'Word' );
280 return 1;
281 }
282
283 # Now, : acts very very differently in different contexts.
284 # Mainly, we need to find out if this is a subroutine attribute.
285 # We'll leave a hint in the token to indicate that, if it is.
2862550µs251.04ms if ( $_[0]->__TOKENIZER__is_an_attribute( $t ) ) {
# spent 1.04ms making 25 calls to PPI::Token::Unknown::__TOKENIZER__is_an_attribute, avg 42µs/call
287 # This : is an attribute indicator
288 $t->{class} = $t->{token}->set_class( 'Operator' );
289 $t->{token}->{_attribute} = 1;
290 return $t->_finalize_token->__TOKENIZER__on_char( $t );
291 }
292
293 # It MIGHT be a label, but its probably the ?: trinary operator
2942554µs25212µs $t->{class} = $t->{token}->set_class( 'Operator' );
# spent 212µs making 25 calls to PPI::Token::set_class, avg 8µs/call
2952575µs25325µs return $t->{class}->__TOKENIZER__on_char( $t );
# spent 325µs making 25 calls to PPI::Token::Operator::__TOKENIZER__on_char, avg 13µs/call
296 }
297
298 # erm...
299 PPI::Exception->throw('Unknown value in PPI::Token::Unknown token');
300}
301
302# Are we at a location where a ':' would indicate a subroutine attribute
303
# spent 1.04ms (345µs+694µs) within PPI::Token::Unknown::__TOKENIZER__is_an_attribute which was called 25 times, avg 42µs/call: # 25 times (345µs+694µs) by PPI::Token::Unknown::__TOKENIZER__on_char at line 286, avg 42µs/call
sub __TOKENIZER__is_an_attribute {
3042510µs my $t = $_[1]; # Tokenizer object
3052540µs25588µs my $tokens = $t->_previous_significant_tokens(3);
# spent 588µs making 25 calls to PPI::Tokenizer::_previous_significant_tokens, avg 24µs/call
3062511µs my $p0 = $tokens->[0];
307
308 # If we just had another attribute, we are also an attribute
30925113µs2544µs return 1 if $p0->isa('PPI::Token::Attribute');
# spent 44µs making 25 calls to UNIVERSAL::isa, avg 2µs/call
310
311 # If we just had a prototype, then we are an attribute
3122598µs2536µs return 1 if $p0->isa('PPI::Token::Prototype');
# spent 36µs making 25 calls to UNIVERSAL::isa, avg 1µs/call
313
314 # Other than that, we would need to have had a bareword
31525154µs2526µs return '' unless $p0->isa('PPI::Token::Word');
# spent 26µs making 25 calls to UNIVERSAL::isa, avg 1µs/call
316
317 # We could be an anonymous subroutine
318 if ( $p0->isa('PPI::Token::Word') and $p0->content eq 'sub' ) {
319 return 1;
320 }
321
322 # Or, we could be a named subroutine
323 my $p1 = $tokens->[1];
324 my $p2 = $tokens->[2];
325 if (
326 $p1->isa('PPI::Token::Word')
327 and
328 $p1->content eq 'sub'
329 and (
330 $p2->isa('PPI::Token::Structure')
331 or (
332 $p2->isa('PPI::Token::Whitespace')
333 and
334 $p2->content eq ''
335 )
336 )
337 ) {
338 return 1;
339 }
340
341 # We arn't an attribute
342 '';
343}
344
34512µs1;
346
347=pod
348
349=head1 SUPPORT
350
351See the L<support section|PPI/SUPPORT> in the main module.
352
353=head1 AUTHOR
354
355Adam Kennedy E<lt>adamk@cpan.orgE<gt>
356
357=head1 COPYRIGHT
358
359Copyright 2001 - 2011 Adam Kennedy.
360
361This program is free software; you can redistribute
362it and/or modify it under the same terms as Perl itself.
363
364The full text of the license can be found in the
365LICENSE file included with this module.
366
367=cut
 
# spent 8.85ms within PPI::Token::Unknown::CORE:match which was called 8844 times, avg 1µs/call: # 6837 times (7.28ms+0s) by PPI::Token::Unknown::__TOKENIZER__on_char at line 126, avg 1µs/call # 888 times (890µs+0s) by PPI::Token::Unknown::__TOKENIZER__on_char at line 155, avg 1µs/call # 167 times (118µs+0s) by PPI::Token::Unknown::__TOKENIZER__on_char at line 228, avg 707ns/call # 167 times (87µs+0s) by PPI::Token::Unknown::__TOKENIZER__on_char at line 235, avg 522ns/call # 142 times (120µs+0s) by PPI::Token::Unknown::__TOKENIZER__on_char at line 198, avg 843ns/call # 142 times (99µs+0s) by PPI::Token::Unknown::__TOKENIZER__on_char at line 185, avg 695ns/call # 139 times (49µs+0s) by PPI::Token::Unknown::__TOKENIZER__on_char at line 240, avg 351ns/call # 119 times (78µs+0s) by PPI::Token::Unknown::__TOKENIZER__on_char at line 253, avg 660ns/call # 110 times (42µs+0s) by PPI::Token::Unknown::__TOKENIZER__on_char at line 265, avg 382ns/call # 85 times (57µs+0s) by PPI::Token::Unknown::__TOKENIZER__on_char at line 170, avg 674ns/call # 23 times (17µs+0s) by PPI::Token::Unknown::__TOKENIZER__on_char at line 213, avg 752ns/call # 22 times (15µs+0s) by PPI::Token::Unknown::__TOKENIZER__on_char at line 206, avg 677ns/call # 2 times (3µs+0s) by PPI::Token::Unknown::__TOKENIZER__on_char at line 55, avg 1µs/call # once (700ns+0s) by PPI::Token::Unknown::__TOKENIZER__on_char at line 141
sub PPI::Token::Unknown::CORE:match; # opcode
# spent 2µs within PPI::Token::Unknown::CORE:qr which was called: # once (2µs+0s) by PPI::Token::Unknown::BEGIN@35 at line 38
sub PPI::Token::Unknown::CORE:qr; # opcode
# spent 280µs within PPI::Token::Unknown::CORE:regcomp which was called 108 times, avg 3µs/call: # 85 times (233µs+0s) by PPI::Token::Unknown::__TOKENIZER__on_char at line 170, avg 3µs/call # 22 times (46µs+0s) by PPI::Token::Unknown::__TOKENIZER__on_char at line 206, avg 2µs/call # once (1µs+0s) by PPI::Token::Unknown::__TOKENIZER__on_char at line 141
sub PPI::Token::Unknown::CORE:regcomp; # opcode