PPI/Token/Unknown.pm

filter: Statementstmt 97.2% 178 / 183 Branchbran 95.4% 126 / 132 Conditioncond 82.5% 52 / 63 MC/DCmcdc 63.6% 21 / 33 Subroutinesub 100% 12 / 12 Podpod n/a totaltotal 91.9% 389 / 423 CC 88 SCAR 32.8
CC
88
Cov
94%
__TOKENIZER__on_char
44.0
_cast_or_op
19.1
__TOKENIZER__is_an_attribute
16.5
CRAP 26.5
« PPI/Transform/UpdateCopyright.pm ↑ Summary PPI/Token/Word.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 62 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 62 ▶use PPI::Token ();
Subroutine BEGIN: called CC=1 SCAR=0.0
32 62 ▶use PPI::Exception ();
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 62 ▶use vars qw{$VERSION @ISA $CURLY_SYMBOL};
Subroutine BEGIN: called CC=1 SCAR=0.0
35 BEGIN {
36 62 ▶ $VERSION = '1.236';
Subroutine BEGIN: called CC=1 SCAR=0.0
37 62 @ISA = 'PPI::Token';
38 62 $CURLY_SYMBOL = qr{\G\^[[:upper:]_]\w+\}};
39 }
40  
41  
42  
43  
44  
45 #####################################################################
46 # Tokenizer Methods
47  
48 sub __TOKENIZER__on_char {
49 24857 ▶ my ( $self, $t ) = @_; # Self and Tokenizer
Subroutine __TOKENIZER__on_char: called CC=44 SCAR=37.8
50 24857 my $c = $t->{token}->{content}; # Current token
51 24857 my $char = substr( $t->{line}, $t->{line_cursor}, 1 ); # Current character
52  
53 # Now, we split on the different values of the current content
54 24857 ▶ if ( $c eq '*' ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($c eq '*') { } 1009 23848 24857
elsif ($c eq '$') { } 15485 8363 23848
elsif ($c eq '@') { } 2733 5630 8363
elsif ($c eq '%') { } 1261 4369 5630
elsif ($c eq '&') { } 1006 3363 4369
elsif ($c eq '-') { } 1850 1513 3363
elsif ($c eq ':') { } 1513 0 1513
55 # Is it a number?
56 1009 ▶ if ( $char =~ /\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /\d/) 88 921 1009
57 # bitwise operator
58 88 $t->{class} = $t->{token}->set_class( 'Operator' );
59 88 return $t->_finalize_token->__TOKENIZER__on_char( $t );
60 }
61  
62 921 ▶ if ( $char =~ /[\w:]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /[\w:]/) 248 673 921
63 # Symbol (unless the thing before it is a number
64 248 my ( $prev ) = $t->_previous_significant_tokens(1);
65 248 ▶ if ( not $prev or not $prev->isa('PPI::Token::Number') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prev and $prev->isa("PPI::Token::Number")) 236 12 248
Condition100%3/3
$prev and $prev->isa("PPI::Token::Number")
!ll&&!rl&&r
3819812
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
66 236 $t->{class} = $t->{token}->set_class( 'Symbol' );
67 236 return 1;
68 }
69 }
70  
71 685 ▶ if ( $char eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "{") 24 661 685
72 # Get rest of line
73 24 pos $t->{line} = $t->{line_cursor} + 1;
74 24 ▶ if ( $t->{line} =~ m/$CURLY_SYMBOL/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"line"} =~ /$PPI::Token::Unknown::CURLY_SYMBOL/cg) 0 24 24
75 # control-character symbol (e.g. *{^_Foo})
76 0 $t->{class} = $t->{token}->set_class( 'Magic' );
77 0 return 1;
78 }
79 }
80  
81 685 ▶ if ( $char eq '*' || $char eq '=' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "*" or $char eq "=") 67 618 685
Condition100%3/3
$char eq "*" or $char eq "="
l!l&&r!l&&!r
3829618
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
82 # Power operator '**' or mult-assign '*='
83 67 $t->{class} = $t->{token}->set_class( 'Operator' );
84 67 return 1;
85 }
86  
87 618 ▶ 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) 91 527 618
88  
89 527 $t->{class} = $t->{token}->set_class( 'Operator' );
90 527 return $t->_finalize_token->__TOKENIZER__on_char( $t );
91  
92  
93  
94 } elsif ( $c eq '$' ) {
95 15485 ▶ if ( $char =~ /[a-z_]/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /[a-z_]/i) 14469 1016 15485
96 # Symbol
97 14469 $t->{class} = $t->{token}->set_class( 'Symbol' );
98 14469 return 1;
99 }
100  
101 1016 ▶ if ( $PPI::Token::Magic::magic{ $c . $char } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI::Token::Magic::magic{$c . $char}) 871 145 1016
102 # Magic variable
103 871 $t->{class} = $t->{token}->set_class( 'Magic' );
104 871 return 1;
105 }
106  
107 145 ▶ if ( $char eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "{") 20 125 145
108 # Get rest of line
109 20 pos $t->{line} = $t->{line_cursor} + 1;
110 20 ▶ if ( $t->{line} =~ m/$CURLY_SYMBOL/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"line"} =~ /$PPI::Token::Unknown::CURLY_SYMBOL/cg) 4 16 20
111 # control-character symbol (e.g. ${^MATCH})
112 4 $t->{class} = $t->{token}->set_class( 'Magic' );
113 4 return 1;
114 }
115 }
116  
117 # Must be a cast
118 141 $t->{class} = $t->{token}->set_class( 'Cast' );
119 141 return $t->_finalize_token->__TOKENIZER__on_char( $t );
120  
121  
122  
123 } elsif ( $c eq '@' ) {
124 2733 ▶ if ( $char =~ /[\w:]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /[\w:]/) 1860 873 2733
125 # Symbol
126 1860 $t->{class} = $t->{token}->set_class( 'Symbol' );
127 1860 return 1;
128 }
129  
130 873 ▶ if ( $PPI::Token::Magic::magic{ $c . $char } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI::Token::Magic::magic{$c . $char}) 35 838 873
131 # Magic variable
132 35 $t->{class} = $t->{token}->set_class( 'Magic' );
133 35 return 1;
134 }
135  
136 838 ▶ if ( $char eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "{") 275 563 838
137 # Get rest of line
138 275 pos $t->{line} = $t->{line_cursor} + 1;
139 275 ▶ if ( $t->{line} =~ m/$CURLY_SYMBOL/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"line"} =~ /$PPI::Token::Unknown::CURLY_SYMBOL/cg) 1 274 275
140 # control-character symbol (e.g. @{^_Foo})
141 1 $t->{class} = $t->{token}->set_class( 'Magic' );
142 1 return 1;
143 }
144 }
145  
146 # Must be a cast
147 837 $t->{class} = $t->{token}->set_class( 'Cast' );
148 837 return $t->_finalize_token->__TOKENIZER__on_char( $t );
149  
150  
151  
152 } elsif ( $c eq '%' ) {
153 # Is it a number?
154 1261 ▶ if ( $char =~ /\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /\d/) 106 1155 1261
155 # bitwise operator
156 106 $t->{class} = $t->{token}->set_class( 'Operator' );
157 106 return $t->_finalize_token->__TOKENIZER__on_char( $t );
158 }
159  
160 # Is it a magic variable?
161 1155 ▶ if ( $char eq '^' || $PPI::Token::Magic::magic{ $c . $char } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "^" or $PPI::Token::Magic::magic{$c . $char}) 61 1094 1155
Condition100%3/3
$char eq "^" or $PPI::Token::Magic::magic{$c . $char}
l!l&&r!l&&!r
17441094
MC/DC100%2/2
$char eq "^" or $PPI::Token::Magic::magic{$c . $char}
$char eq "^" $PPI::Token::Magic::magic{$c . $char}
Truth table100%3/3
A or B
A= $char eq "^"B= $PPI::Token::Magic::magic{$c . $char}
ABresult
1X1
011
000
162 61 $t->{class} = $t->{token}->set_class( 'Magic' );
163 61 return 1;
164 }
165  
166 1094 ▶ if ( $char =~ /[\w:]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /[\w:]/) 411 683 1094
167 # Symbol (unless the thing before it is a number
168 411 my ( $prev ) = $t->_previous_significant_tokens(1);
169 411 ▶ if ( not $prev or not $prev->isa('PPI::Token::Number') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prev and $prev->isa("PPI::Token::Number")) 402 9 411
Condition100%3/3
$prev and $prev->isa("PPI::Token::Number")
!ll&&!rl&&r
323709
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
170 402 $t->{class} = $t->{token}->set_class( 'Symbol' );
171 402 return 1;
172 }
173 }
174  
175 692 ▶ if ( $char eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "{") 46 646 692
176 # Get rest of line
177 46 pos $t->{line} = $t->{line_cursor} + 1;
178 46 ▶ if ( $t->{line} =~ m/$CURLY_SYMBOL/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"line"} =~ /$PPI::Token::Unknown::CURLY_SYMBOL/cg) 1 45 46
179 # control-character symbol (e.g. %{^_Foo})
180 1 $t->{class} = $t->{token}->set_class( 'Magic' );
181 1 return 1;
182 }
183 }
184  
185 691 ▶ 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) 164 527 691
186  
187 # Probably the mod operator
188 527 $t->{class} = $t->{token}->set_class( 'Operator' );
189 527 return $t->{class}->__TOKENIZER__on_char( $t );
190  
191  
192  
193 } elsif ( $c eq '&' ) {
194 # Is it a number?
195 1006 ▶ if ( $char =~ /\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /\d/) 82 924 1006
196 # bitwise operator
197 82 $t->{class} = $t->{token}->set_class( 'Operator' );
198 82 return $t->_finalize_token->__TOKENIZER__on_char( $t );
199 }
200  
201 924 ▶ if ( $char =~ /[\w:]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /[\w:]/) 228 696 924
202 # Symbol (unless the thing before it is a number
203 228 my ( $prev ) = $t->_previous_significant_tokens(1);
204 228 ▶ if ( not $prev or not $prev->isa('PPI::Token::Number') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prev and $prev->isa("PPI::Token::Number")) 213 15 228
Condition100%3/3
$prev and $prev->isa("PPI::Token::Number")
!ll&&!rl&&r
3018315
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
205 213 $t->{class} = $t->{token}->set_class( 'Symbol' );
206 213 return 1;
207 }
208 }
209  
210 711 ▶ 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) 108 603 711
211  
212 # Probably the binary and operator
213 603 $t->{class} = $t->{token}->set_class( 'Operator' );
214 603 return $t->{class}->__TOKENIZER__on_char( $t );
215  
216  
217  
218 } elsif ( $c eq '-' ) {
219 1850 ▶ if ( $char =~ /\d/o ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /\d/o) 116 1734 1850
220 # Number
221 116 $t->{class} = $t->{token}->set_class( 'Number' );
222 116 return 1;
223 }
224  
225 1734 ▶ if ( $char eq '.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq ".") 15 1719 1734
226 # Number::Float
227 15 $t->{class} = $t->{token}->set_class( 'Number::Float' );
228 15 return 1;
229 }
230  
231 1719 ▶ if ( $char =~ /[a-zA-Z]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /[a-zA-Z]/) 205 1514 1719
232 205 $t->{class} = $t->{token}->set_class( 'DashedWord' );
233 205 return 1;
234 }
235  
236 # The numeric negative operator
237 1514 $t->{class} = $t->{token}->set_class( 'Operator' );
238 1514 return $t->{class}->__TOKENIZER__on_char( $t );
239  
240  
241  
242 } elsif ( $c eq ':' ) {
243 1513 ▶ if ( $char eq ':' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq ":") 6 1507 1513
244 # ::foo style bareword
245 6 $t->{class} = $t->{token}->set_class( 'Word' );
246 6 return 1;
247 }
248  
249 # Now, : acts very very differently in different contexts.
250 # Mainly, we need to find out if this is a subroutine attribute.
251 # We'll leave a hint in the token to indicate that, if it is.
252 1507 ▶ if ( $self->__TOKENIZER__is_an_attribute( $t ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__TOKENIZER__is_an_attribute($t)) 923 584 1507
253 # This : is an attribute indicator
254 923 $t->{class} = $t->{token}->set_class( 'Operator' );
255 923 $t->{token}->{_attribute} = 1;
256 923 return $t->_finalize_token->__TOKENIZER__on_char( $t );
257 }
258  
259 # It MIGHT be a label, but it's probably the ?: trinary operator
260 584 $t->{class} = $t->{token}->set_class( 'Operator' );
261 584 return $t->{class}->__TOKENIZER__on_char( $t );
262 }
263  
264 # erm...
265 0 PPI::Exception->throw('Unknown value in PPI::Token::Unknown token');
266 }
267  
268 sub _is_cast_or_op {
269 2020 ▶ my ( $self, $char ) = @_;
Subroutine _is_cast_or_op: called CC=6 SCAR=17.9
270 2020 ▶ return 1 if $char eq '$';
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "\$" 157 1863 2020
271 1863 ▶ return 1 if $char eq '@';
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "\@" 36 1827 1863
272 1827 ▶ return 1 if $char eq '%';
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "%" 32 1795 1827
273 1795 ▶ return 1 if $char eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "*" 37 1758 1795
274 1758 ▶ return 1 if $char eq '{';
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "{" 101 1657 1758
275 1657 return;
276 }
277  
278 sub _as_cast_or_op {
279 363 ▶ my ( $self, $t ) = @_;
Subroutine _as_cast_or_op: called CC=1 SCAR=0.0
280 363 my $class = _cast_or_op( $t );
281 363 $t->{class} = $t->{token}->set_class( $class );
282 363 return $t->_finalize_token->__TOKENIZER__on_char( $t );
283 }
284  
285 sub _prev_significant_w_cursor {
286 507 ▶ my ( $tokens, $cursor, $extra_check ) = @_;
Subroutine _prev_significant_w_cursor: called CC=5 SCAR=16.1
287 507 ▶ while ( $cursor >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cursor >= 0) 659 33 692
288 659 my $token = $tokens->[ $cursor-- ];
289 659 ▶ next if !$token->significant;
Branch: 1 branch
BranchTrueFalseTotal
unless $token->significant 140 519 659
290 519 ▶ next if $extra_check and !$extra_check->($token);
Branch: 1 branch
BranchTrueFalseTotal
if $extra_check and not &$extra_check($token) 45 474 519
Condition100%3/3
$extra_check and not &$extra_check($token)
!ll&&!rl&&r
4373745
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
291 474 return ( $token, $cursor );
292 }
293 33 return ( undef, $cursor );
294 }
295  
296 # Operator/operand-sensitive, multiple or GLOB cast
297 sub _cast_or_op {
298 363 ▶ my ( $t ) = @_;
Subroutine _cast_or_op: called CC=19 SCAR=29.5
299  
300 363 my $tokens = $t->{tokens};
301 363 my $cursor = scalar( @$tokens ) - 1;
302 363 my $token;
303  
304 363 ( $token, $cursor ) = _prev_significant_w_cursor( $tokens, $cursor );
305 363 ▶ return 'Cast' if !$token; # token was first in the document
Branch: 1 branch
BranchTrueFalseTotal
unless $token 19 344 363
306  
307 344 ▶ if ( $token->isa( 'PPI::Token::Structure' ) and $token->content eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->isa("PPI::Token::Structure") and $token->content eq "}") 38 306 344
Condition100%3/3
$token->isa("PPI::Token::Structure") and $token->content eq "}"
!ll&&!rl&&r
2475938
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
308  
309 # Scan the token stream backwards an arbitrarily long way,
310 # looking for the matching opening curly brace.
311 38 my $structure_depth = 1;
312 ( $token, $cursor ) = _prev_significant_w_cursor(
313 $tokens, $cursor,
314 sub {
315 82 ▶ my ( $token ) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.1
316 82 ▶ return if !$token->isa( 'PPI::Token::Structure' );
Branch: 1 branch
BranchTrueFalseTotal
unless $token->isa("PPI::Token::Structure") 43 39 82
317 39 ▶ if ( $token eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq "}") 2 37 39
318 2 $structure_depth++;
319 2 return;
320 }
321 37 ▶ if ( $token eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq "{") 32 5 37
322 32 $structure_depth--;
323 32 ▶ return if $structure_depth;
Branch: 1 branch
BranchTrueFalseTotal
if $structure_depth 0 32 32
324 }
325 37 return 1;
326 }
327 38 );
328 38 ▶ return 'Operator' if !$token; # no matching '{', probably an unbalanced '}'
Branch: 1 branch
BranchTrueFalseTotal
unless $token 1 37 38
329  
330 # Scan past any whitespace
331 37 ( $token, $cursor ) = _prev_significant_w_cursor( $tokens, $cursor );
332 37 ▶ return 'Operator' if !$token; # Document began with what must be a hash constructor.
Branch: 1 branch
BranchTrueFalseTotal
unless $token 1 36 37
333 36 ▶ return 'Operator' if $token->isa( 'PPI::Token::Symbol' ); # subscript
Branch: 1 branch
BranchTrueFalseTotal
if $token->isa("PPI::Token::Symbol") 0 36 36
334  
335 36 my %meth_or_subscript_end = map { $_ => 1 } qw@ -> } ] @;
336 36 ▶ return 'Operator' if $meth_or_subscript_end{ $token->content }; # subscript
Branch: 1 branch
BranchTrueFalseTotal
if $meth_or_subscript_end{$token->content} 9 27 36
337  
338 27 my $content = $token->content;
339 27 ▶ my $produces_or_wants_value =
Condition83%5/6
$token->isa('PPI::Token::Word') && ($content eq 'do' || $content eq 'eval')
!ll&&!rl&&r
3195
$content eq "do" or $content eq "eval"
l!l&&r!l&&!r
0519
MC/DC66%2/3
$token->isa('PPI::Token::Word') && ($content eq 'do' || $content eq 'eval')
$token->isa('PPI::Token::Word') $content eq "do" $content eq "eval"
Truth table75%3/4
A && B or C
A= $token->isa('PPI::Token::Word')B= $content eq "do"C= $content eq "eval"
ABCresult
0XX0
1000
11X1
1011
340 ( $token->isa( 'PPI::Token::Word' ) and ( $content eq 'do' or $content eq 'eval' ) );
341 27 ▶ return $produces_or_wants_value ? 'Operator' : 'Cast';
Branch: 1 branch
BranchTrueFalseTotal
$produces_or_wants_value ? : 5 22 27
342 }
343  
344 306 my %list_start_or_term_end = map { $_ => 1 } qw@ ; ( { [ @;
345 return 'Cast'
346 306 ▶ 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") 69 164 233
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
1357164
$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
7362171
$token->isa("PPI::Token::Structure") and $list_start_or_term_end{$token->content} or $token->isa("PPI::Token::Cast")
l!l&&r!l&&!r
4627233
$token->isa("PPI::Token::Structure") and $list_start_or_term_end{$token->content}
!ll&&!rl&&r
2471346
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
347 or $token->isa( 'PPI::Token::Cast' )
348 or $token->isa( 'PPI::Token::Operator' )
349 or $token->isa( 'PPI::Token::Label' );
350  
351 164 ▶ return 'Operator' if !$token->isa( 'PPI::Token::Word' );
Branch: 1 branch
BranchTrueFalseTotal
unless $token->isa("PPI::Token::Word") 95 69 164
352  
353 69 ( $token, $cursor ) = _prev_significant_w_cursor( $tokens, $cursor );
354 69 ▶ return 'Cast' if !$token || $token->content ne '->';
Branch: 1 branch
BranchTrueFalseTotal
if not $token or $token->content ne "->" 69 0 69
Condition66%2/3
not $token or $token->content ne "->"
l!l&&r!l&&!r
12570
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
355  
356 0 return 'Operator';
357 }
358  
359 # Are we at a location where a ':' would indicate a subroutine attribute
360 sub __TOKENIZER__is_an_attribute {
361 1507 ▶ my $t = $_[1]; # Tokenizer object
Subroutine __TOKENIZER__is_an_attribute: called CC=14 SCAR=28.0
362 1507 my @tokens = $t->_previous_significant_tokens(3);
363 1507 my $p0 = $tokens[0];
364 1507 ▶ return '' if not $p0;
Branch: 1 branch
BranchTrueFalseTotal
unless $p0 75 1432 1507
365  
366 # If we just had another attribute, we are also an attribute
367 1432 ▶ return 1 if $p0->isa('PPI::Token::Attribute');
Branch: 1 branch
BranchTrueFalseTotal
if $p0->isa("PPI::Token::Attribute") 176 1256 1432
368  
369 # If we just had a prototype, then we are an attribute
370 1256 ▶ return 1 if $p0->isa('PPI::Token::Prototype');
Branch: 1 branch
BranchTrueFalseTotal
if $p0->isa("PPI::Token::Prototype") 126 1130 1256
371  
372 # Other than that, we would need to have had a bareword
373 1130 ▶ return '' unless $p0->isa('PPI::Token::Word');
Branch: 1 branch
BranchTrueFalseTotal
unless $p0->isa("PPI::Token::Word") 486 644 1130
374  
375 # We could be an anonymous subroutine
376 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
377 0 return 1;
378 }
379  
380 # Or, we could be a named subroutine
381 644 my $p1 = $tokens[1];
382 644 my $p2 = $tokens[2];
383 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
Condition61%11/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
212621
$p1 and $p1->isa("PPI::Token::Word")
!ll&&!rl&&r
120623
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 table37%3/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
384 $p1
385 and
386 $p1->isa('PPI::Token::Word')
387 and
388 $p1->content eq 'sub'
389 and (
390 not $p2
391 or
392 $p2->isa('PPI::Token::Structure')
393 or (
394 $p2->isa('PPI::Token::Whitespace')
395 and
396 $p2->content eq ''
397 )
398 )
399 ) {
400 621 return 1;
401 }
402  
403 # We aren't an attribute
404 23 '';
405 }
406  
407 62 1;
408  
409 =pod
410  
411 =head1 SUPPORT
412  
413 See the L<support section|PPI/SUPPORT> in the main module.
414  
415 =head1 AUTHOR
416  
417 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
418  
419 =head1 COPYRIGHT
420  
421 Copyright 2001 - 2011 Adam Kennedy.
422  
423 This program is free software; you can redistribute
424 it and/or modify it under the same terms as Perl itself.
425  
426 The full text of the license can be found in the
427 LICENSE file included with this module.
428  
429 =cut
« PPI/Transform/UpdateCopyright.pm ↑ Summary PPI/Token/Word.pm »