1 package PPI::Token::Number::Binary;
7 PPI::Token::Number::Binary - Token class for a binary number
11 $n = 0b1110011; # binary integer
15 PPI::Token::Number::Binary
16 isa PPI::Token::Number
22 The C<PPI::Token::Number::Binary> class is used for tokens that
23 represent base-2 numbers.
30 use PPI::Token::Number ();
32 use vars qw{$VERSION @ISA};
35 @ISA = 'PPI::Token::Number';
42 Returns the base for the number: 2.
54 Return the numeric value of this token.
60 return if $self->{_error};
61 my $str = $self->_literal;
62 my $neg = $str =~ s/^\-//;
65 for my $bit ( $str =~ m/(.)/g ) {
66 $val = $val * 2 + $bit;
68 return $neg ? -$val : $val;
75 #####################################################################
78 sub __TOKENIZER__on_char {
81 my $char = substr( $t->{line}, $t->{line_cursor}, 1 );
83 # Allow underscores straight through
84 return 1 if $char eq '_';
86 if ( $char =~ /[\w\d]/ ) {
87 unless ( $char eq '1' or $char eq '0' ) {
88 # Add a warning if it contains non-hex chars
89 $t->{token}->{_error} = "Illegal character in binary number '$char'";
94 # Doesn't fit a special case, or is after the end of the token
96 $t->_finalize_token->__TOKENIZER__on_char( $t );
105 See the L<support section|PPI/SUPPORT> in the main module.
109 Chris Dolan E<lt>cdolan@cpan.orgE<gt>
113 Copyright 2006 Chris Dolan.
115 This program is free software; you can redistribute
116 it and/or modify it under the same terms as Perl itself.
118 The full text of the license can be found in the
119 LICENSE file included with this module.