PPI/Token/Number/Hex.pm

filter: Statementstmt 100% 24 / 24 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 97.3% 36 / 37 CC 4 SCAR 6.4
CC
4
Cov
97%
__TOKENIZER__on_char
3.0
literal
2.0
BEGIN
1.0
CRAP 1.9
« PPI/XSAccessor.pm ↑ Summary PPI/Token/DashedWord.pm »
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<PPI::Token::Number::Hex> class is used for tokens that
23 represent base-16 numbers.
24  
25 =head1 METHODS
26  
27 =cut
28  
29 62 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 62 ▶use PPI::Token::Number ();
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 62 ▶use vars qw{$VERSION @ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
33 BEGIN {
34 62 ▶ $VERSION = '1.236';
Subroutine BEGIN: called CC=1 SCAR=0.0
35 62 @ISA = 'PPI::Token::Number';
36 }
37  
38 =pod
39  
40 =head2 base
41  
42 Returns the base for the number: 16.
43  
44 =cut
45  
46 sub base() { 16 }
47  
48 =pod
49  
50 =head2 literal
51  
52 Return the numeric value of this token.
53  
54 =cut
55  
56 sub literal {
57 31 ▶ my $self = shift;
Subroutine literal: called CC=2 SCAR=7.0
Pod documented
58 31 my $str = $self->_literal;
59 31 my $neg = $str =~ s/^\-//;
60 31 my $val = hex lc( $str ); # lc for compatibility with perls before 5.14
61 31 ▶ return $neg ? -$val : $val;
Branch: 1 branch
BranchTrueFalseTotal
$neg ? : 0 31 31
62 }
63  
64  
65  
66  
67  
68 #####################################################################
69 # Tokenizer Methods
70  
71 sub __TOKENIZER__on_char {
72 112 ▶ my $class = shift;
Subroutine __TOKENIZER__on_char: called CC=3 SCAR=11.0
73 112 my $t = shift;
74 112 my $char = substr( $t->{line}, $t->{line_cursor}, 1 );
75  
76 # Allow underscores straight through
77 112 ▶ return 1 if $char eq '_';
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "_" 11 101 112
78  
79 101 ▶ if ( $char =~ /[[:xdigit:]]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /[[:xdigit:]]/) 50 51 101
80 50 return 1;
81 }
82  
83 # Doesn't fit a special case, or is after the end of the token
84 # End of token.
85 51 $t->_finalize_token->__TOKENIZER__on_char( $t );
86 }
87  
88 62 1;
89  
90 =pod
91  
92 =head1 SUPPORT
93  
94 See the L<support section|PPI/SUPPORT> in the main module.
95  
96 =head1 AUTHOR
97  
98 Chris Dolan E<lt>cdolan@cpan.orgE<gt>
99  
100 =head1 COPYRIGHT
101  
102 Copyright 2006 Chris Dolan.
103  
104 This program is free software; you can redistribute
105 it and/or modify it under the same terms as Perl itself.
106  
107 The full text of the license can be found in the
108 LICENSE file included with this module.
109  
110 =cut
« PPI/XSAccessor.pm ↑ Summary PPI/Token/DashedWord.pm »