| line | stmt | bran | cond | sub | pod | time | 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 class is used for tokens that | 
| 23 |  |  |  |  |  |  | represent floating point numbers.  A float is identified by n decimal | 
| 24 |  |  |  |  |  |  | point.  Exponential notation (the C or C) is handled by the | 
| 25 |  |  |  |  |  |  | PPI::Token::Number::Exp class. | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | =head1 METHODS | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | =cut | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 65 |  |  | 65 |  | 362 | use strict; | 
|  | 65 |  |  |  |  | 103 |  | 
|  | 65 |  |  |  |  | 1578 |  | 
| 32 | 65 |  |  | 65 |  | 278 | use PPI::Token::Number (); | 
|  | 65 |  |  |  |  | 112 |  | 
|  | 65 |  |  |  |  | 27391 |  | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | our $VERSION = '1.276'; | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | our @ISA = "PPI::Token::Number"; | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =pod | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | =head2 base | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | Returns the base for the number: 10. | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | =cut | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | sub base() { 10 } | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | =pod | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | =head2 literal | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | Return the numeric value of this token. | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | =cut | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | sub literal { | 
| 57 | 11 |  |  | 11 | 1 | 111 | my $self = shift; | 
| 58 | 11 |  |  |  |  | 35 | my $str = $self->_literal; | 
| 59 | 11 |  |  |  |  | 19 | my $neg = $str =~ s/^\-//; | 
| 60 | 11 |  |  |  |  | 19 | $str =~ s/^\./0./; | 
| 61 | 11 |  |  |  |  | 30 | my $val = 0+$str; | 
| 62 | 11 | 100 |  |  |  | 33 | return $neg ? -$val : $val; | 
| 63 |  |  |  |  |  |  | } | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | ##################################################################### | 
| 70 |  |  |  |  |  |  | # Tokenizer Methods | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | sub __TOKENIZER__on_char { | 
| 73 | 8244 |  |  | 8244 |  | 10348 | my $class = shift; | 
| 74 | 8244 |  |  |  |  | 8872 | my $t     = shift; | 
| 75 | 8244 |  |  |  |  | 12521 | my $char  = substr( $t->{line}, $t->{line_cursor}, 1 ); | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | # Allow underscores straight through | 
| 78 | 8244 | 100 |  |  |  | 13199 | return 1 if $char eq '_'; | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | # Allow digits | 
| 81 | 7633 | 100 |  |  |  | 20704 | return 1 if $char =~ /\d/o; | 
| 82 |  |  |  |  |  |  |  | 
| 83 | 2790 | 100 |  |  |  | 4938 | if ( $char eq '.' ) { # A second decimal point? That gets complicated. | 
| 84 | 1354 | 100 |  |  |  | 4202 | if ( $t->{token}{content} =~ /\.$/ ) { | 
|  |  | 100 |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | # We have a .., which is an operator. Take the . off the end of the | 
| 86 |  |  |  |  |  |  | # token and finish it, then make the .. operator. | 
| 87 | 33 |  |  |  |  | 116 | chop $t->{token}{content}; | 
| 88 | 33 |  |  |  |  | 132 | $t->{class} = $t->{token}->set_class( 'Number' ); | 
| 89 | 33 |  |  |  |  | 132 | $t->_new_token('Operator', '..'); | 
| 90 | 33 |  |  |  |  | 88 | return 0; | 
| 91 |  |  |  |  |  |  | } elsif ( $t->{token}{content} =~ /\._/ ) { | 
| 92 |  |  |  |  |  |  | ($t->{token}{content}, my $bareword) | 
| 93 | 171 |  |  |  |  | 573 | = split /\./, $t->{token}{content}; | 
| 94 | 171 |  |  |  |  | 413 | $t->{class} = $t->{token}->set_class( 'Number' ); | 
| 95 | 171 |  |  |  |  | 479 | $t->_new_token('Operator', '.'); | 
| 96 | 171 |  |  |  |  | 389 | $t->_new_token('Word', $bareword); | 
| 97 | 171 |  |  |  |  | 368 | $t->_new_token('Operator', '.'); | 
| 98 | 171 |  |  |  |  | 358 | return 0; | 
| 99 |  |  |  |  |  |  | } else { | 
| 100 | 1150 |  |  |  |  | 2534 | $t->{class} = $t->{token}->set_class( 'Number::Version' ); | 
| 101 | 1150 |  |  |  |  | 2764 | return 1; | 
| 102 |  |  |  |  |  |  | } | 
| 103 |  |  |  |  |  |  | } | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | # perl seems to regard pretty much anything that's not strictly an exp num | 
| 106 |  |  |  |  |  |  | # as float + stuff | 
| 107 | 1436 |  |  |  |  | 2582 | my $char2 = substr $t->{line}, $t->{line_cursor}+1, 1; | 
| 108 | 1436 | 100 |  |  |  | 3271 | if ("$char$char2" =~ /[eE][0-9+-]/) { | 
| 109 | 12 |  |  |  |  | 32 | $t->{class} = $t->{token}->set_class( 'Number::Exp' ); | 
| 110 | 12 |  |  |  |  | 29 | return 1; | 
| 111 |  |  |  |  |  |  | } | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | # Doesn't fit a special case, or is after the end of the token | 
| 114 |  |  |  |  |  |  | # End of token. | 
| 115 | 1424 |  |  |  |  | 2720 | $t->_finalize_token->__TOKENIZER__on_char( $t ); | 
| 116 |  |  |  |  |  |  | } | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | 1; | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | =pod | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | =head1 SUPPORT | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | See the L in the main module. | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | =head1 AUTHOR | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | Chris Dolan Ecdolan@cpan.orgE | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | Copyright 2006 Chris Dolan. | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | This program is free software; you can redistribute | 
| 135 |  |  |  |  |  |  | it and/or modify it under the same terms as Perl itself. | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | The full text of the license can be found in the | 
| 138 |  |  |  |  |  |  | LICENSE file included with this module. | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | =cut |