| 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 | 63 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 63 | ▶ | use PPI::Token::Number (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | |||||||||||
| 32 | 63 | our $VERSION = '1.260'; # VERSION | |||||||||
| 33 | |||||||||||
| 34 | 63 | 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 | ▶ | my $self = shift; | ||||||||
|
Subroutine
literal: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 56 | 31 | my $str = $self->_literal; | |||||||||
| 57 | 31 | my $neg = $str =~ s/^\-//; | |||||||||
| 58 | 31 | my $val = hex lc( $str ); # lc for compatibility with perls before 5.14 | |||||||||
| 59 | 31 | ▶ | return $neg ? -$val : $val; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | |||||||||||
| 63 | |||||||||||
| 64 | |||||||||||
| 65 | |||||||||||
| 66 | ##################################################################### | ||||||||||
| 67 | # Tokenizer Methods | ||||||||||
| 68 | |||||||||||
| 69 | sub __TOKENIZER__on_char { | ||||||||||
| 70 | 114 | ▶ | my $class = shift; | ||||||||
|
Subroutine
__TOKENIZER__on_char: called CC=3 SCAR=11.0
| |||||||||||
| 71 | 114 | my $t = shift; | |||||||||
| 72 | 114 | my $char = substr( $t->{line}, $t->{line_cursor}, 1 ); | |||||||||
| 73 | |||||||||||
| 74 | # Allow underscores straight through | ||||||||||
| 75 | 114 | ▶ | return 1 if $char eq '_'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | |||||||||||
| 77 | 103 | ▶ | if ( $char =~ /[[:xdigit:]]/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 53 | return 1; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | # Doesn't fit a special case, or is after the end of the token | ||||||||||
| 82 | # End of token. | ||||||||||
| 83 | 50 | $t->_finalize_token->__TOKENIZER__on_char( $t ); | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 63 | 1; | |||||||||
| 87 | |||||||||||
| 88 | =pod | ||||||||||
| 89 | |||||||||||
| 90 | =head1 SUPPORT | ||||||||||
| 91 | |||||||||||
| 92 | See the L<support section|PPI/SUPPORT> in the main module. | ||||||||||
| 93 | |||||||||||
| 94 | =head1 AUTHOR | ||||||||||
| 95 | |||||||||||
| 96 | Chris Dolan E<lt>cdolan@cpan.orgE<gt> | ||||||||||
| 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 | ||||||||||