File Coverage

blib/lib/PPI/Token/Number/Octal.pm
Criterion Covered Total %
statement 21 21 100.0
branch 9 10 90.0
condition 3 3 100.0
subroutine 4 4 100.0
pod 1 1 100.0
total 38 39 97.4


line stmt bran cond sub pod time code
1             package PPI::Token::Number::Octal;
2              
3             =pod
4              
5             =head1 NAME
6              
7             PPI::Token::Number::Octal - Token class for a binary number
8              
9             =head1 SYNOPSIS
10              
11             $n = 0777; # octal integer
12              
13             =head1 INHERITANCE
14              
15             PPI::Token::Number::Octal
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 base-8 numbers.
24              
25             =head1 METHODS
26              
27             =cut
28              
29 65     65   368 use strict;
  65         109  
  65         1505  
30 65     65   292 use PPI::Token::Number ();
  65         109  
  65         14016  
31              
32             our $VERSION = '1.276';
33              
34             our @ISA = "PPI::Token::Number";
35              
36             =pod
37              
38             =head2 base
39              
40             Returns the base for the number: 8.
41              
42             =cut
43              
44             sub base() { 8 }
45              
46             =pod
47              
48             =head2 literal
49              
50             Return the numeric value of this token.
51              
52             =cut
53              
54             sub literal {
55 8     8 1 89 my $self = shift;
56 8 100       34 return if $self->{_error};
57 4         12 my $str = $self->_literal;
58 4         12 my $neg = $str =~ s/^\-//;
59 4         11 my $val = oct $str;
60 4 50       10 return $neg ? -$val : $val;
61             }
62              
63              
64              
65              
66              
67             #####################################################################
68             # Tokenizer Methods
69              
70             sub __TOKENIZER__on_char {
71 61     61   116 my $class = shift;
72 61         95 my $t = shift;
73 61         146 my $char = substr( $t->{line}, $t->{line_cursor}, 1 );
74              
75             # Allow underscores straight through
76 61 100       136 return 1 if $char eq '_';
77              
78 59 100       163 if ( $char =~ /\d/ ) {
79             # You cannot have 8s and 9s on octals
80 13 100 100     65 if ( $char eq '8' or $char eq '9' ) {
81 6         21 $t->{token}->{_error} = "Illegal character in octal number '$char'";
82             }
83 13         36 return 1;
84             }
85              
86             # Doesn't fit a special case, or is after the end of the token
87             # End of token.
88 46         130 $t->_finalize_token->__TOKENIZER__on_char( $t );
89             }
90              
91             1;
92              
93             =pod
94              
95             =head1 SUPPORT
96              
97             See the L in the main module.
98              
99             =head1 AUTHOR
100              
101             Chris Dolan Ecdolan@cpan.orgE
102              
103             =head1 COPYRIGHT
104              
105             Copyright 2006 Chris Dolan.
106              
107             This program is free software; you can redistribute
108             it and/or modify it under the same terms as Perl itself.
109              
110             The full text of the license can be found in the
111             LICENSE file included with this module.
112              
113             =cut