| 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<PPI::Token::Number::Octal> class is used for tokens that | ||||||||||||||||||||||||||||
| 23 | represent base-8 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: 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 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
literal: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 8 | ▶ | return if $self->{_error}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 4 | my $str = $self->_literal; | |||||||||||||||||||||||||||
| 58 | 4 | my $neg = $str =~ s/^\-//; | |||||||||||||||||||||||||||
| 59 | 4 | my $val = oct $str; | |||||||||||||||||||||||||||
| 60 | 4 | ▶ | return $neg ? -$val : $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | ##################################################################### | ||||||||||||||||||||||||||||
| 68 | # Tokenizer Methods | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | sub __TOKENIZER__on_char { | ||||||||||||||||||||||||||||
| 71 | 51 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
__TOKENIZER__on_char: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 72 | 51 | my $t = shift; | |||||||||||||||||||||||||||
| 73 | 51 | my $char = substr( $t->{line}, $t->{line_cursor}, 1 ); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # Allow underscores straight through | ||||||||||||||||||||||||||||
| 76 | 51 | ▶ | return 1 if $char eq '_'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 48 | ▶ | if ( $char =~ /\d/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | # You cannot have 8s and 9s on octals | ||||||||||||||||||||||||||||
| 80 | 10 | ▶ | if ( $char eq '8' or $char eq '9' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$char eq 8 or $char eq 9
MC/DC100%2/2
$char eq 8 or $char eq 9
$char eq 8
$char eq 9
Truth table100%3/3
A or B
A= $char eq 8B= $char eq 9
| |||||||||||||||||||||||||||||
| 81 | 5 | $t->{token}->{_error} = "Illegal character in octal number '$char'"; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | 10 | return 1; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # Doesn't fit a special case, or is after the end of the token | ||||||||||||||||||||||||||||
| 87 | # End of token. | ||||||||||||||||||||||||||||
| 88 | 38 | $t->_finalize_token->__TOKENIZER__on_char( $t ); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 63 | 1; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =pod | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | See the L<support section|PPI/SUPPORT> in the main module. | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | Chris Dolan E<lt>cdolan@cpan.orgE<gt> | ||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||