Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / PPI / Token / Number / Float.pm
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 use strict;
32 use PPI::Token::Number ();
33
34 use vars qw{$VERSION @ISA};
35 BEGIN {
36         $VERSION = '1.206';
37         @ISA     = 'PPI::Token::Number';
38 }
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
67
68
69
70
71 #####################################################################
72 # Tokenizer Methods
73
74 sub __TOKENIZER__on_char {
75         my $class = shift;
76         my $t     = shift;
77         my $char  = substr( $t->{line}, $t->{line_cursor}, 1 );
78
79         # Allow underscores straight through
80         return 1 if $char eq '_';
81
82         # Allow digits
83         return 1 if $char =~ /\d/o;
84
85         # Is there a second decimal point?  Then version string or '..' operator
86         if ( $char eq '.' ) {
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', '..');
94                         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         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         $t->_finalize_token->__TOKENIZER__on_char( $t );
109 }
110
111 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