| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Token/Number/Float.pm |
| Statements | Executed 5555 statements in 6.31ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1018 | 1 | 1 | 5.29ms | 13.3ms | PPI::Token::Number::Float::__TOKENIZER__on_char |
| 1020 | 2 | 1 | 697µs | 697µs | PPI::Token::Number::Float::CORE:match (opcode) |
| 1 | 1 | 1 | 11µs | 23µs | PPI::Token::Number::Float::BEGIN@31 |
| 1 | 1 | 1 | 8µs | 8µs | PPI::Token::Number::Float::BEGIN@35 |
| 1 | 1 | 1 | 6µs | 34µs | PPI::Token::Number::Float::BEGIN@34 |
| 1 | 1 | 1 | 3µs | 3µs | PPI::Token::Number::Float::BEGIN@32 |
| 0 | 0 | 0 | 0s | 0s | PPI::Token::Number::Float::literal |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package PPI::Token::Number::Float; | ||||
| 2 | |||||
| 3 | =pod | ||||
| 4 | |||||
| 5 | =head1 NAME | ||||
| 6 | |||||
| 7 | PPI::Token::Number::Float - Token class for a floating-point number | ||||
| 8 | |||||
| 9 | =head1 SYNOPSIS | ||||
| 10 | |||||
| 11 | $n = 1.234; | ||||
| 12 | |||||
| 13 | =head1 INHERITANCE | ||||
| 14 | |||||
| 15 | PPI::Token::Number::Float | ||||
| 16 | isa PPI::Token::Number | ||||
| 17 | isa PPI::Token | ||||
| 18 | isa PPI::Element | ||||
| 19 | |||||
| 20 | =head1 DESCRIPTION | ||||
| 21 | |||||
| 22 | The C<PPI::Token::Number::Float> class is used for tokens that | ||||
| 23 | represent floating point numbers. A float is identified by n decimal | ||||
| 24 | point. Exponential notation (the C<e> or C<E>) is handled by the | ||||
| 25 | PPI::Token::Number::Exp class. | ||||
| 26 | |||||
| 27 | =head1 METHODS | ||||
| 28 | |||||
| 29 | =cut | ||||
| 30 | |||||
| 31 | 2 | 18µs | 2 | 34µs | # spent 23µs (11+12) within PPI::Token::Number::Float::BEGIN@31 which was called:
# once (11µs+12µs) by PPI::Token::BEGIN@46 at line 31 # spent 23µs making 1 call to PPI::Token::Number::Float::BEGIN@31
# spent 12µs making 1 call to strict::import |
| 32 | 2 | 18µs | 1 | 3µs | # spent 3µs within PPI::Token::Number::Float::BEGIN@32 which was called:
# once (3µs+0s) by PPI::Token::BEGIN@46 at line 32 # spent 3µs making 1 call to PPI::Token::Number::Float::BEGIN@32 |
| 33 | |||||
| 34 | 2 | 27µs | 2 | 61µs | # spent 34µs (6+28) within PPI::Token::Number::Float::BEGIN@34 which was called:
# once (6µs+28µs) by PPI::Token::BEGIN@46 at line 34 # spent 34µs making 1 call to PPI::Token::Number::Float::BEGIN@34
# spent 28µs making 1 call to vars::import |
| 35 | # spent 8µs within PPI::Token::Number::Float::BEGIN@35 which was called:
# once (8µs+0s) by PPI::Token::BEGIN@46 at line 38 | ||||
| 36 | 1 | 300ns | $VERSION = '1.215'; | ||
| 37 | 1 | 8µs | @ISA = 'PPI::Token::Number'; | ||
| 38 | 1 | 218µs | 1 | 8µs | } # spent 8µs making 1 call to PPI::Token::Number::Float::BEGIN@35 |
| 39 | |||||
| 40 | =pod | ||||
| 41 | |||||
| 42 | =head2 base | ||||
| 43 | |||||
| 44 | Returns the base for the number: 10. | ||||
| 45 | |||||
| 46 | =cut | ||||
| 47 | |||||
| 48 | sub base () { 10 } | ||||
| 49 | |||||
| 50 | =pod | ||||
| 51 | |||||
| 52 | =head2 literal | ||||
| 53 | |||||
| 54 | Return the numeric value of this token. | ||||
| 55 | |||||
| 56 | =cut | ||||
| 57 | |||||
| 58 | sub literal { | ||||
| 59 | my $self = shift; | ||||
| 60 | my $str = $self->_literal; | ||||
| 61 | my $neg = $str =~ s/^\-//; | ||||
| 62 | $str =~ s/^\./0./; | ||||
| 63 | my $val = 0+$str; | ||||
| 64 | return $neg ? -$val : $val; | ||||
| 65 | } | ||||
| 66 | |||||
| - - | |||||
| 71 | ##################################################################### | ||||
| 72 | # Tokenizer Methods | ||||
| 73 | |||||
| 74 | # spent 13.3ms (5.29+8.04) within PPI::Token::Number::Float::__TOKENIZER__on_char which was called 1018 times, avg 13µs/call:
# 1018 times (5.29ms+8.04ms) by PPI::Tokenizer::_process_next_char at line 554 of PPI/Tokenizer.pm, avg 13µs/call | ||||
| 75 | 1018 | 287µs | my $class = shift; | ||
| 76 | 1018 | 134µs | my $t = shift; | ||
| 77 | 1018 | 446µs | my $char = substr( $t->{line}, $t->{line_cursor}, 1 ); | ||
| 78 | |||||
| 79 | # Allow underscores straight through | ||||
| 80 | 1018 | 153µs | return 1 if $char eq '_'; | ||
| 81 | |||||
| 82 | # Allow digits | ||||
| 83 | 1018 | 4.22ms | 1018 | 694µs | return 1 if $char =~ /\d/o; # spent 694µs making 1018 calls to PPI::Token::Number::Float::CORE:match, avg 681ns/call |
| 84 | |||||
| 85 | # Is there a second decimal point? Then version string or '..' operator | ||||
| 86 | 150 | 49µs | if ( $char eq '.' ) { | ||
| 87 | 2 | 10µs | 2 | 3µs | if ( $t->{token}->{content} =~ /\.$/ ) { # spent 3µs making 2 calls to PPI::Token::Number::Float::CORE:match, avg 1µs/call |
| 88 | # We have a .., which is an operator. | ||||
| 89 | # Take the . off the end of the token.. | ||||
| 90 | # and finish it, then make the .. operator. | ||||
| 91 | 2 | 2µs | chop $t->{token}->{content}; | ||
| 92 | 2 | 8µs | 2 | 16µs | $t->{class} = $t->{token}->set_class( 'Number' ); # spent 16µs making 2 calls to PPI::Token::set_class, avg 8µs/call |
| 93 | 2 | 3µs | 2 | 22µs | $t->_new_token('Operator', '..'); # spent 22µs making 2 calls to PPI::Tokenizer::_new_token, avg 11µs/call |
| 94 | 2 | 4µs | return 0; | ||
| 95 | } elsif ( $t->{token}->{content} !~ /_/ ) { | ||||
| 96 | # Underscore means not a Version, fall through to end token | ||||
| 97 | $t->{class} = $t->{token}->set_class( 'Number::Version' ); | ||||
| 98 | return 1; | ||||
| 99 | } | ||||
| 100 | } | ||||
| 101 | 148 | 69µs | if ($char eq 'e' || $char eq 'E') { | ||
| 102 | $t->{class} = $t->{token}->set_class( 'Number::Exp' ); | ||||
| 103 | return 1; | ||||
| 104 | } | ||||
| 105 | |||||
| 106 | # Doesn't fit a special case, or is after the end of the token | ||||
| 107 | # End of token. | ||||
| 108 | 148 | 630µs | 296 | 7.30ms | $t->_finalize_token->__TOKENIZER__on_char( $t ); # spent 6.79ms making 148 calls to PPI::Token::Whitespace::__TOKENIZER__on_char, avg 46µs/call
# spent 513µs making 148 calls to PPI::Tokenizer::_finalize_token, avg 3µs/call |
| 109 | } | ||||
| 110 | |||||
| 111 | 1 | 2µs | 1; | ||
| 112 | |||||
| 113 | =pod | ||||
| 114 | |||||
| 115 | =head1 SUPPORT | ||||
| 116 | |||||
| 117 | See the L<support section|PPI/SUPPORT> in the main module. | ||||
| 118 | |||||
| 119 | =head1 AUTHOR | ||||
| 120 | |||||
| 121 | Chris Dolan E<lt>cdolan@cpan.orgE<gt> | ||||
| 122 | |||||
| 123 | =head1 COPYRIGHT | ||||
| 124 | |||||
| 125 | Copyright 2006 Chris Dolan. | ||||
| 126 | |||||
| 127 | This program is free software; you can redistribute | ||||
| 128 | it and/or modify it under the same terms as Perl itself. | ||||
| 129 | |||||
| 130 | The full text of the license can be found in the | ||||
| 131 | LICENSE file included with this module. | ||||
| 132 | |||||
| 133 | =cut | ||||
# spent 697µs within PPI::Token::Number::Float::CORE:match which was called 1020 times, avg 683ns/call:
# 1018 times (694µs+0s) by PPI::Token::Number::Float::__TOKENIZER__on_char at line 83, avg 681ns/call
# 2 times (3µs+0s) by PPI::Token::Number::Float::__TOKENIZER__on_char at line 87, avg 1µs/call |