Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Token/Number/Binary.pm |
Statements | Executed 9 statements in 298µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 12µs | 24µs | BEGIN@29 | PPI::Token::Number::Binary::
1 | 1 | 1 | 12µs | 12µs | BEGIN@33 | PPI::Token::Number::Binary::
1 | 1 | 1 | 6µs | 38µs | BEGIN@32 | PPI::Token::Number::Binary::
1 | 1 | 1 | 3µs | 3µs | BEGIN@30 | PPI::Token::Number::Binary::
0 | 0 | 0 | 0s | 0s | __TOKENIZER__on_char | PPI::Token::Number::Binary::
0 | 0 | 0 | 0s | 0s | base | PPI::Token::Number::Binary::
0 | 0 | 0 | 0s | 0s | literal | PPI::Token::Number::Binary::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package PPI::Token::Number::Binary; | ||||
2 | |||||
3 | =pod | ||||
4 | |||||
5 | =head1 NAME | ||||
6 | |||||
7 | PPI::Token::Number::Binary - Token class for a binary number | ||||
8 | |||||
9 | =head1 SYNOPSIS | ||||
10 | |||||
11 | $n = 0b1110011; # binary integer | ||||
12 | |||||
13 | =head1 INHERITANCE | ||||
14 | |||||
15 | PPI::Token::Number::Binary | ||||
16 | isa PPI::Token::Number | ||||
17 | isa PPI::Token | ||||
18 | isa PPI::Element | ||||
19 | |||||
20 | =head1 DESCRIPTION | ||||
21 | |||||
22 | The C<PPI::Token::Number::Binary> class is used for tokens that | ||||
23 | represent base-2 numbers. | ||||
24 | |||||
25 | =head1 METHODS | ||||
26 | |||||
27 | =cut | ||||
28 | |||||
29 | 2 | 20µs | 2 | 36µs | # spent 24µs (12+12) within PPI::Token::Number::Binary::BEGIN@29 which was called:
# once (12µs+12µs) by PPI::Token::BEGIN@43 at line 29 # spent 24µs making 1 call to PPI::Token::Number::Binary::BEGIN@29
# spent 12µs making 1 call to strict::import |
30 | 2 | 24µs | 1 | 3µs | # spent 3µs within PPI::Token::Number::Binary::BEGIN@30 which was called:
# once (3µs+0s) by PPI::Token::BEGIN@43 at line 30 # spent 3µs making 1 call to PPI::Token::Number::Binary::BEGIN@30 |
31 | |||||
32 | 2 | 31µs | 2 | 70µs | # spent 38µs (6+32) within PPI::Token::Number::Binary::BEGIN@32 which was called:
# once (6µs+32µs) by PPI::Token::BEGIN@43 at line 32 # spent 38µs making 1 call to PPI::Token::Number::Binary::BEGIN@32
# spent 32µs making 1 call to vars::import |
33 | # spent 12µs within PPI::Token::Number::Binary::BEGIN@33 which was called:
# once (12µs+0s) by PPI::Token::BEGIN@43 at line 36 | ||||
34 | 1 | 400ns | $VERSION = '1.215'; | ||
35 | 1 | 12µs | @ISA = 'PPI::Token::Number'; | ||
36 | 1 | 208µs | 1 | 12µs | } # spent 12µs making 1 call to PPI::Token::Number::Binary::BEGIN@33 |
37 | |||||
38 | =pod | ||||
39 | |||||
40 | =head2 base | ||||
41 | |||||
42 | Returns the base for the number: 2. | ||||
43 | |||||
44 | =cut | ||||
45 | |||||
46 | sub base { | ||||
47 | return 2; | ||||
48 | } | ||||
49 | |||||
50 | =pod | ||||
51 | |||||
52 | =head2 literal | ||||
53 | |||||
54 | Return the numeric value of this token. | ||||
55 | |||||
56 | =cut | ||||
57 | |||||
58 | sub literal { | ||||
59 | my $self = shift; | ||||
60 | return if $self->{_error}; | ||||
61 | my $str = $self->_literal; | ||||
62 | my $neg = $str =~ s/^\-//; | ||||
63 | $str =~ s/^0b//; | ||||
64 | my $val = 0; | ||||
65 | for my $bit ( $str =~ m/(.)/g ) { | ||||
66 | $val = $val * 2 + $bit; | ||||
67 | } | ||||
68 | return $neg ? -$val : $val; | ||||
69 | } | ||||
70 | |||||
- - | |||||
75 | ##################################################################### | ||||
76 | # Tokenizer Methods | ||||
77 | |||||
78 | sub __TOKENIZER__on_char { | ||||
79 | my $class = shift; | ||||
80 | my $t = shift; | ||||
81 | my $char = substr( $t->{line}, $t->{line_cursor}, 1 ); | ||||
82 | |||||
83 | # Allow underscores straight through | ||||
84 | return 1 if $char eq '_'; | ||||
85 | |||||
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'"; | ||||
90 | } | ||||
91 | return 1; | ||||
92 | } | ||||
93 | |||||
94 | # Doesn't fit a special case, or is after the end of the token | ||||
95 | # End of token. | ||||
96 | $t->_finalize_token->__TOKENIZER__on_char( $t ); | ||||
97 | } | ||||
98 | |||||
99 | 1 | 2µs | 1; | ||
100 | |||||
101 | =pod | ||||
102 | |||||
103 | =head1 SUPPORT | ||||
104 | |||||
105 | See the L<support section|PPI/SUPPORT> in the main module. | ||||
106 | |||||
107 | =head1 AUTHOR | ||||
108 | |||||
109 | Chris Dolan E<lt>cdolan@cpan.orgE<gt> | ||||
110 | |||||
111 | =head1 COPYRIGHT | ||||
112 | |||||
113 | Copyright 2006 Chris Dolan. | ||||
114 | |||||
115 | This program is free software; you can redistribute | ||||
116 | it and/or modify it under the same terms as Perl itself. | ||||
117 | |||||
118 | The full text of the license can be found in the | ||||
119 | LICENSE file included with this module. | ||||
120 | |||||
121 | =cut |