PPI/Token/Number/Float.pm

filter: Statementstmt 100% 36 / 36 Branchbran 92.8% 13 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 98.2% 56 / 57 CC 8 SCAR 14.8
CC
8
Cov
98%
__TOKENIZER__on_char
7.0
literal
2.0
BEGIN
1.0
CRAP 4.4
« PPI/Element.pm ↑ Summary PPI/Cache.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 62 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 62 ▶use PPI::Token::Number ();
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 62 ▶use vars qw{$VERSION @ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
35 BEGIN {
36 62 ▶ $VERSION = '1.236';
Subroutine BEGIN: called CC=1 SCAR=0.0
37 62 @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 11 ▶ my $self = shift;
Subroutine literal: called CC=2 SCAR=6.9
Pod documented
60 11 my $str = $self->_literal;
61 11 my $neg = $str =~ s/^\-//;
62 11 $str =~ s/^\./0./;
63 11 my $val = 0+$str;
64 11 ▶ return $neg ? -$val : $val;
Branch: 1 branch
BranchTrueFalseTotal
$neg ? : 1 10 11
65 }
66  
67  
68  
69  
70  
71 #####################################################################
72 # Tokenizer Methods
73  
74 sub __TOKENIZER__on_char {
75 5152 ▶ my $class = shift;
Subroutine __TOKENIZER__on_char: called CC=7 SCAR=19.5
76 5152 my $t = shift;
77 5152 my $char = substr( $t->{line}, $t->{line_cursor}, 1 );
78  
79 # Allow underscores straight through
80 5152 ▶ return 1 if $char eq '_';
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "_" 9 5143 5152
81  
82 # Allow digits
83 5143 ▶ return 1 if $char =~ /\d/o;
Branch: 1 branch
BranchTrueFalseTotal
if $char =~ /\d/o 3214 1929 5143
84  
85 # Is there a second decimal point? Then version string or '..' operator
86 1929 ▶ if ( $char eq '.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq ".") 767 1162 1929
87 767 ▶ if ( $t->{token}->{content} =~ /\.$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($t->{'token'}{'content'} =~ /\.$/) { } 4 763 767
elsif (not $t->{'token'}{'content'} =~ /_/) { } 763 0 763
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 4 chop $t->{token}->{content};
92 4 $t->{class} = $t->{token}->set_class( 'Number' );
93 4 $t->_new_token('Operator', '..');
94 4 return 0;
95 } elsif ( $t->{token}->{content} !~ /_/ ) {
96 # Underscore means not a Version, fall through to end token
97 763 $t->{class} = $t->{token}->set_class( 'Number::Version' );
98 763 return 1;
99 }
100 }
101  
102 # perl seems to regard pretty much anything that's not strictly an exp num
103 # as float + stuff
104 1162 my $char2 = substr $t->{line}, $t->{line_cursor}+1, 1;
105 1162 ▶ if ("$char$char2" =~ /[eE][0-9+-]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ("$char$char2" =~ /[eE][0-9+-]/) 12 1150 1162
106 12 $t->{class} = $t->{token}->set_class( 'Number::Exp' );
107 12 return 1;
108 }
109  
110 # Doesn't fit a special case, or is after the end of the token
111 # End of token.
112 1150 $t->_finalize_token->__TOKENIZER__on_char( $t );
113 }
114  
115 62 1;
116  
117 =pod
118  
119 =head1 SUPPORT
120  
121 See the L<support section|PPI/SUPPORT> in the main module.
122  
123 =head1 AUTHOR
124  
125 Chris Dolan E<lt>cdolan@cpan.orgE<gt>
126  
127 =head1 COPYRIGHT
128  
129 Copyright 2006 Chris Dolan.
130  
131 This program is free software; you can redistribute
132 it and/or modify it under the same terms as Perl itself.
133  
134 The full text of the license can be found in the
135 LICENSE file included with this module.
136  
137 =cut
« PPI/Element.pm ↑ Summary PPI/Cache.pm »