← 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/Version.pm
StatementsExecuted 1017 statements in 3.26ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
336112.66ms30.1msPPI::Token::Number::Version::::__TOKENIZER__commitPPI::Token::Number::Version::__TOKENIZER__commit
33611429µs429µsPPI::Token::Number::Version::::CORE:matchPPI::Token::Number::Version::CORE:match (opcode)
11112µs23µsPPI::Token::Number::Version::::BEGIN@33PPI::Token::Number::Version::BEGIN@33
11110µs10µsPPI::Token::Number::Version::::BEGIN@37PPI::Token::Number::Version::BEGIN@37
1116µs34µsPPI::Token::Number::Version::::BEGIN@36PPI::Token::Number::Version::BEGIN@36
1113µs3µsPPI::Token::Number::Version::::BEGIN@34PPI::Token::Number::Version::BEGIN@34
0000s0sPPI::Token::Number::Version::::__TOKENIZER__on_charPPI::Token::Number::Version::__TOKENIZER__on_char
0000s0sPPI::Token::Number::Version::::basePPI::Token::Number::Version::base
0000s0sPPI::Token::Number::Version::::literalPPI::Token::Number::Version::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::Version;
2
3=pod
4
5=head1 NAME
6
7PPI::Token::Number::Version - Token class for a byte-packed number
8
9=head1 SYNOPSIS
10
11 $n = 1.1.0;
12 $n = 127.0.0.1;
13 $n = 10_000.10_000.10_000;
14 $n = v1.2.3.4
15
16=head1 INHERITANCE
17
18 PPI::Token::Number::Version
19 isa PPI::Token::Number
20 isa PPI::Token
21 isa PPI::Element
22
23=head1 DESCRIPTION
24
25The C<PPI::Token::Number::Version> class is used for tokens that have
26multiple decimal points. In truth, these aren't treated like numbers
27at all by Perl, but they look like numbers to a parser.
28
29=head1 METHODS
30
31=cut
32
33221µs235µs
# spent 23µs (12+12) within PPI::Token::Number::Version::BEGIN@33 which was called: # once (12µs+12µs) by PPI::Token::BEGIN@48 at line 33
use strict;
# spent 23µs making 1 call to PPI::Token::Number::Version::BEGIN@33 # spent 12µs making 1 call to strict::import
34222µs13µs
# spent 3µs within PPI::Token::Number::Version::BEGIN@34 which was called: # once (3µs+0s) by PPI::Token::BEGIN@48 at line 34
use PPI::Token::Number ();
# spent 3µs making 1 call to PPI::Token::Number::Version::BEGIN@34
35
36227µs262µs
# spent 34µs (6+28) within PPI::Token::Number::Version::BEGIN@36 which was called: # once (6µs+28µs) by PPI::Token::BEGIN@48 at line 36
use vars qw{$VERSION @ISA};
# spent 34µs making 1 call to PPI::Token::Number::Version::BEGIN@36 # spent 28µs making 1 call to vars::import
37
# spent 10µs within PPI::Token::Number::Version::BEGIN@37 which was called: # once (10µs+0s) by PPI::Token::BEGIN@48 at line 40
BEGIN {
381400ns $VERSION = '1.215';
39112µs @ISA = 'PPI::Token::Number';
401246µs110µs}
# spent 10µs making 1 call to PPI::Token::Number::Version::BEGIN@37
41
42=pod
43
44=head2 base
45
46Returns the base for the number: 256.
47
48=cut
49
50sub base {
51 return 256;
52}
53
54=pod
55
56=head2 literal
57
58Return the numeric value of this token.
59
60=cut
61
62sub literal {
63 my $self = shift;
64 my $content = $self->{content};
65 $content =~ s/^v//;
66 return join '', map { chr $_ } ( split /\./, $content );
67}
68
- -
73#####################################################################
74# Tokenizer Methods
75
76=pod
77
78=begin testing 9
79
80my $doc1 = new_ok( 'PPI::Document' => [ \'1.2.3.4' ] );
81my $doc2 = new_ok( 'PPI::Document' => [ \'v1.2.3.4' ] );
82isa_ok( $doc1->child(0), 'PPI::Statement' );
83isa_ok( $doc2->child(0), 'PPI::Statement' );
84isa_ok( $doc1->child(0)->child(0), 'PPI::Token::Number::Version' );
85isa_ok( $doc2->child(0)->child(0), 'PPI::Token::Number::Version' );
86
87my $literal1 = $doc1->child(0)->child(0)->literal;
88my $literal2 = $doc2->child(0)->child(0)->literal;
89is( length($literal1), 4, 'The literal length of doc1 is 4' );
90is( length($literal2), 4, 'The literal length of doc1 is 4' );
91is( $literal1, $literal2, 'Literals match for 1.2.3.4 vs v1.2.3.4' );
92
93=end testing
94
95=cut
96
97sub __TOKENIZER__on_char {
98 my $class = shift;
99 my $t = shift;
100 my $char = substr( $t->{line}, $t->{line_cursor}, 1 );
101
102 # Allow digits
103 return 1 if $char =~ /\d/o;
104
105 # Is this a second decimal point in a row? Then the '..' operator
106 if ( $char eq '.' ) {
107 if ( $t->{token}->{content} =~ /\.$/ ) {
108 # We have a .., which is an operator.
109 # Take the . off the end of the token..
110 # and finish it, then make the .. operator.
111 chop $t->{token}->{content};
112 $t->_new_token('Operator', '..');
113 return 0;
114 } else {
115 return 1;
116 }
117 }
118
119 # Doesn't fit a special case, or is after the end of the token
120 # End of token.
121 $t->_finalize_token->__TOKENIZER__on_char( $t );
122}
123
124
# spent 30.1ms (2.66+27.5) within PPI::Token::Number::Version::__TOKENIZER__commit which was called 336 times, avg 90µs/call: # 336 times (2.66ms+27.5ms) by PPI::Token::Whitespace::__TOKENIZER__on_char at line 206 of PPI/Token/Whitespace.pm, avg 90µs/call
sub __TOKENIZER__commit {
12533699µs my $t = $_[1];
126
127 # Get the rest of the line
128336328µs my $rest = substr( $t->{line}, $t->{line_cursor} );
1293362.50ms67227.5ms unless ( $rest =~ /^(v\d+(?:\.\d+)*)/ ) {
# spent 27.0ms making 336 calls to PPI::Token::Word::__TOKENIZER__commit, avg 80µs/call # spent 429µs making 336 calls to PPI::Token::Number::Version::CORE:match, avg 1µs/call
130 # This was not a v-string after all (it's a word)
131 return PPI::Token::Word->__TOKENIZER__commit($t);
132 }
133
134 # This is a v-string
135 my $vstring = $1;
136 $t->{line_cursor} += length($vstring);
137 $t->_new_token('Number::Version', $vstring);
138 $t->_finalize_token->__TOKENIZER__on_char($t);
139}
140
14112µs1;
142
143=pod
144
145=head1 BUGS
146
147- Does not handle leading minus sign correctly. Should translate to a DashedWord.
148See L<http://perlmonks.org/?node_id=574573>
149
150 -95.0.1.0 --> "-_\000\cA\000"
151 -96.0.1.0 --> Argument "`\0^A\0" isn't numeric in negation (-)
152
153=head1 SUPPORT
154
155See the L<support section|PPI/SUPPORT> in the main module.
156
157=head1 AUTHOR
158
159Chris Dolan E<lt>cdolan@cpan.orgE<gt>
160
161=head1 COPYRIGHT
162
163Copyright 2006 Chris Dolan.
164
165This program is free software; you can redistribute
166it and/or modify it under the same terms as Perl itself.
167
168The full text of the license can be found in the
169LICENSE file included with this module.
170
171=cut
 
# spent 429µs within PPI::Token::Number::Version::CORE:match which was called 336 times, avg 1µs/call: # 336 times (429µs+0s) by PPI::Token::Number::Version::__TOKENIZER__commit at line 129, avg 1µs/call
sub PPI::Token::Number::Version::CORE:match; # opcode