PPI/Token/Number/Octal.pm

filter: Statementstmt 100% 27 / 27 Branchbran 90.0% 9 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 97.9% 48 / 49 CC 7 SCAR 11.5
CC
7
Cov
98%
__TOKENIZER__on_char
5.0
literal
3.0
BEGIN
1.0
CRAP 3.2
« PPI/Token/Attribute.pm ↑ Summary PPI/Token/Comment.pm »
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 62 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 62 ▶use PPI::Token::Number ();
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 62 ▶use vars qw{$VERSION @ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
33 BEGIN {
34 62 ▶ $VERSION = '1.236';
Subroutine BEGIN: called CC=1 SCAR=0.0
35 62 @ISA = 'PPI::Token::Number';
36 }
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 8 ▶ my $self = shift;
Subroutine literal: called CC=3 SCAR=11.0
Pod documented
58 8 ▶ return if $self->{_error};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_error"} 4 4 8
59 4 my $str = $self->_literal;
60 4 my $neg = $str =~ s/^\-//;
61 4 my $val = oct $str;
62 4 ▶ return $neg ? -$val : $val;
Branch: 1 branch
BranchTrueFalseTotal
$neg ? : 0 4 4
63 }
64  
65  
66  
67  
68  
69 #####################################################################
70 # Tokenizer Methods
71  
72 sub __TOKENIZER__on_char {
73 44 ▶ my $class = shift;
Subroutine __TOKENIZER__on_char: called CC=5 SCAR=16.1
74 44 my $t = shift;
75 44 my $char = substr( $t->{line}, $t->{line_cursor}, 1 );
76  
77 # Allow underscores straight through
78 44 ▶ return 1 if $char eq '_';
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "_" 2 42 44
79  
80 42 ▶ if ( $char =~ /\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /\d/) 9 33 42
81 # You cannot have 8s and 9s on octals
82 9 ▶ if ( $char eq '8' or $char eq '9' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq 8 or $char eq 9) 5 4 9
Condition100%3/3
$char eq 8 or $char eq 9
l!l&&r!l&&!r
144
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
ABresult
1X1
011
000
83 5 $t->{token}->{_error} = "Illegal character in octal number '$char'";
84 }
85 9 return 1;
86 }
87  
88 # Doesn't fit a special case, or is after the end of the token
89 # End of token.
90 33 $t->_finalize_token->__TOKENIZER__on_char( $t );
91 }
92  
93 62 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
« PPI/Token/Attribute.pm ↑ Summary PPI/Token/Comment.pm »