1 package PPI::Token::Number::Float;
7 PPI::Token::Number::Float - Token class for a floating-point number
15 PPI::Token::Number::Float
16 isa PPI::Token::Number
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.
32 use PPI::Token::Number ();
34 use vars qw{$VERSION @ISA};
37 @ISA = 'PPI::Token::Number';
44 Returns the base for the number: 10.
54 Return the numeric value of this token.
60 my $str = $self->_literal;
61 my $neg = $str =~ s/^\-//;
64 return $neg ? -$val : $val;
71 #####################################################################
74 sub __TOKENIZER__on_char {
77 my $char = substr( $t->{line}, $t->{line_cursor}, 1 );
79 # Allow underscores straight through
80 return 1 if $char eq '_';
83 return 1 if $char =~ /\d/o;
85 # Is there a second decimal point? Then version string or '..' operator
87 if ( $t->{token}->{content} =~ /\.$/ ) {
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 chop $t->{token}->{content};
92 $t->{class} = $t->{token}->set_class( 'Number' );
93 $t->_new_token('Operator', '..');
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' );
101 if ($char eq 'e' || $char eq 'E') {
102 $t->{class} = $t->{token}->set_class( 'Number::Exp' );
106 # Doesn't fit a special case, or is after the end of the token
108 $t->_finalize_token->__TOKENIZER__on_char( $t );
117 See the L<support section|PPI/SUPPORT> in the main module.
121 Chris Dolan E<lt>cdolan@cpan.orgE<gt>
125 Copyright 2006 Chris Dolan.
127 This program is free software; you can redistribute
128 it and/or modify it under the same terms as Perl itself.
130 The full text of the license can be found in the
131 LICENSE file included with this module.