1 package PPI::Token::Number::Exp;
7 PPI::Token::Number::Exp - Token class for an exponential notation number
16 PPI::Token::Number::Exp
17 isa PPI::Token::Number::Float
18 isa PPI::Token::Number
24 The C<PPI::Token::Number::Exp> class is used for tokens that
25 represent floating point numbers with exponential notation.
32 use PPI::Token::Number::Float ();
34 use vars qw{$VERSION @ISA};
37 @ISA = 'PPI::Token::Number::Float';
44 Return the numeric value of this token.
50 return if $self->{_error};
51 my ($mantissa, $exponent) = split m/e/i, $self->_literal;
52 my $neg = $mantissa =~ s/^\-//;
53 $mantissa =~ s/^\./0./;
55 my $val = $mantissa * 10 ** $exponent;
56 return $neg ? -$val : $val;
63 #####################################################################
66 sub __TOKENIZER__on_char {
69 my $char = substr( $t->{line}, $t->{line_cursor}, 1 );
71 # To get here, the token must have already encountered an 'E'
73 # Allow underscores straight through
74 return 1 if $char eq '_';
77 return 1 if $char =~ /\d/o;
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 '+';
84 # Invalid character in exponent. Recover
85 if ( $t->{token}->{content} =~ s/\.(e)$//i ) {
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 );
93 $t->{token}->{_error} = "Illegal character in exponent '$char'";
97 # Doesn't fit a special case, or is after the end of the token
99 $t->_finalize_token->__TOKENIZER__on_char( $t );
108 See the L<support section|PPI/SUPPORT> in the main module.
112 Chris Dolan E<lt>cdolan@cpan.orgE<gt>
116 Copyright 2006 Chris Dolan.
118 This program is free software; you can redistribute
119 it and/or modify it under the same terms as Perl itself.
121 The full text of the license can be found in the
122 LICENSE file included with this module.