File Coverage

blib/lib/PPI/Token/Number/Hex.pm
Criterion Covered Total %
statement 18 18 100.0
branch 5 6 83.3
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 28 29 96.5


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