← 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/Whitespace.pm
StatementsExecuted 761603 statements in 1.43s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1400431713482ms2.23sPPI::Token::Whitespace::::__TOKENIZER__on_charPPI::Token::Whitespace::__TOKENIZER__on_char (recurses: max depth 1, inclusive time 164ms)
1508722179ms272msPPI::Token::Whitespace::::__TOKENIZER__on_line_startPPI::Token::Whitespace::__TOKENIZER__on_line_start
115422176119ms119msPPI::Token::Whitespace::::significantPPI::Token::Whitespace::significant
95491167.0ms94.4msPPI::Token::Whitespace::::__TOKENIZER__on_line_endPPI::Token::Whitespace::__TOKENIZER__on_line_end
458413128.0ms28.0msPPI::Token::Whitespace::::CORE:matchPPI::Token::Whitespace::CORE:match (opcode)
144111.60ms3.03msPPI::Token::Whitespace::::nullPPI::Token::Whitespace::null
11159µs59µsPPI::Token::Whitespace::::BEGIN@114PPI::Token::Whitespace::BEGIN@114
11112µs24µsPPI::Token::Whitespace::::BEGIN@44PPI::Token::Whitespace::BEGIN@44
1118µs8µsPPI::Token::Whitespace::::BEGIN@49PPI::Token::Whitespace::BEGIN@49
1118µs47µsPPI::Token::Whitespace::::BEGIN@113PPI::Token::Whitespace::BEGIN@113
1117µs42µsPPI::Token::Whitespace::::BEGIN@48PPI::Token::Whitespace::BEGIN@48
1113µs3µsPPI::Token::Whitespace::::BEGIN@45PPI::Token::Whitespace::BEGIN@45
1113µs3µsPPI::Token::Whitespace::::BEGIN@46PPI::Token::Whitespace::BEGIN@46
0000s0sPPI::Token::Whitespace::::tidyPPI::Token::Whitespace::tidy
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::Whitespace;
2
3=pod
4
5=head1 NAME
6
7PPI::Token::Whitespace - Tokens representing ordinary white space
8
9=head1 INHERITANCE
10
11 PPI::Token::Whitespace
12 isa PPI::Token
13 isa PPI::Element
14
15=head1 DESCRIPTION
16
17As a full "round-trip" parser, PPI records every last byte in a
18file and ensure that it is included in the L<PPI::Document> object.
19
20This even includes whitespace. In fact, Perl documents are seen
21as "floating in a sea of whitespace", and thus any document will
22contain vast quantities of C<PPI::Token::Whitespace> objects.
23
24For the most part, you shouldn't notice them. Or at least, you
25shouldn't B<have> to notice them.
26
27This means doing things like consistently using the "S for significant"
28series of L<PPI::Node> and L<PPI::Element> methods to do things.
29
30If you want the nth child element, you should be using C<schild> rather
31than C<child>, and likewise C<snext_sibling>, C<sprevious_sibling>, and
32so on and so forth.
33
34=head1 METHODS
35
36Again, for the most part you should really B<not> need to do anything
37very significant with whitespace.
38
39But there are a couple of convenience methods provided, beyond those
40provided by the parent L<PPI::Token> and L<PPI::Element> classes.
41
42=cut
43
44219µs236µs
# spent 24µs (12+12) within PPI::Token::Whitespace::BEGIN@44 which was called: # once (12µs+12µs) by PPI::Token::BEGIN@39 at line 44
use strict;
# spent 24µs making 1 call to PPI::Token::Whitespace::BEGIN@44 # spent 12µs making 1 call to strict::import
45216µs13µs
# spent 3µs within PPI::Token::Whitespace::BEGIN@45 which was called: # once (3µs+0s) by PPI::Token::BEGIN@39 at line 45
use Clone ();
# spent 3µs making 1 call to PPI::Token::Whitespace::BEGIN@45
46218µs13µs
# spent 3µs within PPI::Token::Whitespace::BEGIN@46 which was called: # once (3µs+0s) by PPI::Token::BEGIN@39 at line 46
use PPI::Token ();
# spent 3µs making 1 call to PPI::Token::Whitespace::BEGIN@46
47
48229µs277µs
# spent 42µs (7+35) within PPI::Token::Whitespace::BEGIN@48 which was called: # once (7µs+35µs) by PPI::Token::BEGIN@39 at line 48
use vars qw{$VERSION @ISA};
# spent 42µs making 1 call to PPI::Token::Whitespace::BEGIN@48 # spent 35µs making 1 call to vars::import
49
# spent 8µs within PPI::Token::Whitespace::BEGIN@49 which was called: # once (8µs+0s) by PPI::Token::BEGIN@39 at line 52
BEGIN {
501400ns $VERSION = '1.215';
51111µs @ISA = 'PPI::Token';
521104µs18µs}
# spent 8µs making 1 call to PPI::Token::Whitespace::BEGIN@49
53
54=pod
55
56=head2 null
57
58Because L<PPI> sees documents as sitting on a sort of substrate made of
59whitespace, there are a couple of corner cases that get particularly
60nasty if they don't find whitespace in certain places.
61
62Imagine walking down the beach to go into the ocean, and then quite
63unexpectedly falling off the side of the planet. Well it's somewhat
64equivalent to that, including the whole screaming death bit.
65
66The C<null> method is a convenience provided to get some internals
67out of some of these corner cases.
68
69Specifically it create a whitespace token that represents nothing,
70or at least the null string C<''>. It's a handy way to have some
71"whitespace" right where you need it, without having to have any
72actual characters.
73
74=cut
75
761300nsmy $null = undef;
77
78
# spent 3.03ms (1.60+1.44) within PPI::Token::Whitespace::null which was called 144 times, avg 21µs/call: # 144 times (1.60ms+1.44ms) by PPI::Tokenizer::_previous_significant_tokens at line 707 of PPI/Tokenizer.pm, avg 21µs/call
sub null {
791441.02ms144224µs $null ||= $_[0]->new('');
# spent 216µs making 143 calls to PPI::Util::TRUE, avg 2µs/call # spent 8µs making 1 call to PPI::Token::new
801442.17ms1441.21ms Clone::clone($null);
# spent 1.21ms making 144 calls to Clone::clone, avg 8µs/call
81}
82
83### XS -> PPI/XS.xs:_PPI_Token_Whitespace__significant 0.900+
84115422368ms
# spent 119ms within PPI::Token::Whitespace::significant which was called 115422 times, avg 1µs/call: # 27638 times (29.5ms+0s) by PPI::Lexer::_lex_statement at line 608 of PPI/Lexer.pm, avg 1µs/call # 25219 times (26.7ms+0s) by PPI::Element::snext_sibling at line 370 of PPI/Element.pm, avg 1µs/call # 14524 times (15.5ms+0s) by PPI::Lexer::_lex_structure at line 1321 of PPI/Lexer.pm, avg 1µs/call # 13592 times (13.8ms+0s) by PPI::Tokenizer::_previous_significant_tokens at line 699 of PPI/Tokenizer.pm, avg 1µs/call # 9921 times (10.0ms+0s) by PPI::Node::schild at line 282 of PPI/Node.pm, avg 1µs/call # 5893 times (5.53ms+0s) by PPI::Node::schildren at line 232 of PPI/Node.pm, avg 939ns/call # 5891 times (5.49ms+0s) by PPI::Node::schildren at line 229 of PPI/Node.pm, avg 933ns/call # 5248 times (5.48ms+0s) by PPI::Lexer::_lex_document at line 272 of PPI/Lexer.pm, avg 1µs/call # 4232 times (3.87ms+0s) by PPI::Statement::Variable::type at line 67 of PPI/Statement/Variable.pm, avg 915ns/call # 1022 times (969µs+0s) by PPI::Lexer::_statement at line 501 of PPI/Lexer.pm, avg 948ns/call # 981 times (1.10ms+0s) by PPI::Lexer::_statement at line 543 of PPI/Lexer.pm, avg 1µs/call # 385 times (386µs+0s) by PPI::Node::schild at line 277 of PPI/Node.pm, avg 1µs/call # 270 times (309µs+0s) by PPI::Element::sprevious_sibling at line 418 of PPI/Element.pm, avg 1µs/call # 205 times (209µs+0s) by Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions::_has_topic_side_effect at line 121 of Perl/Critic/Policy/ControlStructures/ProhibitMutatingListFunctions.pm, avg 1µs/call # 190 times (202µs+0s) by PPI::Lexer::_curly at line 1264 of PPI/Lexer.pm, avg 1µs/call # 159 times (161µs+0s) by PPI::Lexer::_statement at line 430 of PPI/Lexer.pm, avg 1µs/call # 52 times (54µs+0s) by PPI::Tokenizer::_last_significant_token at line 680 of PPI/Tokenizer.pm, avg 1µs/call
sub significant { '' }
85
86=pod
87
88=head2 tidy
89
90C<tidy> is a convenience method for removing unneeded whitespace.
91
92Specifically, it removes any whitespace from the end of a line.
93
94Note that this B<doesn't> include POD, where you may well need
95to keep certain types of whitespace. The entire POD chunk lives
96in its own L<PPI::Token::Pod> object.
97
98=cut
99
100sub tidy {
101 $_[0]->{content} =~ s/^\s+?(?>\n)//;
102 1;
103}
104
- -
109#####################################################################
110# Parsing Methods
111
112# Build the class and commit maps
1132208µs286µs
# spent 47µs (8+40) within PPI::Token::Whitespace::BEGIN@113 which was called: # once (8µs+40µs) by PPI::Token::BEGIN@39 at line 113
use vars qw{ @CLASSMAP @COMMITMAP %MATCHWORD };
# spent 47µs making 1 call to PPI::Token::Whitespace::BEGIN@113 # spent 40µs making 1 call to vars::import
114
# spent 59µs within PPI::Token::Whitespace::BEGIN@114 which was called: # once (59µs+0s) by PPI::Token::BEGIN@39 at line 150
BEGIN {
1151400ns @CLASSMAP = ();
1161100ns @COMMITMAP = ();
1171900ns foreach (
118 'a' .. 'u', 'w', 'y', 'z', 'A' .. 'Z', '_'
119 ) {
1205119µs $COMMITMAP[ord $_] = 'PPI::Token::Word';
121 }
12272µs foreach ( qw!; [ ] { } )! ) { $COMMITMAP[ord $_] = 'PPI::Token::Structure' }
123115µs foreach ( 0 .. 9 ) { $CLASSMAP[ord $_] = 'Number' }
124103µs foreach ( qw{= ? | + > . ! ~ ^} ) { $CLASSMAP[ord $_] = 'Operator' }
12572µs foreach ( qw{* $ @ & : %} ) { $CLASSMAP[ord $_] = 'Unknown' }
126
127 # Miscellaneous remainder
1281300ns $COMMITMAP[ord '#'] = 'PPI::Token::Comment';
1291200ns $COMMITMAP[ord 'v'] = 'PPI::Token::Number::Version';
1301200ns $CLASSMAP[ord ','] = 'PPI::Token::Operator';
1311100ns $CLASSMAP[ord "'"] = 'Quote::Single';
1321200ns $CLASSMAP[ord '"'] = 'Quote::Double';
1331200ns $CLASSMAP[ord '`'] = 'QuoteLike::Backtick';
1341200ns $CLASSMAP[ord '\\'] = 'Cast';
1351100ns $CLASSMAP[ord '_'] = 'Word';
1361200ns $CLASSMAP[9] = 'Whitespace'; # A horizontal tab
1371200ns $CLASSMAP[10] = 'Whitespace'; # A newline
1381100ns $CLASSMAP[13] = 'Whitespace'; # A carriage return
1391100ns $CLASSMAP[32] = 'Whitespace'; # A normal space
140
141 # Words (functions and keywords) after which a following / is
142 # almost certainly going to be a regex
143110µs %MATCHWORD = map { $_ => 1 } qw{
144 split
145 if
146 unless
147 grep
148 map
149 };
1501778µs159µs}
# spent 59µs making 1 call to PPI::Token::Whitespace::BEGIN@114
151
152
# spent 272ms (179+92.9) within PPI::Token::Whitespace::__TOKENIZER__on_line_start which was called 15087 times, avg 18µs/call: # 14943 times (177ms+92.5ms) by PPI::Tokenizer::_process_next_line at line 499 of PPI/Tokenizer.pm, avg 18µs/call # 144 times (1.80ms+440µs) by PPI::Token::BOM::__TOKENIZER__on_line_start at line 90 of PPI/Token/BOM.pm, avg 16µs/call
sub __TOKENIZER__on_line_start {
153150873.29ms my $t = $_[1];
154150873.81ms my $line = $t->{line};
155
156 # Can we classify the entire line in one go
15715087147ms4583828.0ms if ( $line =~ /^\s*$/ ) {
# spent 28.0ms making 45838 calls to PPI::Token::Whitespace::CORE:match, avg 611ns/call
158 # A whitespace line
15937244.52ms372434.9ms $t->_new_token( 'Whitespace', $line );
# spent 34.9ms making 3724 calls to PPI::Tokenizer::_new_token, avg 9µs/call
160372426.0ms return 0;
161
162 } elsif ( $line =~ /^\s*#/ ) {
163 # A comment line
16416682.00ms166826.3ms $t->_new_token( 'Comment', $line );
# spent 26.3ms making 1668 calls to PPI::Tokenizer::_new_token, avg 16µs/call
16516681.75ms16683.76ms $t->_finalize_token;
# spent 3.76ms making 1668 calls to PPI::Tokenizer::_finalize_token, avg 2µs/call
16616687.48ms return 0;
167
168 } elsif ( $line =~ /^=(\w+)/ ) {
169 # A Pod tag... change to pod mode
17022µs224µs $t->_new_token( 'Pod', $line );
# spent 24µs making 2 calls to PPI::Tokenizer::_new_token, avg 12µs/call
17122µs if ( $1 eq 'cut' ) {
172 # This is an error, but one we'll ignore
173 # Don't go into Pod mode, since =cut normally
174 # signals the end of Pod mode
175 } else {
17621µs $t->{class} = 'PPI::Token::Pod';
177 }
17824µs return 0;
179
180 } elsif ( $line =~ /^use v6\-alpha\;/ ) {
181 # Indicates a Perl 6 block. Make the initial
182 # implementation just suck in the entire rest of the
183 # file.
184 my @perl6 = ();
185 while ( 1 ) {
186 my $line6 = $t->_get_line;
187 last unless defined $line6;
188 push @perl6, $line6;
189 }
190 push @{ $t->{perl6} }, join '', @perl6;
191
192 # We only sucked in the block, we don't actially do
193 # anything to the "use v6..." line. So return as if
194 # we didn't find anything at all.
195 return 1;
196 }
197
198969343.2ms 1;
199}
200
201
# spent 2.23s (482ms+1.75) within PPI::Token::Whitespace::__TOKENIZER__on_char which was called 140043 times, avg 16µs/call: # 106218 times (325ms+1.54s) by PPI::Tokenizer::_process_next_char at line 554 of PPI/Tokenizer.pm, avg 18µs/call # 14291 times (79.0ms+-79.0ms) by PPI::Token::Word::__TOKENIZER__commit at line 539 of PPI/Token/Word.pm, avg 0s/call # 7437 times (24.5ms+194ms) by PPI::Token::Operator::__TOKENIZER__on_char at line 112 of PPI/Token/Operator.pm, avg 29µs/call # 7245 times (38.3ms+50.2ms) by PPI::Token::Symbol::__TOKENIZER__on_char at line 216 of PPI/Token/Symbol.pm, avg 12µs/call # 3157 times (9.34ms+18.3ms) by PPI::Token::Structure::__TOKENIZER__on_char at line 70 of PPI/Token/Structure.pm, avg 9µs/call # 832 times (2.83ms+8.42ms) by PPI::Token::Number::__TOKENIZER__on_char at line 125 of PPI/Token/Number.pm, avg 14µs/call # 509 times (2.10ms+7.38ms) by PPI::Token::Symbol::__TOKENIZER__on_char at line 174 of PPI/Token/Symbol.pm, avg 19µs/call # 148 times (689µs+6.10ms) by PPI::Token::Number::Float::__TOKENIZER__on_char at line 108 of PPI/Token/Number/Float.pm, avg 46µs/call # 85 times (360µs+1.43ms) by PPI::Token::Unknown::__TOKENIZER__on_char at line 179 of PPI/Token/Unknown.pm, avg 21µs/call # 61 times (137µs+0s) by PPI::Token::Cast::__TOKENIZER__on_char at line 51 of PPI/Token/Cast.pm, avg 2µs/call # 30 times (101µs+217µs) by PPI::Token::Magic::__TOKENIZER__on_char at line 228 of PPI/Token/Magic.pm, avg 11µs/call # 22 times (87µs+343µs) by PPI::Token::Unknown::__TOKENIZER__on_char at line 216 of PPI/Token/Unknown.pm, avg 20µs/call # 3 times (9µs+17µs) by PPI::Token::ArrayIndex::__TOKENIZER__on_char at line 56 of PPI/Token/ArrayIndex.pm, avg 8µs/call # 2 times (4µs+0s) by PPI::Token::DashedWord::__TOKENIZER__on_char at line 95 of PPI/Token/DashedWord.pm, avg 2µs/call # once (4µs+15µs) by PPI::Token::Unknown::__TOKENIZER__on_char at line 150 of PPI/Token/Unknown.pm # once (4µs+15µs) by PPI::Token::Magic::__TOKENIZER__on_char at line 170 of PPI/Token/Magic.pm # once (2µs+0s) by PPI::Token::HereDoc::__TOKENIZER__on_char at line 218 of PPI/Token/HereDoc.pm
sub __TOKENIZER__on_char {
20214004321.6ms my $t = $_[1];
20314004361.9ms my $char = ord substr $t->{line}, $t->{line_cursor}, 1;
204
205 # Do we definately know what something is?
206140043168ms292391.78s return $COMMITMAP[$char]->__TOKENIZER__commit($t) if $COMMITMAP[$char];
# spent 1.42s making 15152 calls to PPI::Token::Word::__TOKENIZER__commit, avg 94µs/call # spent 313ms making 13365 calls to PPI::Token::Structure::__TOKENIZER__commit, avg 23µs/call # spent 30.1ms making 336 calls to PPI::Token::Number::Version::__TOKENIZER__commit, avg 90µs/call # spent 7.72ms making 242 calls to PPI::Token::Comment::__TOKENIZER__commit, avg 32µs/call # spent 1.31ms making 144 calls to PPI::Element::DESTROY, avg 9µs/call
207
208 # Handle the simple option first
209110948419ms return $CLASSMAP[$char] if $CLASSMAP[$char];
210
21150772.14ms if ( $char == 40 ) { # $char eq '('
212 # Finalise any whitespace token...
21331575.58ms25043.60ms $t->_finalize_token if $t->{token};
# spent 2.71ms making 1252 calls to PPI::Tokenizer::_finalize_token, avg 2µs/call # spent 890µs making 1252 calls to PPI::Util::TRUE, avg 711ns/call
214
215 # Is this the beginning of a sub prototype?
216 # We are a sub prototype IF
217 # 1. The previous significant token is a bareword.
218 # 2. The one before that is the word 'sub'.
219 # 3. The one before that is a 'structure'
220
221 # Get the three previous significant tokens
22231573.74ms315786.2ms my $tokens = $t->_previous_significant_tokens(3);
# spent 86.2ms making 3157 calls to PPI::Tokenizer::_previous_significant_tokens, avg 27µs/call
22331571.22ms if ( $tokens ) {
224 # A normal subroutine declaration
2253157840µs my $p1 = $tokens->[1];
2263157452µs my $p2 = $tokens->[2];
227315719.7ms62266.96ms if (
# spent 6.78ms making 6110 calls to UNIVERSAL::isa, avg 1µs/call # spent 178µs making 116 calls to PPI::Token::content, avg 2µs/call
228 $tokens->[0]->isa('PPI::Token::Word')
229 and
230 $p1->isa('PPI::Token::Word')
231 and
232 $p1->content eq 'sub'
233 and (
234 $p2->isa('PPI::Token::Structure')
235 or (
236 $p2->isa('PPI::Token::Whitespace')
237 and
238 $p2->content eq ''
239 )
240 )
241 ) {
242 # This is a sub prototype
243 return 'Prototype';
244 }
245
246 # An prototyped anonymous subroutine
2473157911µs my $p0 = $tokens->[0];
248315722.2ms61106.81ms if ( $p0->isa('PPI::Token::Word') and $p0->content eq 'sub'
# spent 4.52ms making 2953 calls to PPI::Token::content, avg 2µs/call # spent 2.29ms making 3157 calls to UNIVERSAL::isa, avg 726ns/call
249 # Maybe it's invoking a method named 'sub'
250 and not ( $p1 and $p1->isa('PPI::Token::Operator') and $p1->content eq '->')
251 ) {
252 return 'Prototype';
253 }
254 }
255
256 # This is a normal open bracket
25731577.89ms return 'Structure';
258
259 } elsif ( $char == 60 ) { # $char eq '<'
260 # Finalise any whitespace token...
26151220µs102139µs $t->_finalize_token if $t->{token};
# spent 105µs making 51 calls to PPI::Tokenizer::_finalize_token, avg 2µs/call # spent 34µs making 51 calls to PPI::Util::TRUE, avg 675ns/call
262
263 # This is either "less than" or "readline quote-like"
264 # Do some context stuff to guess which.
2655184µs51577µs my $prev = $t->_last_significant_token;
# spent 577µs making 51 calls to PPI::Tokenizer::_last_significant_token, avg 11µs/call
266
267 # The most common group of less-thans are used like
268 # $foo < $bar
269 # 1 < $bar
270 # $#foo < $bar
27151252µs5162µs return 'Operator' if $prev->isa('PPI::Token::Symbol');
# spent 62µs making 51 calls to UNIVERSAL::isa, avg 1µs/call
2722390µs2328µs return 'Operator' if $prev->isa('PPI::Token::Magic');
# spent 28µs making 23 calls to UNIVERSAL::isa, avg 1µs/call
2732386µs2327µs return 'Operator' if $prev->isa('PPI::Token::Number');
# spent 27µs making 23 calls to UNIVERSAL::isa, avg 1µs/call
2742083µs2033µs return 'Operator' if $prev->isa('PPI::Token::ArrayIndex');
# spent 33µs making 20 calls to UNIVERSAL::isa, avg 2µs/call
275
276 # If it is <<... it's a here-doc instead
2772023µs my $next_char = substr( $t->{line}, $t->{line_cursor} + 1, 1 );
278209µs if ( $next_char eq '<' ) {
279 return 'Operator';
280 }
281
282 # The most common group of readlines are used like
283 # while ( <...> )
284 # while <>;
2851929µs1927µs my $prec = $prev->content;
# spent 27µs making 19 calls to PPI::Token::content, avg 1µs/call
2861969µs1917µs if ( $prev->isa('PPI::Token::Structure') and $prec eq '(' ) {
# spent 17µs making 19 calls to UNIVERSAL::isa, avg 884ns/call
287 return 'QuoteLike::Readline';
288 }
2891870µs1818µs if ( $prev->isa('PPI::Token::Word') and $prec eq 'while' ) {
# spent 18µs making 18 calls to UNIVERSAL::isa, avg 1µs/call
290 return 'QuoteLike::Readline';
291 }
2921883µs1818µs if ( $prev->isa('PPI::Token::Operator') and $prec eq '=' ) {
# spent 18µs making 18 calls to UNIVERSAL::isa, avg 1µs/call
293 return 'QuoteLike::Readline';
294 }
2951454µs1413µs if ( $prev->isa('PPI::Token::Operator') and $prec eq ',' ) {
# spent 13µs making 14 calls to UNIVERSAL::isa, avg 936ns/call
296 return 'QuoteLike::Readline';
297 }
298
2991446µs1410µs if ( $prev->isa('PPI::Token::Structure') and $prec eq '}' ) {
# spent 10µs making 14 calls to UNIVERSAL::isa, avg 714ns/call
300 # Could go either way... do a regex check
301 # $foo->{bar} < 2;
302 # grep { .. } <foo>;
30312µs my $line = substr( $t->{line}, $t->{line_cursor} );
304125µs117µs if ( $line =~ /^<(?!\d)\w+>/ ) {
# spent 17µs making 1 call to PPI::Token::Whitespace::CORE:match
305 # Almost definitely readline
306 return 'QuoteLike::Readline';
307 }
308 }
309
310 # Otherwise, we guess operator, which has been the default up
311 # until this more comprehensive section was created.
3121439µs return 'Operator';
313
314 } elsif ( $char == 47 ) { # $char eq '/'
315 # Finalise any whitespace token...
31617µs23µs $t->_finalize_token if $t->{token};
# spent 2µs making 1 call to PPI::Tokenizer::_finalize_token # spent 900ns making 1 call to PPI::Util::TRUE
317
318 # This is either a "divided by" or a "start regex"
319 # Do some context stuff to guess ( ack ) which.
320 # Hopefully the guess will be good enough.
32112µs111µs my $prev = $t->_last_significant_token;
# spent 11µs making 1 call to PPI::Tokenizer::_last_significant_token
32211µs12µs my $prec = $prev->content;
# spent 2µs making 1 call to PPI::Token::content
323
324 # Most times following an operator, we are a regex.
325 # This includes cases such as:
326 # , - As an argument in a list
327 # .. - The second condition in a flip flop
328 # =~ - A bound regex
329 # !~ - Ditto
330112µs11µs return 'Regexp::Match' if $prev->isa('PPI::Token::Operator');
# spent 1µs making 1 call to UNIVERSAL::isa
331
332 # After a symbol
333112µs11µs return 'Operator' if $prev->isa('PPI::Token::Symbol');
# spent 1µs making 1 call to UNIVERSAL::isa
3341100ns if ( $prec eq ']' and $prev->isa('PPI::Token::Structure') ) {
335 return 'Operator';
336 }
337
338 # After another number
33915µs11µs return 'Operator' if $prev->isa('PPI::Token::Number');
# spent 1µs making 1 call to UNIVERSAL::isa
340
341 # After going into scope/brackets
342111µs1900ns if (
# spent 900ns making 1 call to UNIVERSAL::isa
343 $prev->isa('PPI::Token::Structure')
344 and (
345 $prec eq '('
346 or
347 $prec eq '{'
348 or
349 $prec eq ';'
350 )
351 ) {
352 return 'Regexp::Match';
353 }
354
355 # Functions and keywords
35618µs11µs if (
# spent 1µs making 1 call to UNIVERSAL::isa
357 $MATCHWORD{$prec}
358 and
359 $prev->isa('PPI::Token::Word')
360 ) {
361 return 'Regexp::Match';
362 }
363
364 # Or as the very first thing in a file
365 return 'Regexp::Match' if $prec eq '';
366
367 # What about the char after the slash? There's some things
368 # that would be highly illogical to see if its an operator.
369 my $next_char = substr $t->{line}, $t->{line_cursor} + 1, 1;
370 if ( defined $next_char and length $next_char ) {
371 if ( $next_char =~ /(?:\^|\[|\\)/ ) {
372 return 'Regexp::Match';
373 }
374 }
375
376 # Otherwise... erm... assume operator?
377 # Add more tests here as potential cases come to light
378 return 'Operator';
379
380 } elsif ( $char == 120 ) { # $char eq 'x'
381 # Handle an arcane special case where "string"x10 means the x is an operator.
382 # String in this case means ::Single, ::Double or ::Execute, or the operator versions or same.
38322µs my $nextchar = substr $t->{line}, $t->{line_cursor} + 1, 1;
38422µs213µs my $prev = $t->_previous_significant_tokens(1);
# spent 13µs making 2 calls to PPI::Tokenizer::_previous_significant_tokens, avg 6µs/call
38522µs $prev = ref $prev->[0];
38626µs21µs if ( $nextchar =~ /\d/ and $prev ) {
# spent 1µs making 2 calls to PPI::Token::Whitespace::CORE:match, avg 500ns/call
387 if ( $prev =~ /::Quote::(?:Operator)?(?:Single|Double|Execute)$/ ) {
388 return 'Operator';
389 }
390 }
391
392 # Otherwise, commit like a normal bareword
39327µs2127µs return PPI::Token::Word->__TOKENIZER__commit($t);
# spent 127µs making 2 calls to PPI::Token::Word::__TOKENIZER__commit, avg 63µs/call
394
395 } elsif ( $char == 45 ) { # $char eq '-'
396 # Look for an obvious operator operand context
39718662.78ms186634.6ms my $context = $t->_opcontext;
# spent 34.6ms making 1866 calls to PPI::Tokenizer::_opcontext, avg 19µs/call
39818664.16ms if ( $context eq 'operator' ) {
399 return 'Operator';
400 } else {
401 # More logic needed
402119245µs return 'Unknown';
403 }
404
405 } elsif ( $char >= 128 ) { # Outside ASCII
406 return 'PPI::Token::Word'->__TOKENIZER__commit($t) if $t =~ /\w/;
407 return 'Whitespace' if $t =~ /\s/;
408 }
409
410
411 # All the whitespaces are covered, so what to do
412 ### For now, die
413 PPI::Exception->throw("Encountered unexpected character '$char'");
414}
415
416
# spent 94.4ms (67.0+27.4) within PPI::Token::Whitespace::__TOKENIZER__on_line_end which was called 9549 times, avg 10µs/call: # 9549 times (67.0ms+27.4ms) by PPI::Tokenizer::_process_next_line at line 518 of PPI/Tokenizer.pm, avg 10µs/call
sub __TOKENIZER__on_line_end {
417954973.6ms1909827.4ms $_[1]->_finalize_token if $_[1]->{token};
# spent 20.9ms making 9549 calls to PPI::Tokenizer::_finalize_token, avg 2µs/call # spent 6.50ms making 9549 calls to PPI::Util::TRUE, avg 681ns/call
418}
419
42012µs1;
421
422=pod
423
424=head1 SUPPORT
425
426See the L<support section|PPI/SUPPORT> in the main module.
427
428=head1 AUTHOR
429
430Adam Kennedy E<lt>adamk@cpan.orgE<gt>
431
432=head1 COPYRIGHT
433
434Copyright 2001 - 2011 Adam Kennedy.
435
436This program is free software; you can redistribute
437it and/or modify it under the same terms as Perl itself.
438
439The full text of the license can be found in the
440LICENSE file included with this module.
441
442=cut
 
# spent 28.0ms within PPI::Token::Whitespace::CORE:match which was called 45841 times, avg 611ns/call: # 45838 times (28.0ms+0s) by PPI::Token::Whitespace::__TOKENIZER__on_line_start at line 157, avg 611ns/call # 2 times (1µs+0s) by PPI::Token::Whitespace::__TOKENIZER__on_char at line 386, avg 500ns/call # once (17µs+0s) by PPI::Token::Whitespace::__TOKENIZER__on_char at line 304
sub PPI::Token::Whitespace::CORE:match; # opcode