PPI/Token/Operator.pm

filter: Statementstmt 100% 30 / 30 Branchbran 100% 12 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 100% 47 / 47 CC 7 SCAR 15.7
CC
7
Cov
100%
__TOKENIZER__on_char
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.8
« PPI/Transform.pm ↑ Summary PPI/Statement/Scheduled.pm »
1 package PPI::Token::Operator;
2  
3 =pod
4  
5 =head1 NAME
6  
7 PPI::Token::Operator - Token class for operators
8  
9 =head1 INHERITANCE
10  
11 PPI::Token::Operator
12 isa PPI::Token
13 isa PPI::Element
14  
15 =head1 SYNOPSIS
16  
17 # This is the list of valid operators
18 ++ -- ** ! ~ + -
19 =~ !~ * / % x
20 << >> lt gt le ge cmp ~~
21 == != <=> . .. ... ,
22 & | ^ && || //
23 ? : **= += -= .= *= /=
24 %= x= &= |= ^= <<= >>= &&=
25 ||= //= < > <= >= <> => ->
26 and or xor not eq ne
27  
28  
29 =head1 DESCRIPTION
30  
31 All operators in PPI are created as C<PPI::Token::Operator> objects,
32 including the ones that may superficially look like a L<PPI::Token::Word>
33 object.
34  
35 =head1 METHODS
36  
37 There are no additional methods beyond those provided by the parent
38 L<PPI::Token> and L<PPI::Element> classes.
39  
40 =cut
41  
42 62 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 62 ▶use PPI::Token ();
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 62 ▶use vars qw{$VERSION @ISA %OPERATOR};
Subroutine BEGIN: called CC=1 SCAR=0.0
46 BEGIN {
47 62 ▶ $VERSION = '1.236';
Subroutine BEGIN: called CC=1 SCAR=0.0
48 62 @ISA = 'PPI::Token';
49  
50 # Build the operator index
51 ### NOTE - This is accessed several times explicitly
52 ### in PPI::Token::Word. Do not rename this
53 ### without also correcting them.
54 62 %OPERATOR = map { $_ => 1 } (
55 qw{
56 -> ++ -- ** ! ~ + -
57 =~ !~ * / % x . << >>
58 < > <= >= lt gt le ge
59 == != <=> eq ne cmp ~~
60 & | ^ && || // .. ...
61 ? :
62 = **= += -= .= *= /= %= x= &= |= ^= <<= >>= &&= ||= //=
63 => <>
64 and or xor not
65 }, ',' # Avoids "comma in qw{}" warning
66 );
67 }
68  
69  
70  
71  
72  
73 #####################################################################
74 # Tokenizer Methods
75  
76 sub __TOKENIZER__on_char {
77 42791 ▶ my $t = $_[1];
Subroutine __TOKENIZER__on_char: called CC=7 SCAR=19.5
78 42791 my $char = substr( $t->{line}, $t->{line_cursor}, 1 );
79  
80 # Are we still an operator if we add the next character
81 42791 my $content = $t->{token}->{content};
82 42791 ▶ return 1 if $OPERATOR{ $content . $char };
Branch: 1 branch
BranchTrueFalseTotal
if $PPI::Token::Operator::OPERATOR{$content . $char} 10550 32241 42791
83  
84 # Handle the special case of a .1234 decimal number
85 32241 ▶ if ( $content eq '.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content eq ".") 666 31575 32241
86 666 ▶ if ( $char =~ /^[0-9]$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /^[0-9]$/) 42 624 666
87 # This is a decimal number
88 42 $t->{class} = $t->{token}->set_class('Number::Float');
89 42 return $t->{class}->__TOKENIZER__on_char( $t );
90 }
91 }
92  
93 # Handle the special case if we might be a here-doc
94 32199 ▶ if ( $content eq '<<' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content eq "<<") 512 31687 32199
95 512 pos $t->{line} = $t->{line_cursor};
96 # Either <<FOO or << 'FOO' or <<\FOO
97 ### Is the zero-width look-ahead assertion really
98 ### supposed to be there?
99 512 ▶ if ( $t->{line} =~ m/\G(?: (?!\d)\w | \s*['"`] | \\\w ) /gcx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"line"} =~ /\G(?: (?!\d)\w | \s*['"`] | \\\w ) /cgx) 198 314 512
100 # This is a here-doc.
101 # Change the class and move to the HereDoc's own __TOKENIZER__on_char method.
102 198 $t->{class} = $t->{token}->set_class('HereDoc');
103 198 return $t->{class}->__TOKENIZER__on_char( $t );
104 }
105 }
106  
107 # Handle the special case of the null Readline
108 32001 ▶ if ( $content eq '<>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content eq "<>") 9 31992 32001
109 9 $t->{class} = $t->{token}->set_class('QuoteLike::Readline');
110 }
111  
112 # Finalize normally
113 32001 $t->_finalize_token->__TOKENIZER__on_char( $t );
114 }
115  
116 62 1;
117  
118 =pod
119  
120 =head1 SUPPORT
121  
122 See the L<support section|PPI/SUPPORT> in the main module.
123  
124 =head1 AUTHOR
125  
126 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
127  
128 =head1 COPYRIGHT
129  
130 Copyright 2001 - 2011 Adam Kennedy.
131  
132 This program is free software; you can redistribute
133 it and/or modify it under the same terms as Perl itself.
134  
135 The full text of the license can be found in the
136 LICENSE file included with this module.
137  
138 =cut
« PPI/Transform.pm ↑ Summary PPI/Statement/Scheduled.pm »