← 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