← 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/Number.pm
StatementsExecuted 11431 statements in 18.2ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11701117.7ms38.4msPPI::Token::Number::::__TOKENIZER__on_charPPI::Token::Number::__TOKENIZER__on_char
2626311.80ms1.80msPPI::Token::Number::::CORE:matchPPI::Token::Number::CORE:match (opcode)
11112µs24µsPPI::Token::Number::::BEGIN@32PPI::Token::Number::BEGIN@32
1118µs8µsPPI::Token::Number::::BEGIN@36PPI::Token::Number::BEGIN@36
1116µs35µsPPI::Token::Number::::BEGIN@35PPI::Token::Number::BEGIN@35
1113µs3µsPPI::Token::Number::::BEGIN@33PPI::Token::Number::BEGIN@33
0000s0sPPI::Token::Number::::_literalPPI::Token::Number::_literal
0000s0sPPI::Token::Number::::basePPI::Token::Number::base
0000s0sPPI::Token::Number::::literalPPI::Token::Number::literal
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::Number;
2
3=pod
4
5=head1 NAME
6
7PPI::Token::Number - Token class for a number
8
9=head1 SYNOPSIS
10
11 $n = 1234; # decimal integer
12 $n = 0b1110011; # binary integer
13 $n = 01234; # octal integer
14 $n = 0x1234; # hexadecimal integer
15 $n = 12.34e-56; # exponential notation ( currently not working )
16
17=head1 INHERITANCE
18
19 PPI::Token::Number
20 isa PPI::Token
21 isa PPI::Element
22
23=head1 DESCRIPTION
24
25The C<PPI::Token::Number> class is used for tokens that represent numbers,
26in the various types that Perl supports.
27
28=head1 METHODS
29
30=cut
31
32219µs237µs
# spent 24µs (12+12) within PPI::Token::Number::BEGIN@32 which was called: # once (12µs+12µs) by PPI::Token::BEGIN@42 at line 32
use strict;
# spent 24µs making 1 call to PPI::Token::Number::BEGIN@32 # spent 12µs making 1 call to strict::import
33218µs13µs
# spent 3µs within PPI::Token::Number::BEGIN@33 which was called: # once (3µs+0s) by PPI::Token::BEGIN@42 at line 33
use PPI::Token ();
# spent 3µs making 1 call to PPI::Token::Number::BEGIN@33
34
35228µs264µs
# spent 35µs (6+29) within PPI::Token::Number::BEGIN@35 which was called: # once (6µs+29µs) by PPI::Token::BEGIN@42 at line 35
use vars qw{$VERSION @ISA};
# spent 35µs making 1 call to PPI::Token::Number::BEGIN@35 # spent 29µs making 1 call to vars::import
36
# spent 8µs within PPI::Token::Number::BEGIN@36 which was called: # once (8µs+0s) by PPI::Token::BEGIN@42 at line 39
BEGIN {
371300ns $VERSION = '1.215';
3818µs @ISA = 'PPI::Token';
391282µs18µs}
# spent 8µs making 1 call to PPI::Token::Number::BEGIN@36
40
41=pod
42
43=head2 base
44
45The C<base> method is provided by all of the ::Number subclasses.
46This is 10 for decimal, 16 for hexadecimal, 2 for binary, etc.
47
48=cut
49
50sub base {
51 return 10;
52}
53
54=pod
55
56=head2 literal
57
58Return the numeric value of this token.
59
60=cut
61
62sub literal {
63 return 0 + $_[0]->_literal;
64}
65
66sub _literal {
67 # De-sugar the string representation
68 my $self = shift;
69 my $string = $self->content;
70 $string =~ s/^\+//;
71 $string =~ s/_//g;
72 return $string;
73}
74
- -
79#####################################################################
80# Tokenizer Methods
81
82
# spent 38.4ms (17.7+20.7) within PPI::Token::Number::__TOKENIZER__on_char which was called 1170 times, avg 33µs/call: # 1170 times (17.7ms+20.7ms) by PPI::Tokenizer::_process_next_char at line 554 of PPI/Tokenizer.pm, avg 33µs/call
sub __TOKENIZER__on_char {
831170376µs my $class = shift;
841170223µs my $t = shift;
851170763µs my $char = substr( $t->{line}, $t->{line_cursor}, 1 );
86
87 # Allow underscores straight through
881170291µs return 1 if $char eq '_';
89
90 # Handle the conversion from an unknown to known type.
91 # The regex covers "potential" hex/bin/octal number.
921170317µs my $token = $t->{token};
9311707.13ms11701.02ms if ( $token->{content} =~ /^-?0_*$/ ) {
# spent 1.02ms making 1170 calls to PPI::Token::Number::CORE:match, avg 869ns/call
94 # This could be special
95286735µs286139µs if ( $char eq 'x' ) {
# spent 139µs making 286 calls to PPI::Token::Number::CORE:match, avg 486ns/call
96 $t->{class} = $t->{token}->set_class( 'Number::Hex' );
97 return 1;
98 } elsif ( $char eq 'b' ) {
99 $t->{class} = $t->{token}->set_class( 'Number::Binary' );
100 return 1;
101 } elsif ( $char =~ /\d/ ) {
102 # You cannot have 8s and 9s on octals
103 if ( $char eq '8' or $char eq '9' ) {
104 $token->{_error} = "Illegal character in octal number '$char'";
105 }
106 $t->{class} = $t->{token}->set_class( 'Number::Octal' );
107 return 1;
108 }
109 }
110
111 # Handle the easy case, integer or real.
11211702.80ms1170647µs return 1 if $char =~ /\d/o;
# spent 647µs making 1170 calls to PPI::Token::Number::CORE:match, avg 553ns/call
113
114982250µs if ( $char eq '.' ) {
115150487µs1505.50ms $t->{class} = $t->{token}->set_class( 'Number::Float' );
# spent 5.50ms making 150 calls to PPI::Token::set_class, avg 37µs/call
116150482µs return 1;
117 }
118832332µs if ( $char eq 'e' || $char eq 'E' ) {
119 $t->{class} = $t->{token}->set_class( 'Number::Exp' );
120 return 1;
121 }
122
123 # Doesn't fit a special case, or is after the end of the token
124 # End of token.
1258323.66ms166413.4ms $t->_finalize_token->__TOKENIZER__on_char( $t );
# spent 11.3ms making 832 calls to PPI::Token::Whitespace::__TOKENIZER__on_char, avg 14µs/call # spent 2.14ms making 832 calls to PPI::Tokenizer::_finalize_token, avg 3µs/call
126}
127
12812µs1;
129
130=pod
131
132=head1 CAVEATS
133
134Compared to Perl, the number tokenizer is too liberal about allowing
135underscores anywhere. For example, the following is a syntax error in
136Perl, but is allowed in PPI:
137
138 0_b10
139
140=head1 TO DO
141
142- Treat v-strings as binary strings or barewords, not as "base-256"
143 numbers
144
145- Break out decimal integers into their own subclass?
146
147- Implement literal()
148
149=head1 SUPPORT
150
151See the L<support section|PPI/SUPPORT> in the main module.
152
153=head1 AUTHOR
154
155Adam Kennedy E<lt>adamk@cpan.orgE<gt>
156
157=head1 COPYRIGHT
158
159Copyright 2001 - 2011 Adam Kennedy.
160
161This program is free software; you can redistribute
162it and/or modify it under the same terms as Perl itself.
163
164The full text of the license can be found in the
165LICENSE file included with this module.
166
167=cut
 
# spent 1.80ms within PPI::Token::Number::CORE:match which was called 2626 times, avg 686ns/call: # 1170 times (1.02ms+0s) by PPI::Token::Number::__TOKENIZER__on_char at line 93, avg 869ns/call # 1170 times (647µs+0s) by PPI::Token::Number::__TOKENIZER__on_char at line 112, avg 553ns/call # 286 times (139µs+0s) by PPI::Token::Number::__TOKENIZER__on_char at line 95, avg 486ns/call
sub PPI::Token::Number::CORE:match; # opcode