PPI/Token/Unknown.pm

filter: Statementstmt 96.6% 204 / 211 Branchbran 93.5% 146 / 156 Conditioncond 86.8% 86 / 99 MC/DCmcdc 75.0% 39 / 52 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 91.8% 486 / 529 CC 112 SCAR 37.8
CC
112
Cov
94%
__TOKENIZER__on_char
68.0
_cast_or_op
19.9
__TOKENIZER__is_an_attribute
17.3
CRAP 43.8
« PPI/Token/Whitespace.pm ↑ Summary PPI/Lexer.pm »
1 package PPI::Token::Unknown;
2  
3 =pod
4  
5 =head1 NAME
6  
7 PPI::Token::Unknown - Token of unknown or as-yet undetermined type
8  
9 =head1 INHERITANCE
10  
11 PPI::Token::Unknown
12 isa PPI::Token
13 isa PPI::Element
14  
15 =head1 DESCRIPTION
16  
17 Object of the type C<PPI::Token::Unknown> exist primarily inside the
18 tokenizer, where they are temporarily brought into existing for a very
19 short time to represent a token that could be one of a number of types.
20  
21 Generally, they only exist for a character or two, after which they are
22 resolved and converted into the correct type. For an object of this type
23 to survive the parsing process is considered a major bug.
24  
25 Please report any C<PPI::Token::Unknown> you encounter in a L<PPI::Document>
26 object as a bug.
27  
28 =cut
29  
30 63 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 63 ▶use PPI::Token ();
Subroutine BEGIN: called CC=1 SCAR=0.0
32 63 ▶use PPI::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
33 63 ▶use PPI::Singletons qw' %MAGIC $CURLY_SYMBOL ';
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 63 our $VERSION = '1.260'; # VERSION
36  
37 63 our @ISA = "PPI::Token";
38  
39  
40  
41  
42  
43  
44 #####################################################################
45 # Tokenizer Methods
46  
47 sub __TOKENIZER__on_char {
48 25592 ▶ my ( $self, $t ) = @_; # Self and Tokenizer
Subroutine __TOKENIZER__on_char: called CC=68 SCAR=42.2
49 25592 my $c = $t->{token}->{content}; # Current token
50 25592 my $char = substr( $t->{line}, $t->{line_cursor}, 1 ); # Current character
51  
52 # Now, we split on the different values of the current content
53 25592 ▶ if ( $c eq '*' ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($c eq '*') { } 1013 24579 25592
elsif ($c eq '$') { } 16100 8479 24579
elsif ($c eq '@') { } 2769 5710 8479
elsif ($c eq '%') { } 1285 4425 5710
elsif ($c eq '&') { } 1006 3419 4425
elsif ($c eq '-') { } 1855 1564 3419
elsif ($c eq ':') { } 1564 0 1564
54 # Is it a number?
55 1013 ▶ if ( $char =~ /\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /\d/) 70 943 1013
56 # bitwise operator
57 70 $t->{class} = $t->{token}->set_class( 'Operator' );
58 70 return $t->_finalize_token->__TOKENIZER__on_char( $t );
59 }
60  
61 943 ▶ if ( $char =~ /[\w:]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /[\w:]/) 250 693 943
62 # Symbol (unless the thing before it is a number
63 250 my ( $prev ) = $t->_previous_significant_tokens(1);
64 250 ▶ if ( not $prev or not $prev->isa('PPI::Token::Number') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prev and $prev->isa("PPI::Token::Number")) 237 13 250
Condition100%3/3
$prev and $prev->isa("PPI::Token::Number")
!ll&&!rl&&r
3520213
MC/DC100%2/2
$prev and $prev->isa("PPI::Token::Number")
$prev $prev->isa("PPI::Token::Number")
Truth table100%3/3
A and B
A= $prevB= $prev->isa("PPI::Token::Number")
ABresult
0X0
100
111
65 237 $t->{class} = $t->{token}->set_class( 'Symbol' );
66 237 return 1;
67 }
68 }
69  
70 706 ▶ if ( $char eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "{") 26 680 706
71 # Get rest of line
72 26 pos $t->{line} = $t->{line_cursor} + 1;
73 26 ▶ if ( $t->{line} =~ m/$CURLY_SYMBOL/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"line"} =~ /$PPI::Token::Unknown::CURLY_SYMBOL/cg) 0 26 26
74 # control-character symbol (e.g. *{^_Foo})
75 0 $t->{class} = $t->{token}->set_class( 'Magic' );
76 0 return 1;
77 }
78 }
79  
80 # Postfix dereference: ->**
81 706 ▶ if ( $char eq '*' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "*") 37 669 706
82 37 my ( $prev ) = $t->_previous_significant_tokens(1);
83 37 ▶ if ( $prev and $prev->isa('PPI::Token::Operator') and $prev->content eq '->' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev and $prev->isa("PPI::Token::Operator") and $prev->content eq "->") 1 36 37
Condition100%6/6
$prev and $prev->isa("PPI::Token::Operator") and $prev->content eq "->"
!ll&&!rl&&r
3331
$prev and $prev->isa("PPI::Token::Operator")
!ll&&!rl&&r
1324
MC/DC100%3/3
$prev and $prev->isa("PPI::Token::Operator") and $prev->content eq "->"
$prev $prev->isa("PPI::Token::Operator") $prev->content eq "->"
Truth table100%4/4
A and B and C
A= $prevB= $prev->isa("PPI::Token::Operator")C= $prev->content eq "->"
ABCresult
0XX0
10X0
1100
1111
84 1 $t->{class} = $t->{token}->set_class( 'Cast' );
85 1 return 1;
86 }
87 }
88  
89 705 ▶ if ( $char eq '*' || $char eq '=' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "*" or $char eq "=") 71 634 705
Condition100%3/3
$char eq "*" or $char eq "="
l!l&&r!l&&!r
3635634
MC/DC100%2/2
$char eq "*" or $char eq "="
$char eq "*" $char eq "="
Truth table100%3/3
A or B
A= $char eq "*"B= $char eq "="
ABresult
1X1
011
000
90 # Power operator '**' or mult-assign '*='
91 71 $t->{class} = $t->{token}->set_class( 'Operator' );
92 71 return 1;
93 }
94  
95 634 ▶ return $self->_as_cast_or_op($t) if $self->_is_cast_or_op($char);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_cast_or_op($char) 99 535 634
96  
97 535 $t->{class} = $t->{token}->set_class( 'Operator' );
98 535 return $t->_finalize_token->__TOKENIZER__on_char( $t );
99  
100  
101  
102 } elsif ( $c eq '$' ) {
103 # Postfix dereference: ->$* ->$#*
104 16100 ▶ if ( $char eq '*' || $char eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "*" or $char eq "#") 148 15952 16100
Condition100%3/3
$char eq "*" or $char eq "#"
l!l&&r!l&&!r
1213615952
MC/DC100%2/2
$char eq "*" or $char eq "#"
$char eq "*" $char eq "#"
Truth table100%3/3
A or B
A= $char eq "*"B= $char eq "#"
ABresult
1X1
011
000
105 148 my ( $prev ) = $t->_previous_significant_tokens(1);
106 148 ▶ if ( $prev and $prev->isa('PPI::Token::Operator') and $prev->content eq '->' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev and $prev->isa("PPI::Token::Operator") and $prev->content eq "->") 2 146 148
Condition100%6/6
$prev and $prev->isa("PPI::Token::Operator") and $prev->content eq "->"
!ll&&!rl&&r
97492
$prev and $prev->isa("PPI::Token::Operator")
!ll&&!rl&&r
871051
MC/DC100%3/3
$prev and $prev->isa("PPI::Token::Operator") and $prev->content eq "->"
$prev $prev->isa("PPI::Token::Operator") $prev->content eq "->"
Truth table100%4/4
A and B and C
A= $prevB= $prev->isa("PPI::Token::Operator")C= $prev->content eq "->"
ABCresult
0XX0
10X0
1100
1111
107 2 $t->{class} = $t->{token}->set_class( 'Cast' );
108 2 return 1;
109 }
110 }
111  
112 16098 ▶ if ( $char =~ /[a-z_]/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /[a-z_]/i) 15050 1048 16098
113 # Symbol
114 15050 $t->{class} = $t->{token}->set_class( 'Symbol' );
115 15050 return 1;
116 }
117  
118 1048 ▶ if ( $MAGIC{ $c . $char } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI::Token::Unknown::MAGIC{$c . $char}) 906 142 1048
119 # Magic variable
120 906 $t->{class} = $t->{token}->set_class( 'Magic' );
121 906 return 1;
122 }
123  
124 142 ▶ if ( $char eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "{") 15 127 142
125 # Get rest of line
126 15 pos $t->{line} = $t->{line_cursor} + 1;
127 15 ▶ if ( $t->{line} =~ m/$CURLY_SYMBOL/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"line"} =~ /$PPI::Token::Unknown::CURLY_SYMBOL/cg) 4 11 15
128 # control-character symbol (e.g. ${^MATCH})
129 4 $t->{class} = $t->{token}->set_class( 'Magic' );
130 4 return 1;
131 }
132 }
133  
134 # Must be a cast
135 138 $t->{class} = $t->{token}->set_class( 'Cast' );
136 138 return $t->_finalize_token->__TOKENIZER__on_char( $t );
137  
138  
139  
140 } elsif ( $c eq '@' ) {
141 # Postfix dereference: ->@*
142 2769 ▶ if ( $char eq '*' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "*") 8 2761 2769
143 8 my ( $prev ) = $t->_previous_significant_tokens(1);
144 8 ▶ if ( $prev and $prev->isa('PPI::Token::Operator') and $prev->content eq '->' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev and $prev->isa("PPI::Token::Operator") and $prev->content eq "->") 1 7 8
Condition100%6/6
$prev and $prev->isa("PPI::Token::Operator") and $prev->content eq "->"
!ll&&!rl&&r
611
$prev and $prev->isa("PPI::Token::Operator")
!ll&&!rl&&r
242
MC/DC100%3/3
$prev and $prev->isa("PPI::Token::Operator") and $prev->content eq "->"
$prev $prev->isa("PPI::Token::Operator") $prev->content eq "->"
Truth table100%4/4
A and B and C
A= $prevB= $prev->isa("PPI::Token::Operator")C= $prev->content eq "->"
ABCresult
0XX0
10X0
1100
1111
145 1 $t->{class} = $t->{token}->set_class( 'Cast' );
146 1 return 1;
147 }
148 }
149  
150 2768 ▶ if ( $char =~ /[\w:]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /[\w:]/) 1948 820 2768
151 # Symbol
152 1948 $t->{class} = $t->{token}->set_class( 'Symbol' );
153 1948 return 1;
154 }
155  
156 820 ▶ if ( $MAGIC{ $c . $char } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI::Token::Unknown::MAGIC{$c . $char}) 33 787 820
157 # Magic variable
158 33 $t->{class} = $t->{token}->set_class( 'Magic' );
159 33 return 1;
160 }
161  
162 787 ▶ if ( $char eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "{") 245 542 787
163 # Get rest of line
164 245 pos $t->{line} = $t->{line_cursor} + 1;
165 245 ▶ if ( $t->{line} =~ m/$CURLY_SYMBOL/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"line"} =~ /$PPI::Token::Unknown::CURLY_SYMBOL/cg) 1 244 245
166 # control-character symbol (e.g. @{^_Foo})
167 1 $t->{class} = $t->{token}->set_class( 'Magic' );
168 1 return 1;
169 }
170 }
171  
172 # Must be a cast
173 786 $t->{class} = $t->{token}->set_class( 'Cast' );
174 786 return $t->_finalize_token->__TOKENIZER__on_char( $t );
175  
176  
177  
178 } elsif ( $c eq '%' ) {
179 # Postfix dereference: ->%* ->%[...]
180 1285 ▶ if ( $char eq '*' || $char eq '[' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "*" or $char eq "[") 31 1254 1285
Condition100%3/3
$char eq "*" or $char eq "["
l!l&&r!l&&!r
20111254
MC/DC100%2/2
$char eq "*" or $char eq "["
$char eq "*" $char eq "["
Truth table100%3/3
A or B
A= $char eq "*"B= $char eq "["
ABresult
1X1
011
000
181 31 my ( $prev ) = $t->_previous_significant_tokens(1);
182 31 ▶ if ( $prev and $prev->isa('PPI::Token::Operator') and $prev->content eq '->' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev and $prev->isa("PPI::Token::Operator") and $prev->content eq "->") 2 29 31
Condition100%6/6
$prev and $prev->isa("PPI::Token::Operator") and $prev->content eq "->"
!ll&&!rl&&r
19102
$prev and $prev->isa("PPI::Token::Operator")
!ll&&!rl&&r
21712
MC/DC100%3/3
$prev and $prev->isa("PPI::Token::Operator") and $prev->content eq "->"
$prev $prev->isa("PPI::Token::Operator") $prev->content eq "->"
Truth table100%4/4
A and B and C
A= $prevB= $prev->isa("PPI::Token::Operator")C= $prev->content eq "->"
ABCresult
0XX0
10X0
1100
1111
183 2 ▶ if ( $char eq '*' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "*") 1 1 2
184 1 $t->{class} = $t->{token}->set_class( 'Cast' );
185 1 return 1;
186 }
187 1 ▶ if ( $char eq '[' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "[") 1 0 1
188 1 $t->{class} = $t->{token}->set_class( 'Cast' );
189 1 return $t->_finalize_token->__TOKENIZER__on_char( $t );
190 }
191 }
192 }
193  
194 # Is it a number?
195 1283 ▶ if ( $char =~ /\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /\d/) 101 1182 1283
196 # bitwise operator
197 101 $t->{class} = $t->{token}->set_class( 'Operator' );
198 101 return $t->_finalize_token->__TOKENIZER__on_char( $t );
199 }
200  
201 # Is it a magic variable?
202 1182 ▶ if ( $char eq '^' || $MAGIC{ $c . $char } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "^" or $PPI::Token::Unknown::MAGIC{$c . $char}) 70 1112 1182
Condition100%3/3
$char eq "^" or $PPI::Token::Unknown::MAGIC{$c . $char}
l!l&&r!l&&!r
22481112
MC/DC100%2/2
$char eq "^" or $PPI::Token::Unknown::MAGIC{$c . $char}
$char eq "^" $PPI::Token::Unknown::MAGIC{$c . $char}
Truth table100%3/3
A or B
A= $char eq "^"B= $PPI::Token::Unknown::MAGIC{$c . $char}
ABresult
1X1
011
000
203 70 $t->{class} = $t->{token}->set_class( 'Magic' );
204 70 return 1;
205 }
206  
207 1112 ▶ if ( $char =~ /[\w:]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /[\w:]/) 420 692 1112
208 # Symbol (unless the thing before it is a number
209 420 my ( $prev ) = $t->_previous_significant_tokens(1);
210 420 ▶ if ( not $prev or not $prev->isa('PPI::Token::Number') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prev and $prev->isa("PPI::Token::Number")) 413 7 420
Condition100%3/3
$prev and $prev->isa("PPI::Token::Number")
!ll&&!rl&&r
323817
MC/DC100%2/2
$prev and $prev->isa("PPI::Token::Number")
$prev $prev->isa("PPI::Token::Number")
Truth table100%3/3
A and B
A= $prevB= $prev->isa("PPI::Token::Number")
ABresult
0X0
100
111
211 413 $t->{class} = $t->{token}->set_class( 'Symbol' );
212 413 return 1;
213 }
214 }
215  
216 699 ▶ if ( $char eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "{") 43 656 699
217 # Get rest of line
218 43 pos $t->{line} = $t->{line_cursor} + 1;
219 43 ▶ if ( $t->{line} =~ m/$CURLY_SYMBOL/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"line"} =~ /$PPI::Token::Unknown::CURLY_SYMBOL/cg) 1 42 43
220 # control-character symbol (e.g. %{^_Foo})
221 1 $t->{class} = $t->{token}->set_class( 'Magic' );
222 1 return 1;
223 }
224 }
225  
226 698 ▶ return $self->_as_cast_or_op($t) if $self->_is_cast_or_op($char);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_cast_or_op($char) 155 543 698
227  
228 # Probably the mod operator
229 543 $t->{class} = $t->{token}->set_class( 'Operator' );
230 543 return $t->{class}->__TOKENIZER__on_char( $t );
231  
232  
233  
234 } elsif ( $c eq '&' ) {
235 # Postfix dereference: ->&*
236 1006 ▶ if ( $char eq '*' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "*") 14 992 1006
237 14 my ( $prev ) = $t->_previous_significant_tokens(1);
238 14 ▶ if ( $prev and $prev->isa('PPI::Token::Operator') and $prev->content eq '->' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev and $prev->isa("PPI::Token::Operator") and $prev->content eq "->") 1 13 14
Condition100%6/6
$prev and $prev->isa("PPI::Token::Operator") and $prev->content eq "->"
!ll&&!rl&&r
1031
$prev and $prev->isa("PPI::Token::Operator")
!ll&&!rl&&r
284
MC/DC100%3/3
$prev and $prev->isa("PPI::Token::Operator") and $prev->content eq "->"
$prev $prev->isa("PPI::Token::Operator") $prev->content eq "->"
Truth table100%4/4
A and B and C
A= $prevB= $prev->isa("PPI::Token::Operator")C= $prev->content eq "->"
ABCresult
0XX0
10X0
1100
1111
239 1 $t->{class} = $t->{token}->set_class( 'Cast' );
240 1 return 1;
241 }
242 }
243  
244 # Is it a number?
245 1005 ▶ if ( $char =~ /\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /\d/) 99 906 1005
246 # bitwise operator
247 99 $t->{class} = $t->{token}->set_class( 'Operator' );
248 99 return $t->_finalize_token->__TOKENIZER__on_char( $t );
249 }
250  
251 906 ▶ if ( $char =~ /[\w:]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /[\w:]/) 215 691 906
252 # Symbol (unless the thing before it is a number
253 215 my ( $prev ) = $t->_previous_significant_tokens(1);
254 215 ▶ if ( not $prev or not $prev->isa('PPI::Token::Number') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prev and $prev->isa("PPI::Token::Number")) 203 12 215
Condition100%3/3
$prev and $prev->isa("PPI::Token::Number")
!ll&&!rl&&r
3017312
MC/DC100%2/2
$prev and $prev->isa("PPI::Token::Number")
$prev $prev->isa("PPI::Token::Number")
Truth table100%3/3
A and B
A= $prevB= $prev->isa("PPI::Token::Number")
ABresult
0X0
100
111
255 203 $t->{class} = $t->{token}->set_class( 'Symbol' );
256 203 return 1;
257 }
258 }
259  
260 703 ▶ return $self->_as_cast_or_op($t) if $self->_is_cast_or_op($char);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_cast_or_op($char) 102 601 703
261  
262 # Probably the binary and operator
263 601 $t->{class} = $t->{token}->set_class( 'Operator' );
264 601 return $t->{class}->__TOKENIZER__on_char( $t );
265  
266  
267  
268 } elsif ( $c eq '-' ) {
269 1855 ▶ if ( $char =~ /\d/o ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /\d/o) 120 1735 1855
270 # Number
271 120 $t->{class} = $t->{token}->set_class( 'Number' );
272 120 return 1;
273 }
274  
275 1735 ▶ if ( $char eq '.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq ".") 8 1727 1735
276 # Number::Float
277 8 $t->{class} = $t->{token}->set_class( 'Number::Float' );
278 8 return 1;
279 }
280  
281 1727 ▶ if ( $char =~ /[a-zA-Z]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /[a-zA-Z]/) 187 1540 1727
282 187 $t->{class} = $t->{token}->set_class( 'DashedWord' );
283 187 return 1;
284 }
285  
286 # The numeric negative operator
287 1540 $t->{class} = $t->{token}->set_class( 'Operator' );
288 1540 return $t->{class}->__TOKENIZER__on_char( $t );
289  
290  
291  
292 } elsif ( $c eq ':' ) {
293 1564 ▶ if ( $char eq ':' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq ":") 6 1558 1564
294 # ::foo style bareword
295 6 $t->{class} = $t->{token}->set_class( 'Word' );
296 6 return 1;
297 }
298  
299 # Now, : acts very very differently in different contexts.
300 # Mainly, we need to find out if this is a subroutine attribute.
301 # We'll leave a hint in the token to indicate that, if it is.
302 1558 ▶ if ( $self->__TOKENIZER__is_an_attribute( $t ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__TOKENIZER__is_an_attribute($t)) 923 635 1558
303 # This : is an attribute indicator
304 923 $t->{class} = $t->{token}->set_class( 'Operator' );
305 923 $t->{token}->{_attribute} = 1;
306 923 return $t->_finalize_token->__TOKENIZER__on_char( $t );
307 }
308  
309 # It MIGHT be a label, but it's probably the ?: trinary operator
310 635 $t->{class} = $t->{token}->set_class( 'Operator' );
311 635 return $t->{class}->__TOKENIZER__on_char( $t );
312 }
313  
314 # erm...
315 0 PPI::Exception->throw('Unknown value in PPI::Token::Unknown token');
316 }
317  
318 sub _is_cast_or_op {
319 2035 ▶ my ( $self, $char ) = @_;
Subroutine _is_cast_or_op: called CC=6 SCAR=17.9
320 2035 ▶ return 1 if $char eq '$';
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "\$" 149 1886 2035
321 1886 ▶ return 1 if $char eq '@';
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "\@" 41 1845 1886
322 1845 ▶ return 1 if $char eq '%';
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "%" 42 1803 1845
323 1803 ▶ return 1 if $char eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "*" 32 1771 1803
324 1771 ▶ return 1 if $char eq '{';
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "{" 92 1679 1771
325 1679 return;
326 }
327  
328 sub _as_cast_or_op {
329 356 ▶ my ( $self, $t ) = @_;
Subroutine _as_cast_or_op: called CC=1 SCAR=0.0
330 356 my $class = _cast_or_op( $t );
331 356 $t->{class} = $t->{token}->set_class( $class );
332 356 return $t->_finalize_token->__TOKENIZER__on_char( $t );
333 }
334  
335 sub _prev_significant_w_cursor {
336 483 ▶ my ( $tokens, $cursor, $extra_check ) = @_;
Subroutine _prev_significant_w_cursor: called CC=5 SCAR=16.1
337 483 ▶ while ( $cursor >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cursor >= 0) 599 38 637
338 599 my $token = $tokens->[ $cursor-- ];
339 599 ▶ next if !$token->significant;
Branch: 1 branch
BranchTrueFalseTotal
unless $token->significant 134 465 599
340 465 ▶ next if $extra_check and !$extra_check->($token);
Branch: 1 branch
BranchTrueFalseTotal
if $extra_check and not &$extra_check($token) 20 445 465
Condition100%3/3
$extra_check and not &$extra_check($token)
!ll&&!rl&&r
4133220
MC/DC100%2/2
$extra_check and not &$extra_check($token)
$extra_check not &$extra_check($token)
Truth table100%3/3
A and not(B)
A= $extra_checkB= not &$extra_check($token)
ABresult
0X0
100
111
341 445 return ( $token, $cursor );
342 }
343 38 return ( undef, $cursor );
344 }
345  
346 # Operator/operand-sensitive, multiple or GLOB cast
347 sub _cast_or_op {
348 356 ▶ my ( $t ) = @_;
Subroutine _cast_or_op: called CC=19 SCAR=29.9
349  
350 356 my $tokens = $t->{tokens};
351 356 my $cursor = scalar( @$tokens ) - 1;
352 356 my $token;
353  
354 356 ( $token, $cursor ) = _prev_significant_w_cursor( $tokens, $cursor );
355 356 ▶ return 'Cast' if !$token; # token was first in the document
Branch: 1 branch
BranchTrueFalseTotal
unless $token 27 329 356
356  
357 329 ▶ if ( $token->isa( 'PPI::Token::Structure' ) and $token->content eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->isa("PPI::Token::Structure") and $token->content eq "}") 33 296 329
Condition100%3/3
$token->isa("PPI::Token::Structure") and $token->content eq "}"
!ll&&!rl&&r
2435333
MC/DC100%2/2
$token->isa("PPI::Token::Structure") and $token->content eq "}"
$token->isa("PPI::Token::Structure") $token->content eq "}"
Truth table100%3/3
A and B
A= $token->isa("PPI::Token::Structure")B= $token->content eq "}"
ABresult
0X0
100
111
358  
359 # Scan the token stream backwards an arbitrarily long way,
360 # looking for the matching opening curly brace.
361 33 my $structure_depth = 1;
362 ( $token, $cursor ) = _prev_significant_w_cursor(
363 $tokens, $cursor,
364 sub {
365 52 ▶ my ( $token ) = @_;
Subroutine __ANON__: called CC=5 SCAR=17.3
366 52 ▶ return if !$token->isa( 'PPI::Token::Structure' );
Branch: 1 branch
BranchTrueFalseTotal
unless $token->isa("PPI::Token::Structure") 20 32 52
367 32 ▶ if ( $token eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq "}") 0 32 32
368 0 $structure_depth++;
369 0 return;
370 }
371 32 ▶ if ( $token eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq "{") 32 0 32
372 32 $structure_depth--;
373 32 ▶ return if $structure_depth;
Branch: 1 branch
BranchTrueFalseTotal
if $structure_depth 0 32 32
374 }
375 32 return 1;
376 }
377 33 );
378 33 ▶ return 'Operator' if !$token; # no matching '{', probably an unbalanced '}'
Branch: 1 branch
BranchTrueFalseTotal
unless $token 1 32 33
379  
380 # Scan past any whitespace
381 32 ( $token, $cursor ) = _prev_significant_w_cursor( $tokens, $cursor );
382 32 ▶ return 'Operator' if !$token; # Document began with what must be a hash constructor.
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 32 32
383 32 ▶ return 'Operator' if $token->isa( 'PPI::Token::Symbol' ); # subscript
Branch: 1 branch
BranchTrueFalseTotal
if $token->isa("PPI::Token::Symbol") 0 32 32
384  
385 32 my %meth_or_subscript_end = map { $_ => 1 } qw@ -> } ] @;
386 32 ▶ return 'Operator' if $meth_or_subscript_end{ $token->content }; # subscript
Branch: 1 branch
BranchTrueFalseTotal
if $meth_or_subscript_end{$token->content} 9 23 32
387  
388 23 my $content = $token->content;
389 23 ▶ my $produces_or_wants_value =
Condition66%4/6
$token->isa('PPI::Token::Word') && ($content eq 'do' || $content eq 'eval')
!ll&&!rl&&r
0185
$content eq "do" or $content eq "eval"
l!l&&r!l&&!r
0518
MC/DC33%1/3
$token->isa('PPI::Token::Word') && ($content eq 'do' || $content eq 'eval')
$token->isa('PPI::Token::Word') $content eq "do" $content eq "eval"
Truth table50%2/4
A && B or C
A= $token->isa('PPI::Token::Word')B= $content eq "do"C= $content eq "eval"
ABCresult
0XX0
1000
11X1
1011
390 ( $token->isa( 'PPI::Token::Word' ) and ( $content eq 'do' or $content eq 'eval' ) );
391 23 ▶ return $produces_or_wants_value ? 'Operator' : 'Cast';
Branch: 1 branch
BranchTrueFalseTotal
$produces_or_wants_value ? : 5 18 23
392 }
393  
394 296 my %list_start_or_term_end = map { $_ => 1 } qw@ ; ( { [ @;
395 return 'Cast'
396 296 ▶ if $token->isa( 'PPI::Token::Structure' ) and $list_start_or_term_end{ $token->content }
Branch: 1 branch
BranchTrueFalseTotal
if $token->isa("PPI::Token::Structure") and $list_start_or_term_end{$token->content} or $token->isa("PPI::Token::Cast") or $token->isa("PPI::Token::Operator") or $token->isa("PPI::Token::Label") 80 145 225
Condition100%12/12
$token->isa("PPI::Token::Structure") and $list_start_or_term_end{$token->content} or $token->isa("PPI::Token::Cast") or $token->isa("PPI::Token::Operator") or $token->isa("PPI::Token::Label")
l!l&&r!l&&!r
1447145
$token->isa("PPI::Token::Structure") and $list_start_or_term_end{$token->content} or $token->isa("PPI::Token::Cast") or $token->isa("PPI::Token::Operator")
l!l&&r!l&&!r
7173152
$token->isa("PPI::Token::Structure") and $list_start_or_term_end{$token->content} or $token->isa("PPI::Token::Cast")
l!l&&r!l&&!r
4526225
$token->isa("PPI::Token::Structure") and $list_start_or_term_end{$token->content}
!ll&&!rl&&r
243845
MC/DC100%5/5
$token->isa("PPI::Token::Structure") and $list_start_or_term_end{$token->content} or $token->isa("PPI::Token::Cast") or $token->isa("PPI::Token::Operator") or $token->isa("PPI::Token::Label")
$token->isa("PPI::Token::Structure") $list_start_or_term_end{$token->content} $token->isa("PPI::Token::Cast") $token->isa("PPI::Token::Operator") $token->isa("PPI::Token::Label")
Truth table66%6/9
A and B or C or D or E
A= $token->isa("PPI::Token::Structure")B= $list_start_or_term_end{$token->content}C= $token->isa("PPI::Token::Cast")D= $token->isa("PPI::Token::Operator")E= $token->isa("PPI::Token::Label")
ABCDEresult
11XXX1
0X1XX1
101XX1
0X01X1
1001X1
0X0011
100011
0X0000
100000
397 or $token->isa( 'PPI::Token::Cast' )
398 or $token->isa( 'PPI::Token::Operator' )
399 or $token->isa( 'PPI::Token::Label' );
400  
401 145 ▶ return 'Operator' if !$token->isa( 'PPI::Token::Word' );
Branch: 1 branch
BranchTrueFalseTotal
unless $token->isa("PPI::Token::Word") 83 62 145
402  
403 62 ( $token, $cursor ) = _prev_significant_w_cursor( $tokens, $cursor );
404 62 ▶ return 'Cast' if !$token || $token->content ne '->';
Branch: 1 branch
BranchTrueFalseTotal
if not $token or $token->content ne "->" 62 0 62
Condition66%2/3
not $token or $token->content ne "->"
l!l&&r!l&&!r
10520
MC/DC0%0/2
not $token or $token->content ne "->"
not $token $token->content ne "->"
Truth table66%2/3
not(A) or B
A= not $tokenB= $token->content ne "->"
ABresult
1X1
011
000
405  
406 0 return 'Operator';
407 }
408  
409 # Are we at a location where a ':' would indicate a subroutine attribute
410 sub __TOKENIZER__is_an_attribute {
411 1558 ▶ my $t = $_[1]; # Tokenizer object
Subroutine __TOKENIZER__is_an_attribute: called CC=14 SCAR=28.5
412 1558 my @tokens = $t->_previous_significant_tokens(3);
413 1558 my $p0 = $tokens[0];
414 1558 ▶ return '' if not $p0;
Branch: 1 branch
BranchTrueFalseTotal
unless $p0 76 1482 1558
415  
416 # If we just had another attribute, we are also an attribute
417 1482 ▶ return 1 if $p0->isa('PPI::Token::Attribute');
Branch: 1 branch
BranchTrueFalseTotal
if $p0->isa("PPI::Token::Attribute") 176 1306 1482
418  
419 # If we just had a prototype, then we are an attribute
420 1306 ▶ return 1 if $p0->isa('PPI::Token::Prototype');
Branch: 1 branch
BranchTrueFalseTotal
if $p0->isa("PPI::Token::Prototype") 126 1180 1306
421  
422 # Other than that, we would need to have had a bareword
423 1180 ▶ return '' unless $p0->isa('PPI::Token::Word');
Branch: 1 branch
BranchTrueFalseTotal
unless $p0->isa("PPI::Token::Word") 536 644 1180
424  
425 # We could be an anonymous subroutine
426 644 ▶ if ( $p0->isa('PPI::Token::Word') and $p0->content eq 'sub' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p0->isa("PPI::Token::Word") and $p0->content eq "sub") 0 644 644
Condition33%1/3
$p0->isa("PPI::Token::Word") and $p0->content eq "sub"
!ll&&!rl&&r
06440
MC/DC0%0/2
$p0->isa("PPI::Token::Word") and $p0->content eq "sub"
$p0->isa("PPI::Token::Word") $p0->content eq "sub"
Truth table33%1/3
A and B
A= $p0->isa("PPI::Token::Word")B= $p0->content eq "sub"
ABresult
0X0
100
111
427 0 return 1;
428 }
429  
430 # Or, we could be a named subroutine
431 644 my $p1 = $tokens[1];
432 644 my $p2 = $tokens[2];
433 644 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($p1 and $p1->isa("PPI::Token::Word") and $p1->content eq "sub" and !$p2 || $p2->isa("PPI::Token::Structure") || $p2->isa("PPI::Token::Whitespace") && $p2->content eq "") 108 23 131
Condition55%10/18
$p1 and $p1->isa("PPI::Token::Word") and $p1->content eq "sub" and !$p2 || $p2->isa("PPI::Token::Structure") || $p2->isa("PPI::Token::Whitespace") && $p2->content eq ""
!ll&&!rl&&r
236210
$p1 and $p1->isa("PPI::Token::Word") and $p1->content eq "sub"
!ll&&!rl&&r
203621
$p1 and $p1->isa("PPI::Token::Word")
!ll&&!rl&&r
020624
not $p2 or $p2->isa("PPI::Token::Structure") or $p2->isa("PPI::Token::Whitespace") and $p2->content eq ""
l!l&&r!l&&!r
62100
not $p2 or $p2->isa("PPI::Token::Structure")
l!l&&r!l&&!r
5131080
$p2->isa("PPI::Token::Whitespace") and $p2->content eq ""
!ll&&!rl&&r
000
MC/DC0%0/7
$p1 and $p1->isa("PPI::Token::Word") and $p1->content eq "sub" and !$p2 || $p2->isa("PPI::Token::Structure") || $p2->isa("PPI::Token::Whitespace") && $p2->content eq ""
$p1 $p1->isa("PPI::Token::Word") $p1->content eq "sub" not $p2 $p2->isa("PPI::Token::Structure") $p2->isa("PPI::Token::Whitespace") $p2->content eq ""
Truth table25%2/8
A and B and C and not(D) or E or F and G
A= $p1B= $p1->isa("PPI::Token::Word")C= $p1->content eq "sub"D= not $p2E= $p2->isa("PPI::Token::Structure")F= $p2->isa("PPI::Token::Whitespace")G= $p2->content eq ""
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
111000X0
11100100
1111XXX1
11101XX1
11100111
434 $p1
435 and
436 $p1->isa('PPI::Token::Word')
437 and
438 $p1->content eq 'sub'
439 and (
440 not $p2
441 or
442 $p2->isa('PPI::Token::Structure')
443 or (
444 $p2->isa('PPI::Token::Whitespace')
445 and
446 $p2->content eq ''
447 )
448 )
449 ) {
450 621 return 1;
451 }
452  
453 # We aren't an attribute
454 23 '';
455 }
456  
457 63 1;
458  
459 =pod
460  
461 =head1 SUPPORT
462  
463 See the L<support section|PPI/SUPPORT> in the main module.
464  
465 =head1 AUTHOR
466  
467 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
468  
469 =head1 COPYRIGHT
470  
471 Copyright 2001 - 2011 Adam Kennedy.
472  
473 This program is free software; you can redistribute
474 it and/or modify it under the same terms as Perl itself.
475  
476 The full text of the license can be found in the
477 LICENSE file included with this module.
478  
479 =cut
« PPI/Token/Whitespace.pm ↑ Summary PPI/Lexer.pm »