PPI/Token/Word.pm

filter: Statementstmt 82.4% 103 / 125 Branchbran 74.2% 52 / 70 Conditioncond 95.5% 43 / 45 MC/DCmcdc 83.3% 20 / 24 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 83.2% 229 / 275 CC 51 SCAR 32.2
CC
51
Cov
82%
__TOKENIZER__on_char
49.1
__TOKENIZER__commit
27.2
method_call
12.0
CRAP 25.1
« PPI/Token/Unknown.pm ↑ Summary PPI/Normal/Standard.pm »
1 package PPI::Token::Word;
2  
3 =pod
4  
5 =head1 NAME
6  
7 PPI::Token::Word - The generic "word" Token
8  
9 =head1 INHERITANCE
10  
11 PPI::Token::Word
12 isa PPI::Token
13 isa PPI::Element
14  
15 =head1 DESCRIPTION
16  
17 A C<PPI::Token::Word> object is a PPI-specific representation of several
18 different types of word-like things, and is one of the most common Token
19 classes found in typical documents.
20  
21 Specifically, it includes not only barewords, but also any other valid
22 Perl identifier including non-operator keywords and core functions, and
23 any include C<::> separators inside it, as long as it fits the
24 format of a class, function, etc.
25  
26 =head1 METHODS
27  
28 There are no methods available for C<PPI::Token::Word> beyond those
29 provided by its L<PPI::Token> and L<PPI::Element> parent
30 classes.
31  
32 We expect to add additional methods to help further resolve a Word as
33 a function, method, etc over time. If you need such a thing right
34 now, look at L<Perl::Critic::Utils>.
35  
36 =cut
37  
38 62 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 62 ▶use PPI::Token ();
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 62 ▶use vars qw{$VERSION @ISA %OPERATOR %QUOTELIKE %KEYWORDS};
Subroutine BEGIN: called CC=1 SCAR=0.0
42 BEGIN {
43 62 ▶ $VERSION = '1.236';
Subroutine BEGIN: called CC=1 SCAR=0.0
44 62 @ISA = 'PPI::Token';
45  
46 # Copy in OPERATOR from PPI::Token::Operator
47 62 *OPERATOR = *PPI::Token::Operator::OPERATOR;
48  
49 62 %QUOTELIKE = (
50 'q' => 'Quote::Literal',
51 'qq' => 'Quote::Interpolate',
52 'qx' => 'QuoteLike::Command',
53 'qw' => 'QuoteLike::Words',
54 'qr' => 'QuoteLike::Regexp',
55 'm' => 'Regexp::Match',
56 's' => 'Regexp::Substitute',
57 'tr' => 'Regexp::Transliterate',
58 'y' => 'Regexp::Transliterate',
59 );
60  
61 # List of keywords is from regen/keywords.pl in the perl source.
62 62 %KEYWORDS = map { $_ => 1 } qw{
63 abs accept alarm and atan2 bind binmode bless break caller chdir chmod
64 chomp chop chown chr chroot close closedir cmp connect continue cos
65 crypt dbmclose dbmopen default defined delete die do dump each else
66 elsif endgrent endhostent endnetent endprotoent endpwent endservent
67 eof eq eval evalbytes exec exists exit exp fc fcntl fileno flock for
68 foreach fork format formline ge getc getgrent getgrgid getgrnam
69 gethostbyaddr gethostbyname gethostent getlogin getnetbyaddr
70 getnetbyname getnetent getpeername getpgrp getppid getpriority
71 getprotobyname getprotobynumber getprotoent getpwent getpwnam
72 getpwuid getservbyname getservbyport getservent getsockname
73 getsockopt given glob gmtime goto grep gt hex if index int ioctl join
74 keys kill last lc lcfirst le length link listen local localtime lock
75 log lstat lt m map mkdir msgctl msgget msgrcv msgsnd my ne next no
76 not oct open opendir or ord our pack package pipe pop pos print
77 printf prototype push q qq qr quotemeta qw qx rand read readdir
78 readline readlink readpipe recv redo ref rename require reset return
79 reverse rewinddir rindex rmdir s say scalar seek seekdir select semctl
80 semget semop send setgrent sethostent setnetent setpgrp
81 setpriority setprotoent setpwent setservent setsockopt shift shmctl
82 shmget shmread shmwrite shutdown sin sleep socket socketpair sort
83 splice split sprintf sqrt srand stat state study sub substr symlink
84 syscall sysopen sysread sysseek system syswrite tell telldir tie tied
85 time times tr truncate uc ucfirst umask undef unless unlink unpack
86 unshift untie until use utime values vec wait waitpid wantarray warn
87 when while write x xor y
88 };
89 }
90  
91 =pod
92  
93 =head2 literal
94  
95 Returns the value of the Word as a string. This assumes (often
96 incorrectly) that the Word is a bareword and not a function, method,
97 keyword, etc. This differs from C<content> because C<Foo'Bar> expands
98 to C<Foo::Bar>.
99  
100 =cut
101  
102 sub literal {
103 3 ▶ my $self = shift;
Subroutine literal: called CC=1 SCAR=0.0
Pod documented
104 3 my $word = $self->content;
105  
106 # Expand Foo'Bar to Foo::Bar
107 3 $word =~ s/\'/::/g;
108  
109 3 return $word;
110 }
111  
112 =pod
113  
114 =head2 method_call
115  
116 Answers whether this is the name of a method in a method call. Returns true if
117 yes, false if no, and nothing if unknown.
118  
119 =cut
120  
121 sub method_call {
122 22 ▶ my $self = shift;
Subroutine method_call: called CC=12 SCAR=24.8
Pod documented
123  
124 22 my $previous = $self->sprevious_sibling;
125 22 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($previous and $previous->isa("PPI::Token::Operator") and $previous->content eq "->") 4 18 22
Condition100%6/6
$previous and $previous->isa("PPI::Token::Operator") and $previous->content eq "->"
!ll&&!rl&&r
1444
$previous and $previous->isa("PPI::Token::Operator")
!ll&&!rl&&r
1138
MC/DC100%3/3
$previous and $previous->isa("PPI::Token::Operator") and $previous->content eq "->"
$previous $previous->isa("PPI::Token::Operator") $previous->content eq "->"
Truth table100%4/4
A and B and C
A= $previousB= $previous->isa("PPI::Token::Operator")C= $previous->content eq "->"
ABCresult
0XX0
10X0
1100
1111
126 $previous
127 and
128 $previous->isa('PPI::Token::Operator')
129 and
130 $previous->content eq '->'
131 ) {
132 4 return 1;
133 }
134  
135 18 my $snext = $self->snext_sibling;
136 18 ▶ return 0 unless $snext;
Branch: 1 branch
BranchTrueFalseTotal
unless $snext 3 15 18
137  
138 15 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($snext->isa("PPI::Structure::List") or $snext->isa("PPI::Token::Structure") or $snext->isa("PPI::Token::Operator") and $snext->content eq "," || $snext->content eq "=>") 8 6 14
Condition100%12/12
$snext->isa("PPI::Structure::List") or $snext->isa("PPI::Token::Structure") or $snext->isa("PPI::Token::Operator") and $snext->content eq "," || $snext->content eq "=>"
l!l&&r!l&&!r
474
$snext->isa("PPI::Structure::List") or $snext->isa("PPI::Token::Structure")
l!l&&r!l&&!r
1311
$snext->isa("PPI::Token::Operator") and $snext->content eq "," || $snext->content eq "=>"
!ll&&!rl&&r
515
$snext->content eq "," or $snext->content eq "=>"
l!l&&r!l&&!r
411
MC/DC60%3/5
$snext->isa("PPI::Structure::List") or $snext->isa("PPI::Token::Structure") or $snext->isa("PPI::Token::Operator") and $snext->content eq "," || $snext->content eq "=>"
$snext->isa("PPI::Structure::List") $snext->isa("PPI::Token::Structure") $snext->isa("PPI::Token::Operator") $snext->content eq "," $snext->content eq "=>"
Truth table66%4/6
A or B or C and D or E
A= $snext->isa("PPI::Structure::List")B= $snext->isa("PPI::Token::Structure")C= $snext->isa("PPI::Token::Operator")D= $snext->content eq ","E= $snext->content eq "=>"
ABCDEresult
1XXXX1
01XXX1
0011X1
001011
000XX0
001000
139 $snext->isa('PPI::Structure::List')
140 or
141 $snext->isa('PPI::Token::Structure')
142 or
143 $snext->isa('PPI::Token::Operator')
144 and (
145 $snext->content eq ','
146 or
147 $snext->content eq '=>'
148 )
149 ) {
150 9 return 0;
151 }
152  
153 6 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($snext->isa("PPI::Token::Word") and $snext->content =~ / \w :: \z /msx) 1 5 6
Condition100%3/3
$snext->isa("PPI::Token::Word") and $snext->content =~ / \w :: \z /msx
!ll&&!rl&&r
231
MC/DC100%2/2
$snext->isa("PPI::Token::Word") and $snext->content =~ / \w :: \z /msx
$snext->isa("PPI::Token::Word") $snext->content =~ / \w :: \z /msx
Truth table100%3/3
A and B
A= $snext->isa("PPI::Token::Word")B= $snext->content =~ / \w :: \z /msx
ABresult
0X0
100
111
154 $snext->isa('PPI::Token::Word')
155 and
156 $snext->content =~ m< \w :: \z >xms
157 ) {
158 1 return 1;
159 }
160  
161 5 return;
162 }
163  
164  
165 sub __TOKENIZER__on_char {
166 6 ▶ my $class = shift;
Subroutine __TOKENIZER__on_char: called CC=12 SCAR=38.9
167 6 my $t = shift;
168  
169 # Suck in till the end of the bareword
170 6 pos $t->{line} = $t->{line_cursor};
171 6 ▶ if ( $t->{line} =~ m/\G(\w+(?:(?:\'|::)\w+)*(?:::)?)/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"line"} =~ /\G(\w+(?:(?:\'|::)\w+)*(?:::)?)/cg) 3 3 6
172 3 my $word = $1;
173 # Special Case: If we accidentally treat eq'foo' like
174 # the word "eq'foo", then just make 'eq' (or whatever
175 # else is in the %KEYWORDS hash.
176 3 ▶ if ( $word =~ /^(\w+)'/ && $KEYWORDS{$1} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word =~ /^(\w+)'/ and $PPI::Token::Word::KEYWORDS{$1}) 0 3 3
Condition33%1/3
$word =~ /^(\w+)'/ and $PPI::Token::Word::KEYWORDS{$1}
!ll&&!rl&&r
300
MC/DC0%0/2
$word =~ /^(\w+)'/ and $PPI::Token::Word::KEYWORDS{$1}
$word =~ /^(\w+)'/ $PPI::Token::Word::KEYWORDS{$1}
Truth table33%1/3
A and B
A= $word =~ /^(\w+)'/B= $PPI::Token::Word::KEYWORDS{$1}
ABresult
0X0
100
111
177 0 $word = $1;
178 }
179 3 $t->{token}->{content} .= $word;
180 3 $t->{line_cursor} += length $word;
181  
182 }
183  
184 # We might be a subroutine attribute.
185 6 ▶ if ( __current_token_is_attribute($t) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (__current_token_is_attribute($t)) 0 6 6
186 0 $t->{class} = $t->{token}->set_class( 'Attribute' );
187 0 return $t->{class}->__TOKENIZER__commit( $t );
188 }
189  
190 6 my $word = $t->{token}->{content};
191 6 ▶ if ( $KEYWORDS{$word} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI::Token::Word::KEYWORDS{$word}) 0 6 6
192 # Check for a Perl keyword that is forced to be a normal word instead
193 0 ▶ if ( $t->__current_token_is_forced_word ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->__current_token_is_forced_word) 0 0 0
194 0 $t->{class} = $t->{token}->set_class( 'Word' );
195 0 return $t->{class}->__TOKENIZER__on_char( $t );
196 }
197  
198 # Check for a quote like operator. %QUOTELIKE must be subset of %KEYWORDS
199 0 ▶ if ( $QUOTELIKE{$word} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI::Token::Word::QUOTELIKE{$word}) 0 0 0
200 0 $t->{class} = $t->{token}->set_class( $QUOTELIKE{$word} );
201 0 return $t->{class}->__TOKENIZER__on_char( $t );
202 }
203  
204 # Or one of the word operators. %OPERATOR must be subset of %KEYWORDS
205 0 ▶ if ( $OPERATOR{$word} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PPI::Token::Word::OPERATOR{$word}) 0 0 0
206 0 $t->{class} = $t->{token}->set_class( 'Operator' );
207 0 return $t->_finalize_token->__TOKENIZER__on_char( $t );
208 }
209 }
210  
211 # Unless this is a simple identifier, at this point
212 # it has to be a normal bareword
213 6 ▶ if ( $word =~ /\:/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word =~ /\:/) 6 0 6
214 6 return $t->_finalize_token->__TOKENIZER__on_char( $t );
215 }
216  
217 # If the NEXT character in the line is a colon, this
218 # is a label.
219 0 my $char = substr( $t->{line}, $t->{line_cursor}, 1 );
220 0 ▶ if ( $char eq ':' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($char eq ':') { } 0 0 0
elsif ($word eq '_') { } 0 0 0
221 0 $t->{token}->{content} .= ':';
222 0 $t->{line_cursor}++;
223 0 $t->{class} = $t->{token}->set_class( 'Label' );
224  
225 # If not a label, '_' on its own is the magic filehandle
226 } elsif ( $word eq '_' ) {
227 0 $t->{class} = $t->{token}->set_class( 'Magic' );
228  
229 }
230  
231 # Finalise and process the character again
232 0 $t->_finalize_token->__TOKENIZER__on_char( $t );
233 }
234  
235  
236  
237 # We are committed to being a bareword.
238 # Or so we would like to believe.
239 sub __TOKENIZER__commit {
240 51121 ▶ my ($class, $t) = @_;
Subroutine __TOKENIZER__commit: called CC=27 SCAR=33.0
241  
242 # Our current position is the first character of the bareword.
243 # Capture the bareword.
244 51121 pos $t->{line} = $t->{line_cursor};
245 51121 ▶ unless ( $t->{line} =~ m/\G((?!\d)\w+(?:(?:\'|::)\w+)*(?:::)?)/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($t->{"line"} =~ /\G((?!\d)\w+(?:(?:\'|::)\w+)*(?:::)?)/cg) 0 51121 51121
246 # Programmer error
247 0 die sprintf "Fatal error... regex failed to match in '%s' when expected", substr $t->{line}, $t->{line_cursor};
248 }
249  
250 # Special Case: If we accidentally treat eq'foo' like the word "eq'foo",
251 # then unwind it and just make it 'eq' (or the other stringy comparitors)
252 51121 my $word = $1;
253 51121 ▶ if ( $word =~ /^(\w+)'/ && $KEYWORDS{$1} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word =~ /^(\w+)'/ and $PPI::Token::Word::KEYWORDS{$1}) 253 50868 51121
Condition100%3/3
$word =~ /^(\w+)'/ and $PPI::Token::Word::KEYWORDS{$1}
!ll&&!rl&&r
5081751253
MC/DC100%2/2
$word =~ /^(\w+)'/ and $PPI::Token::Word::KEYWORDS{$1}
$word =~ /^(\w+)'/ $PPI::Token::Word::KEYWORDS{$1}
Truth table100%3/3
A and B
A= $word =~ /^(\w+)'/B= $PPI::Token::Word::KEYWORDS{$1}
ABresult
0X0
100
111
254 253 $word = $1;
255 }
256  
257 # Advance the position one after the end of the bareword
258 51121 $t->{line_cursor} += length $word;
259  
260 # We might be a subroutine attribute.
261 51121 ▶ if ( __current_token_is_attribute($t) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (__current_token_is_attribute($t)) 1062 50059 51121
262 1062 $t->_new_token( 'Attribute', $word );
263 return ($t->{line_cursor} >= $t->{line_length}) ? 0
264 1062 ▶ : $t->{class}->__TOKENIZER__on_char($t);
Branch: 1 branch
BranchTrueFalseTotal
$t->{'line_cursor'} >= $t->{'line_length'} ? : 0 1062 1062
265 }
266  
267 # Check for the end of the file
268 50059 ▶ if ( $word eq '__END__' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word eq "__END__") 8 50051 50059
269 # Create the token for the __END__ itself
270 8 $t->_new_token( 'Separator', $1 );
271 8 $t->_finalize_token;
272  
273 # Move into the End zone (heh)
274 8 $t->{zone} = 'PPI::Token::End';
275  
276 # Add the rest of the line as a comment, and a whitespace newline
277 # Anything after the __END__ on the line is "ignored". So we must
278 # also ignore it, by turning it into a comment.
279 8 my $end_rest = substr( $t->{line}, $t->{line_cursor} );
280 8 $t->{line_cursor} = length $t->{line};
281 8 ▶ if ( $end_rest =~ /\n$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end_rest =~ /\n$/) { } 6 2 8
282 6 chomp $end_rest;
283 6 ▶ $t->_new_token( 'Comment', $end_rest ) if length $end_rest;
Branch: 1 branch
BranchTrueFalseTotal
if length $end_rest 1 5 6
284 6 $t->_new_token( 'Whitespace', "\n" );
285 } else {
286 2 ▶ $t->_new_token( 'Comment', $end_rest ) if length $end_rest;
Branch: 1 branch
BranchTrueFalseTotal
if length $end_rest 1 1 2
287 }
288 8 $t->_finalize_token;
289  
290 8 return 0;
291 }
292  
293 # Check for the data section
294 50051 ▶ if ( $word eq '__DATA__' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word eq "__DATA__") 6 50045 50051
295 # Create the token for the __DATA__ itself
296 6 $t->_new_token( 'Separator', "$1" );
297 6 $t->_finalize_token;
298  
299 # Move into the Data zone
300 6 $t->{zone} = 'PPI::Token::Data';
301  
302 # Add the rest of the line as the Data token
303 6 my $data_rest = substr( $t->{line}, $t->{line_cursor} );
304 6 $t->{line_cursor} = length $t->{line};
305 6 ▶ if ( $data_rest =~ /\n$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_rest =~ /\n$/) { } 4 2 6
306 4 chomp $data_rest;
307 4 ▶ $t->_new_token( 'Comment', $data_rest ) if length $data_rest;
Branch: 1 branch
BranchTrueFalseTotal
if length $data_rest 1 3 4
308 4 $t->_new_token( 'Whitespace', "\n" );
309 } else {
310 2 ▶ $t->_new_token( 'Comment', $data_rest ) if length $data_rest;
Branch: 1 branch
BranchTrueFalseTotal
if length $data_rest 1 1 2
311 }
312 6 $t->_finalize_token;
313  
314 6 return 0;
315 }
316  
317 50045 my $token_class;
318 50045 ▶ if ( $word =~ /\:/ ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($word =~ /\:/) { } 1380 48665 50045
elsif ($PPI::Token::Word::KEYWORDS{$word} and $t->__current_token_is_forced_word) { } 6616 42049 48665
elsif ($PPI::Token::Word::QUOTELIKE{$word}) { } 2612 39437 42049
elsif ($PPI::Token::Word::OPERATOR{$word} and $word ne 'x' || $t->_current_x_is_operator) { } 1423 38014 39437
319 # Since it's not a simple identifier...
320 1380 $token_class = 'Word';
321  
322 ▶ } elsif ( $KEYWORDS{$word} and $t->__current_token_is_forced_word ) {
Condition100%3/3
$PPI::Token::Word::KEYWORDS{$word} and $t->__current_token_is_forced_word
!ll&&!rl&&r
17885241646616
MC/DC100%2/2
$PPI::Token::Word::KEYWORDS{$word} and $t->__current_token_is_forced_word
$PPI::Token::Word::KEYWORDS{$word} $t->__current_token_is_forced_word
Truth table100%3/3
A and B
A= $PPI::Token::Word::KEYWORDS{$word}B= $t->__current_token_is_forced_word
ABresult
0X0
100
111
323 6616 $token_class = 'Word';
324  
325 } elsif ( $QUOTELIKE{$word} ) {
326 # Special Case: A Quote-like operator
327 2612 $t->_new_token( $QUOTELIKE{$word}, $word );
328 return ($t->{line_cursor} >= $t->{line_length}) ? 0
329 2612 ▶ : $t->{class}->__TOKENIZER__on_char( $t );
Branch: 1 branch
BranchTrueFalseTotal
$t->{'line_cursor'} >= $t->{'line_length'} ? : 0 2612 2612
330  
331 ▶ } elsif ( $OPERATOR{$word} && ($word ne 'x' || $t->_current_x_is_operator) ) {
Condition100%6/6
$PPI::Token::Word::OPERATOR{$word} and $word ne "x" || $t->_current_x_is_operator
!ll&&!rl&&r
377892251423
$word ne "x" or $t->_current_x_is_operator
l!l&&r!l&&!r
139231225
MC/DC100%3/3
$PPI::Token::Word::OPERATOR{$word} and $word ne "x" || $t->_current_x_is_operator
$PPI::Token::Word::OPERATOR{$word} $word ne "x" $t->_current_x_is_operator
Truth table100%4/4
A and B or C
A= $PPI::Token::Word::OPERATOR{$word}B= $word ne "x"C= $t->_current_x_is_operator
ABCresult
0XX0
1000
11X1
1011
332 # Word operator
333 1423 $token_class = 'Operator';
334  
335 } else {
336 # Get tokens early to be sure to not disturb state set up by pos and m//gc.
337 38014 my @tokens = $t->_previous_significant_tokens(1);
338  
339 # If the next character is a ':' then it's a label...
340 38014 pos $t->{line} = $t->{line_cursor};
341 38014 ▶ if ( $t->{line} =~ m/\G(\s*:)(?!:)/gc ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($t->{'line'} =~ /\G(\s*:)(?!:)/cg) { } 1133 36881 38014
elsif ($word eq '_') { } 268 36613 36881
342 1133 ▶ if ( $tokens[0] and $tokens[0]->{content} eq 'sub' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens[0] and $tokens[0]{'content'} eq 'sub') { } 621 512 1133
Condition100%3/3
$tokens[0] and $tokens[0]{"content"} eq "sub"
!ll&&!rl&&r
117395621
MC/DC100%2/2
$tokens[0] and $tokens[0]{"content"} eq "sub"
$tokens[0] $tokens[0]{"content"} eq "sub"
Truth table100%3/3
A and B
A= $tokens[0]B= $tokens[0]{"content"} eq "sub"
ABresult
0X0
100
111
343 # ... UNLESS it's after 'sub' in which
344 # case it is a sub name and an attribute
345 # operator.
346 # We COULD have checked this at the top
347 # level of checks, but this would impose
348 # an additional performance per-word
349 # penalty, and every other case where the
350 # attribute operator doesn't directly
351 # touch the object name already works.
352 621 $token_class = 'Word';
353 } else {
354 512 $word .= $1;
355 512 $t->{line_cursor} += length($1);
356 512 $token_class = 'Label';
357 }
358 } elsif ( $word eq '_' ) {
359 268 $token_class = 'Magic';
360 } else {
361 36613 $token_class = 'Word';
362 }
363 }
364  
365 # Create the new token and finalise
366 47433 $t->_new_token( $token_class, $word );
367 47433 ▶ if ( $t->{line_cursor} >= $t->{line_length} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"line_cursor"} >= $t->{"line_length"}) 0 47433 47433
368 # End of the line
369 0 $t->_finalize_token;
370 0 return 0;
371 }
372 47433 $t->_finalize_token->__TOKENIZER__on_char($t);
373 }
374  
375  
376  
377 # Is the current Word really a subroutine attribute?
378 sub __current_token_is_attribute {
379 51127 ▶ my ( $t ) = @_;
Subroutine __current_token_is_attribute: called CC=3 SCAR=11.0
380 51127 my @tokens = $t->_previous_significant_tokens(1);
381 return (
382 $tokens[0]
383 and (
384 # hint from tokenizer
385 $tokens[0]->{_attribute}
386 # nothing between attribute and us except whitespace
387 51127 ▶ or $tokens[0]->isa('PPI::Token::Attribute')
Condition100%6/6
$tokens[0] && ($tokens[0]{'_attribute'} || $tokens[0]->isa('PPI::Token::Attribute'))
!ll&&!rl&&r
10518395471062
$tokens[0]{"_attribute"} or $tokens[0]->isa("PPI::Token::Attribute")
l!l&&r!l&&!r
90515739547
MC/DC100%3/3
$tokens[0] && ($tokens[0]{'_attribute'} || $tokens[0]->isa('PPI::Token::Attribute'))
$tokens[0] $tokens[0]{"_attribute"} $tokens[0]->isa("PPI::Token::Attribute")
Truth table100%4/4
A && B or C
A= $tokens[0]B= $tokens[0]{"_attribute"}C= $tokens[0]->isa("PPI::Token::Attribute")
ABCresult
0XX0
1000
11X1
1011
388 )
389 );
390 }
391  
392 62 1;
393  
394 =pod
395  
396 =head1 TO DO
397  
398 - Add C<function>, C<method> etc detector methods
399  
400 =head1 SUPPORT
401  
402 See the L<support section|PPI/SUPPORT> in the main module.
403  
404 =head1 AUTHOR
405  
406 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
407  
408 =head1 COPYRIGHT
409  
410 Copyright 2001 - 2011 Adam Kennedy.
411  
412 This program is free software; you can redistribute
413 it and/or modify it under the same terms as Perl itself.
414  
415 The full text of the license can be found in the
416 LICENSE file included with this module.
417  
418 =cut
« PPI/Token/Unknown.pm ↑ Summary PPI/Normal/Standard.pm »