Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Token/Number/Exp.pm |
Statements | Executed 9 statements in 311µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 11µs | 22µs | BEGIN@31 | PPI::Token::Number::Exp::
1 | 1 | 1 | 10µs | 10µs | BEGIN@35 | PPI::Token::Number::Exp::
1 | 1 | 1 | 6µs | 33µs | BEGIN@34 | PPI::Token::Number::Exp::
1 | 1 | 1 | 3µs | 3µs | BEGIN@32 | PPI::Token::Number::Exp::
0 | 0 | 0 | 0s | 0s | __TOKENIZER__on_char | PPI::Token::Number::Exp::
0 | 0 | 0 | 0s | 0s | literal | PPI::Token::Number::Exp::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package PPI::Token::Number::Exp; | ||||
2 | |||||
3 | =pod | ||||
4 | |||||
5 | =head1 NAME | ||||
6 | |||||
7 | PPI::Token::Number::Exp - Token class for an exponential notation number | ||||
8 | |||||
9 | =head1 SYNOPSIS | ||||
10 | |||||
11 | $n = 1.0e-2; | ||||
12 | $n = 1e+2; | ||||
13 | |||||
14 | =head1 INHERITANCE | ||||
15 | |||||
16 | PPI::Token::Number::Exp | ||||
17 | isa PPI::Token::Number::Float | ||||
18 | isa PPI::Token::Number | ||||
19 | isa PPI::Token | ||||
20 | isa PPI::Element | ||||
21 | |||||
22 | =head1 DESCRIPTION | ||||
23 | |||||
24 | The C<PPI::Token::Number::Exp> class is used for tokens that | ||||
25 | represent floating point numbers with exponential notation. | ||||
26 | |||||
27 | =head1 METHODS | ||||
28 | |||||
29 | =cut | ||||
30 | |||||
31 | 2 | 18µs | 2 | 33µs | # spent 22µs (11+11) within PPI::Token::Number::Exp::BEGIN@31 which was called:
# once (11µs+11µs) by PPI::Token::BEGIN@47 at line 31 # spent 22µs making 1 call to PPI::Token::Number::Exp::BEGIN@31
# spent 11µs making 1 call to strict::import |
32 | 2 | 22µs | 1 | 3µs | # spent 3µs within PPI::Token::Number::Exp::BEGIN@32 which was called:
# once (3µs+0s) by PPI::Token::BEGIN@47 at line 32 # spent 3µs making 1 call to PPI::Token::Number::Exp::BEGIN@32 |
33 | |||||
34 | 2 | 27µs | 2 | 60µs | # spent 33µs (6+27) within PPI::Token::Number::Exp::BEGIN@34 which was called:
# once (6µs+27µs) by PPI::Token::BEGIN@47 at line 34 # spent 33µs making 1 call to PPI::Token::Number::Exp::BEGIN@34
# spent 27µs making 1 call to vars::import |
35 | # spent 10µs within PPI::Token::Number::Exp::BEGIN@35 which was called:
# once (10µs+0s) by PPI::Token::BEGIN@47 at line 38 | ||||
36 | 1 | 300ns | $VERSION = '1.215'; | ||
37 | 1 | 10µs | @ISA = 'PPI::Token::Number::Float'; | ||
38 | 1 | 231µs | 1 | 10µs | } # spent 10µs making 1 call to PPI::Token::Number::Exp::BEGIN@35 |
39 | |||||
40 | =pod | ||||
41 | |||||
42 | =head2 literal | ||||
43 | |||||
44 | Return the numeric value of this token. | ||||
45 | |||||
46 | =cut | ||||
47 | |||||
48 | sub literal { | ||||
49 | my $self = shift; | ||||
50 | return if $self->{_error}; | ||||
51 | my ($mantissa, $exponent) = split m/e/i, $self->_literal; | ||||
52 | my $neg = $mantissa =~ s/^\-//; | ||||
53 | $mantissa =~ s/^\./0./; | ||||
54 | $exponent =~ s/^\+//; | ||||
55 | my $val = $mantissa * 10 ** $exponent; | ||||
56 | return $neg ? -$val : $val; | ||||
57 | } | ||||
58 | |||||
- - | |||||
63 | ##################################################################### | ||||
64 | # Tokenizer Methods | ||||
65 | |||||
66 | sub __TOKENIZER__on_char { | ||||
67 | my $class = shift; | ||||
68 | my $t = shift; | ||||
69 | my $char = substr( $t->{line}, $t->{line_cursor}, 1 ); | ||||
70 | |||||
71 | # To get here, the token must have already encountered an 'E' | ||||
72 | |||||
73 | # Allow underscores straight through | ||||
74 | return 1 if $char eq '_'; | ||||
75 | |||||
76 | # Allow digits | ||||
77 | return 1 if $char =~ /\d/o; | ||||
78 | |||||
79 | # Start of exponent is special | ||||
80 | if ( $t->{token}->{content} =~ /e$/i ) { | ||||
81 | # Allow leading +/- in exponent | ||||
82 | return 1 if $char eq '-' || $char eq '+'; | ||||
83 | |||||
84 | # Invalid character in exponent. Recover | ||||
85 | if ( $t->{token}->{content} =~ s/\.(e)$//i ) { | ||||
86 | my $word = $1; | ||||
87 | $t->{class} = $t->{token}->set_class('Number'); | ||||
88 | $t->_new_token('Operator', '.'); | ||||
89 | $t->_new_token('Word', $word); | ||||
90 | return $t->{class}->__TOKENIZER__on_char( $t ); | ||||
91 | } | ||||
92 | else { | ||||
93 | $t->{token}->{_error} = "Illegal character in exponent '$char'"; | ||||
94 | } | ||||
95 | } | ||||
96 | |||||
97 | # Doesn't fit a special case, or is after the end of the token | ||||
98 | # End of token. | ||||
99 | $t->_finalize_token->__TOKENIZER__on_char( $t ); | ||||
100 | } | ||||
101 | |||||
102 | 1 | 2µs | 1; | ||
103 | |||||
104 | =pod | ||||
105 | |||||
106 | =head1 SUPPORT | ||||
107 | |||||
108 | See the L<support section|PPI/SUPPORT> in the main module. | ||||
109 | |||||
110 | =head1 AUTHOR | ||||
111 | |||||
112 | Chris Dolan E<lt>cdolan@cpan.orgE<gt> | ||||
113 | |||||
114 | =head1 COPYRIGHT | ||||
115 | |||||
116 | Copyright 2006 Chris Dolan. | ||||
117 | |||||
118 | This program is free software; you can redistribute | ||||
119 | it and/or modify it under the same terms as Perl itself. | ||||
120 | |||||
121 | The full text of the license can be found in the | ||||
122 | LICENSE file included with this module. | ||||
123 | |||||
124 | =cut |