Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Token/Number/Octal.pm |
Statements | Executed 9 statements in 273µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 11µs | 23µs | BEGIN@29 | PPI::Token::Number::Octal::
1 | 1 | 1 | 8µs | 8µs | BEGIN@33 | PPI::Token::Number::Octal::
1 | 1 | 1 | 6µs | 34µs | BEGIN@32 | PPI::Token::Number::Octal::
1 | 1 | 1 | 3µs | 3µs | BEGIN@30 | PPI::Token::Number::Octal::
0 | 0 | 0 | 0s | 0s | __TOKENIZER__on_char | PPI::Token::Number::Octal::
0 | 0 | 0 | 0s | 0s | literal | PPI::Token::Number::Octal::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
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 | 2 | 19µs | 2 | 34µs | # spent 23µs (11+12) within PPI::Token::Number::Octal::BEGIN@29 which was called:
# once (11µs+12µs) by PPI::Token::BEGIN@44 at line 29 # spent 23µs making 1 call to PPI::Token::Number::Octal::BEGIN@29
# spent 12µs making 1 call to strict::import |
30 | 2 | 22µs | 1 | 3µs | # spent 3µs within PPI::Token::Number::Octal::BEGIN@30 which was called:
# once (3µs+0s) by PPI::Token::BEGIN@44 at line 30 # spent 3µs making 1 call to PPI::Token::Number::Octal::BEGIN@30 |
31 | |||||
32 | 2 | 28µs | 2 | 62µs | # spent 34µs (6+28) within PPI::Token::Number::Octal::BEGIN@32 which was called:
# once (6µs+28µs) by PPI::Token::BEGIN@44 at line 32 # spent 34µs making 1 call to PPI::Token::Number::Octal::BEGIN@32
# spent 28µs making 1 call to vars::import |
33 | # spent 8µs within PPI::Token::Number::Octal::BEGIN@33 which was called:
# once (8µs+0s) by PPI::Token::BEGIN@44 at line 36 | ||||
34 | 1 | 300ns | $VERSION = '1.215'; | ||
35 | 1 | 8µs | @ISA = 'PPI::Token::Number'; | ||
36 | 1 | 194µs | 1 | 8µs | } # spent 8µs making 1 call to PPI::Token::Number::Octal::BEGIN@33 |
37 | |||||
38 | =pod | ||||
39 | |||||
40 | =head2 base | ||||
41 | |||||
42 | Returns the base for the number: 8. | ||||
43 | |||||
44 | =cut | ||||
45 | |||||
46 | sub base () { 8 } | ||||
47 | |||||
48 | =pod | ||||
49 | |||||
50 | =head2 literal | ||||
51 | |||||
52 | Return the numeric value of this token. | ||||
53 | |||||
54 | =cut | ||||
55 | |||||
56 | sub literal { | ||||
57 | my $self = shift; | ||||
58 | return if $self->{_error}; | ||||
59 | my $str = $self->_literal; | ||||
60 | my $neg = $str =~ s/^\-//; | ||||
61 | my $val = oct $str; | ||||
62 | return $neg ? -$val : $val; | ||||
63 | } | ||||
64 | |||||
- - | |||||
69 | ##################################################################### | ||||
70 | # Tokenizer Methods | ||||
71 | |||||
72 | sub __TOKENIZER__on_char { | ||||
73 | my $class = shift; | ||||
74 | my $t = shift; | ||||
75 | my $char = substr( $t->{line}, $t->{line_cursor}, 1 ); | ||||
76 | |||||
77 | # Allow underscores straight through | ||||
78 | return 1 if $char eq '_'; | ||||
79 | |||||
80 | if ( $char =~ /\d/ ) { | ||||
81 | # You cannot have 8s and 9s on octals | ||||
82 | if ( $char eq '8' or $char eq '9' ) { | ||||
83 | $t->{token}->{_error} = "Illegal character in octal number '$char'"; | ||||
84 | } | ||||
85 | return 1; | ||||
86 | } | ||||
87 | |||||
88 | # Doesn't fit a special case, or is after the end of the token | ||||
89 | # End of token. | ||||
90 | $t->_finalize_token->__TOKENIZER__on_char( $t ); | ||||
91 | } | ||||
92 | |||||
93 | 1 | 2µs | 1; | ||
94 | |||||
95 | =pod | ||||
96 | |||||
97 | =head1 SUPPORT | ||||
98 | |||||
99 | See the L<support section|PPI/SUPPORT> in the main module. | ||||
100 | |||||
101 | =head1 AUTHOR | ||||
102 | |||||
103 | Chris Dolan E<lt>cdolan@cpan.orgE<gt> | ||||
104 | |||||
105 | =head1 COPYRIGHT | ||||
106 | |||||
107 | Copyright 2006 Chris Dolan. | ||||
108 | |||||
109 | This program is free software; you can redistribute | ||||
110 | it and/or modify it under the same terms as Perl itself. | ||||
111 | |||||
112 | The full text of the license can be found in the | ||||
113 | LICENSE file included with this module. | ||||
114 | |||||
115 | =cut |