| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Token/Number/Version.pm | 
| Statements | Executed 1017 statements in 3.26ms | 
| Calls | P | F | Exclusive Time | Inclusive Time | Subroutine | 
|---|---|---|---|---|---|
| 336 | 1 | 1 | 2.66ms | 30.1ms | PPI::Token::Number::Version::__TOKENIZER__commit | 
| 336 | 1 | 1 | 429µs | 429µs | PPI::Token::Number::Version::CORE:match (opcode) | 
| 1 | 1 | 1 | 12µs | 23µs | PPI::Token::Number::Version::BEGIN@33 | 
| 1 | 1 | 1 | 10µs | 10µs | PPI::Token::Number::Version::BEGIN@37 | 
| 1 | 1 | 1 | 6µs | 34µs | PPI::Token::Number::Version::BEGIN@36 | 
| 1 | 1 | 1 | 3µs | 3µs | PPI::Token::Number::Version::BEGIN@34 | 
| 0 | 0 | 0 | 0s | 0s | PPI::Token::Number::Version::__TOKENIZER__on_char | 
| 0 | 0 | 0 | 0s | 0s | PPI::Token::Number::Version::base | 
| 0 | 0 | 0 | 0s | 0s | PPI::Token::Number::Version::literal | 
| Line | State ments | Time on line | Calls | Time in subs | Code | 
|---|---|---|---|---|---|
| 1 | package PPI::Token::Number::Version; | ||||
| 2 | |||||
| 3 | =pod | ||||
| 4 | |||||
| 5 | =head1 NAME | ||||
| 6 | |||||
| 7 | PPI::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 | |||||
| 25 | The C<PPI::Token::Number::Version> class is used for tokens that have | ||||
| 26 | multiple decimal points. In truth, these aren't treated like numbers | ||||
| 27 | at all by Perl, but they look like numbers to a parser. | ||||
| 28 | |||||
| 29 | =head1 METHODS | ||||
| 30 | |||||
| 31 | =cut | ||||
| 32 | |||||
| 33 | 2 | 21µs | 2 | 35µ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 # spent    23µs making 1 call to PPI::Token::Number::Version::BEGIN@33
# spent    12µs making 1 call to strict::import | 
| 34 | 2 | 22µs | 1 | 3µ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 # spent     3µs making 1 call to PPI::Token::Number::Version::BEGIN@34 | 
| 35 | |||||
| 36 | 2 | 27µs | 2 | 62µ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 # 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 | ||||
| 38 | 1 | 400ns | $VERSION = '1.215'; | ||
| 39 | 1 | 12µs | @ISA = 'PPI::Token::Number'; | ||
| 40 | 1 | 246µs | 1 | 10µs | } # spent    10µs making 1 call to PPI::Token::Number::Version::BEGIN@37 | 
| 41 | |||||
| 42 | =pod | ||||
| 43 | |||||
| 44 | =head2 base | ||||
| 45 | |||||
| 46 | Returns the base for the number: 256. | ||||
| 47 | |||||
| 48 | =cut | ||||
| 49 | |||||
| 50 | sub base { | ||||
| 51 | return 256; | ||||
| 52 | } | ||||
| 53 | |||||
| 54 | =pod | ||||
| 55 | |||||
| 56 | =head2 literal | ||||
| 57 | |||||
| 58 | Return the numeric value of this token. | ||||
| 59 | |||||
| 60 | =cut | ||||
| 61 | |||||
| 62 | sub 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 | |||||
| 80 | my $doc1 = new_ok( 'PPI::Document' => [ \'1.2.3.4' ] ); | ||||
| 81 | my $doc2 = new_ok( 'PPI::Document' => [ \'v1.2.3.4' ] ); | ||||
| 82 | isa_ok( $doc1->child(0), 'PPI::Statement' ); | ||||
| 83 | isa_ok( $doc2->child(0), 'PPI::Statement' ); | ||||
| 84 | isa_ok( $doc1->child(0)->child(0), 'PPI::Token::Number::Version' ); | ||||
| 85 | isa_ok( $doc2->child(0)->child(0), 'PPI::Token::Number::Version' ); | ||||
| 86 | |||||
| 87 | my $literal1 = $doc1->child(0)->child(0)->literal; | ||||
| 88 | my $literal2 = $doc2->child(0)->child(0)->literal; | ||||
| 89 | is( length($literal1), 4, 'The literal length of doc1 is 4' ); | ||||
| 90 | is( length($literal2), 4, 'The literal length of doc1 is 4' ); | ||||
| 91 | is( $literal1, $literal2, 'Literals match for 1.2.3.4 vs v1.2.3.4' ); | ||||
| 92 | |||||
| 93 | =end testing | ||||
| 94 | |||||
| 95 | =cut | ||||
| 96 | |||||
| 97 | sub __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 | ||||
| 125 | 336 | 99µs | my $t = $_[1]; | ||
| 126 | |||||
| 127 | # Get the rest of the line | ||||
| 128 | 336 | 328µs | my $rest = substr( $t->{line}, $t->{line_cursor} ); | ||
| 129 | 336 | 2.50ms | 672 | 27.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 | |||||
| 141 | 1 | 2µs | 1; | ||
| 142 | |||||
| 143 | =pod | ||||
| 144 | |||||
| 145 | =head1 BUGS | ||||
| 146 | |||||
| 147 | - Does not handle leading minus sign correctly. Should translate to a DashedWord. | ||||
| 148 | See 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 | |||||
| 155 | See the L<support section|PPI/SUPPORT> in the main module. | ||||
| 156 | |||||
| 157 | =head1 AUTHOR | ||||
| 158 | |||||
| 159 | Chris Dolan E<lt>cdolan@cpan.orgE<gt> | ||||
| 160 | |||||
| 161 | =head1 COPYRIGHT | ||||
| 162 | |||||
| 163 | Copyright 2006 Chris Dolan. | ||||
| 164 | |||||
| 165 | This program is free software; you can redistribute | ||||
| 166 | it and/or modify it under the same terms as Perl itself. | ||||
| 167 | |||||
| 168 | The full text of the license can be found in the | ||||
| 169 | LICENSE 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 |