Tidy/Tokenizer.pm

filter: Statementstmt 73.2% 2792 / 3811 Branchbran 66.4% 1311 / 1972 Conditioncond 64.9% 810 / 1247 MC/DCmcdc 40.5% 276 / 680 Subroutinesub 83.1% 168 / 202 Podpod 0.0% 0 / 147 totaltotal 66.4% 5357 / 8059 CC 1482 SCAR 43.1
CC
1482
Cov
70%
show_indentation_table
650.0
do_BAREWORD
225.8
guess_if_pattern_or_division
182.0
CRAP 74.1
« Tidy.pm ↑ Summary Tidy/Logger.pm »
1 package Perl::Tidy::Tokenizer;
2  
3 #####################################################################
4 #
5 # Perl::Tidy::Tokenizer reads a source and breaks it into a stream of tokens
6 #
7 # Usage Outline:
8 #
9 # STEP 1: initialize or re-initialize Tokenizer with user options
10 # Perl::Tidy::Tokenizer::check_options($rOpts);
11 #
12 # STEP 2: create a tokenizer for a specific input source object
13 # my $tokenizer = Perl::Tidy::Tokenizer->new(
14 # source_object => $source,
15 # ...
16 # );
17 #
18 # STEP 3: get and process each tokenized 'line' (a hash ref of token info)
19 # while ( my $line = $tokenizer->get_line() ) {
20 # $formatter->write_line($line);
21 # }
22 #
23 # STEP 4: report errors
24 # my $severe_error = $tokenizer->report_tokenization_errors();
25 #
26 # The source object can be a STRING ref, an ARRAY ref, or an object with a
27 # get_line() method which supplies one line (a character string) perl call.
28 #
29 # NOTE: This is not a real class. Only one tokenizer my be used.
30 #
31 ########################################################################
32  
33 45 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 45 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 45 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 45 our $VERSION = '20260808';
38  
39 45 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 45 ▶use constant DEVEL_MODE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 45 ▶use constant DEBUG_GUESS_MODE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 45 ▶use constant EMPTY_STRING => q{};
Subroutine BEGIN: called CC=1 SCAR=0.0
44 45 ▶use constant SPACE => q{ };
Subroutine BEGIN: called CC=1 SCAR=0.0
45 45 ▶use constant COMMA => q{,};
Subroutine BEGIN: called CC=1 SCAR=0.0
46 45 ▶use constant BACKSLASH => q{\\};
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 { #<<< A non-indenting brace to contain all lexical variables
49  
50 # List of hash keys to prevent -duk from listing them.
51 # (note the backtick in this list)
52 45 my @unique_hash_keys_uu = qw( ` RPerl _rtype_sequence _ending_in_quote );
53  
54 # Parent sequence number of tree of containers; must be 1
55 45 ▶use constant SEQ_ROOT => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
56  
57 # Defaults for guessing old indentation
58 45 ▶use constant INDENT_COLUMNS_DEFAULT => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 45 ▶use constant TAB_SIZE_DEFAULT => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 # Decimal values of some ascii characters for quick checks
62 45 ▶use constant ORD_TAB => 9;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 45 ▶use constant ORD_SPACE => 32;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 45 ▶use constant ORD_PRINTABLE_MIN => 33;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 45 ▶use constant ORD_PRINTABLE_MAX => 126;
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67 # GLOBAL VARIABLES which change during tokenization:
68 # These could also be stored in $self but it is more convenient and
69 # efficient to make them global lexical variables.
70 # INITIALIZER: sub prepare_for_a_new_file
71 my (
72  
73 45 $brace_depth,
74 $context,
75 $current_package,
76 $last_nonblank_block_type,
77 $last_nonblank_token,
78 $last_nonblank_type,
79 $next_sequence_number,
80 $paren_depth,
81 $rbrace_context,
82 $rbrace_package,
83 $rbrace_structural_type,
84 $rbrace_type,
85 $rcurrent_depth,
86 $rcurrent_sequence_number,
87 $ris_lexical_sub,
88 $rdepth_array,
89 $ris_block_function,
90 $ris_block_list_function,
91 $ris_constant,
92 $ris_user_function,
93 $rnested_statement_type,
94 $rnested_ternary_flag,
95 $rparen_semicolon_count,
96 $rparen_vars,
97 $rparen_type,
98 $rsaw_function_definition,
99 $rsaw_use_module,
100 $rsquare_bracket_structural_type,
101 $rsquare_bracket_type,
102 $rstarting_line_of_current_depth,
103 $rtotal_depth,
104 $ruser_function_prototype,
105 $square_bracket_depth,
106 $statement_type,
107 $total_depth,
108 );
109  
110 my (
111  
112 # GLOBAL CONSTANTS for routines in this package,
113 # INITIALIZER: BEGIN block.
114 45 %can_start_digraph,
115 %expecting_operator_token,
116 %expecting_operator_types,
117 %expecting_term_token,
118 %expecting_term_types,
119 %is_block_operator,
120 %is_digraph,
121 %is_file_test_operator,
122 %is_if_elsif_unless,
123 %is_if_elsif_unless_case_when,
124 %is_indirect_object_taker,
125 %is_keyword_rejecting_question_as_pattern_delimiter,
126 %is_keyword_rejecting_slash_as_pattern_delimiter,
127 %is_keyword_taking_list,
128 %is_keyword_taking_optional_arg,
129 %is_q_qq_qw_qx_qr_s_y_tr_m,
130 %is_q_qq_qx_qr_s_y_tr_m,
131 %quote_modifiers,
132 %is_semicolon_or_t,
133 %is_sort_map_grep,
134 %is_sort_map_grep_eval_do_sub,
135 %is_tetragraph,
136 %is_trigraph,
137 %is_valid_token_type,
138 %other_line_endings,
139 %is_binary_operator_type,
140 %is_binary_keyword,
141 %is_binary_or_unary_operator_type,
142 %is_binary_or_unary_keyword,
143 %is_not_a_TERM_producer_type,
144 @closing_brace_names,
145 @opening_brace_names,
146  
147 # GLOBAL CONSTANT hash lookup table of operator expected values
148 # INITIALIZER: BEGIN block
149 %op_expected_table,
150  
151 # GLOBAL VARIABLES which are constant after being configured.
152 # INITIALIZER: BEGIN block and modified by sub check_options
153 %is_code_block_token,
154 %is_zero_continuation_block_type,
155 %is_keyword,
156 %is_TERM_keyword,
157 %is_OPERATOR_keyword,
158 %is_my_our_state,
159 %is_package,
160 %matching_end_token,
161  
162 # INITIALIZER: sub check_options
163 $code_skipping_pattern_begin,
164 $code_skipping_pattern_end,
165 $format_skipping_pattern_begin,
166 $format_skipping_pattern_end,
167  
168 $rOpts_code_skipping,
169 $rOpts_code_skipping_begin,
170 $rOpts_format_skipping,
171 $rOpts_format_skipping_begin,
172 $rOpts_format_skipping_end,
173 $rOpts_starting_indentation_level,
174 $rOpts_indent_columns,
175 $rOpts_look_for_hash_bang,
176 $rOpts_look_for_autoloader,
177 $rOpts_look_for_selfloader,
178 $rOpts_trim_qw,
179 $rOpts_extended_syntax,
180 $rOpts_continuation_indentation,
181 $rOpts_outdent_labels,
182 $rOpts_maximum_level_errors,
183 $rOpts_maximum_unexpected_errors,
184 $rOpts_indent_closing_brace,
185 $rOpts_non_indenting_braces,
186 $rOpts_non_indenting_brace_prefix,
187 $rOpts_whitespace_cycle,
188  
189 $tabsize,
190 %is_END_DATA_format_sub,
191 %is_grep_alias,
192 %is_sub,
193 $guess_if_method,
194 );
195  
196 # possible values of operator_expected()
197 45 ▶use constant TERM => -1;
Subroutine BEGIN: called CC=1 SCAR=0.0
198 45 ▶use constant UNKNOWN => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
199 45 ▶use constant OPERATOR => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
200  
201 # possible values of context
202 45 ▶use constant SCALAR_CONTEXT => -1;
Subroutine BEGIN: called CC=1 SCAR=0.0
203 45 ▶use constant UNKNOWN_CONTEXT => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
204 45 ▶use constant LIST_CONTEXT => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
205  
206 # Maximum number of little messages; probably need not be changed.
207 45 ▶use constant MAX_NAG_MESSAGES => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
208  
209 BEGIN {
210  
211 # Array index names for $self.
212 # Do not combine with other BEGIN blocks (c101).
213 45 ▶ my $i = 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
214 use constant {
215 45 _rhere_target_list_ => $i++,
216 _in_here_doc_ => $i++,
217 _here_doc_target_ => $i++,
218 _here_quote_character_ => $i++,
219 _in_data_ => $i++,
220 _in_end_ => $i++,
221 _in_format_ => $i++,
222 _in_error_ => $i++,
223 _do_not_format_ => $i++,
224 _warning_count_ => $i++,
225 _html_tag_count_ => $i++,
226 _in_pod_ => $i++,
227 _in_code_skipping_ => $i++,
228 _in_format_skipping_ => $i++,
229 _rformat_skipping_list_ => $i++,
230 _in_attribute_list_ => $i++,
231 _in_quote_ => $i++,
232 _quote_target_ => $i++,
233 _line_start_quote_ => $i++,
234 _starting_level_ => $i++,
235 _know_starting_level_ => $i++,
236 _last_line_number_ => $i++,
237 _saw_perl_dash_P_ => $i++,
238 _saw_perl_dash_w_ => $i++,
239 _saw_use_strict_ => $i++,
240 _saw_brace_error_ => $i++,
241 _hit_bug_ => $i++,
242 _look_for_autoloader_ => $i++,
243 _look_for_selfloader_ => $i++,
244 _saw_autoloader_ => $i++,
245 _saw_selfloader_ => $i++,
246 _saw_hash_bang_ => $i++,
247 _saw_end_ => $i++,
248 _saw_data_ => $i++,
249 _saw_negative_indentation_ => $i++,
250 _started_tokenizing_ => $i++,
251 _debugger_object_ => $i++,
252 _diagnostics_object_ => $i++,
253 _logger_object_ => $i++,
254 _save_logfile_ => $i++,
255 _unexpected_error_count_ => $i++,
256 _started_looking_for_here_target_at_ => $i++,
257 _nearly_matched_here_target_at_ => $i++,
258 _line_of_text_ => $i++,
259 _rlower_case_labels_at_ => $i++,
260 _maximum_level_ => $i++,
261 _true_brace_error_count_ => $i++,
262 _rOpts_ => $i++,
263 _rinput_lines_ => $i++,
264 _input_line_index_next_ => $i++,
265 _rtrimmed_input_lines_ => $i++,
266 _rclosing_brace_indentation_hash_ => $i++,
267 _show_indentation_table_ => $i++,
268 _rnon_indenting_brace_stack_ => $i++,
269 _rseqno_at_depth_ => $i++,
270 _rbareword_info_ => $i++,
271 _rsaw_unknown_syntax_in_seqno_ => $i++,
272 45 ▶ };
Subroutine BEGIN: called CC=1 SCAR=0.0
273 } ## end BEGIN
274  
275 { ## closure for subs to count instances
276  
277 # methods to count instances
278 45 my $_count = 0;
279 0 ▶ sub get_count { return $_count; }
Subroutine get_count: not called CC=1 SCAR=6.9
Pod undocumented
280 662 ▶ sub _increment_count { return ++$_count }
Subroutine _increment_count: called CC=1 SCAR=0.0
281 662 ▶ sub _decrement_count { return --$_count }
Subroutine _decrement_count: called CC=1 SCAR=0.0
282 }
283  
284 45 sub DESTROY {
285 662 ▶ my $self = shift;
Subroutine DESTROY: called CC=1 SCAR=0.0
286 662 _decrement_count();
287 662 return;
288 }
289  
290 sub AUTOLOAD {
291  
292 # Catch any undefined sub calls so that we are sure to get
293 # some diagnostic information. This sub should never be called
294 # except for a programming error.
295 0 ▶ our $AUTOLOAD;
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
296 0 ▶ return if ( $AUTOLOAD =~ /\bDESTROY$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $Perl::Tidy::Tokenizer::AUTOLOAD =~ /\bDESTROY$/ 0 0 0
297 0 my ( $pkg, $fname, $lno ) = caller();
298 0 my $my_package = __PACKAGE__;
299 0 print {*STDERR} <<EOM;
300 ======================================================================
301 Error detected in package '$my_package', version $VERSION
302 Received unexpected AUTOLOAD call for sub '$AUTOLOAD'
303 Called from package: '$pkg'
304 Called from File '$fname' at line '$lno'
305 This error is probably due to a recent programming change
306 ======================================================================
307 EOM
308 0 exit 1;
309 } ## end sub AUTOLOAD
310  
311 sub Die {
312 0 ▶ my ($msg) = @_;
Subroutine Die: not called CC=1 SCAR=6.9
Pod undocumented
313 0 Perl::Tidy::Die($msg);
314 0 croak "unexpected return from Perl::Tidy::Die";
315 }
316  
317 sub Warn {
318 0 ▶ my ($msg) = @_;
Subroutine Warn: not called CC=1 SCAR=6.9
Pod undocumented
319 0 Perl::Tidy::Warn($msg);
320 0 return;
321 }
322  
323 sub Fault {
324 0 ▶ my ($msg) = @_;
Subroutine Fault: not called CC=1 SCAR=6.9
Pod undocumented
325  
326 # This routine is called for errors that really should not occur
327 # except if there has been a bug introduced by a recent program change.
328 # Please add comments at calls to Fault to explain why the call
329 # should not occur, and where to look to fix it.
330 0 my ( $package0_uu, $filename0_uu, $line0, $subroutine0_uu ) = caller(0);
331 0 my ( $package1_uu, $filename1, $line1, $subroutine1 ) = caller(1);
332 0 my ( $package2_uu, $filename2_uu, $line2_uu, $subroutine2 ) = caller(2);
333 0 my $pkg = __PACKAGE__;
334 0 my $input_stream_name = Perl::Tidy::get_input_stream_name();
335  
336 0 Die(<<EOM);
337 ==============================================================================
338 While operating on input stream with name: '$input_stream_name'
339 A fault was detected at line $line0 of sub '$subroutine1'
340 in file '$filename1'
341 which was called from line $line1 of sub '$subroutine2'
342 Message: '$msg'
343 This is probably an error introduced by a recent programming change.
344 $pkg reports VERSION='$VERSION'.
345 ==============================================================================
346 EOM
347  
348 0 croak "unexpected return from sub Die";
349 } ## end sub Fault
350  
351 sub bad_pattern {
352 2640 ▶ my ($pattern) = @_;
Subroutine bad_pattern: called CC=1 SCAR=0.0
Pod undocumented
353  
354 # Return true if a regex pattern has an error
355 # Note: Formatter.pm also has a copy of this
356 2640 my $regex_uu = eval { qr/$pattern/ };
357 2640 return $EVAL_ERROR;
358 } ## end sub bad_pattern
359  
360 sub make_skipping_pattern {
361 2640 ▶ my ( $rOpts, $opt_name, $default ) = @_;
Subroutine make_skipping_pattern: called CC=4 SCAR=14.4
Pod undocumented
362  
363 # Make regex patterns for the format-skipping and code-skipping options
364 2640 my $param = $rOpts->{$opt_name};
365 2640 ▶ if ( !$param ) { $param = $default }
Branch: 1 branch
BranchTrueFalseTotal
unless ($param) 2636 4 2640
366 2640 $param =~ s/^\s+//;
367 2640 ▶ if ( $param !~ /^#/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($param =~ /^#/) 0 2640 2640
368 0 Die("ERROR: the $opt_name parameter '$param' must begin with '#'\n");
369 }
370  
371 # Note that the ending \s will match a newline
372 2640 my $pattern = '^\s*' . $param . '\s';
373 2640 ▶ if ( bad_pattern($pattern) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (bad_pattern($pattern)) 0 2640 2640
374 0 Die(
375 "ERROR: the $opt_name parameter '$param' causes the invalid regex '$pattern'\n"
376 );
377 }
378 2640 return $pattern;
379 } ## end sub make_skipping_pattern
380  
381 sub check_options {
382  
383 # Check and pre-process tokenizer parameters
384 660 ▶ my $rOpts = shift;
Subroutine check_options: called CC=16 SCAR=29.2
Pod undocumented
385  
386 660 %is_sub = ();
387 660 $is_sub{'sub'} = 1;
388  
389 660 %is_END_DATA_format_sub = (
390 '__END__' => 1,
391 '__DATA__' => 1,
392 'format' => 1,
393 'sub' => 1,
394 );
395  
396 # Install any aliases to 'sub'
397 660 ▶ if ( $rOpts->{'sub-alias-list'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rOpts->{"sub-alias-list"}) 3 657 660
398  
399 # Note that any 'sub-alias-list' has been preprocessed to
400 # be a trimmed, space-separated list which includes 'sub'
401 # for example, it might be 'sub method fun'
402 3 my @sub_alias_list = split /\s+/, $rOpts->{'sub-alias-list'};
403 3 foreach my $word (@sub_alias_list) {
404 11 $is_sub{$word} = 1;
405 11 $is_END_DATA_format_sub{$word} = 1;
406 }
407 }
408  
409 # Set global flag to say if we have to guess if bareword 'method' is
410 # a sub when 'method' is in %is_sub. This will be true unless:
411 # (1) the user entered 'method' as sub alias, or
412 # (2) the user set --use-feature=class
413 # In these two cases we can assume that 'method' is a sub alias.
414 660 $guess_if_method = 1;
415 660 ▶ if ( $is_sub{'method'} ) { $guess_if_method = 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($is_sub{"method"}) 2 658 660
416  
417 #------------------------------------------------
418 # Update hash values for any -use-feature options
419 #------------------------------------------------
420  
421 660 my $use_feature_class = 1;
422  
423 660 my $str = $rOpts->{'use-feature'};
424 660 ▶ if ( defined($str) && length($str) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $str and length $str) 0 660 660
Condition33%1/3
defined $str and length $str
!ll&&!rl&&r
66000
MC/DC0%0/2
defined $str and length $str
defined $str length $str
Truth table33%1/3
A and B
A= defined $strB= length $str
ABresult
0X0
100
111
425 0 $str =~ s/^\s+//;
426 0 $str =~ s/\s+$//;
427 0 ▶ if ( !length($str) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not length $str) { } 0 0 0
elsif ($str =~ /\bnoclass\b/) { } 0 0 0
elsif ($str =~ /\bclass\b/) { } 0 0 0
428 ## all spaces
429 }
430 elsif ( $str =~ /\bnoclass\b/ ) {
431 0 $use_feature_class = 0;
432 }
433 elsif ( $str =~ /\bclass\b/ ) {
434 0 $guess_if_method = 0;
435 }
436 else {
437 # At present, only 'class' and 'noclass' are valid strings
438 # This is just a Warn, for testing, but will eventually be Die
439 0 Warn(
440 "Unexpected text in --use-feature: expecting 'class' or 'noclass'\n"
441 );
442 }
443 }
444  
445 # These are the main updates for this option. There are additional
446 # changes elsewhere, usually indicated with a comment 'rt145706'
447  
448 # Update hash values for use_feature=class, added for rt145706
449 # see 'perlclass.pod'
450  
451 # IMPORTANT: We are changing global hash values initially set in a BEGIN
452 # block. Values must be defined (true or false) for each of these new
453 # words whether true or false. Otherwise, programs using the module which
454 # change options between runs (such as test code) will have
455 # incorrect settings and fail.
456  
457 # There are 4 new keywords:
458  
459 # 'class' - treated specially as generalization of 'package'
460 # Note: we must not set 'class' to be a keyword to avoid problems
461 # with older uses.
462 660 $is_package{'class'} = $use_feature_class;
463  
464 # 'method' - treated like sub using the sub-alias-list option
465 # Note: we must not set 'method' to be a keyword to avoid problems
466 # with older uses.
467 660 ▶ if ($use_feature_class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_feature_class) 660 0 660
468 660 $is_sub{'method'} = 1;
469 660 $is_END_DATA_format_sub{'method'} = 1;
470 }
471  
472 # 'field' - added as a keyword, and works like 'my'
473 # Setting zero_continuation_block_type allows inclusion in table of level
474 # differences in case of a missing or extra brace (see sub wrapup).
475 660 $is_keyword{'field'} = $use_feature_class;
476 660 $is_my_our_state{'field'} = $use_feature_class;
477 660 $is_zero_continuation_block_type{'field'} = $use_feature_class;
478  
479 # 'ADJUST' - added as a keyword and works like 'BEGIN'
480 # See update git #182 for 'ADJUST :params'
481 # Setting zero_continuation_block_type allows inclusion in table of level
482 # differences in case of a missing or extra brace (see sub wrapup).
483 660 $is_keyword{'ADJUST'} = $use_feature_class;
484 660 $is_code_block_token{'ADJUST'} = $use_feature_class;
485 660 $is_zero_continuation_block_type{'ADJUST'} = $use_feature_class;
486  
487 660 %is_grep_alias = ();
488 660 ▶ if ( $rOpts->{'grep-alias-list'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rOpts->{"grep-alias-list"}) 660 0 660
489  
490 # Note that 'grep-alias-list' has been preprocessed to be a trimmed,
491 # space-separated list
492 660 my @q = split /\s+/, $rOpts->{'grep-alias-list'};
493 660 $is_grep_alias{$_} = 1 for @q;
494 }
495  
496 660 $rOpts_starting_indentation_level = $rOpts->{'starting-indentation-level'};
497 660 $rOpts_indent_columns = $rOpts->{'indent-columns'};
498 660 $rOpts_look_for_hash_bang = $rOpts->{'look-for-hash-bang'};
499 660 $rOpts_look_for_autoloader = $rOpts->{'look-for-autoloader'};
500 660 $rOpts_look_for_selfloader = $rOpts->{'look-for-selfloader'};
501 660 $rOpts_trim_qw = $rOpts->{'trim-qw'};
502 660 $rOpts_extended_syntax = $rOpts->{'extended-syntax'};
503 660 $rOpts_continuation_indentation = $rOpts->{'continuation-indentation'};
504 660 $rOpts_outdent_labels = $rOpts->{'outdent-labels'};
505 660 $rOpts_maximum_level_errors = $rOpts->{'maximum-level-errors'};
506 660 $rOpts_maximum_unexpected_errors = $rOpts->{'maximum-unexpected-errors'};
507 660 $rOpts_code_skipping = $rOpts->{'code-skipping'};
508 660 $rOpts_code_skipping_begin = $rOpts->{'code-skipping-begin'};
509 660 $rOpts_format_skipping = $rOpts->{'format-skipping'};
510 660 $rOpts_format_skipping_begin = $rOpts->{'format-skipping-begin'};
511 660 $rOpts_format_skipping_end = $rOpts->{'format-skipping-end'};
512 660 $rOpts_indent_closing_brace = $rOpts->{'indent-closing-brace'};
513 660 $rOpts_non_indenting_braces = $rOpts->{'non-indenting-braces'};
514 660 $rOpts_non_indenting_brace_prefix = $rOpts->{'non-indenting-brace-prefix'};
515 660 $rOpts_whitespace_cycle = $rOpts->{'whitespace-cycle'};
516  
517 # In the Tokenizer, --indent-columns is just used for guessing old
518 # indentation, and must be positive. If -i=0 is used for this run (which
519 # is possible) we'll just guess that the old run used 4 spaces per level.
520 660 ▶ if ( !$rOpts_indent_columns ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rOpts_indent_columns) 12 648 660
521 12 $rOpts_indent_columns = INDENT_COLUMNS_DEFAULT;
522 }
523  
524 # Define $tabsize, the number of spaces per tab for use in
525 # guessing the indentation of source lines with leading tabs.
526 # Assume same as for this run if tabs are used, otherwise assume
527 # a default value, typically 8
528 $tabsize =
529 $rOpts->{'entab-leading-whitespace'}
530 ? $rOpts->{'entab-leading-whitespace'}
531 : $rOpts->{'tabs'} ? $rOpts->{'indent-columns'}
532 660 ▶ : $rOpts->{'default-tabsize'};
Branch: 2 branches
BranchTrueFalseTotal
$rOpts->{'entab-leading-whitespace'} ? : 2 658 660
$rOpts->{'tabs'} ? : 0 658 658
533 660 ▶ if ( !$tabsize ) { $tabsize = TAB_SIZE_DEFAULT }
Branch: 1 branch
BranchTrueFalseTotal
unless ($tabsize) 0 660 660
534  
535 $code_skipping_pattern_begin =
536 660 make_skipping_pattern( $rOpts, 'code-skipping-begin', '#<<V' );
537 660 $code_skipping_pattern_end =
538 make_skipping_pattern( $rOpts, 'code-skipping-end', '#>>V' );
539  
540 660 $format_skipping_pattern_begin =
541 make_skipping_pattern( $rOpts, 'format-skipping-begin', '#<<<' );
542 660 $format_skipping_pattern_end =
543 make_skipping_pattern( $rOpts, 'format-skipping-end', '#>>>' );
544  
545 660 return;
546 } ## end sub check_options
547  
548 sub new {
549  
550 662 ▶ my ( $class, @arglist ) = @_;
Subroutine new: called CC=7 SCAR=19.6
Pod undocumented
551 662 ▶ if ( @arglist % 2 ) { croak "Odd number of items in arg hash list\n" }
Branch: 1 branch
BranchTrueFalseTotal
if (@arglist % 2) 0 662 662
552  
553 662 my %defaults = (
554 source_object => undef,
555 debugger_object => undef,
556 diagnostics_object => undef,
557 logger_object => undef,
558 starting_level => undef,
559 starting_line_number => 1,
560 rOpts => {},
561 );
562 662 my %args = ( %defaults, @arglist );
563  
564 # we are given an object with a get_line() method to supply source lines
565 662 my $source_object = $args{source_object};
566 662 my $rOpts = $args{rOpts};
567  
568 # Check call args
569 662 ▶ if ( !defined($source_object) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $source_object) 0 662 662
570 0 Die(
571 "Perl::Tidy::Tokenizer::new called without a 'source_object' parameter\n"
572 );
573 }
574 662 ▶ if ( !ref($source_object) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $source_object) 0 662 662
575 0 Die(<<EOM);
576 sub Perl::Tidy::Tokenizer::new received a 'source_object' parameter which is not a reference;
577 'source_object' must be a reference to a STRING, ARRAY, or object with a 'getline' method
578 EOM
579 }
580  
581 662 my $logger_object = $args{logger_object};
582  
583 # Tokenizer state data is as follows:
584 # _rhere_target_list_ reference to list of here-doc targets
585 # _here_doc_target_ the target string for a here document
586 # _here_quote_character_ the type of here-doc quoting (" ' ` or none)
587 # to determine if interpolation is done
588 # _quote_target_ character we seek if chasing a quote
589 # _line_start_quote_ line where we started looking for a long quote
590 # _in_here_doc_ flag indicating if we are in a here-doc
591 # _in_pod_ flag set if we are in pod documentation
592 # _in_code_skipping_ flag set if we are in a code skipping section
593 # _in_format_skipping_ flag set if we are in a format skipping section
594 # _in_error_ flag set if we saw severe error (binary in script)
595 # _do_not_format_ flag set if formatting should be skipped
596 # _warning_count_ number of calls to logger sub warning
597 # _html_tag_count_ number of apparent html tags seen (indicates html)
598 # _in_data_ flag set if we are in __DATA__ section
599 # _in_end_ flag set if we are in __END__ section
600 # _in_format_ flag set if we are in a format description
601 # _in_attribute_list_ flag telling if we are looking for attributes
602 # _in_quote_ flag telling if we are chasing a quote
603 # _starting_level_ indentation level of first line
604 # _diagnostics_object_ place to write debugging information
605 # _unexpected_error_count_ error count used to limit output
606 # _lower_case_labels_at_ line numbers where lower case labels seen
607 # _hit_bug_ program bug detected
608  
609 662 my $self = [];
610 662 $self->[_rhere_target_list_] = [];
611 662 $self->[_in_here_doc_] = 0;
612 662 $self->[_here_doc_target_] = EMPTY_STRING;
613 662 $self->[_here_quote_character_] = EMPTY_STRING;
614 662 $self->[_in_data_] = 0;
615 662 $self->[_in_end_] = 0;
616 662 $self->[_in_format_] = 0;
617 662 $self->[_in_error_] = 0;
618 662 $self->[_do_not_format_] = 0;
619 662 $self->[_warning_count_] = 0;
620 662 $self->[_html_tag_count_] = 0;
621 662 $self->[_in_pod_] = 0;
622 $self->[_in_code_skipping_] =
623 662 ▶ $rOpts->{'code-skipping-from-start'} && $rOpts_code_skipping;
Condition33%1/3
$rOpts->{'code-skipping-from-start'} && $rOpts_code_skipping
!ll&&!rl&&r
66200
MC/DC0%0/2
$rOpts->{'code-skipping-from-start'} && $rOpts_code_skipping
$rOpts->{'code-skipping-from-start'} $rOpts_code_skipping
Truth table33%1/3
A && B
A= $rOpts->{'code-skipping-from-start'}B= $rOpts_code_skipping
ABresult
0X0
100
111
624 662 $self->[_in_format_skipping_] = 0;
625 662 $self->[_rformat_skipping_list_] = [];
626 662 $self->[_in_attribute_list_] = 0;
627 662 $self->[_in_quote_] = 0;
628 662 $self->[_quote_target_] = EMPTY_STRING;
629 662 $self->[_line_start_quote_] = -1;
630 662 $self->[_starting_level_] = $args{starting_level};
631 662 $self->[_know_starting_level_] = defined( $args{starting_level} );
632 662 $self->[_last_line_number_] = $args{starting_line_number} - 1;
633 662 $self->[_saw_perl_dash_P_] = 0;
634 662 $self->[_saw_perl_dash_w_] = 0;
635 662 $self->[_saw_use_strict_] = 0;
636 662 $self->[_saw_brace_error_] = 0;
637 662 $self->[_hit_bug_] = 0;
638 662 $self->[_look_for_autoloader_] = $rOpts_look_for_autoloader;
639 662 $self->[_look_for_selfloader_] = $rOpts_look_for_selfloader;
640 662 $self->[_saw_autoloader_] = 0;
641 662 $self->[_saw_selfloader_] = 0;
642 662 $self->[_saw_hash_bang_] = 0;
643 662 $self->[_saw_end_] = 0;
644 662 $self->[_saw_data_] = 0;
645 662 $self->[_saw_negative_indentation_] = 0;
646 662 $self->[_started_tokenizing_] = 0;
647 662 $self->[_debugger_object_] = $args{debugger_object};
648 662 $self->[_diagnostics_object_] = $args{diagnostics_object};
649 662 $self->[_logger_object_] = $logger_object;
650 662 $self->[_unexpected_error_count_] = 0;
651 662 $self->[_started_looking_for_here_target_at_] = 0;
652 662 $self->[_nearly_matched_here_target_at_] = undef;
653 662 $self->[_line_of_text_] = EMPTY_STRING;
654 662 $self->[_rlower_case_labels_at_] = undef;
655 662 $self->[_maximum_level_] = 0;
656 662 $self->[_true_brace_error_count_] = 0;
657 662 $self->[_rnon_indenting_brace_stack_] = [];
658 662 $self->[_rseqno_at_depth_] = [SEQ_ROOT];
659 662 $self->[_show_indentation_table_] = 0;
660 662 $self->[_rbareword_info_] = {};
661 662 $self->[_rsaw_unknown_syntax_in_seqno_] = {};
662  
663 662 $self->[_rclosing_brace_indentation_hash_] = {
664 valid => undef,
665 rhistory_line_number => [0],
666 rhistory_level_diff => [0],
667 rhistory_anchor_point => [1],
668 };
669  
670 662 $self->[_rOpts_] = $rOpts;
671 662 ▶ $self->[_save_logfile_] =
Condition100%3/3
defined $logger_object && $logger_object->get_save_logfile
!ll&&!rl&&r
26591
MC/DC100%2/2
defined $logger_object && $logger_object->get_save_logfile
defined $logger_object $logger_object->get_save_logfile
Truth table100%3/3
A && B
A= defined $logger_objectB= $logger_object->get_save_logfile
ABresult
0X0
100
111
672 defined($logger_object) && $logger_object->get_save_logfile();
673  
674 662 bless $self, $class;
675  
676 662 $self->prepare_for_a_new_file($source_object);
677 662 $self->find_starting_indentation_level();
678  
679 # This is not a full class yet, so die if an attempt is made to
680 # create more than one object.
681  
682 662 ▶ if ( _increment_count() > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_increment_count() > 1) 0 662 662
683 0 confess
684 "Attempt to create more than 1 object in $class, which is not a true class yet\n";
685 }
686  
687 662 return $self;
688  
689 } ## end sub new
690  
691 # Called externally
692 sub get_unexpected_error_count {
693 4 ▶ my ($self) = @_;
Subroutine get_unexpected_error_count: called CC=1 SCAR=0.0
Pod undocumented
694 4 return $self->[_unexpected_error_count_];
695 }
696  
697 # Called externally
698 sub is_keyword {
699 4 ▶ my ($str) = @_;
Subroutine is_keyword: called CC=1 SCAR=0.0
Pod undocumented
700 4 return $is_keyword{$str};
701 }
702  
703 #----------------------------------------------------------------
704 # Line input routines, previously handled by the LineBuffer class
705 #----------------------------------------------------------------
706 sub make_source_array {
707  
708 662 ▶ my ( $self, $line_source_object ) = @_;
Subroutine make_source_array: called CC=8 SCAR=25.4
Pod undocumented
709  
710 # Convert the source into an array of lines
711 # Given:
712 # $line_source_object = the input source stream
713 # Task:
714 # Convert the source to an array ref and store in $self
715  
716 662 my $rinput_lines = [];
717  
718 662 my $rsource = ref($line_source_object);
719 662 my $source_string;
720  
721 662 ▶ if ( !$rsource ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $rsource) { } 0 662 662
elsif ($rsource eq 'ARRAY') { } 0 662 662
elsif ($rsource eq 'SCALAR') { } 662 0 662
722  
723 # shouldn't happen: this should have been checked in sub new
724 0 Fault(<<EOM);
725 sub Perl::Tidy::Tokenizer::new received a 'source_object' parameter which is not a reference;
726 'source_object' must be a reference to a STRING, ARRAY, or object with a 'getline' method
727 EOM
728 }
729  
730 # handle an ARRAY ref
731 elsif ( $rsource eq 'ARRAY' ) {
732 0 $rinput_lines = $line_source_object;
733 0 $source_string = join( EMPTY_STRING, @{$line_source_object} );
734 }
735  
736 # handle a SCALAR ref
737 elsif ( $rsource eq 'SCALAR' ) {
738 662 $source_string = ${$line_source_object};
739 662 my @lines = split /^/, $source_string;
740 662 $rinput_lines = \@lines;
741 }
742  
743 # handle an object - must have a get_line method
744 else {
745  
746 # This will die if user's object does have a 'get_line' method
747 0 my $line;
748 0 ▶ while ( defined( $line = $line_source_object->get_line() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $line_source_object->get_line)) 0 0 0
749 0 push @{$rinput_lines}, $line;
750 }
751 0 $source_string = join( EMPTY_STRING, @{$rinput_lines} );
752 }
753  
754 # Get trimmed lines. It is much faster to strip leading whitespace from
755 # the whole input file at once than line-by-line.
756  
757 # Add a terminal newline if needed to keep line count unchanged:
758 # - avoids problem of losing a last line which is just \r and no \n (c283)
759 # - but check input line count to avoid adding line to an empty file (c286)
760 662 ▶ if ( @{$rinput_lines} && $source_string !~ /\n$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rinput_lines;} and not $source_string =~ /\n$/) 1 661 662
Condition100%3/3
@{$rinput_lines;} and not $source_string =~ /\n$/
!ll&&!rl&&r
26591
MC/DC100%2/2
@{$rinput_lines;} and not $source_string =~ /\n$/
@{$rinput_lines;} not $source_string =~ /\n$/
Truth table100%3/3
A and not(B)
A= @{$rinput_lines;}B= not $source_string =~ /\n$/
ABresult
0X0
100
111
761 1 $source_string .= "\n";
762 }
763  
764 # Remove leading whitespace except newlines
765 662 $source_string =~ s/^ [^\S\n]+ //gxm;
766  
767 # Then break the string into lines
768 662 my @trimmed_lines = split /^/, $source_string;
769  
770 # Safety check - a change in number of lines would be a disaster
771 662 ▶ if ( @trimmed_lines != @{$rinput_lines} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@trimmed_lines != @{$rinput_lines;}) 0 662 662
772  
773 # Shouldn't happen - die in DEVEL_MODE and fix
774 0 my $ntr = @trimmed_lines;
775 0 my $utr = @{$rinput_lines};
776 0 DEVEL_MODE
777 && Fault("trimmed / untrimmed line counts differ: $ntr / $utr\n");
778  
779 # Otherwise we can safely continue with undefined trimmed lines. They
780 # will be detected and fixed later.
781 0 @trimmed_lines = ();
782 }
783  
784 662 $self->[_rinput_lines_] = $rinput_lines;
785 662 $self->[_rtrimmed_input_lines_] = \@trimmed_lines;
786 662 $self->[_input_line_index_next_] = 0;
787 662 return;
788 } ## end sub make_source_array
789  
790 sub peek_ahead {
791 1400 ▶ my ( $self, $buffer_index ) = @_;
Subroutine peek_ahead: called CC=2 SCAR=6.9
Pod undocumented
792  
793 # look $buffer_index lines ahead of the current location in the input
794 # stream without disturbing the input
795 1400 my $line;
796 1400 my $rinput_lines = $self->[_rinput_lines_];
797 1400 my $line_index = $buffer_index + $self->[_input_line_index_next_];
798 1400 ▶ if ( $line_index < @{$rinput_lines} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line_index < @{$rinput_lines;}) 1388 12 1400
799 1388 $line = $rinput_lines->[$line_index];
800 }
801 1400 return $line;
802 } ## end sub peek_ahead
803  
804 #-----------------------------------------
805 # interface to Perl::Tidy::Logger routines
806 #-----------------------------------------
807 sub warning {
808  
809 0 ▶ my ( $self, $msg ) = @_;
Subroutine warning: not called CC=2 SCAR=17.9
Pod undocumented
810  
811 0 my $logger_object = $self->[_logger_object_];
812 0 $self->[_warning_count_]++;
813 0 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 0 0 0
814 0 my $msg_line_number = $self->[_last_line_number_];
815 0 $logger_object->warning( $msg, $msg_line_number );
816 }
817 0 return;
818 } ## end sub warning
819  
820 sub warning_do_not_format {
821 0 ▶ my ( $self, $msg ) = @_;
Subroutine warning_do_not_format: not called CC=1 SCAR=6.9
Pod undocumented
822  
823 # Issue a warning message and set a flag to skip formatting this file.
824 0 $self->warning($msg);
825 0 $self->[_do_not_format_] = 1;
826 0 return;
827 } ## end sub warning_do_not_format
828  
829 sub complain {
830  
831 39 ▶ my ( $self, $msg ) = @_;
Subroutine complain: called CC=2 SCAR=7.0
Pod undocumented
832  
833 39 my $logger_object = $self->[_logger_object_];
834 39 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 39 0 39
835 39 my $input_line_number = $self->[_last_line_number_];
836 39 $logger_object->complain( $msg, $input_line_number );
837 }
838 39 return;
839 } ## end sub complain
840  
841 sub write_logfile_entry {
842  
843 2257 ▶ my ( $self, $msg ) = @_;
Subroutine write_logfile_entry: called CC=2 SCAR=6.9
Pod undocumented
844  
845 2257 my $logger_object = $self->[_logger_object_];
846 2257 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 2251 6 2257
847 2251 $logger_object->write_logfile_entry($msg);
848 }
849 2257 return;
850 } ## end sub write_logfile_entry
851  
852 sub interrupt_logfile {
853  
854 0 ▶ my $self = shift;
Subroutine interrupt_logfile: not called CC=2 SCAR=17.9
Pod undocumented
855  
856 0 my $logger_object = $self->[_logger_object_];
857 0 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 0 0 0
858 0 $logger_object->interrupt_logfile();
859 }
860 0 return;
861 } ## end sub interrupt_logfile
862  
863 sub resume_logfile {
864  
865 0 ▶ my $self = shift;
Subroutine resume_logfile: not called CC=2 SCAR=17.9
Pod undocumented
866  
867 0 my $logger_object = $self->[_logger_object_];
868 0 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 0 0 0
869 0 $logger_object->resume_logfile();
870 }
871 0 return;
872 } ## end sub resume_logfile
873  
874 sub brace_warning {
875 0 ▶ my ( $self, $msg ) = @_;
Subroutine brace_warning: not called CC=2 SCAR=17.9
Pod undocumented
876 0 $self->[_saw_brace_error_]++;
877  
878 0 my $logger_object = $self->[_logger_object_];
879 0 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 0 0 0
880 0 my $msg_line_number = $self->[_last_line_number_];
881 0 $logger_object->brace_warning( $msg, $msg_line_number );
882 }
883 0 return;
884 } ## end sub brace_warning
885  
886 sub increment_brace_error {
887  
888 # This is same as sub brace_warning but without a message
889 0 ▶ my $self = shift;
Subroutine increment_brace_error: not called CC=2 SCAR=17.9
Pod undocumented
890 0 $self->[_saw_brace_error_]++;
891  
892 0 my $logger_object = $self->[_logger_object_];
893 0 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 0 0 0
894 0 $logger_object->increment_brace_error();
895 }
896 0 return;
897 } ## end sub increment_brace_error
898  
899 sub get_saw_brace_error {
900 0 ▶ my $self = shift;
Subroutine get_saw_brace_error: not called CC=1 SCAR=6.9
Pod undocumented
901 0 return $self->[_saw_brace_error_];
902 }
903  
904 sub report_definite_bug {
905 0 ▶ my $self = shift;
Subroutine report_definite_bug: not called CC=2 SCAR=17.9
Pod undocumented
906 0 $self->[_hit_bug_] = 1;
907 0 my $logger_object = $self->[_logger_object_];
908 0 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 0 0 0
909 0 $logger_object->report_definite_bug();
910 }
911 0 return;
912 } ## end sub report_definite_bug
913  
914 #-------------------------------------
915 # Interface to Perl::Tidy::Diagnostics
916 #-------------------------------------
917 sub write_diagnostics {
918 0 ▶ my ( $self, $msg ) = @_;
Subroutine write_diagnostics: not called CC=2 SCAR=17.9
Pod undocumented
919 0 my $input_line_number = $self->[_last_line_number_];
920 0 my $diagnostics_object = $self->[_diagnostics_object_];
921 0 ▶ if ($diagnostics_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diagnostics_object) 0 0 0
922 0 $diagnostics_object->write_diagnostics( $msg, $input_line_number );
923 }
924 0 return;
925 } ## end sub write_diagnostics
926  
927 sub report_tokenization_errors {
928  
929 662 ▶ my ($self) = @_;
Subroutine report_tokenization_errors: called CC=34 SCAR=51.8
Pod undocumented
930  
931 # Report any tokenization errors and return a flag '$severe_error'.
932 # Set $severe_error = 1 if the tokenization errors are so severe that
933 # the formatter should not attempt to format the file. Instead, it will
934 # just output the file verbatim.
935  
936 # set severe error flag if tokenizer has encountered file reading problems
937 # (i.e. unexpected binary characters)
938 # or code which may not be formatted correctly (such as 'my sub q')
939 # The difference between _in_error_ and _do_not_format_ is that
940 # _in_error_ stops the tokenizer immediately whereas
941 # _do_not_format_ lets the tokenizer finish so that all errors are seen
942 # Both block formatting and cause the input stream to be output verbatim.
943 662 ▶ my $severe_error = $self->[_in_error_] || $self->[_do_not_format_];
Condition33%1/3
$self->[7] || $self->[8]
l!l&&r!l&&!r
00662
MC/DC0%0/2
$self->[7] || $self->[8]
$self->[7] $self->[8]
Truth table33%1/3
A || B
A= $self->[7]B= $self->[8]
ABresult
1X1
011
000
944  
945 # And do not format if it looks like an html file (c209)
946 662 ▶ $severe_error ||= $self->[_html_tag_count_] && $self->[_warning_count_];
Condition33%2/6
$severe_error ||= $self->[10] && $self->[9]
l!l&&r!l&&!r
00662
$self->[10] && $self->[9]
!ll&&!rl&&r
66200
MC/DC0%0/3
$severe_error ||= $self->[10] && $self->[9]
$severe_error $self->[10] $self->[9]
Truth table0%0/4
A ||= B && C
A= $severe_errorB= $self->[10]C= $self->[9]
ABCresult
1XX1
0111
00X0
0100
947  
948 # Inform the logger object on length of input stream
949 662 my $logger_object = $self->[_logger_object_];
950 662 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 660 2 662
951 660 my $last_line_number = $self->[_last_line_number_];
952 660 $logger_object->set_last_input_line_number($last_line_number);
953 }
954  
955 662 my $maxle = $rOpts_maximum_level_errors;
956 662 my $maxue = $rOpts_maximum_unexpected_errors;
957 662 ▶ $maxle = 1 unless ( defined($maxle) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $maxle 0 662 662
958 662 ▶ $maxue = 0 unless ( defined($maxue) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $maxue 0 662 662
959  
960 662 my $level = get_indentation_level();
961 662 ▶ if ( $level != $self->[_starting_level_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level != $self->[19]) 0 662 662
962 0 $self->warning("final indentation level: $level\n");
963  
964 0 $self->[_show_indentation_table_] = 1;
965  
966 0 my $level_diff = $self->[_starting_level_] - $level;
967 0 ▶ if ( $level_diff < 0 ) { $level_diff = -$level_diff }
Branch: 1 branch
BranchTrueFalseTotal
if ($level_diff < 0) 0 0 0
968  
969 # Set severe error flag if the level error is greater than 1.
970 # The formatter can function for any level error but it is probably
971 # best not to attempt formatting for a high level error.
972 0 ▶ if ( $maxle >= 0 && $level_diff > $maxle ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($maxle >= 0 and $level_diff > $maxle) 0 0 0
Condition0%0/3
$maxle >= 0 and $level_diff > $maxle
!ll&&!rl&&r
000
MC/DC0%0/2
$maxle >= 0 and $level_diff > $maxle
$maxle >= 0 $level_diff > $maxle
Truth table0%0/3
A and B
A= $maxle >= 0B= $level_diff > $maxle
ABresult
0X0
100
111
973 0 $severe_error = 1;
974 0 $self->warning(<<EOM);
975 Formatting will be skipped because level error '$level_diff' exceeds -maxle=$maxle; use -maxle=-1 to force formatting
976 EOM
977 }
978 }
979  
980 662 $self->check_final_nesting_depths();
981  
982 662 ▶ if ( $self->[_show_indentation_table_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[52]) 0 662 662
983 0 $self->show_indentation_table();
984 }
985  
986 # Likewise, large numbers of brace errors usually indicate non-perl
987 # scripts, so set the severe error flag at a low number. This is similar
988 # to the level check, but different because braces may balance but be
989 # incorrectly interlaced.
990 662 ▶ if ( $self->[_true_brace_error_count_] > 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[46] > 2) 0 662 662
991 0 $severe_error = 1;
992 }
993  
994 662 ▶ if ( $rOpts_look_for_hash_bang
Branch: 1 branch
BranchTrueFalseTotal
if ($rOpts_look_for_hash_bang and not $self->[31]) 0 662 662
Condition66%2/3
$rOpts_look_for_hash_bang and not $self->[31]
!ll&&!rl&&r
66110
MC/DC0%0/2
$rOpts_look_for_hash_bang and not $self->[31]
$rOpts_look_for_hash_bang not $self->[31]
Truth table66%2/3
A and not(B)
A= $rOpts_look_for_hash_bangB= not $self->[31]
ABresult
0X0
100
111
995 && !$self->[_saw_hash_bang_] )
996 {
997 0 $self->warning(
998 "hit EOF without seeing hash-bang line; maybe don't need -x?\n");
999 }
1000  
1001 662 ▶ if ( $self->[_in_format_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[6]) 0 662 662
1002 0 $self->warning("hit EOF while in format description\n");
1003 }
1004  
1005 662 ▶ if ( $self->[_in_code_skipping_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[12]) 0 662 662
1006 0 $self->write_logfile_entry(
1007 "hit EOF while in lines skipped with --code-skipping\n");
1008 }
1009  
1010 662 ▶ if ( $self->[_in_pod_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[11]) 0 662 662
1011  
1012 # Just write log entry if this is after __END__ or __DATA__
1013 # because this happens to often, and it is not likely to be
1014 # a parsing error.
1015 0 ▶ if ( $self->[_saw_data_] || $self->[_saw_end_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[33] or $self->[32]) { } 0 0 0
Condition0%0/3
$self->[33] or $self->[32]
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[33] or $self->[32]
$self->[33] $self->[32]
Truth table0%0/3
A or B
A= $self->[33]B= $self->[32]
ABresult
1X1
011
000
1016 0 $self->write_logfile_entry(
1017 "hit eof while in pod documentation (no =cut seen)\n\tthis can cause trouble with some pod utilities\n"
1018 );
1019 }
1020  
1021 else {
1022 0 $self->complain(
1023 "hit eof while in pod documentation (no =cut seen)\n\tthis can cause trouble with some pod utilities\n"
1024 );
1025 }
1026  
1027 }
1028  
1029 662 ▶ if ( $self->[_in_here_doc_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[1]) 0 662 662
1030 0 $severe_error = 1;
1031 0 my $here_doc_target = $self->[_here_doc_target_];
1032 0 my $started_looking_for_here_target_at =
1033 $self->[_started_looking_for_here_target_at_];
1034 0 ▶ if ($here_doc_target) {
Branch: 1 branch
BranchTrueFalseTotal
if ($here_doc_target) { } 0 0 0
1035 0 $self->warning(
1036 "hit EOF in here document starting at line $started_looking_for_here_target_at with target: $here_doc_target\n"
1037 );
1038 }
1039 else {
1040 0 $self->warning(<<EOM);
1041 Hit EOF in here document starting at line $started_looking_for_here_target_at with empty target string.
1042 (Perl will match to the end of file but this may not be intended).
1043 EOM
1044 }
1045 0 my $nearly_matched_here_target_at =
1046 $self->[_nearly_matched_here_target_at_];
1047 0 ▶ if ($nearly_matched_here_target_at) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nearly_matched_here_target_at) 0 0 0
1048 0 $self->warning(
1049 "NOTE: almost matched at input line $nearly_matched_here_target_at except for whitespace\n"
1050 );
1051 }
1052 }
1053  
1054 # Something is seriously wrong if we ended inside a quote
1055 662 ▶ if ( $self->[_in_quote_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[16]) 0 662 662
1056 0 $severe_error = 1;
1057 0 my $line_start_quote = $self->[_line_start_quote_];
1058 0 my $quote_target = $self->[_quote_target_];
1059 0 ▶ my $what =
Branch: 1 branch
BranchTrueFalseTotal
$self->[15] ? : 0 0 0
1060 ( $self->[_in_attribute_list_] )
1061 ? "attribute list"
1062 : "quote/pattern";
1063 0 $self->warning(
1064 "hit EOF seeking end of $what starting at line $line_start_quote ending in $quote_target\n"
1065 );
1066 }
1067  
1068 662 ▶ if ( $self->[_hit_bug_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[26]) 0 662 662
1069 0 $severe_error = 1;
1070 }
1071  
1072 # Multiple "unexpected" type tokenization errors usually indicate parsing
1073 # non-perl scripts, or that something is seriously wrong, so we should
1074 # avoid formatting them. This can happen for example if we run perltidy on
1075 # a shell script or an html file. But unfortunately this check can
1076 # interfere with some extended syntaxes, such as RPerl, so it has to be off
1077 # by default.
1078 662 my $ue_count = $self->[_unexpected_error_count_];
1079 662 ▶ if ( $maxue > 0 && $ue_count > $maxue ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($maxue > 0 and $ue_count > $maxue) 0 662 662
Condition33%1/3
$maxue > 0 and $ue_count > $maxue
!ll&&!rl&&r
66200
MC/DC0%0/2
$maxue > 0 and $ue_count > $maxue
$maxue > 0 $ue_count > $maxue
Truth table33%1/3
A and B
A= $maxue > 0B= $ue_count > $maxue
ABresult
0X0
100
111
1080 0 $self->warning(<<EOM);
1081 Formatting will be skipped since unexpected token count = $ue_count > -maxue=$maxue; use -maxue=0 to force formatting
1082 EOM
1083 0 $severe_error = 1;
1084 }
1085  
1086 662 ▶ if ( !$self->[_saw_perl_dash_w_] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[23]) 645 17 662
1087 645 $self->write_logfile_entry("Suggest including 'use warnings;'\n");
1088 }
1089  
1090 662 ▶ if ( $self->[_saw_perl_dash_P_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[22]) 0 662 662
1091 0 $self->write_logfile_entry(
1092 "Use of -P parameter for defines is discouraged\n");
1093 }
1094  
1095 662 ▶ if ( !$self->[_saw_use_strict_] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[24]) 648 14 662
1096 648 $self->write_logfile_entry("Suggest including 'use strict;'\n");
1097 }
1098  
1099 # it is suggested that labels have at least one upper case character
1100 # for legibility and to avoid code breakage as new keywords are introduced
1101 662 ▶ if ( $self->[_rlower_case_labels_at_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[44]) 12 650 662
1102 12 my @lower_case_labels_at = @{ $self->[_rlower_case_labels_at_] };
1103 12 $self->write_logfile_entry(
1104 "Suggest using upper case characters in label(s)\n");
1105 12 local $LIST_SEPARATOR = ')(';
1106 12 $self->write_logfile_entry(
1107 " defined at line(s): (@lower_case_labels_at)\n");
1108 }
1109  
1110 # Get the text of any leading format skipping tag
1111 662 my $early_FS_end_marker;
1112 662 my $rformat_skipping_list = $self->[_rformat_skipping_list_];
1113 662 ▶ if ( @{$rformat_skipping_list} && $rformat_skipping_list->[0]->[0] == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rformat_skipping_list;} and $rformat_skipping_list->[0][0] == -1) 3 659 662
Condition100%3/3
@{$rformat_skipping_list;} and $rformat_skipping_list->[0][0] == -1
!ll&&!rl&&r
649103
MC/DC100%2/2
@{$rformat_skipping_list;} and $rformat_skipping_list->[0][0] == -1
@{$rformat_skipping_list;} $rformat_skipping_list->[0][0] == -1
Truth table100%3/3
A and B
A= @{$rformat_skipping_list;}B= $rformat_skipping_list->[0][0] == -1
ABresult
0X0
100
111
1114 3 $early_FS_end_marker = $rformat_skipping_list->[0]->[2];
1115 }
1116  
1117 return {
1118 662 severe_error => $severe_error,
1119 early_FS_end_marker => $early_FS_end_marker,
1120 };
1121  
1122 } ## end sub report_tokenization_errors
1123  
1124 sub show_indentation_table {
1125 0 ▶ my ($self) = @_;
Subroutine show_indentation_table: not called CC=25 SCAR=64.8
Pod undocumented
1126  
1127 # Output indentation table made at closing braces. This can be helpful for
1128 # the case of a missing brace in a previously formatted file.
1129  
1130 # skip if problem reading file
1131 0 ▶ return if ( $self->[_in_error_] );
Branch: 1 branch
BranchTrueFalseTotal
if $self->[7] 0 0 0
1132  
1133 # skip if -wc is used (rare); it is too complex to use
1134 0 ▶ return if ($rOpts_whitespace_cycle);
Branch: 1 branch
BranchTrueFalseTotal
if $rOpts_whitespace_cycle 0 0 0
1135  
1136 # skip if non-indenting-brace-prefix (very rare, but could be fixed)
1137 0 ▶ return if ($rOpts_non_indenting_brace_prefix);
Branch: 1 branch
BranchTrueFalseTotal
if $rOpts_non_indenting_brace_prefix 0 0 0
1138  
1139 # skip if starting level is not zero (probably in editor)
1140 0 ▶ return if ($rOpts_starting_indentation_level);
Branch: 1 branch
BranchTrueFalseTotal
if $rOpts_starting_indentation_level 0 0 0
1141  
1142 # skip if indentation analysis is not valid
1143 0 my $rhash = $self->[_rclosing_brace_indentation_hash_];
1144 0 ▶ return if ( !$rhash->{valid} );
Branch: 1 branch
BranchTrueFalseTotal
unless $rhash->{"valid"} 0 0 0
1145  
1146 0 my $rhistory_line_number = $rhash->{rhistory_line_number};
1147 0 my $rhistory_level_diff = $rhash->{rhistory_level_diff};
1148 0 my $rhistory_anchor_point = $rhash->{rhistory_anchor_point};
1149  
1150 # Remove the first artificial point from the table
1151 0 shift @{$rhistory_line_number};
1152 0 shift @{$rhistory_level_diff};
1153 0 shift @{$rhistory_anchor_point};
1154  
1155 # Remove dubious points at an anchor point = 2 and beyond
1156 # These can occur when non-indenting braces are used
1157 0 my $num_his = @{$rhistory_level_diff};
1158 0 foreach my $i ( 0 .. $num_his - 1 ) {
1159 0 ▶ if ( $rhistory_anchor_point->[$i] == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rhistory_anchor_point->[$i] == 2) 0 0 0
1160 0 $num_his = $i;
1161 0 last;
1162 }
1163 }
1164 0 ▶ return if ( $num_his <= 1 );
Branch: 1 branch
BranchTrueFalseTotal
if $num_his <= 1 0 0 0
1165  
1166 # Ignore an ending non-anchor point
1167 0 ▶ if ( !$rhistory_anchor_point->[-1] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rhistory_anchor_point->[-1]) 0 0 0
1168 0 $num_his -= 1;
1169 }
1170  
1171 # Ignore an ending point which is the same as the previous point
1172 0 ▶ if ( $num_his > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num_his > 1) 0 0 0
1173 0 ▶ if ( $rhistory_level_diff->[ $num_his - 1 ] ==
Branch: 1 branch
BranchTrueFalseTotal
if ($$rhistory_level_diff[$num_his - 1] == $$rhistory_level_diff[$num_his - 2]) 0 0 0
1174 $rhistory_level_diff->[ $num_his - 2 ] )
1175 {
1176 0 $num_his -= 1;
1177 }
1178 }
1179  
1180 # Skip if the table does not have at least 2 points to pinpoint an error
1181 0 ▶ return if ( $num_his <= 1 );
Branch: 1 branch
BranchTrueFalseTotal
if $num_his <= 1 0 0 0
1182  
1183 # Skip if first point shows a level error - the analysis may not be valid
1184 0 ▶ return if ( $rhistory_level_diff->[0] );
Branch: 1 branch
BranchTrueFalseTotal
if $rhistory_level_diff->[0] 0 0 0
1185  
1186 # Remove table points which return from negative to zero; they follow
1187 # an error and may not be correct. c448.
1188 0 my $min_lev = $rhistory_level_diff->[0];
1189 0 foreach my $ii ( 1 .. $num_his - 1 ) {
1190 0 my $lev = $rhistory_level_diff->[$ii];
1191 0 ▶ if ( $lev < $min_lev ) { $min_lev = $lev; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($lev < $min_lev) 0 0 0
1192 0 ▶ if ( $min_lev < 0 && $lev >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($min_lev < 0 and $lev >= 0) 0 0 0
Condition0%0/3
$min_lev < 0 and $lev >= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$min_lev < 0 and $lev >= 0
$min_lev < 0 $lev >= 0
Truth table0%0/3
A and B
A= $min_lev < 0B= $lev >= 0
ABresult
0X0
100
111
1193 0 $num_his = $ii;
1194 0 last;
1195 }
1196 }
1197  
1198 # Since the table could be arbitrarily large, we will limit the table to N
1199 # lines. If there are more lines than that, we will show N-3 lines, then
1200 # ..., then the last 2 lines. Allow about 3 lines per error, so a table
1201 # limit of 10 can localize up to about 3 errors in a file.
1202 0 my $nlines_max = 10;
1203 0 my @pre_indexes = ( 0 .. $num_his - 1 );
1204 0 my @post_indexes = ();
1205 0 ▶ if ( @pre_indexes > $nlines_max ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pre_indexes > $nlines_max) 0 0 0
1206 0 ▶ if ( $nlines_max >= 5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nlines_max >= 5) { } 0 0 0
1207 0 @pre_indexes = ( 0 .. $nlines_max - 4 );
1208 0 @post_indexes = ( $num_his - 2, $num_his - 1 );
1209 }
1210 else {
1211 0 @pre_indexes = ( 0 .. $nlines_max - 1 );
1212 }
1213 }
1214  
1215 0 my @output_lines;
1216 0 push @output_lines, <<EOM;
1217 Table of initial nesting level differences at closing braces.
1218 This might help localize brace errors IF perltidy previously formatted the file.
1219 line: error=[new brace level]-[old indentation level]
1220 EOM
1221 0 foreach my $i (@pre_indexes) {
1222 0 my $lno = $rhistory_line_number->[$i];
1223 0 my $diff = $rhistory_level_diff->[$i];
1224 0 push @output_lines, <<EOM;
1225 $lno: $diff
1226 EOM
1227 }
1228 0 ▶ if (@post_indexes) {
Branch: 1 branch
BranchTrueFalseTotal
if (@post_indexes) 0 0 0
1229 0 push @output_lines, "...\n";
1230 0 foreach my $i (@post_indexes) {
1231 0 my $lno = $rhistory_line_number->[$i];
1232 0 my $diff = $rhistory_level_diff->[$i];
1233 0 push @output_lines, <<EOM;
1234 $lno: $diff
1235 EOM
1236 }
1237 }
1238  
1239 # Try to give a hint
1240 0 my $level_diff_1 = $rhistory_level_diff->[1];
1241 0 my $ln_0 = $rhistory_line_number->[0];
1242 0 my $ln_1 = $rhistory_line_number->[1];
1243 0 ▶ if ( $level_diff_1 < 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($level_diff_1 < 0) { } 0 0 0
elsif ($level_diff_1 > 0) { } 0 0 0
1244 0 push @output_lines,
1245 "There may be an extra '}' or missing '{' between lines $ln_0 and $ln_1\n";
1246 }
1247 elsif ( $level_diff_1 > 0 ) {
1248 0 push @output_lines,
1249 "There may be a missing '}' or extra '{' between lines $ln_0 and $ln_1\n";
1250 }
1251 else {
1252 ## two leading zeros in the table - probably can't happen - no hint
1253 }
1254  
1255 0 push @output_lines, "\n";
1256 0 my $output_str = join( EMPTY_STRING, @output_lines );
1257  
1258 0 $self->interrupt_logfile();
1259 0 $self->warning($output_str);
1260 0 $self->resume_logfile();
1261  
1262 0 return;
1263 } ## end sub show_indentation_table
1264  
1265 sub report_v_string {
1266  
1267 # warn if this version can't handle v-strings
1268 2 ▶ my ( $self, $tok ) = @_;
Subroutine report_v_string: called CC=2 SCAR=7.6
Pod undocumented
1269 2 ▶ if ( $] < 5.006 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.006") 0 2 2
1270 0 $self->warning(
1271 "Found v-string '$tok' but v-strings are not implemented in your version of perl; see Camel 3 book ch 2\n"
1272 );
1273 }
1274 2 return;
1275 } ## end sub report_v_string
1276  
1277 sub is_valid_token_type {
1278 448 ▶ my ($type) = @_;
Subroutine is_valid_token_type: called CC=1 SCAR=0.0
Pod undocumented
1279 448 return $is_valid_token_type{$type};
1280 }
1281  
1282 sub log_numbered_msg {
1283 264 ▶ my ( $self, $msg ) = @_;
Subroutine log_numbered_msg: called CC=1 SCAR=0.0
Pod undocumented
1284  
1285 # write input line number + message to logfile
1286 264 my $input_line_number = $self->[_last_line_number_];
1287 264 $self->write_logfile_entry("Line $input_line_number: $msg");
1288 264 return;
1289 } ## end sub log_numbered_msg
1290  
1291 sub get_line {
1292  
1293 9856 ▶ my $self = shift;
Subroutine get_line: called CC=70 SCAR=48.7
Pod undocumented
1294  
1295 # Read the next input line and tokenize it
1296 # Returns:
1297 # $line_of_tokens = ref to hash of info for the tokenized line
1298  
1299 # USES GLOBAL VARIABLES:
1300 # $brace_depth, $square_bracket_depth, $paren_depth
1301  
1302 # get the next line from the input array
1303 9856 my $input_line;
1304 my $trimmed_input_line;
1305 9856 my $line_index = $self->[_input_line_index_next_];
1306 9856 my $rinput_lines = $self->[_rinput_lines_];
1307 9856 ▶ if ( $line_index < @{$rinput_lines} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line_index < @{$rinput_lines;}) { } 9194 662 9856
1308 9194 $trimmed_input_line = $self->[_rtrimmed_input_lines_]->[$line_index];
1309 9194 $input_line = $rinput_lines->[ $line_index++ ];
1310 9194 $self->[_input_line_index_next_] = $line_index;
1311 }
1312  
1313 # End of file .. check if file ends in a binary operator (c565)
1314 else {
1315 662 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($is_binary_or_unary_operator_type{$last_nonblank_type} or $last_nonblank_type eq "k" and $is_binary_or_unary_keyword{$last_nonblank_token}) 0 662 662
Condition33%2/6
$is_binary_or_unary_operator_type{$last_nonblank_type} or $last_nonblank_type eq "k" and $is_binary_or_unary_keyword{$last_nonblank_token}
l!l&&r!l&&!r
00662
$last_nonblank_type eq "k" and $is_binary_or_unary_keyword{$last_nonblank_token}
!ll&&!rl&&r
66200
MC/DC0%0/3
$is_binary_or_unary_operator_type{$last_nonblank_type} or $last_nonblank_type eq "k" and $is_binary_or_unary_keyword{$last_nonblank_token}
$is_binary_or_unary_operator_type{$last_nonblank_type} $last_nonblank_type eq "k" $is_binary_or_unary_keyword{$last_nonblank_token}
Truth table0%0/4
A or B and C
A= $is_binary_or_unary_operator_type{$last_nonblank_type}B= $last_nonblank_type eq "k"C= $is_binary_or_unary_keyword{$last_nonblank_token}
ABCresult
1XX1
0111
00X0
0100
1316 $is_binary_or_unary_operator_type{$last_nonblank_type}
1317 || ( $last_nonblank_type eq 'k'
1318 && $is_binary_or_unary_keyword{$last_nonblank_token} )
1319 )
1320 {
1321 0 $self->warning(
1322 "Unexpected EOF at operator '$last_nonblank_token'\n");
1323  
1324 # avoid repeating this message
1325 0 $last_nonblank_token = ';';
1326 0 $last_nonblank_type = ';';
1327 }
1328 }
1329  
1330 9856 $self->[_line_of_text_] = $input_line;
1331  
1332 9856 ▶ return if ( !defined($input_line) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $input_line 662 9194 9856
1333  
1334 9194 my $input_line_number = ++$self->[_last_line_number_];
1335  
1336 # Find and remove what characters terminate this line, including any
1337 # control r
1338 9194 my $input_line_separator = EMPTY_STRING;
1339 9194 ▶ if ( chomp $input_line ) {
Branch: 1 branch
BranchTrueFalseTotal
if (chomp $input_line) 9193 1 9194
1340 9193 $input_line_separator = $INPUT_RECORD_SEPARATOR;
1341 }
1342  
1343 # The first test here very significantly speeds things up, but be sure to
1344 # keep the regex and hash %other_line_endings the same.
1345 9194 ▶ if ( $other_line_endings{ substr( $input_line, -1 ) } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other_line_endings{substr $input_line, -1}) 0 9194 9194
1346 0 ▶ if ( $input_line =~ s/([\r\035\032])+$// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ s/([\r\035\032])+$//) 0 0 0
1347 0 $input_line_separator = $1 . $input_line_separator;
1348  
1349 # This could make the trimmed input line incorrect, so the
1350 # safe thing to do is to make it undef to force it to be
1351 # recomputed later.
1352 0 $trimmed_input_line = undef;
1353 }
1354 }
1355  
1356 # For backwards compatibility we keep the line text terminated with
1357 # a newline character
1358 9194 $input_line .= "\n";
1359 9194 $self->[_line_of_text_] = $input_line;
1360  
1361 # create a data structure describing this line which will be
1362 # returned to the caller.
1363  
1364 # _line_type codes are:
1365 # SYSTEM - system-specific code before hash-bang line
1366 # CODE - line of perl code (including comments)
1367 # POD_START - line starting pod, such as '=head'
1368 # POD - pod documentation text
1369 # POD_END - last line of pod section, '=cut'
1370 # HERE - text of here-document
1371 # HERE_END - last line of here-doc (target word)
1372 # FORMAT - format section
1373 # FORMAT_END - last line of format section, '.'
1374 # SKIP - code skipping section
1375 # SKIP_END - last line of code skipping section, '#>>V'
1376 # DATA_START - __DATA__ line
1377 # DATA - unidentified text following __DATA__
1378 # END_START - __END__ line
1379 # END - unidentified text following __END__
1380 # ERROR - we are in big trouble, probably not a perl script
1381  
1382 # Other variables:
1383 # _curly_brace_depth - depth of curly braces at start of line
1384 # _square_bracket_depth - depth of square brackets at start of line
1385 # _paren_depth - depth of parens at start of line
1386 # _starting_in_quote - this line continues a multi-line quote
1387 # (so don't trim leading blanks!)
1388 # _ending_in_quote - this line ends in a multi-line quote
1389 # (so don't trim trailing blanks!)
1390 9194 my $line_of_tokens = {
1391 _line_type => 'EOF',
1392 _line_text => $input_line,
1393 _line_number => $input_line_number,
1394 _guessed_indentation_level => 0,
1395 _curly_brace_depth => $brace_depth,
1396 _square_bracket_depth => $square_bracket_depth,
1397 _paren_depth => $paren_depth,
1398 ## Skip these needless initializations for efficiency:
1399 ## _rtoken_type => undef,
1400 ## _rtokens => undef,
1401 ## _rlevels => undef,
1402 ## _rblock_type => undef,
1403 ## _rtype_sequence => undef,
1404 ## _starting_in_quote => 0,
1405 ## _ending_in_quote => 0,
1406 };
1407  
1408 # Must print line unchanged if we are in a here document
1409 9194 ▶ if ( $self->[_in_here_doc_] ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($self->[1]) { } 104 9090 9194
elsif ($self->[6]) { } 3 9087 9090
elsif ($self->[11]) { } 51 9036 9087
elsif ($self->[12]) { } 8 9028 9036
elsif ($self->[7]) { } 0 9028 9028
elsif ($self->[4]) { } 1 9027 9028
elsif ($self->[5]) { } 56 8971 9027
1410  
1411 104 $line_of_tokens->{_line_type} = 'HERE';
1412 104 my $here_doc_target = $self->[_here_doc_target_];
1413 104 my $here_quote_character = $self->[_here_quote_character_];
1414 104 my $candidate_target = $input_line;
1415 104 my $leading_whitespace = EMPTY_STRING;
1416 104 chomp $candidate_target;
1417  
1418 # Handle <<~ targets, which are indicated here by a leading space on
1419 # the here quote character. c603 has test cases.
1420 # the leading whitespace of all here text lines match it.
1421 104 my $ix = rindex( $candidate_target, $here_doc_target );
1422 104 ▶ if ( $ix > 0 && $here_quote_character =~ /^\s/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ix > 0 and $here_quote_character =~ /^\s/) 18 86 104
Condition66%2/3
$ix > 0 and $here_quote_character =~ /^\s/
!ll&&!rl&&r
86018
MC/DC50%1/2
$ix > 0 and $here_quote_character =~ /^\s/
$ix > 0 $here_quote_character =~ /^\s/
Truth table66%2/3
A and B
A= $ix > 0B= $here_quote_character =~ /^\s/
ABresult
0X0
100
111
1423 18 $leading_whitespace = substr( $candidate_target, 0, $ix );
1424 18 ▶ if ( $leading_whitespace !~ /^\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($leading_whitespace =~ /^\s*$/) 0 18 18
1425 0 $leading_whitespace = EMPTY_STRING;
1426 }
1427 }
1428  
1429 104 ▶ if ( $candidate_target eq $leading_whitespace . $here_doc_target ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($candidate_target eq $leading_whitespace . $here_doc_target) { } 41 63 104
1430 41 $self->[_nearly_matched_here_target_at_] = undef;
1431 41 $line_of_tokens->{_line_type} = 'HERE_END';
1432 41 $self->log_numbered_msg("Exiting HERE document $here_doc_target\n");
1433  
1434 41 my $rhere_target_list = $self->[_rhere_target_list_];
1435 41 ▶ if ( @{$rhere_target_list} ) { # there can be multiple here targets
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rhere_target_list;}) { } 10 31 41
1436 ( $here_doc_target, $here_quote_character ) =
1437 10 @{ shift @{$rhere_target_list} };
1438 10 $self->[_here_doc_target_] = $here_doc_target;
1439 10 $self->[_here_quote_character_] = $here_quote_character;
1440 10 $self->log_numbered_msg(
1441 "Entering HERE document $here_doc_target\n");
1442 10 $self->[_nearly_matched_here_target_at_] = undef;
1443 10 $self->[_started_looking_for_here_target_at_] =
1444 $input_line_number;
1445 }
1446 else {
1447 31 $self->[_in_here_doc_] = 0;
1448 31 $self->[_here_doc_target_] = EMPTY_STRING;
1449 31 $self->[_here_quote_character_] = EMPTY_STRING;
1450 }
1451 }
1452  
1453 # check for error of extra whitespace
1454 # note for PERL6: leading whitespace is allowed
1455 else {
1456 63 $candidate_target =~ s/^ \s+ | \s+ $//gx; # trim both ends
1457 63 ▶ if ( $candidate_target eq $here_doc_target ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($candidate_target eq $here_doc_target) 0 63 63
1458 0 $self->[_nearly_matched_here_target_at_] = $input_line_number;
1459 }
1460 }
1461 104 return $line_of_tokens;
1462 }
1463  
1464 # Print line unchanged if we are in a format section
1465 elsif ( $self->[_in_format_] ) {
1466  
1467 3 ▶ if ( $input_line =~ /^\.[\s#]*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^\.[\s#]*$/) { } 1 2 3
1468  
1469 # Decrement format depth count at a '.' after a 'format'
1470 1 $self->[_in_format_]--;
1471  
1472 # This is the end when count reaches 0
1473 1 ▶ if ( !$self->[_in_format_] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[6]) 1 0 1
1474 1 $self->log_numbered_msg("Exiting format section\n");
1475 1 $line_of_tokens->{_line_type} = 'FORMAT_END';
1476  
1477 # Make the tokenizer mark an opening brace which follows
1478 # as a code block. Fixes issue c202/t032.
1479 1 $last_nonblank_token = ';';
1480 1 $last_nonblank_type = ';';
1481 }
1482 }
1483 else {
1484 2 $line_of_tokens->{_line_type} = 'FORMAT';
1485 2 ▶ if ( $input_line =~ /^\s*format\s+\w+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^\s*format\s+\w+/) 0 2 2
1486  
1487 # Increment format depth count at a 'format' within a 'format'
1488 # This is a simple way to handle nested formats (issue c019).
1489 0 $self->[_in_format_]++;
1490 }
1491 }
1492 3 return $line_of_tokens;
1493 }
1494  
1495 # must print line unchanged if we are in pod documentation
1496 elsif ( $self->[_in_pod_] ) {
1497  
1498 51 $line_of_tokens->{_line_type} = 'POD';
1499 51 ▶ if ( $input_line =~ /^=cut/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^=cut/) 22 29 51
1500 22 $line_of_tokens->{_line_type} = 'POD_END';
1501 22 $self->log_numbered_msg("Exiting POD section\n");
1502 22 $self->[_in_pod_] = 0;
1503 }
1504 51 ▶ if ( $input_line =~ /^\#\!.*perl\b/ && !$self->[_in_end_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^\#\!.*perl\b/ and not $self->[5]) 0 51 51
Condition33%1/3
$input_line =~ /^\#\!.*perl\b/ and not $self->[5]
!ll&&!rl&&r
5100
MC/DC0%0/2
$input_line =~ /^\#\!.*perl\b/ and not $self->[5]
$input_line =~ /^\#\!.*perl\b/ not $self->[5]
Truth table33%1/3
A and not(B)
A= $input_line =~ /^\#\!.*perl\b/B= not $self->[5]
ABresult
0X0
100
111
1505 0 $self->warning(
1506 "Hash-bang in pod can cause older versions of perl to fail! \n"
1507 );
1508 }
1509  
1510 51 return $line_of_tokens;
1511 }
1512  
1513 # print line unchanged if in skipped section
1514 elsif ( $self->[_in_code_skipping_] ) {
1515  
1516 8 $line_of_tokens->{_line_type} = 'SKIP';
1517 8 ▶ if ( $input_line =~ /$code_skipping_pattern_end/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($input_line =~ /$code_skipping_pattern_end/) { } 2 6 8
elsif ($input_line =~ /$code_skipping_pattern_begin/) { } 0 6 6
1518 2 $line_of_tokens->{_line_type} = 'SKIP_END';
1519 2 $self->log_numbered_msg("Exiting code-skipping section\n");
1520 2 $self->[_in_code_skipping_] = 0;
1521 }
1522 elsif ( $input_line =~ /$code_skipping_pattern_begin/ ) {
1523  
1524 # warn of duplicate starting comment lines, git #118
1525 0 my $lno = $self->[_in_code_skipping_];
1526 0 $self->warning(
1527 "Already in code-skipping section which started at line $lno\n"
1528 );
1529 }
1530 else {
1531 ## not a code-skipping control line
1532 }
1533 8 return $line_of_tokens;
1534 }
1535  
1536 # must print line unchanged if we have seen a severe error (i.e., we
1537 # are seeing illegal tokens and cannot continue. Syntax errors do
1538 # not pass this route). Calling routine can decide what to do, but
1539 # the default can be to just pass all lines as if they were after __END__
1540 elsif ( $self->[_in_error_] ) {
1541 0 $line_of_tokens->{_line_type} = 'ERROR';
1542 0 return $line_of_tokens;
1543 }
1544  
1545 # print line unchanged if we are __DATA__ section
1546 elsif ( $self->[_in_data_] ) {
1547  
1548 # ...but look for POD
1549 # Note that the _in_data and _in_end flags remain set
1550 # so that we return to that state after seeing the
1551 # end of a pod section
1552 1 ▶ if ( $input_line =~ /^=(\w+)\b/ && $1 ne 'cut' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^=(\w+)\b/ and $1 ne 'cut') { } 0 1 1
Condition33%1/3
$input_line =~ /^=(\w+)\b/ and $1 ne "cut"
!ll&&!rl&&r
100
MC/DC0%0/2
$input_line =~ /^=(\w+)\b/ and $1 ne "cut"
$input_line =~ /^=(\w+)\b/ $1 ne "cut"
Truth table33%1/3
A and B
A= $input_line =~ /^=(\w+)\b/B= $1 ne "cut"
ABresult
0X0
100
111
1553 0 $line_of_tokens->{_line_type} = 'POD_START';
1554 0 $self->log_numbered_msg("Entering POD section\n");
1555 0 $self->[_in_pod_] = 1;
1556 0 return $line_of_tokens;
1557 }
1558 else {
1559 1 $line_of_tokens->{_line_type} = 'DATA';
1560 1 return $line_of_tokens;
1561 }
1562 }
1563  
1564 # print line unchanged if we are in __END__ section
1565 elsif ( $self->[_in_end_] ) {
1566  
1567 # ...but look for POD
1568 # Note that the _in_data and _in_end flags remain set
1569 # so that we return to that state after seeing the
1570 # end of a pod section
1571 56 ▶ if ( $input_line =~ /^=(\w+)\b/ && $1 ne 'cut' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^=(\w+)\b/ and $1 ne 'cut') { } 7 49 56
Condition66%2/3
$input_line =~ /^=(\w+)\b/ and $1 ne "cut"
!ll&&!rl&&r
4907
MC/DC50%1/2
$input_line =~ /^=(\w+)\b/ and $1 ne "cut"
$input_line =~ /^=(\w+)\b/ $1 ne "cut"
Truth table66%2/3
A and B
A= $input_line =~ /^=(\w+)\b/B= $1 ne "cut"
ABresult
0X0
100
111
1572 7 $line_of_tokens->{_line_type} = 'POD_START';
1573 7 $self->log_numbered_msg("Entering POD section\n");
1574 7 $self->[_in_pod_] = 1;
1575 7 return $line_of_tokens;
1576 }
1577 else {
1578 49 $line_of_tokens->{_line_type} = 'END';
1579 49 return $line_of_tokens;
1580 }
1581 }
1582 else {
1583 ## not a special control line
1584 }
1585  
1586 # check for a hash-bang line if we haven't seen one
1587 8971 ▶ if ( !$self->[_saw_hash_bang_]
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->[31] and substr($input_line, 0, 2) eq "#!" and $input_line =~ /^\#\!.*perl\b/) 16 8955 8971
Condition83%5/6
not $self->[31] and substr($input_line, 0, 2) eq "#!" and $input_line =~ /^\#\!.*perl\b/
!ll&&!rl&&r
8955016
not $self->[31] and substr($input_line, 0, 2) eq "#!"
!ll&&!rl&&r
628832716
MC/DC66%2/3
not $self->[31] and substr($input_line, 0, 2) eq "#!" and $input_line =~ /^\#\!.*perl\b/
not $self->[31] substr($input_line, 0, 2) eq "#!" $input_line =~ /^\#\!.*perl\b/
Truth table75%3/4
not(A) and B and C
A= not $self->[31]B= substr($input_line, 0, 2) eq "#!"C= $input_line =~ /^\#\!.*perl\b/
ABCresult
0XX0
10X0
1100
1111
1588 && substr( $input_line, 0, 2 ) eq '#!'
1589 && $input_line =~ /^\#\!.*perl\b/ )
1590 {
1591 16 $self->[_saw_hash_bang_] = $input_line_number;
1592  
1593 # check for -w and -P flags
1594 16 ▶ if ( $input_line =~ /^\#\!.*perl\s.*-.*P/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^\#\!.*perl\s.*-.*P/) 0 16 16
1595 0 $self->[_saw_perl_dash_P_] = 1;
1596 }
1597  
1598 16 ▶ if ( $input_line =~ /^\#\!.*perl\s.*-.*w/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^\#\!.*perl\s.*-.*w/) 9 7 16
1599 9 $self->[_saw_perl_dash_w_] = 1;
1600 }
1601  
1602 16 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line_number > 1 and not $last_nonblank_block_type && $last_nonblank_block_type eq 'BEGIN' and not $rOpts_look_for_hash_bang and $input_line =~ /^\#\!(\s+)?(\S+)?perl/) { } 1 15 16
Condition66%8/12
$input_line_number > 1 and not $last_nonblank_block_type && $last_nonblank_block_type eq "BEGIN" and not $rOpts_look_for_hash_bang and $input_line =~ /^\#\!(\s+)?(\S+)?perl/
!ll&&!rl&&r
1501
$input_line_number > 1 and not $last_nonblank_block_type && $last_nonblank_block_type eq "BEGIN" and not $rOpts_look_for_hash_bang
!ll&&!rl&&r
1411
$input_line_number > 1 and not $last_nonblank_block_type && $last_nonblank_block_type eq "BEGIN"
!ll&&!rl&&r
1402
$last_nonblank_block_type && $last_nonblank_block_type eq 'BEGIN'
!ll&&!rl&&r
200
MC/DC40%2/5
$input_line_number > 1 and not $last_nonblank_block_type && $last_nonblank_block_type eq "BEGIN" and not $rOpts_look_for_hash_bang and $input_line =~ /^\#\!(\s+)?(\S+)?perl/
$input_line_number > 1 $last_nonblank_block_type $last_nonblank_block_type eq 'BEGIN' not $rOpts_look_for_hash_bang $input_line =~ /^\#\!(\s+)?(\S+)?perl/
Truth table37%3/8
A and not(B && C) and not(D) and E
A= $input_line_number > 1B= $last_nonblank_block_typeC= $last_nonblank_block_type eq 'BEGIN'D= not $rOpts_look_for_hash_bangE= $input_line =~ /^\#\!(\s+)?(\S+)?perl/
ABCDEresult
0XXXX0
111XX0
10X0X0
1100X0
10X100
110100
10X111
110111
1603 $input_line_number > 1
1604  
1605 # leave any hash bang in a BEGIN block alone
1606 # i.e. see 'debugger-duck_type.t'
1607 && !(
1608 $last_nonblank_block_type
1609 && $last_nonblank_block_type eq 'BEGIN'
1610 )
1611 && !$rOpts_look_for_hash_bang
1612  
1613 # Try to avoid giving a false alarm at a simple comment.
1614 # These look like valid hash-bang lines:
1615  
1616 #!/usr/bin/perl -w
1617 #! /usr/bin/perl -w
1618 #!c:\perl\bin\perl.exe
1619  
1620 # These are comments:
1621 #! I love perl
1622 #! sunos does not yet provide a /usr/bin/perl
1623  
1624 # Comments typically have multiple spaces, which suggests
1625 # the filter
1626 && $input_line =~ /^\#\!(\s+)?(\S+)?perl/
1627 )
1628 {
1629  
1630 # this is helpful for VMS systems; we may have accidentally
1631 # tokenized some DCL commands
1632 1 ▶ if ( $self->[_started_tokenizing_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[35]) { } 0 1 1
1633 0 $self->warning(
1634 "There seems to be a hash-bang after line 1; do you need to run with -x ?\n"
1635 );
1636 }
1637 else {
1638 1 $self->complain("Useless hash-bang after line 1\n");
1639 }
1640 }
1641  
1642 # Report the leading hash-bang as a system line
1643 # This will prevent -dac from deleting it
1644 else {
1645 15 $line_of_tokens->{_line_type} = 'SYSTEM';
1646 15 return $line_of_tokens;
1647 }
1648 }
1649  
1650 # wait for a hash-bang before parsing if the user invoked us with -x
1651 8956 ▶ if ( $rOpts_look_for_hash_bang
Branch: 1 branch
BranchTrueFalseTotal
if ($rOpts_look_for_hash_bang and not $self->[31]) 5 8951 8956
Condition100%3/3
$rOpts_look_for_hash_bang and not $self->[31]
!ll&&!rl&&r
895015
MC/DC100%2/2
$rOpts_look_for_hash_bang and not $self->[31]
$rOpts_look_for_hash_bang not $self->[31]
Truth table100%3/3
A and not(B)
A= $rOpts_look_for_hash_bangB= not $self->[31]
ABresult
0X0
100
111
1652 && !$self->[_saw_hash_bang_] )
1653 {
1654 5 $line_of_tokens->{_line_type} = 'SYSTEM';
1655 5 return $line_of_tokens;
1656 }
1657  
1658 # a first line of the form ': #' will be marked as SYSTEM
1659 # since lines of this form may be used by tcsh
1660 8951 ▶ if ( $input_line_number == 1 && $input_line =~ /^\s*\:\s*\#/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line_number == 1 and $input_line =~ /^\s*\:\s*\#/) 0 8951 8951
Condition66%2/3
$input_line_number == 1 and $input_line =~ /^\s*\:\s*\#/
!ll&&!rl&&r
83066450
MC/DC0%0/2
$input_line_number == 1 and $input_line =~ /^\s*\:\s*\#/
$input_line_number == 1 $input_line =~ /^\s*\:\s*\#/
Truth table66%2/3
A and B
A= $input_line_number == 1B= $input_line =~ /^\s*\:\s*\#/
ABresult
0X0
100
111
1661 0 $line_of_tokens->{_line_type} = 'SYSTEM';
1662 0 return $line_of_tokens;
1663 }
1664  
1665 # now we know that it is ok to tokenize the line...
1666 # the line tokenizer will modify any of these private variables:
1667 # _rhere_target_list_
1668 # _in_data_
1669 # _in_end_
1670 # _in_format_
1671 # _in_error_
1672 # _in_code_skipping_
1673 # _in_format_skipping_
1674 # _in_pod_
1675 # _in_quote_
1676  
1677 8951 $self->tokenize_this_line( $line_of_tokens, $trimmed_input_line );
1678  
1679 # Now finish defining the return structure and return it
1680 8951 $line_of_tokens->{_ending_in_quote} = $self->[_in_quote_];
1681  
1682 # handle severe error (binary data in script)
1683 8951 ▶ if ( $self->[_in_error_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[7]) 0 8951 8951
1684 0 $self->[_in_quote_] = 0; # to avoid any more messages
1685 0 $self->warning("Giving up after error\n");
1686 0 $line_of_tokens->{_line_type} = 'ERROR';
1687 0 reset_indentation_level(0); # avoid error messages
1688 0 return $line_of_tokens;
1689 }
1690  
1691 # handle start of pod documentation
1692 8951 ▶ if ( $self->[_in_pod_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[11]) 15 8936 8951
1693  
1694 # This gets tricky..above a __DATA__ or __END__ section, perl
1695 # accepts '=cut' as the start of pod section. But afterwards,
1696 # only pod utilities see it and they may ignore an =cut without
1697 # leading =head. In any case, this isn't good.
1698 15 ▶ if ( $input_line =~ /^=cut\b/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^=cut\b/) { } 0 15 15
1699 0 ▶ if ( $self->[_saw_data_] || $self->[_saw_end_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[33] or $self->[32]) { } 0 0 0
Condition0%0/3
$self->[33] or $self->[32]
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[33] or $self->[32]
$self->[33] $self->[32]
Truth table0%0/3
A or B
A= $self->[33]B= $self->[32]
ABresult
1X1
011
000
1700 0 $self->complain("=cut while not in pod ignored\n");
1701 0 $self->[_in_pod_] = 0;
1702 0 $line_of_tokens->{_line_type} = 'POD_END';
1703 }
1704 else {
1705 0 $line_of_tokens->{_line_type} = 'POD_START';
1706 0 if ( !DEVEL_MODE ) {
1707 0 $self->warning(
1708 "=cut starts a pod section .. this can fool pod utilities.\n"
1709 );
1710 }
1711 0 $self->log_numbered_msg("Entering POD section\n");
1712 }
1713 }
1714  
1715 else {
1716 15 $line_of_tokens->{_line_type} = 'POD_START';
1717 15 $self->log_numbered_msg("Entering POD section\n");
1718 }
1719  
1720 15 return $line_of_tokens;
1721 }
1722  
1723 # handle start of skipped section
1724 8936 ▶ if ( $self->[_in_code_skipping_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[12]) 2 8934 8936
1725  
1726 2 $line_of_tokens->{_line_type} = 'SKIP';
1727 2 $self->log_numbered_msg("Entering code-skipping section\n");
1728 2 return $line_of_tokens;
1729 }
1730  
1731 # see if this line contains here doc targets
1732 8934 my $rhere_target_list = $self->[_rhere_target_list_];
1733 8934 ▶ if ( @{$rhere_target_list} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rhere_target_list;}) 31 8903 8934
1734  
1735 my ( $here_doc_target, $here_quote_character ) =
1736 31 @{ shift @{$rhere_target_list} };
1737 31 $self->[_in_here_doc_] = 1;
1738 31 $self->[_here_doc_target_] = $here_doc_target;
1739 31 $self->[_here_quote_character_] = $here_quote_character;
1740 31 $self->log_numbered_msg("Entering HERE document $here_doc_target\n");
1741 31 $self->[_started_looking_for_here_target_at_] = $input_line_number;
1742 }
1743  
1744 # NOTE: __END__ and __DATA__ statements are written unformatted
1745 # because they can theoretically contain additional characters
1746 # which are not tokenized (and cannot be read with <DATA> either!).
1747 8934 ▶ if ( $self->[_in_data_] ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->[4]) { } 1 8933 8934
elsif ($self->[5]) { } 7 8926 8933
1748 1 $line_of_tokens->{_line_type} = 'DATA_START';
1749 1 $self->log_numbered_msg("Starting __DATA__ section\n");
1750 1 $self->[_saw_data_] = 1;
1751  
1752 # keep parsing after __DATA__ if use SelfLoader was seen
1753 1 ▶ if ( $self->[_saw_selfloader_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[30]) 0 1 1
1754 0 $self->[_in_data_] = 0;
1755 0 $self->log_numbered_msg(
1756 "SelfLoader seen, continuing; -nlsl deactivates\n");
1757 }
1758  
1759 1 return $line_of_tokens;
1760 }
1761  
1762 elsif ( $self->[_in_end_] ) {
1763 7 $line_of_tokens->{_line_type} = 'END_START';
1764 7 $self->log_numbered_msg("Starting __END__ section\n");
1765 7 $self->[_saw_end_] = 1;
1766  
1767 # keep parsing after __END__ if use AutoLoader was seen
1768 7 ▶ if ( $self->[_saw_autoloader_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[29]) 0 7 7
1769 0 $self->[_in_end_] = 0;
1770 0 $self->log_numbered_msg(
1771 "AutoLoader seen, continuing; -nlal deactivates\n");
1772 }
1773 7 return $line_of_tokens;
1774 }
1775 else {
1776 ## not in __END__ or __DATA__
1777 }
1778  
1779 # now, finally, we know that this line is type 'CODE'
1780 8926 $line_of_tokens->{_line_type} = 'CODE';
1781  
1782 # remember if we have seen any real code
1783 8926 ▶ if ( !$self->[_started_tokenizing_]
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[35] or $input_line =~ /^\s*$/ or $input_line =~ /^\s*#/) 658 8268 8926
Condition100%6/6
$self->[35] or $input_line =~ /^\s*$/ or $input_line =~ /^\s*#/
l!l&&r!l&&!r
7940328658
$self->[35] or $input_line =~ /^\s*$/
l!l&&r!l&&!r
792020986
MC/DC100%3/3
$self->[35] or $input_line =~ /^\s*$/ or $input_line =~ /^\s*#/
$self->[35] $input_line =~ /^\s*$/ $input_line =~ /^\s*#/
Truth table100%4/4
A or B or C
A= $self->[35]B= $input_line =~ /^\s*$/C= $input_line =~ /^\s*#/
ABCresult
1XX1
01X1
0011
0000
1784 && $input_line !~ /^\s*$/
1785 && $input_line !~ /^\s*#/ )
1786 {
1787 658 $self->[_started_tokenizing_] = 1;
1788 }
1789  
1790 8926 ▶ if ( $self->[_debugger_object_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[36]) 7 8919 8926
1791 7 $self->[_debugger_object_]->write_debug_entry($line_of_tokens);
1792 }
1793  
1794 # Note: if keyword 'format' occurs in this line code, it is still CODE
1795 # (keyword 'format' need not start a line)
1796 8926 ▶ if ( $self->[_in_format_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[6]) 1 8925 8926
1797 1 $self->log_numbered_msg("Entering format section\n");
1798 }
1799  
1800 8926 ▶ if ( $self->[_in_quote_]
Branch: 2 branches
BranchTrueFalseTotal
if ($self->[16] and $self->[18] < 0) { } 63 8863 8926
elsif ($self->[18] >= 0 and not $self->[16]) { } 62 8801 8863
Condition100%3/3
$self->[16] and $self->[18] < 0
!ll&&!rl&&r
867918463
MC/DC100%2/2
$self->[16] and $self->[18] < 0
$self->[16] $self->[18] < 0
Truth table100%3/3
A and B
A= $self->[16]B= $self->[18] < 0
ABresult
0X0
100
111
1801 and ( $self->[_line_start_quote_] < 0 ) )
1802 {
1803 63 ▶ if ( ( my $quote_target = $self->[_quote_target_] ) !~ /^\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ((my $quote_target = $self->[17]) =~ /^\s*$/) 62 1 63
1804 62 $self->[_line_start_quote_] = $input_line_number;
1805 62 $self->log_numbered_msg(
1806 "Start multi-line quote or pattern ending in $quote_target\n");
1807 }
1808 }
1809 ▶ elsif ( ( $self->[_line_start_quote_] >= 0 )
Condition100%3/3
$self->[18] >= 0 and not $self->[16]
!ll&&!rl&&r
861718462
MC/DC100%2/2
$self->[18] >= 0 and not $self->[16]
$self->[18] >= 0 not $self->[16]
Truth table100%3/3
A and not(B)
A= $self->[18] >= 0B= not $self->[16]
ABresult
0X0
100
111
1810 && !$self->[_in_quote_] )
1811 {
1812 62 $self->[_line_start_quote_] = -1;
1813 62 $self->log_numbered_msg("End of multi-line quote or pattern\n");
1814 }
1815 else {
1816 ## not at the edge of a quote
1817 }
1818  
1819 # we are returning a line of CODE
1820 8926 return $line_of_tokens;
1821 } ## end sub get_line
1822  
1823 sub find_starting_indentation_level {
1824  
1825 # We need to find the indentation level of the first line of the
1826 # script being formatted. Often it will be zero for an entire file,
1827 # but if we are formatting a local block of code (within an editor for
1828 # example) it may not be zero. The user may specify this with the
1829 # -sil=n parameter but normally doesn't so we have to guess.
1830 #
1831 662 ▶ my ($self) = @_;
Subroutine find_starting_indentation_level: called CC=15 SCAR=28.0
Pod undocumented
1832 662 my $starting_level = 0;
1833  
1834 # use value if given as parameter
1835 662 ▶ if ( $self->[_know_starting_level_] ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->[20]) { } 1 661 662
elsif ($rOpts_look_for_hash_bang) { } 1 660 661
1836 1 $starting_level = $self->[_starting_level_];
1837 }
1838  
1839 # if we know there is a hash_bang line, the level must be zero
1840 elsif ($rOpts_look_for_hash_bang) {
1841 1 $self->[_know_starting_level_] = 1;
1842 }
1843  
1844 # otherwise figure it out from the input file
1845 else {
1846 660 my $line;
1847 660 my $i = 0;
1848  
1849 # keep looking at lines until we find a hash bang or piece of code
1850 # ( or, for now, an =pod line)
1851 660 my $msg = EMPTY_STRING;
1852 660 my $in_code_skipping;
1853 my $line_for_guess;
1854 660 ▶ while ( defined( $line = $self->peek_ahead( $i++ ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->peek_ahead($i++))) 988 2 990
1855  
1856 # if first line is #! then assume starting level is zero
1857 988 ▶ if ( $i == 1 && $line =~ /^\#\!/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 1 and $line =~ /^\#\!/) 14 974 988
Condition100%3/3
$i == 1 and $line =~ /^\#\!/
!ll&&!rl&&r
33064414
MC/DC100%2/2
$i == 1 and $line =~ /^\#\!/
$i == 1 $line =~ /^\#\!/
Truth table100%3/3
A and B
A= $i == 1B= $line =~ /^\#\!/
ABresult
0X0
100
111
1858 14 $starting_level = 0;
1859 14 last;
1860 }
1861  
1862 # ignore lines fenced off with code-skipping comments
1863 974 ▶ if ( $line =~ /^\s*#/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*#/) 312 662 974
1864  
1865 # use first comment for indentation guess in case of no code
1866 312 ▶ if ( !defined($line_for_guess) ) { $line_for_guess = $line }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $line_for_guess) 256 56 312
1867  
1868 312 ▶ if ( !$in_code_skipping ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $in_code_skipping) { } 312 0 312
1869 312 ▶ if ( $rOpts_code_skipping
Branch: 1 branch
BranchTrueFalseTotal
if ($rOpts_code_skipping and $line =~ /$code_skipping_pattern_begin/) 0 312 312
Condition33%1/3
$rOpts_code_skipping and $line =~ /$code_skipping_pattern_begin/
!ll&&!rl&&r
03120
MC/DC0%0/2
$rOpts_code_skipping and $line =~ /$code_skipping_pattern_begin/
$rOpts_code_skipping $line =~ /$code_skipping_pattern_begin/
Truth table33%1/3
A and B
A= $rOpts_code_skippingB= $line =~ /$code_skipping_pattern_begin/
ABresult
0X0
100
111
1870 && $line =~ /$code_skipping_pattern_begin/ )
1871 {
1872 0 $in_code_skipping = 1;
1873 0 next;
1874 }
1875 }
1876 else {
1877 0 ▶ if ( $line =~ /$code_skipping_pattern_end/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /$code_skipping_pattern_end/) 0 0 0
1878 0 $in_code_skipping = 0;
1879 }
1880 0 next;
1881 }
1882  
1883 # Note that we could also ignore format-skipping lines here
1884 # but it isn't clear if that would be best.
1885 # See c326 for example code.
1886  
1887 312 next;
1888 }
1889 662 ▶ next if ($in_code_skipping);
Branch: 1 branch
BranchTrueFalseTotal
if $in_code_skipping 0 662 662
1890  
1891 662 ▶ next if ( $line =~ /^\s*$/ ); # skip past blank lines
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 18 644 662
1892  
1893 # use first line of code for indentation guess
1894 644 $line_for_guess = $line;
1895 644 last;
1896 } ## end while ( defined( $line = ...))
1897  
1898 660 ▶ if ( defined($line_for_guess) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line_for_guess) 644 16 660
1899 644 $starting_level =
1900 $self->guess_old_indentation_level($line_for_guess);
1901 }
1902 660 $msg = "Line $i implies starting-indentation-level = $starting_level\n";
1903 660 $self->write_logfile_entry("$msg");
1904 }
1905 662 $self->[_starting_level_] = $starting_level;
1906 662 reset_indentation_level($starting_level);
1907 662 return;
1908 } ## end sub find_starting_indentation_level
1909  
1910 sub guess_old_indentation_level {
1911 647 ▶ my ( $self, $line ) = @_;
Subroutine guess_old_indentation_level: called CC=7 SCAR=19.6
Pod undocumented
1912  
1913 # Guess the indentation level of an input line.
1914 #
1915 # For the first line of code this result will define the starting
1916 # indentation level. It will mainly be non-zero when perltidy is applied
1917 # within an editor to a local block of code.
1918 #
1919 # This is an impossible task in general because we can't know what tabs
1920 # meant for the old script and how many spaces were used for one
1921 # indentation level in the given input script. For example it may have
1922 # been previously formatted with -i=7 -et=3. But we can at least try to
1923 # make sure that perltidy guesses correctly if it is applied repeatedly to
1924 # a block of code within an editor, so that the block stays at the same
1925 # level when perltidy is applied repeatedly.
1926 #
1927 # USES GLOBAL VARIABLES: (none)
1928 647 my $level = 0;
1929  
1930 # find leading tabs, spaces, and any statement label
1931 647 my $spaces = 0;
1932 647 ▶ if ( $line =~ /^(\t+)?(\s+)?(\w+:[^:])?/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(\t+)?(\s+)?(\w+:[^:])?/) 647 0 647
1933  
1934 # If there are leading tabs, we use the tab scheme for this run, if
1935 # any, so that the code will remain stable when editing.
1936 647 ▶ if ($1) { $spaces += length($1) * $tabsize }
Branch: 1 branch
BranchTrueFalseTotal
if ($1) 2 645 647
1937  
1938 647 ▶ if ($2) { $spaces += length($2) }
Branch: 1 branch
BranchTrueFalseTotal
if ($2) 90 557 647
1939  
1940 # correct for outdented labels
1941 647 ▶ if ( $3
Branch: 1 branch
BranchTrueFalseTotal
if ($3 and $rOpts_outdent_labels and $rOpts_continuation_indentation > 0) 1 646 647
Condition66%4/6
$3 and $rOpts_outdent_labels and $rOpts_continuation_indentation > 0
!ll&&!rl&&r
64601
$3 and $rOpts_outdent_labels
!ll&&!rl&&r
64601
MC/DC33%1/3
$3 and $rOpts_outdent_labels and $rOpts_continuation_indentation > 0
$3 $rOpts_outdent_labels $rOpts_continuation_indentation > 0
Truth table50%2/4
A and B and C
A= $3B= $rOpts_outdent_labelsC= $rOpts_continuation_indentation > 0
ABCresult
0XX0
10X0
1100
1111
1942 && $rOpts_outdent_labels
1943 && $rOpts_continuation_indentation > 0 )
1944 {
1945 1 $spaces += $rOpts_continuation_indentation;
1946 }
1947 }
1948  
1949 647 $level = int( $spaces / $rOpts_indent_columns );
1950 647 return ($level);
1951 } ## end sub guess_old_indentation_level
1952  
1953 sub dump_functions {
1954  
1955 # This is an unused debug routine, save for future use
1956  
1957 0 ▶ my $fh = *STDOUT;
Subroutine dump_functions: not called CC=7 SCAR=40.3
Pod undocumented
1958 0 foreach my $pkg ( keys %{$ris_user_function} ) {
1959 0 $fh->print("\nnon-constant subs in package $pkg\n");
1960  
1961 0 foreach my $sub ( keys %{ $ris_user_function->{$pkg} } ) {
1962 0 my $msg = EMPTY_STRING;
1963 0 ▶ if ( $ris_block_list_function->{$pkg}->{$sub} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ris_block_list_function->{$pkg}{$sub}) 0 0 0
1964 0 $msg = 'block_list';
1965 }
1966  
1967 0 ▶ if ( $ris_block_function->{$pkg}->{$sub} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ris_block_function->{$pkg}{$sub}) 0 0 0
1968 0 $msg = 'block';
1969 }
1970 0 $fh->print("$sub $msg\n");
1971 }
1972 }
1973  
1974 0 foreach my $pkg ( keys %{$ris_constant} ) {
1975 0 $fh->print("\nconstants and constant subs in package $pkg\n");
1976  
1977 0 foreach my $sub ( keys %{ $ris_constant->{$pkg} } ) {
1978 0 $fh->print("$sub\n");
1979 }
1980 }
1981 0 return;
1982 } ## end sub dump_functions
1983  
1984 sub prepare_for_a_new_file {
1985  
1986 662 ▶ my ( $self, $source_object ) = @_;
Subroutine prepare_for_a_new_file: called CC=1 SCAR=0.0
Pod undocumented
1987  
1988 # copy the source object lines to an array of lines
1989 662 $self->make_source_array($source_object);
1990  
1991 # previous tokens needed to determine what to expect next
1992 662 $last_nonblank_token = ';'; # the only possible starting state which
1993 662 $last_nonblank_type = ';'; # will make a leading brace a code block
1994 662 $last_nonblank_block_type = EMPTY_STRING;
1995  
1996 # scalars for remembering statement types across multiple lines
1997 662 $statement_type = EMPTY_STRING; # '' or 'use' or 'sub..' or 'case..'
1998  
1999 # scalars for remembering where we are in the file
2000 662 $current_package = "main";
2001 662 $context = UNKNOWN_CONTEXT;
2002  
2003 # hashes used to remember function information
2004 662 $ris_constant = {}; # user-defined constants
2005 662 $ris_user_function = {}; # user-defined functions
2006 662 $ruser_function_prototype = {}; # their prototypes
2007 662 $ris_block_function = {};
2008 662 $ris_block_list_function = {};
2009 662 $rsaw_function_definition = {};
2010 662 $rsaw_use_module = {};
2011  
2012 # variables used to track depths of various containers
2013 # and report nesting errors
2014 662 $paren_depth = 0;
2015 662 $brace_depth = 0;
2016 662 $square_bracket_depth = 0;
2017 662 $rcurrent_depth = [ (0) x scalar(@closing_brace_names) ];
2018 662 $total_depth = 0;
2019 662 $rtotal_depth = [];
2020 662 $rcurrent_sequence_number = [];
2021 662 $ris_lexical_sub = {};
2022 662 $next_sequence_number = SEQ_ROOT + 1;
2023  
2024 662 $rparen_type = [];
2025 662 $rparen_semicolon_count = [];
2026 662 $rparen_vars = [];
2027 662 $rbrace_type = [];
2028 662 $rbrace_structural_type = [];
2029 662 $rbrace_context = [];
2030 662 $rbrace_package = [];
2031 662 $rsquare_bracket_type = [];
2032 662 $rsquare_bracket_structural_type = [];
2033 662 $rdepth_array = [];
2034 662 $rnested_ternary_flag = [];
2035 662 $rnested_statement_type = [];
2036 662 $rstarting_line_of_current_depth = [];
2037  
2038 662 $rparen_type->[$paren_depth] = EMPTY_STRING;
2039 662 $rparen_semicolon_count->[$paren_depth] = 0;
2040 662 $rparen_vars->[$paren_depth] = [];
2041 662 $rbrace_type->[$brace_depth] = ';'; # identify opening brace as code block
2042 662 $rbrace_structural_type->[$brace_depth] = EMPTY_STRING;
2043 662 $rbrace_context->[$brace_depth] = UNKNOWN_CONTEXT;
2044 662 $rbrace_package->[$paren_depth] = $current_package;
2045 662 $rsquare_bracket_type->[$square_bracket_depth] = EMPTY_STRING;
2046 662 $rsquare_bracket_structural_type->[$square_bracket_depth] = EMPTY_STRING;
2047  
2048 662 initialize_tokenizer_state();
2049 662 return;
2050 } ## end sub prepare_for_a_new_file
2051  
2052 { ## closure for sub tokenize_this_line
2053  
2054 45 ▶ use constant BRACE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2055 45 ▶ use constant SQUARE_BRACKET => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
2056 45 ▶ use constant PAREN => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
2057 45 ▶ use constant QUESTION_COLON => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
2058  
2059 # TV1: scalars for processing one LINE.
2060 # Re-initialized on each entry to sub tokenize_this_line.
2061 my (
2062 45 $block_type, $container_type, $expecting,
2063 $i, $i_tok, $input_line,
2064 $input_line_number, $last_nonblank_i, $max_token_index,
2065 $next_tok, $next_type, $peeked_ahead,
2066 $prototype, $rhere_target_list, $rtoken_map,
2067 $rtoken_type, $rtokens, $tok,
2068 $type, $type_sequence, $indent_flag,
2069 );
2070  
2071 # TV2: refs to ARRAYS for processing one LINE
2072 # Re-initialized on each call.
2073 45 my $routput_token_list = []; # stack of output token indexes
2074 45 my $routput_token_type = []; # token types
2075 45 my $routput_block_type = []; # types of code block
2076 45 my $routput_type_sequence = []; # nesting sequential number
2077 45 my $routput_indent_flag = []; #
2078  
2079 # TV3: SCALARS for quote variables. These are initialized with a
2080 # subroutine call and continually updated as lines are processed.
2081 my (
2082 45 $in_quote, $quote_type,
2083 $quote_character, $quote_pos,
2084 $quote_depth, $quoted_string_1,
2085 $quoted_string_2, $allowed_quote_modifiers,
2086 $quote_starting_tok, $quote_here_target_2,
2087 );
2088  
2089 # TV4: SCALARS for multi-line identifiers and
2090 # statements. These are initialized with a subroutine call
2091 # and continually updated as lines are processed.
2092 45 my ( $id_scan_state, $identifier, $want_paren );
2093  
2094 # TV5: SCALARS for tracking indentation level.
2095 # Initialized once and continually updated as lines are
2096 # processed.
2097 my (
2098 45 $nesting_token_string, $nesting_block_string,
2099 $nesting_block_flag, $level_in_tokenizer,
2100 );
2101  
2102 # TV6: SCALARS for remembering several previous
2103 # tokens. Initialized once and continually updated as
2104 # lines are processed.
2105 my (
2106 45 $last_nonblank_container_type, $last_nonblank_type_sequence,
2107 $last_last_nonblank_token, $last_last_nonblank_type,
2108 $last_nonblank_prototype,
2109 );
2110  
2111 # ----------------------------------------------------------------
2112 # beginning of tokenizer variable access and manipulation routines
2113 # ----------------------------------------------------------------
2114  
2115 sub initialize_tokenizer_state {
2116  
2117 # GV1: initialized once
2118 # TV1: initialized on each call
2119 # TV2: initialized on each call
2120 # TV3:
2121 662 ▶ $in_quote = 0;
Subroutine initialize_tokenizer_state: called CC=1 SCAR=0.0
Pod undocumented
2122 662 $quote_type = 'Q';
2123 662 $quote_character = EMPTY_STRING;
2124 662 $quote_pos = 0;
2125 662 $quote_depth = 0;
2126 662 $quoted_string_1 = EMPTY_STRING;
2127 662 $quoted_string_2 = EMPTY_STRING;
2128 662 $allowed_quote_modifiers = EMPTY_STRING;
2129 662 $quote_starting_tok = EMPTY_STRING;
2130 662 $quote_here_target_2 = undef;
2131  
2132 # TV4:
2133 662 $id_scan_state = EMPTY_STRING;
2134 662 $identifier = EMPTY_STRING;
2135 662 $want_paren = EMPTY_STRING;
2136  
2137 # TV5:
2138 662 $nesting_token_string = EMPTY_STRING;
2139 662 $nesting_block_string = '1'; # initially in a block
2140 662 $nesting_block_flag = 1;
2141 662 $level_in_tokenizer = 0;
2142  
2143 # TV6:
2144 662 $last_nonblank_container_type = EMPTY_STRING;
2145 662 $last_nonblank_type_sequence = EMPTY_STRING;
2146 662 $last_last_nonblank_token = ';';
2147 662 $last_last_nonblank_type = ';';
2148 662 $last_nonblank_prototype = EMPTY_STRING;
2149 662 return;
2150 } ## end sub initialize_tokenizer_state
2151  
2152 sub save_tokenizer_state {
2153  
2154 # Global variables:
2155 0 ▶ my $rGV1 = [
Subroutine save_tokenizer_state: not called CC=1 SCAR=6.9
Pod undocumented
2156 $brace_depth,
2157 $context,
2158 $current_package,
2159 $last_nonblank_block_type,
2160 $last_nonblank_token,
2161 $last_nonblank_type,
2162 $next_sequence_number,
2163 $paren_depth,
2164 $rbrace_context,
2165 $rbrace_package,
2166 $rbrace_structural_type,
2167 $rbrace_type,
2168 $rcurrent_depth,
2169 $rcurrent_sequence_number,
2170 $ris_lexical_sub,
2171 $rdepth_array,
2172 $ris_block_function,
2173 $ris_block_list_function,
2174 $ris_constant,
2175 $ris_user_function,
2176 $rnested_statement_type,
2177 $rnested_ternary_flag,
2178 $rparen_semicolon_count,
2179 $rparen_vars,
2180 $rparen_type,
2181 $rsaw_function_definition,
2182 $rsaw_use_module,
2183 $rsquare_bracket_structural_type,
2184 $rsquare_bracket_type,
2185 $rstarting_line_of_current_depth,
2186 $rtotal_depth,
2187 $ruser_function_prototype,
2188 $square_bracket_depth,
2189 $statement_type,
2190 $total_depth,
2191  
2192 ];
2193  
2194 # Tokenizer closure variables:
2195 0 my $rTV1 = [
2196 $block_type, $container_type, $expecting,
2197 $i, $i_tok, $input_line,
2198 $input_line_number, $last_nonblank_i, $max_token_index,
2199 $next_tok, $next_type, $peeked_ahead,
2200 $prototype, $rhere_target_list, $rtoken_map,
2201 $rtoken_type, $rtokens, $tok,
2202 $type, $type_sequence, $indent_flag,
2203 ];
2204  
2205 0 my $rTV2 = [
2206 $routput_token_list, $routput_token_type,
2207 $routput_block_type, $routput_type_sequence,
2208 $routput_indent_flag,
2209 ];
2210  
2211 0 my $rTV3 = [
2212 $in_quote, $quote_type,
2213 $quote_character, $quote_pos,
2214 $quote_depth, $quoted_string_1,
2215 $quoted_string_2, $allowed_quote_modifiers,
2216 $quote_starting_tok, $quote_here_target_2,
2217 ];
2218  
2219 0 my $rTV4 = [ $id_scan_state, $identifier, $want_paren ];
2220  
2221 0 my $rTV5 = [
2222 $nesting_token_string, $nesting_block_string,
2223 $nesting_block_flag, $level_in_tokenizer,
2224 ];
2225  
2226 0 my $rTV6 = [
2227 $last_nonblank_container_type, $last_nonblank_type_sequence,
2228 $last_last_nonblank_token, $last_last_nonblank_type,
2229 $last_nonblank_prototype,
2230 ];
2231 0 return [ $rGV1, $rTV1, $rTV2, $rTV3, $rTV4, $rTV5, $rTV6 ];
2232 } ## end sub save_tokenizer_state
2233  
2234 sub restore_tokenizer_state {
2235 0 ▶ my ($rstate) = @_;
Subroutine restore_tokenizer_state: not called CC=1 SCAR=6.9
Pod undocumented
2236 0 my ( $rGV1, $rTV1, $rTV2, $rTV3, $rTV4, $rTV5, $rTV6 ) = @{$rstate};
2237  
2238 (
2239 $brace_depth,
2240 $context,
2241 $current_package,
2242 $last_nonblank_block_type,
2243 $last_nonblank_token,
2244 $last_nonblank_type,
2245 $next_sequence_number,
2246 $paren_depth,
2247 $rbrace_context,
2248 $rbrace_package,
2249 $rbrace_structural_type,
2250 $rbrace_type,
2251 $rcurrent_depth,
2252 $rcurrent_sequence_number,
2253 $ris_lexical_sub,
2254 $rdepth_array,
2255 $ris_block_function,
2256 $ris_block_list_function,
2257 $ris_constant,
2258 $ris_user_function,
2259 $rnested_statement_type,
2260 $rnested_ternary_flag,
2261 $rparen_semicolon_count,
2262 $rparen_vars,
2263 $rparen_type,
2264 $rsaw_function_definition,
2265 $rsaw_use_module,
2266 $rsquare_bracket_structural_type,
2267 $rsquare_bracket_type,
2268 $rstarting_line_of_current_depth,
2269 $rtotal_depth,
2270 $ruser_function_prototype,
2271 $square_bracket_depth,
2272 $statement_type,
2273 $total_depth,
2274  
2275 0 ) = @{$rGV1};
2276  
2277 (
2278 $block_type, $container_type, $expecting,
2279 $i, $i_tok, $input_line,
2280 $input_line_number, $last_nonblank_i, $max_token_index,
2281 $next_tok, $next_type, $peeked_ahead,
2282 $prototype, $rhere_target_list, $rtoken_map,
2283 $rtoken_type, $rtokens, $tok,
2284 $type, $type_sequence, $indent_flag,
2285 0 ) = @{$rTV1};
2286  
2287 (
2288 $routput_token_list, $routput_token_type,
2289 $routput_block_type, $routput_type_sequence,
2290 $routput_indent_flag,
2291 0 ) = @{$rTV2};
2292  
2293 (
2294 $in_quote, $quote_type,
2295 $quote_character, $quote_pos,
2296 $quote_depth, $quoted_string_1,
2297 $quoted_string_2, $allowed_quote_modifiers,
2298 $quote_starting_tok, $quote_here_target_2,
2299 0 ) = @{$rTV3};
2300  
2301 0 ( $id_scan_state, $identifier, $want_paren ) = @{$rTV4};
2302  
2303 (
2304 $nesting_token_string, $nesting_block_string,
2305 $nesting_block_flag, $level_in_tokenizer,
2306 0 ) = @{$rTV5};
2307  
2308 (
2309 $last_nonblank_container_type, $last_nonblank_type_sequence,
2310 $last_last_nonblank_token, $last_last_nonblank_type,
2311 $last_nonblank_prototype,
2312 0 ) = @{$rTV6};
2313 0 return;
2314 } ## end sub restore_tokenizer_state
2315  
2316 sub split_pretoken {
2317  
2318 8 ▶ my ( $self, $numc ) = @_;
Subroutine split_pretoken: called CC=8 SCAR=21.2
Pod undocumented
2319  
2320 # This provides a way to work around the limitations of the
2321 # pre-tokenization scheme upon which perltidy is based. It is rarely
2322 # needed.
2323  
2324 # Split the leading $numc characters from the current token (at
2325 # index=$i) which is pre-type 'w' and insert the remainder back into
2326 # the pretoken stream with appropriate settings. Since we are
2327 # splitting a pre-type 'w', there are three cases, depending on if the
2328 # remainder starts with a digit:
2329 # Case 1: remainder is type 'd', all digits
2330 # Case 2: remainder is type 'd' and type 'w': digits & other characters
2331 # Case 3: remainder is type 'w'
2332  
2333 # Examples, for $numc=1:
2334 # $tok => $tok_0 $tok_1 $tok_2
2335 # 'x10' => 'x' '10' # case 1
2336 # 'x10if' => 'x' '10' 'if' # case 2
2337 # '0ne => 'O' 'ne' # case 3
2338  
2339 # where:
2340 # $tok_1 is a possible string of digits (pre-type 'd')
2341 # $tok_2 is a possible word (pre-type 'w')
2342  
2343 # return 1 if successful
2344 # return undef if error (shouldn't happen)
2345  
2346 # Calling routine should update '$type' and '$tok' if successful.
2347  
2348 8 my $pretoken = $rtokens->[$i];
2349 8 ▶ if ( $pretoken
Branch: 1 branch
BranchTrueFalseTotal
if ($pretoken and length $pretoken > $numc and substr($pretoken, $numc) =~ /^(\d*)(.*)$/) 8 0 8
Condition33%2/6
$pretoken and length $pretoken > $numc and substr($pretoken, $numc) =~ /^(\d*)(.*)$/
!ll&&!rl&&r
008
$pretoken and length $pretoken > $numc
!ll&&!rl&&r
008
MC/DC0%0/3
$pretoken and length $pretoken > $numc and substr($pretoken, $numc) =~ /^(\d*)(.*)$/
$pretoken length $pretoken > $numc substr($pretoken, $numc) =~ /^(\d*)(.*)$/
Truth table25%1/4
A and B and C
A= $pretokenB= length $pretoken > $numcC= substr($pretoken, $numc) =~ /^(\d*)(.*)$/
ABCresult
0XX0
10X0
1100
1111
2350 && length($pretoken) > $numc
2351 && substr( $pretoken, $numc ) =~ /^(\d*)(.*)$/ )
2352 {
2353  
2354 # Split $tok into up to 3 tokens:
2355 8 my $tok_0 = substr( $pretoken, 0, $numc );
2356 8 ▶ my $tok_1 = defined($1) ? $1 : EMPTY_STRING;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 8 0 8
2357 8 ▶ my $tok_2 = defined($2) ? $2 : EMPTY_STRING;
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 8 0 8
2358  
2359 8 my $len_0 = length($tok_0);
2360 8 my $len_1 = length($tok_1);
2361 8 my $len_2 = length($tok_2);
2362  
2363 ##my $pre_type_0 = 'w';
2364 8 my $pre_type_1 = 'd';
2365 8 my $pre_type_2 = 'w';
2366  
2367 8 my $pos_0 = $rtoken_map->[$i];
2368 8 my $pos_1 = $pos_0 + $len_0;
2369 8 my $pos_2 = $pos_1 + $len_1;
2370  
2371 8 my $isplice = $i + 1;
2372  
2373 # Splice in any digits
2374 8 ▶ if ($len_1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len_1) 5 3 8
2375 5 splice( @{$rtoken_map}, $isplice, 0, $pos_1 );
2376 5 splice( @{$rtokens}, $isplice, 0, $tok_1 );
2377 5 splice( @{$rtoken_type}, $isplice, 0, $pre_type_1 );
2378 5 $max_token_index++;
2379 5 $isplice++;
2380 }
2381  
2382 # Splice in any trailing word
2383 8 ▶ if ($len_2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len_2) 4 4 8
2384 4 splice( @{$rtoken_map}, $isplice, 0, $pos_2 );
2385 4 splice( @{$rtokens}, $isplice, 0, $tok_2 );
2386 4 splice( @{$rtoken_type}, $isplice, 0, $pre_type_2 );
2387 4 $max_token_index++;
2388 }
2389  
2390 8 $rtokens->[$i] = $tok_0;
2391 8 return 1;
2392 }
2393  
2394 # Shouldn't get here - bad call parameters
2395 0 if (DEVEL_MODE) {
2396 Fault(<<EOM);
2397 While working near line number $input_line_number, bad arg '$tok' passed to sub split_pretoken()
2398 EOM
2399 }
2400 0 return;
2401 } ## end sub split_pretoken
2402  
2403 sub get_indentation_level {
2404 662 ▶ return $level_in_tokenizer;
Subroutine get_indentation_level: called CC=1 SCAR=0.0
Pod undocumented
2405 }
2406  
2407 sub reset_indentation_level {
2408 662 ▶ $level_in_tokenizer = shift;
Subroutine reset_indentation_level: called CC=1 SCAR=0.0
Pod undocumented
2409 662 return;
2410 }
2411  
2412 sub peeked_ahead {
2413 288 ▶ ( ( my $flag ) ) = @_;
Subroutine peeked_ahead: called CC=2 SCAR=6.9
Pod undocumented
2414  
2415 # get or set the closure flag '$peeked_ahead':
2416 # - set $peeked_ahead to $flag if given, then
2417 # - return current value
2418 288 ▶ $peeked_ahead = defined($flag) ? $flag : $peeked_ahead;
Branch: 1 branch
BranchTrueFalseTotal
defined $flag ? : 143 145 288
2419 288 return $peeked_ahead;
2420 } ## end sub peeked_ahead
2421  
2422 # ------------------------------------------------------------
2423 # end of tokenizer variable access and manipulation routines
2424 # ------------------------------------------------------------
2425  
2426 #------------------------------
2427 # beginning of tokenizer hashes
2428 #------------------------------
2429  
2430 45 my %matching_start_token = ( '}' => '{', ']' => '[', ')' => '(' );
2431  
2432 45 my @q;
2433  
2434 # 'L' is token for opening { at hash key
2435 my %is_opening_type;
2436 45 @q = qw< L { ( [ >;
2437 45 $is_opening_type{$_} = 1 for @q;
2438  
2439 45 my %is_opening_or_ternary_type;
2440 45 push @q, '?';
2441 45 $is_opening_or_ternary_type{$_} = 1 for @q;
2442  
2443 # 'R' is token for closing } at hash key
2444 45 my %is_closing_type;
2445 45 @q = qw< R } ) ] >;
2446 45 $is_closing_type{$_} = 1 for @q;
2447  
2448 45 my %is_closing_or_ternary_type;
2449 45 push @q, ':';
2450 45 $is_closing_or_ternary_type{$_} = 1 for @q;
2451  
2452 45 my %is_redo_last_next_goto;
2453 45 @q = qw( redo last next goto );
2454 45 $is_redo_last_next_goto{$_} = 1 for @q;
2455  
2456 45 my %is_use_require;
2457 45 @q = qw( use require );
2458 45 $is_use_require{$_} = 1 for @q;
2459  
2460 # This hash holds the array index in $self for these keywords:
2461 # Fix for issue c035: removed 'format' from this hash
2462 45 my %is_END_DATA = (
2463 '__END__' => _in_end_,
2464 '__DATA__' => _in_data_,
2465 );
2466  
2467 # table showing how many quoted things to look for after quote operator..
2468 # s, y, tr have 2 (pattern and replacement)
2469 # others have 1 (pattern only)
2470 45 my %quote_items = (
2471 's' => 2,
2472 'y' => 2,
2473 'tr' => 2,
2474 'm' => 1,
2475 'qr' => 1,
2476 'q' => 1,
2477 'qq' => 1,
2478 'qw' => 1,
2479 'qx' => 1,
2480 );
2481  
2482 45 my %is_for_foreach;
2483 45 @q = qw( for foreach );
2484 45 $is_for_foreach{$_} = 1 for @q;
2485  
2486 # These keywords may introduce blocks after parenthesized expressions,
2487 # in the form:
2488 # keyword ( .... ) { BLOCK }
2489 # patch for SWITCH/CASE: added 'switch' 'case' 'given' 'when'
2490 45 my %is_blocktype_with_paren;
2491 45 @q =
2492 qw(if elsif unless while until for foreach switch case given when catch);
2493 45 $is_blocktype_with_paren{$_} = 1 for @q;
2494  
2495 45 my %is_case_default;
2496 45 @q = qw( case default );
2497 45 $is_case_default{$_} = 1 for @q;
2498  
2499 #------------------------
2500 # end of tokenizer hashes
2501 #------------------------
2502  
2503 # ------------------------------------------------------------
2504 # beginning of various scanner interface routines
2505 # ------------------------------------------------------------
2506 sub scan_replacement_text {
2507  
2508 # check for here-docs in replacement text invoked by
2509 # a substitution operator with executable modifier 'e'.
2510 #
2511 # given:
2512 # $replacement_text
2513 # return:
2514 # $rht = reference to any here-doc targets
2515 0 ▶ my ( $self, $replacement_text ) = @_;
Subroutine scan_replacement_text: not called CC=5 SCAR=34.0
Pod undocumented
2516  
2517 # quick check
2518 0 ▶ return if ( $replacement_text !~ /<</ );
Branch: 1 branch
BranchTrueFalseTotal
unless $replacement_text =~ /<</ 0 0 0
2519  
2520 0 $self->write_logfile_entry(
2521 "scanning replacement text for here-doc targets\n");
2522  
2523 # save the logger object for error messages
2524 0 my $logger_object = $self->[_logger_object_];
2525  
2526 # save all lexical variables
2527 0 my $rstate = save_tokenizer_state();
2528 0 _decrement_count(); # avoid error check for multiple tokenizers
2529  
2530 # make a new tokenizer
2531 0 my $tokenizer = Perl::Tidy::Tokenizer->new(
2532 source_object => \$replacement_text,
2533 logger_object => $logger_object,
2534 starting_line_number => $input_line_number,
2535 );
2536  
2537 # scan the replacement text
2538 0 ▶ while ( $tokenizer->get_line() ) { }
Branch: 1 branch
BranchTrueFalseTotal
if ($tokenizer->get_line) 0 0 0
2539  
2540 # remove any here doc targets
2541 0 my $rht = undef;
2542 0 ▶ if ( $tokenizer->[_in_here_doc_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokenizer->[1]) 0 0 0
2543 0 $rht = [];
2544 0 push @{$rht},
2545 [
2546 $tokenizer->[_here_doc_target_],
2547 $tokenizer->[_here_quote_character_],
2548 ];
2549 0 ▶ if ( $tokenizer->[_rhere_target_list_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokenizer->[0]) 0 0 0
2550 0 push @{$rht}, @{ $tokenizer->[_rhere_target_list_] };
2551 0 $tokenizer->[_rhere_target_list_] = undef;
2552 }
2553 0 $tokenizer->[_in_here_doc_] = undef;
2554 }
2555  
2556 # now its safe to report errors
2557 0 my $rtokenization_info_uu = $tokenizer->report_tokenization_errors();
2558  
2559 # TODO: Could propagate a severe error up
2560  
2561 # restore all tokenizer lexical variables
2562 0 restore_tokenizer_state($rstate);
2563  
2564 # return the here doc targets
2565 0 return $rht;
2566 } ## end sub scan_replacement_text
2567  
2568 sub scan_bare_identifier {
2569 1870 ▶ my $self = shift;
Subroutine scan_bare_identifier: called CC=1 SCAR=0.0
Pod undocumented
2570  
2571 # Scan a token starting with an alphanumeric variable or package
2572 # separator, :: or '.
2573  
2574 1870 ( $i, $tok, $type, $prototype ) = $self->scan_bare_identifier_do(
2575  
2576 $input_line,
2577 $i,
2578 $tok,
2579 $type,
2580 $prototype,
2581 $rtoken_map,
2582 $max_token_index,
2583 );
2584 1870 return;
2585 } ## end sub scan_bare_identifier
2586  
2587 sub scan_identifier {
2588  
2589 # Scan for an identifier following a sigil or -> or other
2590 # identifier prefix, such as '::'
2591  
2592 557 ▶ my $self = shift;
Subroutine scan_identifier: called CC=5 SCAR=19.9
Pod undocumented
2593  
2594 (
2595  
2596 557 $i,
2597 $tok,
2598 $type,
2599 $id_scan_state,
2600 $identifier,
2601 my $split_pretoken_flag,
2602  
2603 ) = $self->scan_complex_identifier(
2604  
2605 $i,
2606 $id_scan_state,
2607 $identifier,
2608 $rtokens,
2609 $max_token_index,
2610 $expecting,
2611 $rparen_type->[$paren_depth],
2612 );
2613  
2614 # Check for signal to fix a special variable adjacent to a keyword,
2615 # such as '$^One$0'.
2616 557 ▶ if ($split_pretoken_flag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($split_pretoken_flag) 3 554 557
2617  
2618 # Try to fix it by splitting the pretoken
2619 3 ▶ if ( $i > 0
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0 and $$rtokens[$i - 1] eq '^' and $self->split_pretoken(1)) { } 3 0 3
Condition33%2/6
$i > 0 and $$rtokens[$i - 1] eq "^" and $self->split_pretoken(1)
!ll&&!rl&&r
003
$i > 0 and $$rtokens[$i - 1] eq "^"
!ll&&!rl&&r
003
MC/DC0%0/3
$i > 0 and $$rtokens[$i - 1] eq "^" and $self->split_pretoken(1)
$i > 0 $$rtokens[$i - 1] eq "^" $self->split_pretoken(1)
Truth table25%1/4
A and B and C
A= $i > 0B= $$rtokens[$i - 1] eq "^"C= $self->split_pretoken(1)
ABCresult
0XX0
10X0
1100
1111
2620 && $rtokens->[ $i - 1 ] eq '^'
2621 && $self->split_pretoken(1) )
2622 {
2623 3 $identifier = substr( $identifier, 0, 3 );
2624 3 $tok = $identifier;
2625 }
2626 else {
2627  
2628 # This shouldn't happen ...
2629 0 my $var = substr( $tok, 0, 3 );
2630 0 my $excess = substr( $tok, 3 );
2631 0 $self->interrupt_logfile();
2632 0 $self->warning(<<EOM);
2633 $input_line_number: Trouble parsing at characters '$excess' after special variable '$var'.
2634 A space may be needed after '$var'.
2635 EOM
2636 0 $self->resume_logfile();
2637 }
2638 }
2639 557 return;
2640 } ## end sub scan_identifier
2641  
2642 45 ▶ use constant VERIFY_FASTSCAN => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2643 45 my %fast_scan_context;
2644  
2645 BEGIN {
2646 45 ▶ %fast_scan_context = (
Subroutine BEGIN: called CC=1 SCAR=0.0
2647 '$' => SCALAR_CONTEXT,
2648 '*' => SCALAR_CONTEXT,
2649 '@' => LIST_CONTEXT,
2650 '%' => LIST_CONTEXT,
2651 '&' => UNKNOWN_CONTEXT,
2652 );
2653 } ## end BEGIN
2654  
2655 sub scan_simple_identifier {
2656  
2657 5752 ▶ my $self = shift;
Subroutine scan_simple_identifier: called CC=19 SCAR=30.4
Pod undocumented
2658  
2659 # This is a wrapper for sub scan_identifier. It does a fast preliminary
2660 # scan for certain common identifiers:
2661 # '$var', '@var', %var, *var, &var, '@{...}', '%{...}'
2662 # If it does not find one of these, or this is a restart, it calls the
2663 # original scanner directly.
2664  
2665 # This gives the same results as the full scanner in about 1/4 the
2666 # total runtime for a typical input stream.
2667  
2668 # Notation:
2669 # $var * 2
2670 # ^^ ^
2671 # || |
2672 # || ---- $i_next [= next nonblank pretoken ]
2673 # |----$i_plus_1 [= a bareword ]
2674 # ---$i_begin [= a sigil]
2675  
2676 5752 my $i_begin = $i;
2677 5752 my $tok_begin = $tok;
2678 5752 my $i_plus_1 = $i + 1;
2679 5752 my $fast_scan_type;
2680  
2681 #-------------------------------------------------------
2682 # Do full scan for anything following a pointer, such as
2683 # $cref->&*; # a postderef
2684 #-------------------------------------------------------
2685 5752 ▶ if ( $last_nonblank_token eq '->' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($last_nonblank_token eq '->') { } 8 5744 5752
elsif (not $id_scan_state and $i_plus_1 <= $max_token_index and $fast_scan_context{$tok}) { } 5638 106 5744
elsif ($tok eq '->' and $i < $max_token_index and $rtokens->[$i_plus_1] eq '{' || $rtokens->[$i_plus_1] eq '[') { } 0 106 106
2686  
2687 }
2688  
2689 #------------------------------
2690 # quick scan with leading sigil
2691 #------------------------------
2692 ▶ elsif ( !$id_scan_state
Condition83%5/6
not $id_scan_state and $i_plus_1 <= $max_token_index and $fast_scan_context{$tok}
!ll&&!rl&&r
41025638
not $id_scan_state and $i_plus_1 <= $max_token_index
!ll&&!rl&&r
045740
MC/DC66%2/3
not $id_scan_state and $i_plus_1 <= $max_token_index and $fast_scan_context{$tok}
not $id_scan_state $i_plus_1 <= $max_token_index $fast_scan_context{$tok}
Truth table75%3/4
not(A) and B and C
A= not $id_scan_stateB= $i_plus_1 <= $max_token_indexC= $fast_scan_context{$tok}
ABCresult
0XX0
10X0
1100
1111
2693 && $i_plus_1 <= $max_token_index
2694 && $fast_scan_context{$tok} )
2695 {
2696 5638 $context = $fast_scan_context{$tok};
2697  
2698 # look for $var, @var, ...
2699 5638 ▶ if ( $rtoken_type->[$i_plus_1] eq 'w' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rtoken_type->[$i_plus_1] eq 'w') { } 5275 363 5638
elsif ($rtoken_type->[$i_plus_1] eq '{' and $tok_begin eq '@' || $tok_begin eq '%') { } 43 320 363
2700 5275 my $pretype_next = EMPTY_STRING;
2701 5275 ▶ if ( $i_plus_1 < $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_plus_1 < $max_token_index) 5153 122 5275
2702 5153 my $i_next = $i_plus_1 + 1;
2703 5153 ▶ if ( $rtoken_type->[$i_next] eq 'b'
Branch: 1 branch
BranchTrueFalseTotal
if ($rtoken_type->[$i_next] eq "b" and $i_next < $max_token_index) 2071 3082 5153
Condition100%3/3
$rtoken_type->[$i_next] eq "b" and $i_next < $max_token_index
!ll&&!rl&&r
307932071
MC/DC100%2/2
$rtoken_type->[$i_next] eq "b" and $i_next < $max_token_index
$rtoken_type->[$i_next] eq "b" $i_next < $max_token_index
Truth table100%3/3
A and B
A= $rtoken_type->[$i_next] eq "b"B= $i_next < $max_token_index
ABresult
0X0
100
111
2704 && $i_next < $max_token_index )
2705 {
2706 2071 $i_next += 1;
2707 }
2708 5153 $pretype_next = $rtoken_type->[$i_next];
2709 }
2710 5275 ▶ if ( $pretype_next ne ':' && $pretype_next ne "'" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pretype_next ne ":" and $pretype_next ne "'") 5159 116 5275
Condition100%3/3
$pretype_next ne ":" and $pretype_next ne "'"
!ll&&!rl&&r
10885159
MC/DC100%2/2
$pretype_next ne ":" and $pretype_next ne "'"
$pretype_next ne ":" $pretype_next ne "'"
Truth table100%3/3
A and B
A= $pretype_next ne ":"B= $pretype_next ne "'"
ABresult
0X0
100
111
2711  
2712 # Found type 'i' like '$var', '@var', or '%var'
2713 5159 $identifier = $tok . $rtokens->[$i_plus_1];
2714 5159 $tok = $identifier;
2715 5159 $type = 'i';
2716 5159 $i = $i_plus_1;
2717 5159 $fast_scan_type = $type;
2718 }
2719 }
2720  
2721 # Look for @{ or %{ .
2722 # But we must let the full scanner handle things ${ because it may
2723 # keep going to get a complete identifier like '${#}' .
2724 ▶ elsif (
Condition100%6/6
$rtoken_type->[$i_plus_1] eq "{" and $tok_begin eq "\@" || $tok_begin eq "%"
!ll&&!rl&&r
2833743
$tok_begin eq "\@" or $tok_begin eq "%"
l!l&&r!l&&!r
311237
MC/DC100%3/3
$rtoken_type->[$i_plus_1] eq "{" and $tok_begin eq "\@" || $tok_begin eq "%"
$rtoken_type->[$i_plus_1] eq "{" $tok_begin eq "\@" $tok_begin eq "%"
Truth table100%4/4
A and B or C
A= $rtoken_type->[$i_plus_1] eq "{"B= $tok_begin eq "\@"C= $tok_begin eq "%"
ABCresult
0XX0
1000
11X1
1011
2725 $rtoken_type->[$i_plus_1] eq '{'
2726 && ( $tok_begin eq '@'
2727 || $tok_begin eq '%' )
2728 )
2729 {
2730  
2731 43 $identifier = $tok;
2732 43 $type = 't';
2733 43 $fast_scan_type = $type;
2734 }
2735 else {
2736 ## out of tricks
2737 }
2738 }
2739  
2740 #---------------------------
2741 # Quick scan with leading ->
2742 # Look for ->[ and ->{
2743 #---------------------------
2744 ▶ elsif (
Condition22%2/9
$tok eq "->" and $i < $max_token_index and $rtokens->[$i_plus_1] eq "{" || $rtokens->[$i_plus_1] eq "["
!ll&&!rl&&r
10600
$tok eq "->" and $i < $max_token_index
!ll&&!rl&&r
10600
$rtokens->[$i_plus_1] eq "{" or $rtokens->[$i_plus_1] eq "["
l!l&&r!l&&!r
000
MC/DC0%0/4
$tok eq "->" and $i < $max_token_index and $rtokens->[$i_plus_1] eq "{" || $rtokens->[$i_plus_1] eq "["
$tok eq "->" $i < $max_token_index $rtokens->[$i_plus_1] eq "{" $rtokens->[$i_plus_1] eq "["
Truth table20%1/5
A and B and C or D
A= $tok eq "->"B= $i < $max_token_indexC= $rtokens->[$i_plus_1] eq "{"D= $rtokens->[$i_plus_1] eq "["
ABCDresult
0XXX0
10XX0
11000
111X1
11011
2745 $tok eq '->'
2746 && $i < $max_token_index
2747 && ( $rtokens->[$i_plus_1] eq '{'
2748 || $rtokens->[$i_plus_1] eq '[' )
2749 )
2750 {
2751 0 $type = $tok;
2752 0 $fast_scan_type = $type;
2753 0 $identifier = $tok;
2754 0 $context = UNKNOWN_CONTEXT;
2755 }
2756 else {
2757 ## out of tricks
2758 }
2759  
2760 #--------------------------------------
2761 # Verify correctness during development
2762 #--------------------------------------
2763 5752 if ( VERIFY_FASTSCAN && $fast_scan_type ) {
2764  
2765 # We will call the full method
2766 my $identifier_simple = $identifier;
2767 my $tok_simple = $tok;
2768 my $i_simple = $i;
2769 my $context_simple = $context;
2770  
2771 $tok = $tok_begin;
2772 $i = $i_begin;
2773 $self->scan_identifier();
2774  
2775 if ( $tok ne $tok_simple
2776 || $type ne $fast_scan_type
2777 || $i != $i_simple
2778 || $identifier ne $identifier_simple
2779 || $id_scan_state
2780 || $context ne $context_simple )
2781 {
2782 print {*STDERR} <<EOM;
2783 scan_simple_identifier differs from scan_identifier:
2784 simple: i=$i_simple, tok=$tok_simple, type=$fast_scan_type, ident=$identifier_simple, context='$context_simple
2785 full: i=$i, tok=$tok, type=$type, ident=$identifier, context='$context state=$id_scan_state
2786 EOM
2787 }
2788 }
2789  
2790 #-------------------------------------------------
2791 # call full scanner if fast method did not succeed
2792 #-------------------------------------------------
2793 5752 ▶ if ( !$fast_scan_type ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fast_scan_type) 550 5202 5752
2794 550 $self->scan_identifier();
2795 }
2796 5752 return;
2797 } ## end sub scan_simple_identifier
2798  
2799 sub method_ok_here {
2800  
2801 14 ▶ my ( $self, $next_nonblank_token ) = @_;
Subroutine method_ok_here: called CC=12 SCAR=25.5
Pod undocumented
2802  
2803 # Return:
2804 # false if this is definitely an invalid method declaration
2805 # true otherwise (even if not sure)
2806  
2807 # We are trying to avoid problems with old uses of 'method'
2808 # when --use-feature=class is set (rt145706).
2809 # For example, this should cause a return of 'false':
2810  
2811 # method paint => sub {
2812 # return;
2813 # };
2814  
2815 # Assume non-method if an error would occur
2816 14 ▶ return if ( $expecting == OPERATOR );
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 14 14
2817  
2818 # Currently marking a line-ending 'method' as a bareword (fix c532)
2819 14 ▶ return if ( $i_tok >= $max_token_index );
Branch: 1 branch
BranchTrueFalseTotal
if $i_tok >= $max_token_index 0 14 14
2820  
2821 # If a '$' follows 'method'...
2822 # Check for possible Object::Pad lexical method like
2823 # 'method $var {'
2824 # TODO: maybe merge this with the code below by increasing pos by 1
2825 14 ▶ if ( $next_nonblank_token eq '$' && new_statement_ok() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "\$" and new_statement_ok()) 2 12 14
Condition66%2/3
$next_nonblank_token eq "\$" and new_statement_ok()
!ll&&!rl&&r
1202
MC/DC50%1/2
$next_nonblank_token eq "\$" and new_statement_ok()
$next_nonblank_token eq "\$" new_statement_ok()
Truth table66%2/3
A and B
A= $next_nonblank_token eq "\$"B= new_statement_ok()
ABresult
0X0
100
111
2826 2 return 1;
2827 }
2828  
2829 # Otherwise, not a method if non-word follows ..
2830 12 ▶ if ( $next_nonblank_token !~ /^[\w\:]/ ) { return }
Branch: 1 branch
BranchTrueFalseTotal
unless ($next_nonblank_token =~ /^[\w\:]/) 4 8 12
2831  
2832 # from do_scan_sub:
2833 8 my $i_beg = $i + 1;
2834 8 my $pos_beg = $rtoken_map->[$i_beg];
2835 8 pos($input_line) = $pos_beg;
2836  
2837 # TEST 1: look a valid sub NAME
2838 8 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /\G\s* ((?:\w*(?:'|::))*) # package - something that ends in :: or ' (\w+) # NAME - required /cgx) { } 8 0 8
2839 $input_line =~ m{\G\s*
2840 ((?:\w*(?:'|::))*) # package - something that ends in :: or '
2841 (\w+) # NAME - required
2842 }gcx
2843 )
2844 {
2845 # For possible future use..
2846 ##my $subname = $2;
2847 ##my $package = $1 ? $1 : EMPTY_STRING;
2848 }
2849 else {
2850 0 return;
2851 }
2852  
2853 # TEST 2: look for invalid characters after name, such as here:
2854 # method paint => sub {
2855 # ...
2856 # }
2857 8 my $next_char = EMPTY_STRING;
2858 8 ▶ if ( $input_line =~ m/\s*(\S)/gcx ) { $next_char = $1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /\s*(\S)/cgx) 7 1 8
2859 8 ▶ if ( !$next_char || $next_char eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $next_char or $next_char eq "#") 1 7 8
Condition66%2/3
not $next_char or $next_char eq "#"
l!l&&r!l&&!r
107
MC/DC50%1/2
not $next_char or $next_char eq "#"
not $next_char $next_char eq "#"
Truth table66%2/3
not(A) or B
A= not $next_charB= $next_char eq "#"
ABresult
1X1
011
000
2860 1 ( $next_char, my $i_next_uu ) =
2861 $self->find_next_nonblank_token( $max_token_index,
2862 $rtokens, $max_token_index );
2863 }
2864  
2865 8 ▶ if ( !$next_char ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($next_char) 0 8 8
2866  
2867 # out of characters - give up
2868 0 return;
2869 }
2870  
2871 # Possibly valid next token types:
2872 # '(' could start prototype or signature
2873 # ':' could start ATTRIBUTE
2874 # '{' cold start BLOCK
2875 # ';' or '}' could end a statement
2876 8 ▶ if ( $next_char !~ /^[\(\:\{\;\}]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($next_char =~ /^[\(\:\{\;\}]/) 3 5 8
2877  
2878 # This does not match use feature 'class' syntax
2879 3 return;
2880 }
2881  
2882 # We will stop here and assume that this is valid syntax for
2883 # use feature 'class'.
2884 5 return 1;
2885 } ## end sub method_ok_here
2886  
2887 sub class_ok_here {
2888  
2889 12 ▶ my $self = shift;
Subroutine class_ok_here: called CC=8 SCAR=21.5
Pod undocumented
2890  
2891 # Return:
2892 # false if this is definitely an invalid class declaration
2893 # true otherwise (even if not sure)
2894  
2895 # We are trying to avoid problems with old uses of 'class'
2896 # when --use-feature=class is set (rt145706). We look ahead
2897 # see if this use of 'class' is obviously inconsistent with
2898 # the syntax of use feature 'class'. This allows the default
2899 # setting --use-feature=class to work for old syntax too.
2900  
2901 # Valid class declarations look like
2902 # class NAME ?ATTRS ?VERSION ?BLOCK
2903 # where ATTRS VERSION and BLOCK are optional
2904  
2905 # For example, this should produce a return of 'false':
2906 #
2907 # class ExtendsBasicAttributes is BasicAttributes{
2908  
2909 # TEST 1: class stmt can only go where a new statement can start
2910 12 ▶ if ( !new_statement_ok() ) { return }
Branch: 1 branch
BranchTrueFalseTotal
unless (new_statement_ok()) 0 12 12
2911  
2912 12 my $i_beg = $i + 1;
2913 12 my $pos_beg = $rtoken_map->[$i_beg];
2914 12 pos($input_line) = $pos_beg;
2915  
2916 # TEST 2: look for a valid NAME
2917 12 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /\G\s* ((?:\w*(?:'|::))*) # package - something that ends in :: or ' (\w+) # NAME - required /cgx) { } 12 0 12
2918 $input_line =~ m{\G\s*
2919 ((?:\w*(?:'|::))*) # package - something that ends in :: or '
2920 (\w+) # NAME - required
2921 }gcx
2922 )
2923 {
2924 # For possible future use..
2925 ##my $subname = $2;
2926 ##my $package = $1 ? $1 : EMPTY_STRING;
2927 }
2928 else {
2929 0 return;
2930 }
2931  
2932 # TEST 3: look for valid characters after NAME
2933 12 my $next_char = EMPTY_STRING;
2934 12 ▶ if ( $input_line =~ m/\s*(\S)/gcx ) { $next_char = $1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /\s*(\S)/cgx) 11 1 12
2935 12 ▶ if ( !$next_char || $next_char eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $next_char or $next_char eq "#") 1 11 12
Condition66%2/3
not $next_char or $next_char eq "#"
l!l&&r!l&&!r
1011
MC/DC50%1/2
not $next_char or $next_char eq "#"
not $next_char $next_char eq "#"
Truth table66%2/3
not(A) or B
A= not $next_charB= $next_char eq "#"
ABresult
1X1
011
000
2936 1 ( $next_char, my $i_next_uu ) =
2937 $self->find_next_nonblank_token( $max_token_index,
2938 $rtokens, $max_token_index );
2939 }
2940 12 ▶ if ( !$next_char ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($next_char) 0 12 12
2941  
2942 # out of characters - give up
2943 0 return;
2944 }
2945  
2946 # Must see one of: ATTRIBUTE, VERSION, BLOCK, or end stmt
2947  
2948 # Possibly valid next token types:
2949 # ':' could start ATTRIBUTE
2950 # '\d' could start VERSION
2951 # '{' cold start BLOCK
2952 # ';' could end a statement
2953 # '}' could end statement but would be strange
2954  
2955 12 ▶ if ( $next_char !~ /^[\:\d\{\;\}]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($next_char =~ /^[\:\d\{\;\}]/) 2 10 12
2956  
2957 # This does not match use feature 'class' syntax
2958 2 return;
2959 }
2960  
2961 # We will stop here and assume that this is valid syntax for
2962 # use feature 'class'.
2963 10 return 1;
2964 } ## end sub class_ok_here
2965  
2966 sub scan_id {
2967 425 ▶ my $self = shift;
Subroutine scan_id: called CC=1 SCAR=0.0
Pod undocumented
2968  
2969 # Scan for a sub or package name
2970  
2971 425 ( $i, $tok, $type, $id_scan_state ) = $self->scan_id_do(
2972  
2973 $input_line,
2974 $i, $tok,
2975 $rtokens,
2976 $rtoken_map,
2977 $id_scan_state,
2978 $max_token_index,
2979 );
2980 425 return;
2981 } ## end sub scan_id
2982  
2983 sub scan_number {
2984 687 ▶ my $self = shift;
Subroutine scan_number: called CC=1 SCAR=0.0
Pod undocumented
2985 687 my $number;
2986 687 ( $i, $type, $number ) =
2987 $self->scan_number_do( $input_line, $i, $rtoken_map, $type,
2988 $max_token_index );
2989 687 return $number;
2990 } ## end sub scan_number
2991  
2992 45 ▶ use constant VERIFY_FASTNUM => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2993  
2994 sub scan_number_fast {
2995  
2996 2913 ▶ my $self = shift;
Subroutine scan_number_fast: called CC=13 SCAR=25.7
Pod undocumented
2997  
2998 # This is a wrapper for sub scan_number. It does a fast preliminary
2999 # scan for a simple integer. It calls the original scan_number if it
3000 # does not find one.
3001  
3002 2913 my $i_begin = $i;
3003 2913 my $tok_begin = $tok;
3004 2913 my $number;
3005  
3006 #---------------------------------
3007 # Quick check for (signed) integer
3008 #---------------------------------
3009  
3010 # This will be the string of digits:
3011 2913 my $i_d = $i;
3012 2913 my $tok_d = $tok;
3013 2913 my $typ_d = $rtoken_type->[$i_d];
3014  
3015 # check for signed integer
3016 2913 my $sign = EMPTY_STRING;
3017 2913 ▶ if ( $typ_d ne 'd'
Branch: 1 branch
BranchTrueFalseTotal
if ($typ_d ne "d" and $typ_d eq "+" || $typ_d eq "-" and $i_d < $max_token_index) 392 2521 2913
Condition66%6/9
$typ_d ne "d" and $typ_d eq "+" || $typ_d eq "-" and $i_d < $max_token_index
!ll&&!rl&&r
25210392
$typ_d ne "d" and $typ_d eq "+" || $typ_d eq "-"
!ll&&!rl&&r
25210392
$typ_d eq "+" or $typ_d eq "-"
l!l&&r!l&&!r
143780
MC/DC25%1/4
$typ_d ne "d" and $typ_d eq "+" || $typ_d eq "-" and $i_d < $max_token_index
$typ_d ne "d" $typ_d eq "+" $typ_d eq "-" $i_d < $max_token_index
Truth table50%3/6
A and B or C and D
A= $typ_d ne "d"B= $typ_d eq "+"C= $typ_d eq "-"D= $i_d < $max_token_index
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
3018 && ( $typ_d eq '+' || $typ_d eq '-' )
3019 && $i_d < $max_token_index )
3020 {
3021 392 $sign = $tok_d;
3022 392 $i_d++;
3023 392 $tok_d = $rtokens->[$i_d];
3024 392 $typ_d = $rtoken_type->[$i_d];
3025 }
3026  
3027 # Handle integers
3028 2913 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($typ_d eq "d" and $i_d == $max_token_index || $i_d < $max_token_index && $$rtoken_type[$i_d + 1] ne "." && $$rtoken_type[$i_d + 1] ne "w") 2293 620 2913
Condition91%11/12
$typ_d eq "d" and $i_d == $max_token_index || $i_d < $max_token_index && $$rtoken_type[$i_d + 1] ne "." && $$rtoken_type[$i_d + 1] ne "w"
!ll&&!rl&&r
302522559
$i_d == $max_token_index or $i_d < $max_token_index and $$rtoken_type[$i_d + 1] ne "." and $$rtoken_type[$i_d + 1] ne "w"
l!l&&r!l&&!r
27253549
$i_d < $max_token_index and $$rtoken_type[$i_d + 1] ne "." and $$rtoken_type[$i_d + 1] ne "w"
!ll&&!rl&&r
283352266
$i_d < $max_token_index and $$rtoken_type[$i_d + 1] ne "."
!ll&&!rl&&r
02832301
MC/DC40%2/5
$typ_d eq "d" and $i_d == $max_token_index || $i_d < $max_token_index && $$rtoken_type[$i_d + 1] ne "." && $$rtoken_type[$i_d + 1] ne "w"
$typ_d eq "d" $i_d == $max_token_index $i_d < $max_token_index $$rtoken_type[$i_d + 1] ne "." $$rtoken_type[$i_d + 1] ne "w"
Truth table50%3/6
A and B or C and D and E
A= $typ_d eq "d"B= $i_d == $max_token_indexC= $i_d < $max_token_indexD= $$rtoken_type[$i_d + 1] ne "."E= $$rtoken_type[$i_d + 1] ne "w"
ABCDEresult
0XXXX0
100XX0
1010X0
101100
11XXX1
101111
3029 $typ_d eq 'd'
3030 && (
3031 $i_d == $max_token_index
3032 || ( $i_d < $max_token_index
3033 && $rtoken_type->[ $i_d + 1 ] ne '.'
3034 && $rtoken_type->[ $i_d + 1 ] ne 'w' )
3035 )
3036 )
3037 {
3038 # Let the full scanner handle multi-digit integers beginning with
3039 # '0' because there could be error messages. For example, '009' is
3040 # not a valid number.
3041  
3042 2293 ▶ if ( $tok_d eq '0' || substr( $tok_d, 0, 1 ) ne '0' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok_d eq 0 or substr($tok_d, 0, 1) ne 0) 2236 57 2293
Condition100%3/3
$tok_d eq 0 or substr($tok_d, 0, 1) ne 0
l!l&&r!l&&!r
452178457
MC/DC100%2/2
$tok_d eq 0 or substr($tok_d, 0, 1) ne 0
$tok_d eq 0 substr($tok_d, 0, 1) ne 0
Truth table100%3/3
A or B
A= $tok_d eq 0B= substr($tok_d, 0, 1) ne 0
ABresult
1X1
011
000
3043 2236 $number = $sign . $tok_d;
3044 2236 $type = 'n';
3045 2236 $i = $i_d;
3046 }
3047 }
3048  
3049 #--------------------------------------
3050 # Verify correctness during development
3051 #--------------------------------------
3052 2913 if ( VERIFY_FASTNUM && defined($number) ) {
3053  
3054 # We will call the full method
3055 my $type_simple = $type;
3056 my $i_simple = $i;
3057 my $number_simple = $number;
3058  
3059 $tok = $tok_begin;
3060 $i = $i_begin;
3061 $number = $self->scan_number();
3062  
3063 if ( $type ne $type_simple
3064 || ( $i != $i_simple && $i <= $max_token_index )
3065 || $number ne $number_simple )
3066 {
3067 print {*STDERR} <<EOM;
3068 scan_number_fast differs from scan_number:
3069 simple: i=$i_simple, type=$type_simple, number=$number_simple
3070 full: i=$i, type=$type, number=$number
3071 EOM
3072 }
3073 }
3074  
3075 #----------------------------------------
3076 # call full scanner if may not be integer
3077 #----------------------------------------
3078 2913 ▶ if ( !defined($number) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $number) 677 2236 2913
3079 677 $number = $self->scan_number();
3080 }
3081 2913 return $number;
3082 } ## end sub scan_number_fast
3083  
3084 sub error_if_expecting_TERM {
3085 1685 ▶ my ($self) = @_;
Subroutine error_if_expecting_TERM: called CC=9 SCAR=26.2
Pod undocumented
3086  
3087 # Issue a warning if a binary operator is missing a term to operate on
3088  
3089 # This should only be called if a term is expected here
3090 1685 ▶ if ( $expecting != TERM ) { return }
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting != -1) 0 1685 1685
3091  
3092 # Be sure a TERM is definitely required ..
3093 1685 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($is_binary_or_unary_operator_type{$last_nonblank_type} or $last_nonblank_type eq "k" and $is_binary_or_unary_keyword{$last_nonblank_token} or $is_not_a_TERM_producer_type{$last_nonblank_type} and $is_binary_operator_type{$tok}) 0 1684 1684
Condition66%8/12
$is_binary_or_unary_operator_type{$last_nonblank_type} or $last_nonblank_type eq "k" and $is_binary_or_unary_keyword{$last_nonblank_token} or $is_not_a_TERM_producer_type{$last_nonblank_type} and $is_binary_operator_type{$tok}
l!l&&r!l&&!r
101684
$is_binary_or_unary_operator_type{$last_nonblank_type} or $last_nonblank_type eq "k" and $is_binary_or_unary_keyword{$last_nonblank_token}
l!l&&r!l&&!r
101684
$last_nonblank_type eq "k" and $is_binary_or_unary_keyword{$last_nonblank_token}
!ll&&!rl&&r
15281560
$is_not_a_TERM_producer_type{$last_nonblank_type} and $is_binary_operator_type{$tok}
!ll&&!rl&&r
8508340
MC/DC20%1/5
$is_binary_or_unary_operator_type{$last_nonblank_type} or $last_nonblank_type eq "k" and $is_binary_or_unary_keyword{$last_nonblank_token} or $is_not_a_TERM_producer_type{$last_nonblank_type} and $is_binary_operator_type{$tok}
$is_binary_or_unary_operator_type{$last_nonblank_type} $last_nonblank_type eq "k" $is_binary_or_unary_keyword{$last_nonblank_token} $is_not_a_TERM_producer_type{$last_nonblank_type} $is_binary_operator_type{$tok}
Truth table25%2/8
A or B and C or D and E
A= $is_binary_or_unary_operator_type{$last_nonblank_type}B= $last_nonblank_type eq "k"C= $is_binary_or_unary_keyword{$last_nonblank_token}D= $is_not_a_TERM_producer_type{$last_nonblank_type}E= $is_binary_operator_type{$tok}
ABCDEresult
1XXXX1
011XX1
00X111
010111
00X0X0
00X100
0100X0
010100
3094  
3095 # .. following a binary operator token type, like '='
3096 $is_binary_or_unary_operator_type{$last_nonblank_type}
3097  
3098 # .. or following a binary keyword operator, like 'and'
3099 || ( $last_nonblank_type eq 'k'
3100 && $is_binary_or_unary_keyword{$last_nonblank_token} )
3101  
3102 # .. or for a binary operator following something like a ';'
3103 || ( $is_not_a_TERM_producer_type{$last_nonblank_type}
3104 && $is_binary_operator_type{$tok} )
3105 )
3106 {
3107  
3108 # We must exclude error checking in sub signatures which have some
3109 # unusual syntax. For example the following syntax is okay within
3110 # a signature:
3111 # sub mysub ($=,) {...}
3112 # $ = undef
3113 1 my $ct = $rparen_type->[$paren_depth];
3114 1 ▶ if ( $ct && $ct =~ /^sub\b/ ) { return }
Branch: 1 branch
BranchTrueFalseTotal
if ($ct and $ct =~ /^sub\b/) 1 0 1
Condition33%1/3
$ct and $ct =~ /^sub\b/
!ll&&!rl&&r
001
MC/DC0%0/2
$ct and $ct =~ /^sub\b/
$ct $ct =~ /^sub\b/
Truth table33%1/3
A and B
A= $ctB= $ct =~ /^sub\b/
ABresult
0X0
100
111
3115  
3116 $self->report_unexpected(
3117 {
3118 0 found => $tok,
3119 expecting => "term",
3120 i_tok => $i_tok,
3121 last_nonblank_i => $last_nonblank_i,
3122 rpretoken_map => $rtoken_map,
3123 rpretoken_type => $rtoken_type,
3124 input_line => $input_line,
3125 }
3126 );
3127 0 return 1;
3128 }
3129 1684 return;
3130 } ## end sub error_if_expecting_TERM
3131  
3132 # a sub to warn if token found where operator expected
3133 sub error_if_expecting_OPERATOR {
3134  
3135 823 ▶ my ( $self, ($thing) ) = @_;
Subroutine error_if_expecting_OPERATOR: called CC=4 SCAR=24.1
Pod undocumented
3136  
3137 # Issue warning on error if expecting operator
3138 # Given:
3139 # $thing = the unexpected token or issue
3140 # = undef to use current pre-token
3141  
3142 823 ▶ if ( $expecting == OPERATOR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == 1) 0 823 823
3143 0 ▶ if ( !defined($thing) ) { $thing = $tok }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $thing) 0 0 0
3144 $self->report_unexpected(
3145 {
3146 0 found => $thing,
3147 expecting => "operator",
3148 i_tok => $i_tok,
3149 last_nonblank_i => $last_nonblank_i,
3150 rpretoken_map => $rtoken_map,
3151 rpretoken_type => $rtoken_type,
3152 input_line => $input_line,
3153 }
3154 );
3155 0 ▶ if ( $i_tok == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_tok == 0) 0 0 0
3156 0 $self->interrupt_logfile();
3157 0 $self->warning("Missing ';' or ',' above?\n");
3158 0 $self->resume_logfile();
3159 }
3160 0 return 1;
3161 }
3162 823 return;
3163 } ## end sub error_if_expecting_OPERATOR
3164  
3165 # ------------------------------------------------------------
3166 # end scanner interfaces
3167 # ------------------------------------------------------------
3168  
3169 #------------------
3170 # Tokenization subs
3171 #------------------
3172 # An identifier in possible indirect object location followed by any of
3173 # these tokens: -> , ; } (plus others) is not an indirect object. Fix c257.
3174 my %Z_test_hash;
3175  
3176 BEGIN {
3177 45 ▶ my @qZ = qw#
Subroutine BEGIN: called CC=2 SCAR=6.9
3178 -> ; } ) ]
3179 => =~ = == !~ || >= != *= .. && |= .= -= += <= %=
3180 ^= &&= ||= //= <=>
3181 #;
3182 45 push @qZ, COMMA;
3183 45 $Z_test_hash{$_} = 1 for @qZ;
3184 }
3185  
3186 sub do_DOLLAR_SIGN {
3187  
3188 4890 ▶ my $self = shift;
Subroutine do_DOLLAR_SIGN: called CC=10 SCAR=23.2
Pod undocumented
3189  
3190 # '$'
3191 # start looking for a scalar
3192 4890 ▶ $self->error_if_expecting_OPERATOR("Scalar")
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 4890 4890
3193 if ( $expecting == OPERATOR );
3194 4890 $self->scan_simple_identifier();
3195  
3196 4890 ▶ if ( $identifier eq '$^W' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($identifier eq "\$^W") 1 4889 4890
3197 1 $self->[_saw_perl_dash_w_] = 1;
3198 }
3199  
3200 # Check for identifier in indirect object slot
3201 # (vorboard.pl, sort.t). Something like:
3202 # /^(print|printf|sort|exec|system)$/
3203 4890 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($is_indirect_object_taker{$last_nonblank_token} and $last_nonblank_type eq "k" or $last_nonblank_token eq "(" and $is_indirect_object_taker{$rparen_type->[$paren_depth]} or ($last_nonblank_type eq "w" or $last_nonblank_type eq "U")) 67 4780 4847
Condition80%12/15
$is_indirect_object_taker{$last_nonblank_token} and $last_nonblank_type eq "k" or $last_nonblank_token eq "(" and $is_indirect_object_taker{$rparen_type->[$paren_depth]} or ($last_nonblank_type eq "w" or $last_nonblank_type eq "U")
l!l&&r!l&&!r
6504825
$is_indirect_object_taker{$last_nonblank_token} and $last_nonblank_type eq "k" or $last_nonblank_token eq "(" and $is_indirect_object_taker{$rparen_type->[$paren_depth]}
l!l&&r!l&&!r
43224825
$is_indirect_object_taker{$last_nonblank_token} and $last_nonblank_type eq "k"
!ll&&!rl&&r
4847043
$last_nonblank_token eq "(" and $is_indirect_object_taker{$rparen_type->[$paren_depth]}
!ll&&!rl&&r
395487122
$last_nonblank_type eq "w" or $last_nonblank_type eq "U"
l!l&&r!l&&!r
4504780
MC/DC50%3/6
$is_indirect_object_taker{$last_nonblank_token} and $last_nonblank_type eq "k" or $last_nonblank_token eq "(" and $is_indirect_object_taker{$rparen_type->[$paren_depth]} or ($last_nonblank_type eq "w" or $last_nonblank_type eq "U")
$is_indirect_object_taker{$last_nonblank_token} $last_nonblank_type eq "k" $last_nonblank_token eq "(" $is_indirect_object_taker{$rparen_type->[$paren_depth]} $last_nonblank_type eq "w" $last_nonblank_type eq "U"
Truth table26%4/15
A and B or C and D or E or F
A= $is_indirect_object_taker{$last_nonblank_token}B= $last_nonblank_type eq "k"C= $last_nonblank_token eq "("D= $is_indirect_object_taker{$rparen_type->[$paren_depth]}E= $last_nonblank_type eq "w"F= $last_nonblank_type eq "U"
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X1X1
0X0X011
0X101X1
0X10011
100X1X1
100X011
10101X1
1010011
0X0X000
0X10000
100X000
1010000
3204 $is_indirect_object_taker{$last_nonblank_token}
3205 && $last_nonblank_type eq 'k'
3206 || ( ( $last_nonblank_token eq '(' )
3207 && $is_indirect_object_taker{ $rparen_type->[$paren_depth] } )
3208 || ( $last_nonblank_type eq 'w'
3209 || $last_nonblank_type eq 'U' ) # possible object
3210 )
3211 {
3212  
3213 # An identifier followed by '->' is not indirect object;
3214 # fixes b1175, b1176. Fix c257: Likewise for other tokens like
3215 # comma, semicolon, closing brace, and single space.
3216 110 my ( $next_nonblank_token, $i_next_uu ) =
3217 $self->find_next_noncomment_token( $i, $rtokens,
3218 $max_token_index );
3219 110 ▶ $type = 'Z' if ( !$Z_test_hash{$next_nonblank_token} );
Branch: 1 branch
BranchTrueFalseTotal
unless $Z_test_hash{$next_nonblank_token} 45 65 110
3220 }
3221 4890 return;
3222 } ## end sub do_DOLLAR_SIGN
3223  
3224 sub do_LEFT_PARENTHESIS {
3225  
3226 2445 ▶ my $self = shift;
Subroutine do_LEFT_PARENTHESIS: called CC=19 SCAR=38.3
Pod undocumented
3227  
3228 # '('
3229 2445 ++$paren_depth;
3230  
3231 # variable to enable check for brace after closing paren (c230)
3232 2445 my $want_brace = EMPTY_STRING;
3233  
3234 2445 ▶ if ($want_paren) {
Branch: 2 branches
BranchTrueFalseTotal
if ($want_paren) { } 295 2150 2445
elsif (substr($statement_type, 0, 3) eq 'sub' and $statement_type =~ /^sub\b/) { } 20 2130 2150
3235 295 $container_type = $want_paren;
3236 295 $want_brace = $want_paren;
3237 295 $want_paren = EMPTY_STRING;
3238 }
3239 ▶ elsif ( substr( $statement_type, 0, 3 ) eq 'sub'
Condition66%2/3
substr($statement_type, 0, 3) eq "sub" and $statement_type =~ /^sub\b/
!ll&&!rl&&r
2130020
MC/DC50%1/2
substr($statement_type, 0, 3) eq "sub" and $statement_type =~ /^sub\b/
substr($statement_type, 0, 3) eq "sub" $statement_type =~ /^sub\b/
Truth table66%2/3
A and B
A= substr($statement_type, 0, 3) eq "sub"B= $statement_type =~ /^sub\b/
ABresult
0X0
100
111
3240 && $statement_type =~ /^sub\b/ )
3241 {
3242 20 $container_type = $statement_type;
3243 }
3244 else {
3245 2130 $container_type = $last_nonblank_token;
3246  
3247 # We can check for a syntax error here of unexpected '(',
3248 # but this is going to get messy...
3249 2130 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == 1 and not $last_nonblank_token =~ /^(?:[\]\}\)\&]|\-\>)/) 3 2127 2130
Condition100%3/3
$expecting == 1 and not $last_nonblank_token =~ /^(?:[\]\}\)\&]|\-\>)/
!ll&&!rl&&r
14806473
MC/DC100%2/2
$expecting == 1 and not $last_nonblank_token =~ /^(?:[\]\}\)\&]|\-\>)/
$expecting == 1 not $last_nonblank_token =~ /^(?:[\]\}\)\&]|\-\>)/
Truth table100%3/3
A and not(B)
A= $expecting == 1B= not $last_nonblank_token =~ /^(?:[\]\}\)\&]|\-\>)/
ABresult
0X0
100
111
3250 $expecting == OPERATOR
3251  
3252 # Be sure this is not a method call of the form
3253 # &method(...), $method->(..), &{method}(...),
3254 # $ref[2](list) is ok & short for $ref[2]->(list)
3255 # NOTE: at present, braces in something like &{ xxx }
3256 # are not marked as a block, we might have a method call.
3257 # Added ')' to fix case c017, something like ()()()
3258 && $last_nonblank_token !~ /^(?:[\]\}\)\&]|\-\>)/
3259 )
3260 {
3261  
3262 # ref: camel 3 p 703.
3263 3 ▶ if ( $last_last_nonblank_token eq 'do' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_last_nonblank_token eq 'do') { } 0 3 3
3264 0 $self->complain(
3265 "do SUBROUTINE is deprecated; consider & or -> notation\n"
3266 );
3267 }
3268 else {
3269  
3270 # if this is an empty list, (), then it is not an
3271 # error; for example, we might have a constant pi and
3272 # invoke it with pi() or just pi;
3273 3 my ( $next_nonblank_token, $i_next_uu ) =
3274 $self->find_next_nonblank_token( $i, $rtokens,
3275 $max_token_index );
3276  
3277 # Patch for c029: give up error check if
3278 # a side comment follows
3279 3 ▶ if ( $next_nonblank_token ne ')'
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token ne ")" and $next_nonblank_token ne "#") 0 3 3
Condition33%1/3
$next_nonblank_token ne ")" and $next_nonblank_token ne "#"
!ll&&!rl&&r
300
MC/DC0%0/2
$next_nonblank_token ne ")" and $next_nonblank_token ne "#"
$next_nonblank_token ne ")" $next_nonblank_token ne "#"
Truth table33%1/3
A and B
A= $next_nonblank_token ne ")"B= $next_nonblank_token ne "#"
ABresult
0X0
100
111
3280 && $next_nonblank_token ne '#' )
3281 {
3282 0 my $hint;
3283  
3284 0 $self->error_if_expecting_OPERATOR('(');
3285  
3286 0 ▶ if ( $last_nonblank_type eq 'C' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($last_nonblank_type eq 'C') { } 0 0 0
elsif ($last_nonblank_type eq 'i') { } 0 0 0
3287 0 $hint =
3288 "$last_nonblank_token has a void prototype\n";
3289 }
3290 elsif ( $last_nonblank_type eq 'i' ) {
3291 0 ▶ if ( $i_tok > 0
Branch: 1 branch
BranchTrueFalseTotal
if ($i_tok > 0 and $last_nonblank_token =~ /^\$/) 0 0 0
Condition0%0/3
$i_tok > 0 and $last_nonblank_token =~ /^\$/
!ll&&!rl&&r
000
MC/DC0%0/2
$i_tok > 0 and $last_nonblank_token =~ /^\$/
$i_tok > 0 $last_nonblank_token =~ /^\$/
Truth table0%0/3
A and B
A= $i_tok > 0B= $last_nonblank_token =~ /^\$/
ABresult
0X0
100
111
3292 && $last_nonblank_token =~ /^\$/ )
3293 {
3294 0 $hint =
3295 "Do you mean '$last_nonblank_token->(' ?";
3296 0 ▶ if ( $is_for_foreach{ $rtokens->[0] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_for_foreach{$rtokens->[0]}) 0 0 0
3297 0 $hint .= " ... or is a ';' missing above?";
3298 }
3299 0 $hint .= "\n";
3300 }
3301 }
3302 else {
3303 ## no hint
3304 }
3305 0 ▶ if ($hint) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hint) 0 0 0
3306 0 $self->interrupt_logfile();
3307 0 $self->warning($hint);
3308 0 $self->resume_logfile();
3309 }
3310 } ## end if ( $next_nonblank_token...
3311 } ## end else [ if ( $last_last_nonblank_token...
3312 } ## end if ( $expecting == OPERATOR...
3313 }
3314  
3315 2445 ( $type_sequence, $indent_flag ) =
3316 $self->increase_nesting_depth( PAREN, $rtoken_map->[$i_tok] );
3317  
3318 # propagate types down through nested parens
3319 # for example: the second paren in 'if ((' would be structural
3320 # since the first is.
3321  
3322 2445 ▶ if ( $last_nonblank_token eq '(' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_token eq '(') { } 61 2384 2445
3323 61 $type = $last_nonblank_type;
3324 }
3325  
3326 # We exclude parens as structural after a ',' because it
3327 # causes subtle problems with continuation indentation for
3328 # something like this, where the first 'or' will not get
3329 # indented.
3330 #
3331 # assert(
3332 # __LINE__,
3333 # ( not defined $check )
3334 # or ref $check
3335 # or $check eq "new"
3336 # or $check eq "old",
3337 # );
3338 #
3339 # Likewise, we exclude parens where a statement can start
3340 # because of problems with continuation indentation, like
3341 # these:
3342 #
3343 # ($firstline =~ /^#\!.*perl/)
3344 # and (print $File::Find::name, "\n")
3345 # and (return 1);
3346 #
3347 # (ref($usage_fref) =~ /CODE/)
3348 # ? &$usage_fref
3349 # : (&blast_usage, &blast_params, &blast_general_params);
3350  
3351 else {
3352 2384 $type = '{';
3353 }
3354  
3355 2445 ▶ if ( $last_nonblank_type eq ')' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq ")") 0 2445 2445
3356 0 $self->warning(
3357 "Syntax error? found token '$last_nonblank_type' then '('\n");
3358 }
3359  
3360 # git #105: Copy container type and want-brace flag at ') (';
3361 # propagate the container type onward so that any subsequent brace gets
3362 # correctly marked. I have implemented this as a general rule, which
3363 # should be safe, but if necessary it could be restricted to certain
3364 # container statement types such as 'for'.
3365 2445 ▶ if ( $last_nonblank_token eq ')' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_token eq ")") 1 2444 2445
3366 1 my $rvars = $rparen_vars->[$paren_depth];
3367 1 ▶ if ( defined($rvars) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rvars) 1 0 1
3368 1 $container_type = $rparen_type->[$paren_depth];
3369 1 ( my $type_lp_uu, $want_brace ) = @{$rvars};
3370 }
3371 }
3372  
3373 2445 $rparen_type->[$paren_depth] = $container_type;
3374 2445 $rparen_vars->[$paren_depth] = [ $type, $want_brace ];
3375 2445 $rparen_semicolon_count->[$paren_depth] = 0;
3376  
3377 2445 return;
3378  
3379 } ## end sub do_LEFT_PARENTHESIS
3380  
3381 sub do_RIGHT_PARENTHESIS {
3382  
3383 2445 ▶ my $self = shift;
Subroutine do_RIGHT_PARENTHESIS: called CC=12 SCAR=25.5
Pod undocumented
3384  
3385 2445 ( $type_sequence, $indent_flag ) =
3386 $self->decrease_nesting_depth( PAREN, $rtoken_map->[$i_tok] );
3387  
3388 # ')'
3389 2445 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) 361 2084 2445
3390 $self->error_if_expecting_TERM()
3391 361 ▶ if ( !$self->[_rsaw_unknown_syntax_in_seqno_]->{$type_sequence} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->[56]{$type_sequence} 359 2 361
3392 }
3393  
3394 2445 my $rvars = $rparen_vars->[$paren_depth];
3395 2445 ▶ if ( defined($rvars) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rvars) 2445 0 2445
3396 2445 my ( $type_lp, $want_brace_uu ) = @{$rvars};
3397 2445 ▶ if ( $type_lp && $type_lp eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_lp and $type_lp eq "{") 2445 0 2445
Condition33%1/3
$type_lp and $type_lp eq "{"
!ll&&!rl&&r
002445
MC/DC0%0/2
$type_lp and $type_lp eq "{"
$type_lp $type_lp eq "{"
Truth table33%1/3
A and B
A= $type_lpB= $type_lp eq "{"
ABresult
0X0
100
111
3398 2445 $type = '}';
3399 }
3400 }
3401  
3402 2445 $container_type = $rparen_type->[$paren_depth];
3403  
3404 # restore statement type as 'sub' at closing paren of a signature
3405 # so that a subsequent ':' is identified as an attribute
3406 2445 ▶ if ( substr( $container_type, 0, 3 ) eq 'sub'
Branch: 1 branch
BranchTrueFalseTotal
if (substr($container_type, 0, 3) eq "sub" and $container_type =~ /^sub\b/) 30 2415 2445
Condition100%3/3
substr($container_type, 0, 3) eq "sub" and $container_type =~ /^sub\b/
!ll&&!rl&&r
2414130
MC/DC100%2/2
substr($container_type, 0, 3) eq "sub" and $container_type =~ /^sub\b/
substr($container_type, 0, 3) eq "sub" $container_type =~ /^sub\b/
Truth table100%3/3
A and B
A= substr($container_type, 0, 3) eq "sub"B= $container_type =~ /^sub\b/
ABresult
0X0
100
111
3407 && $container_type =~ /^sub\b/ )
3408 {
3409 30 $statement_type = $container_type;
3410 }
3411  
3412 2445 ▶ if ( $is_for_foreach{ $rparen_type->[$paren_depth] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_for_foreach{$rparen_type->[$paren_depth]}) 79 2366 2445
3413 79 my $num_sc = $rparen_semicolon_count->[$paren_depth];
3414 79 ▶ if ( $num_sc > 0 && $num_sc != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num_sc > 0 and $num_sc != 2) 0 79 79
Condition66%2/3
$num_sc > 0 and $num_sc != 2
!ll&&!rl&&r
62170
MC/DC0%0/2
$num_sc > 0 and $num_sc != 2
$num_sc > 0 $num_sc != 2
Truth table66%2/3
A and B
A= $num_sc > 0B= $num_sc != 2
ABresult
0X0
100
111
3415 0 $self->warning("Expected 2 ';' in 'for(;;)' but saw $num_sc\n");
3416 }
3417 }
3418  
3419 2445 ▶ if ( $paren_depth > 0 ) { $paren_depth-- }
Branch: 1 branch
BranchTrueFalseTotal
if ($paren_depth > 0) 2445 0 2445
3420 2445 return;
3421 } ## end sub do_RIGHT_PARENTHESIS
3422  
3423 sub do_COMMA {
3424  
3425 3720 ▶ my $self = shift;
Subroutine do_COMMA: called CC=5 SCAR=16.8
Pod undocumented
3426  
3427 # ','
3428 3720 ▶ if ( $last_nonblank_type eq COMMA ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($last_nonblank_type eq ',') { } 10 3710 3720
elsif ($last_nonblank_token eq '(' and $last_nonblank_type eq '{') { } 0 3710 3710
3429 10 $self->complain("Repeated ','s \n");
3430 }
3431  
3432 # Note that we have to check both token and type here because a
3433 # comma following a qw list can have last token='(' but type = 'q'
3434 ▶ elsif ( $last_nonblank_token eq '(' && $last_nonblank_type eq '{' ) {
Condition33%1/3
$last_nonblank_token eq "(" and $last_nonblank_type eq "{"
!ll&&!rl&&r
371000
MC/DC0%0/2
$last_nonblank_token eq "(" and $last_nonblank_type eq "{"
$last_nonblank_token eq "(" $last_nonblank_type eq "{"
Truth table33%1/3
A and B
A= $last_nonblank_token eq "("B= $last_nonblank_type eq "{"
ABresult
0X0
100
111
3435 0 $self->warning("Unexpected leading ',' after a '('\n");
3436 }
3437 else {
3438 ## Error check added in update c565, moved to end of $code loop.
3439 }
3440  
3441 # patch for operator_expected: note if we are in the list (use.t)
3442 3720 ▶ if ( $statement_type eq 'use' ) { $statement_type = '_use' }
Branch: 1 branch
BranchTrueFalseTotal
if ($statement_type eq "use") 6 3714 3720
3443 3720 return;
3444  
3445 } ## end sub do_COMMA
3446  
3447 sub do_SEMICOLON {
3448  
3449 2961 ▶ my $self = shift;
Subroutine do_SEMICOLON: called CC=4 SCAR=13.9
Pod undocumented
3450  
3451 # ';'
3452 2961 $context = UNKNOWN_CONTEXT;
3453 2961 $statement_type = EMPTY_STRING;
3454 2961 $want_paren = EMPTY_STRING;
3455  
3456 2961 ▶ if ( $is_for_foreach{ $rparen_type->[$paren_depth] } )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_for_foreach{$rparen_type->[$paren_depth]}) { } 35 2926 2961
3457 { # mark ; in for loop
3458  
3459 # Be careful: we do not want a semicolon such as the
3460 # following to be included:
3461 #
3462 # for (sort {strcoll($a,$b);} keys %investments) {
3463  
3464 35 ▶ if ( $brace_depth == $rdepth_array->[PAREN]->[BRACE]->[$paren_depth]
Branch: 1 branch
BranchTrueFalseTotal
if ($brace_depth == $rdepth_array->[2][0][$paren_depth] and $square_bracket_depth == $rdepth_array->[2][1][$paren_depth]) 34 1 35
Condition66%2/3
$brace_depth == $rdepth_array->[2][0][$paren_depth] and $square_bracket_depth == $rdepth_array->[2][1][$paren_depth]
!ll&&!rl&&r
1034
MC/DC50%1/2
$brace_depth == $rdepth_array->[2][0][$paren_depth] and $square_bracket_depth == $rdepth_array->[2][1][$paren_depth]
$brace_depth == $rdepth_array->[2][0][$paren_depth] $square_bracket_depth == $rdepth_array->[2][1][$paren_depth]
Truth table66%2/3
A and B
A= $brace_depth == $rdepth_array->[2][0][$paren_depth]B= $square_bracket_depth == $rdepth_array->[2][1][$paren_depth]
ABresult
0X0
100
111
3465 && $square_bracket_depth ==
3466 $rdepth_array->[PAREN]->[SQUARE_BRACKET]->[$paren_depth] )
3467 {
3468  
3469 34 $type = 'f';
3470 34 $rparen_semicolon_count->[$paren_depth]++;
3471 }
3472 }
3473 else {
3474 ## Error check added in update c565, moved to end of $code loop.
3475 }
3476 2961 return;
3477 } ## end sub do_SEMICOLON
3478  
3479 sub do_QUOTATION_MARK {
3480  
3481 1297 ▶ my $self = shift;
Subroutine do_QUOTATION_MARK: called CC=2 SCAR=7.0
Pod undocumented
3482  
3483 # '"'
3484 1297 ▶ $self->error_if_expecting_OPERATOR("String")
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 1297 1297
3485 if ( $expecting == OPERATOR );
3486 1297 $in_quote = 1;
3487 1297 $type = 'Q';
3488 1297 $allowed_quote_modifiers = EMPTY_STRING;
3489 1297 $quote_starting_tok = $tok;
3490 1297 $quote_here_target_2 = undef;
3491 1297 return;
3492 } ## end sub do_QUOTATION_MARK
3493  
3494 sub do_APOSTROPHE {
3495  
3496 1349 ▶ my $self = shift;
Subroutine do_APOSTROPHE: called CC=2 SCAR=7.0
Pod undocumented
3497  
3498 # "'"
3499 1349 ▶ $self->error_if_expecting_OPERATOR("String")
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 1349 1349
3500 if ( $expecting == OPERATOR );
3501 1349 $in_quote = 1;
3502 1349 $type = 'Q';
3503 1349 $allowed_quote_modifiers = EMPTY_STRING;
3504 1349 $quote_starting_tok = $tok;
3505 1349 $quote_here_target_2 = undef;
3506 1349 return;
3507 } ## end sub do_APOSTROPHE
3508  
3509 sub do_BACKTICK {
3510  
3511 0 ▶ my $self = shift;
Subroutine do_BACKTICK: not called CC=2 SCAR=17.9
Pod undocumented
3512  
3513 # '`'
3514 0 ▶ $self->error_if_expecting_OPERATOR("String")
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 0 0
3515 if ( $expecting == OPERATOR );
3516 0 $in_quote = 1;
3517 0 $type = 'Q';
3518 0 $allowed_quote_modifiers = EMPTY_STRING;
3519 0 $quote_starting_tok = $tok;
3520 0 $quote_here_target_2 = undef;
3521 0 return;
3522 } ## end sub do_BACKTICK
3523  
3524 sub do_SLASH {
3525  
3526 225 ▶ my $self = shift;
Subroutine do_SLASH: called CC=7 SCAR=21.6
Pod undocumented
3527  
3528 # '/'
3529 225 my $is_pattern;
3530  
3531 # a pattern cannot follow certain keywords which take optional
3532 # arguments, like 'shift' and 'pop'. See also '?'.
3533 225 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($last_nonblank_type eq 'k' and $is_keyword_rejecting_slash_as_pattern_delimiter{$last_nonblank_token}) { } 0 225 225
elsif ($expecting == 0) { } 0 225 225
Condition66%2/3
$last_nonblank_type eq "k" and $is_keyword_rejecting_slash_as_pattern_delimiter{$last_nonblank_token}
!ll&&!rl&&r
213120
MC/DC0%0/2
$last_nonblank_type eq "k" and $is_keyword_rejecting_slash_as_pattern_delimiter{$last_nonblank_token}
$last_nonblank_type eq "k" $is_keyword_rejecting_slash_as_pattern_delimiter{$last_nonblank_token}
Truth table66%2/3
A and B
A= $last_nonblank_type eq "k"B= $is_keyword_rejecting_slash_as_pattern_delimiter{$last_nonblank_token}
ABresult
0X0
100
111
3534 $last_nonblank_type eq 'k'
3535 && $is_keyword_rejecting_slash_as_pattern_delimiter{
3536 $last_nonblank_token}
3537 )
3538 {
3539 0 $is_pattern = 0;
3540 }
3541 elsif ( $expecting == UNKNOWN ) { # indeterminate, must guess..
3542 (
3543 0 $is_pattern,
3544 my $msg,
3545  
3546 ) = $self->guess_if_pattern_or_division(
3547  
3548 $i,
3549 $rtokens,
3550 $rtoken_type,
3551 $rtoken_map,
3552 $max_token_index,
3553 );
3554  
3555 0 ▶ if ($msg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg) 0 0 0
3556 0 if ( 0 && DEBUG_GUESS_MODE ) {
3557 $self->warning("DEBUG_GUESS_MODE message:\n$msg\n");
3558 }
3559 0 $self->write_diagnostics("DIVIDE:$msg\n");
3560 0 $self->write_logfile_entry($msg);
3561 }
3562 }
3563 else {
3564 225 $is_pattern = ( $expecting == TERM );
3565 }
3566  
3567 225 ▶ if ($is_pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_pattern) { } 88 137 225
3568 88 $in_quote = 1;
3569 88 $type = 'Q';
3570 88 $allowed_quote_modifiers = $quote_modifiers{'m'};
3571 88 $quote_starting_tok = 'm';
3572 88 $quote_here_target_2 = undef;
3573 }
3574 else { # not a pattern; check for a /= token
3575  
3576 137 ▶ if ( $rtokens->[ $i + 1 ] eq '=' ) { # form token /=
Branch: 1 branch
BranchTrueFalseTotal
if ($$rtokens[$i + 1] eq "=") 4 133 137
3577 4 $i++;
3578 4 $tok = '/=';
3579 4 $type = $tok;
3580 }
3581  
3582 #DEBUG - collecting info on what tokens follow a divide
3583 # for development of guessing algorithm
3584 ## if (
3585 ## $self->is_possible_numerator( $i, $rtokens,
3586 ## $max_token_index ) < 0
3587 ## )
3588 ## {
3589 ## $self->write_diagnostics("DIVIDE? $input_line\n");
3590 ## }
3591 }
3592 225 return;
3593 } ## end sub do_SLASH
3594  
3595 sub do_LEFT_CURLY_BRACKET {
3596  
3597 2082 ▶ my $self = shift;
Subroutine do_LEFT_CURLY_BRACKET: called CC=40 SCAR=46.7
Pod undocumented
3598  
3599 # '{'
3600 2082 if ( 0 && $next_tok eq '%' ) {
3601 ## c583: Spot for possible future check for a '{% ' which starts
3602 ## a simple macro. If there is a matching closing '%}' on this
3603 ## line then mark the whole structure as a quote.
3604 }
3605  
3606 # if we just saw a ')', we will label this block with
3607 # its type. We need to do this to allow sub
3608 # code_block_type to determine if this brace starts a
3609 # code block or anonymous hash. (The type of a paren
3610 # pair is the preceding token, such as 'if', 'else',
3611 # etc).
3612 2082 $container_type = EMPTY_STRING;
3613  
3614 # ATTRS: for a '{' following an attribute list, reset
3615 # things to look like we just saw a sub name
3616 # Added 'package' (can be 'class') for --use-feature=class (rt145706)
3617 2082 ▶ if ( substr( $statement_type, 0, 3 ) eq 'sub' ) {
Branch: 5 branches
BranchTrueFalseTotal
if (substr($statement_type, 0, 3) eq 'sub') { } 36 2046 2082
elsif (substr($statement_type, 0, 7) eq 'package') { } 10 2036 2046
elsif ($statement_type eq 'case' || $statement_type eq 'when' and $statement_type eq $last_nonblank_token) { } 0 2036 2036
elsif ($last_nonblank_token eq ')') { } 301 1735 2036
elsif ($last_nonblank_token eq 'qw' and $is_for_foreach{$want_paren}) { } 0 1735 1735
3618 36 $last_nonblank_token = $statement_type;
3619 36 $last_nonblank_type = 'S'; # c250 change
3620 36 $statement_type = EMPTY_STRING;
3621 }
3622 elsif ( substr( $statement_type, 0, 7 ) eq 'package' ) {
3623 10 $last_nonblank_token = $statement_type;
3624 10 $last_nonblank_type = 'P'; # c250 change
3625 10 $statement_type = EMPTY_STRING;
3626 }
3627  
3628 # patch for SWITCH/CASE: hide these keywords from an immediately
3629 # following opening brace
3630 ▶ elsif ( ( $statement_type eq 'case' || $statement_type eq 'when' )
Condition83%5/6
$statement_type eq "case" || $statement_type eq "when" and $statement_type eq $last_nonblank_token
!ll&&!rl&&r
1988480
$statement_type eq "case" or $statement_type eq "when"
l!l&&r!l&&!r
4351988
MC/DC0%0/3
$statement_type eq "case" || $statement_type eq "when" and $statement_type eq $last_nonblank_token
$statement_type eq "case" $statement_type eq "when" $statement_type eq $last_nonblank_token
Truth table60%3/5
A or B and C
A= $statement_type eq "case"B= $statement_type eq "when"C= $statement_type eq $last_nonblank_token
ABCresult
00X0
1X00
0100
1X11
0111
3631 && $statement_type eq $last_nonblank_token )
3632 {
3633 0 $last_nonblank_token = ";";
3634 }
3635  
3636 elsif ( $last_nonblank_token eq ')' ) {
3637 301 $last_nonblank_token = $rparen_type->[ $paren_depth + 1 ];
3638  
3639 # defensive move in case of a nesting error (pbug.t)
3640 # in which this ')' had no previous '('
3641 # this nesting error will have been caught
3642 301 ▶ if ( !defined($last_nonblank_token) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $last_nonblank_token) 0 301 301
3643 0 $last_nonblank_token = 'if';
3644 }
3645  
3646 # Syntax check at '){'
3647 301 ▶ if ( $is_blocktype_with_paren{$last_nonblank_token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_blocktype_with_paren{$last_nonblank_token}) { } 285 16 301
3648  
3649 285 my $rvars = $rparen_vars->[ $paren_depth + 1 ];
3650 285 ▶ if ( defined($rvars) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rvars) 285 0 285
3651 285 my ( $type_lp_uu, $want_brace ) = @{$rvars};
3652  
3653 # OLD: Now verify that this is not a trailing form
3654 # FIX for git #124: we have to skip this check because
3655 # the 'gather' keyword of List::Gather can operate on
3656 # a full statement, so it isn't possible to be sure
3657 # this is a trailing form.
3658 285 if ( 0 && !$want_brace ) {
3659 $self->warning(
3660 "syntax error at ') {', unexpected '{' after closing ')' of a trailing '$last_nonblank_token'\n"
3661 );
3662 }
3663 }
3664 }
3665 else {
3666 16 ▶ if ($rOpts_extended_syntax) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rOpts_extended_syntax) { } 16 0 16
3667  
3668 # we append a trailing () to mark this as an unknown
3669 # block type. This allows perltidy to format some
3670 # common extensions of perl syntax.
3671 # This is used by sub code_block_type
3672 16 $last_nonblank_token .= '()';
3673 }
3674 else {
3675 0 my $list =
3676 join( SPACE, sort keys %is_blocktype_with_paren );
3677 0 $self->warning(
3678 "syntax error at ') {', didn't see one of: <<$list>>; If this code is okay try using the -xs flag\n"
3679 );
3680 }
3681 }
3682 }
3683  
3684 # patch for paren-less for/foreach glitch, part 2.
3685 # see note below under 'qw'
3686 ▶ elsif ($last_nonblank_token eq 'qw'
Condition33%1/3
$last_nonblank_token eq "qw" and $is_for_foreach{$want_paren}
!ll&&!rl&&r
173500
MC/DC0%0/2
$last_nonblank_token eq "qw" and $is_for_foreach{$want_paren}
$last_nonblank_token eq "qw" $is_for_foreach{$want_paren}
Truth table33%1/3
A and B
A= $last_nonblank_token eq "qw"B= $is_for_foreach{$want_paren}
ABresult
0X0
100
111
3687 && $is_for_foreach{$want_paren} )
3688 {
3689 0 $last_nonblank_token = $want_paren;
3690 0 ▶ if ( $last_last_nonblank_token eq $want_paren ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_last_nonblank_token eq $want_paren) 0 0 0
3691 0 $self->warning(
3692 "syntax error at '$want_paren .. {' -- missing \$ loop variable\n"
3693 );
3694  
3695 }
3696 0 $want_paren = EMPTY_STRING;
3697 }
3698 else {
3699 ## not special
3700 }
3701  
3702 # now identify which of the three possible types of
3703 # curly braces we have: hash index container, anonymous
3704 # hash reference, or code block.
3705  
3706 # Patch for Object::Pad "field $var BLOCK"
3707 2082 ▶ if ( $statement_type eq 'field'
Branch: 2 branches
BranchTrueFalseTotal
if ($statement_type eq 'field' and $last_last_nonblank_token eq 'field' and $last_nonblank_type eq 'i' and $last_last_nonblank_type eq 'k') { } 8 2074 2082
elsif (is_non_structural_brace()) { } 588 1486 2074
Condition66%6/9
$statement_type eq "field" and $last_last_nonblank_token eq "field" and $last_nonblank_type eq "i" and $last_last_nonblank_type eq "k"
!ll&&!rl&&r
207408
$statement_type eq "field" and $last_last_nonblank_token eq "field" and $last_nonblank_type eq "i"
!ll&&!rl&&r
207408
$statement_type eq "field" and $last_last_nonblank_token eq "field"
!ll&&!rl&&r
207408
MC/DC25%1/4
$statement_type eq "field" and $last_last_nonblank_token eq "field" and $last_nonblank_type eq "i" and $last_last_nonblank_type eq "k"
$statement_type eq "field" $last_last_nonblank_token eq "field" $last_nonblank_type eq "i" $last_last_nonblank_type eq "k"
Truth table40%2/5
A and B and C and D
A= $statement_type eq "field"B= $last_last_nonblank_token eq "field"C= $last_nonblank_type eq "i"D= $last_last_nonblank_type eq "k"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
3708 && $last_last_nonblank_token eq 'field'
3709 && $last_nonblank_type eq 'i'
3710 && $last_last_nonblank_type eq 'k' )
3711 {
3712 8 $type = '{';
3713 8 $block_type = $statement_type;
3714 }
3715  
3716 # non-structural (hash index) curly brace pair
3717 # get marked 'L' and 'R'
3718 elsif ( is_non_structural_brace() ) {
3719 588 $type = 'L';
3720  
3721 # patch for SWITCH/CASE:
3722 # allow paren-less identifier after 'when'
3723 # if the brace is preceded by a space
3724 588 ▶ if ( $statement_type eq 'when'
Branch: 1 branch
BranchTrueFalseTotal
if ($statement_type eq "when" and $last_nonblank_type eq "i" and $last_last_nonblank_type eq "k" and $i_tok == 0 || $$rtoken_type[$i_tok - 1] eq "b") 0 588 588
Condition25%3/12
$statement_type eq "when" and $last_nonblank_type eq "i" and $last_last_nonblank_type eq "k" and $i_tok == 0 || $$rtoken_type[$i_tok - 1] eq "b"
!ll&&!rl&&r
58800
$statement_type eq "when" and $last_nonblank_type eq "i" and $last_last_nonblank_type eq "k"
!ll&&!rl&&r
58800
$statement_type eq "when" and $last_nonblank_type eq "i"
!ll&&!rl&&r
58800
$i_tok == 0 or $$rtoken_type[$i_tok - 1] eq "b"
l!l&&r!l&&!r
000
MC/DC0%0/5
$statement_type eq "when" and $last_nonblank_type eq "i" and $last_last_nonblank_type eq "k" and $i_tok == 0 || $$rtoken_type[$i_tok - 1] eq "b"
$statement_type eq "when" $last_nonblank_type eq "i" $last_last_nonblank_type eq "k" $i_tok == 0 $$rtoken_type[$i_tok - 1] eq "b"
Truth table16%1/6
A and B and C and D or E
A= $statement_type eq "when"B= $last_nonblank_type eq "i"C= $last_last_nonblank_type eq "k"D= $i_tok == 0E= $$rtoken_type[$i_tok - 1] eq "b"
ABCDEresult
0XXXX0
10XXX0
110XX0
111000
1111X1
111011
3725 && $last_nonblank_type eq 'i'
3726 && $last_last_nonblank_type eq 'k'
3727 && ( $i_tok == 0 || $rtoken_type->[ $i_tok - 1 ] eq 'b' ) )
3728 {
3729 0 $type = '{';
3730 0 $block_type = $statement_type;
3731 }
3732 }
3733  
3734 # code and anonymous hash have the same type, '{', but are
3735 # distinguished by 'block_type',
3736 # which will be blank for an anonymous hash
3737 else {
3738 1486 $block_type =
3739 $self->code_block_type( $i_tok, $rtokens, $rtoken_type,
3740 $max_token_index );
3741  
3742 # Is a new lexical sub looking for its block sequence number?
3743 # This is indicated with a special '911' signal.
3744 1486 ▶ if ( $block_type
Branch: 1 branch
BranchTrueFalseTotal
if ($block_type and $ris_lexical_sub->{911} and $last_nonblank_type eq "S" and substr($block_type, 0, 3) eq "sub") 0 1486 1486
Condition44%4/9
$block_type and $ris_lexical_sub->{911} and $last_nonblank_type eq "S" and substr($block_type, 0, 3) eq "sub"
!ll&&!rl&&r
148600
$block_type and $ris_lexical_sub->{911} and $last_nonblank_type eq "S"
!ll&&!rl&&r
148600
$block_type and $ris_lexical_sub->{911}
!ll&&!rl&&r
34111450
MC/DC0%0/4
$block_type and $ris_lexical_sub->{911} and $last_nonblank_type eq "S" and substr($block_type, 0, 3) eq "sub"
$block_type $ris_lexical_sub->{911} $last_nonblank_type eq "S" substr($block_type, 0, 3) eq "sub"
Truth table40%2/5
A and B and C and D
A= $block_typeB= $ris_lexical_sub->{911}C= $last_nonblank_type eq "S"D= substr($block_type, 0, 3) eq "sub"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
3745 && $ris_lexical_sub->{911}
3746 && $last_nonblank_type eq 'S'
3747 && substr( $block_type, 0, 3 ) eq 'sub' )
3748 {
3749 0 my ( $subname, $package ) = @{ $ris_lexical_sub->{911} };
3750 0 ▶ if ( $block_type =~ /^sub $subname/
Branch: 1 branch
BranchTrueFalseTotal
if ($block_type =~ /^sub $subname/ and $is_my_our_state{$last_last_nonblank_token}) 0 0 0
Condition0%0/3
$block_type =~ /^sub $subname/ and $is_my_our_state{$last_last_nonblank_token}
!ll&&!rl&&r
000
MC/DC0%0/2
$block_type =~ /^sub $subname/ and $is_my_our_state{$last_last_nonblank_token}
$block_type =~ /^sub $subname/ $is_my_our_state{$last_last_nonblank_token}
Truth table0%0/3
A and B
A= $block_type =~ /^sub $subname/B= $is_my_our_state{$last_last_nonblank_token}
ABresult
0X0
100
111
3751 && $is_my_our_state{$last_last_nonblank_token} )
3752 {
3753 0 $ris_lexical_sub->{$subname}->{$package} =
3754 $next_sequence_number;
3755 }
3756  
3757 # Turn the signal off, even if we did not find the block being
3758 # sought - it may not exist if the sub statement was a simple
3759 # declaration without a block definition.
3760 0 $ris_lexical_sub->{911} = undef;
3761 }
3762  
3763 # patch to promote bareword type to function taking block
3764 1486 ▶ if ( $block_type
Branch: 1 branch
BranchTrueFalseTotal
if ($block_type and $last_nonblank_type eq "w" and $last_nonblank_i >= 0) 36 1450 1486
Condition83%5/6
$block_type and $last_nonblank_type eq "w" and $last_nonblank_i >= 0
!ll&&!rl&&r
1450036
$block_type and $last_nonblank_type eq "w"
!ll&&!rl&&r
341110936
MC/DC66%2/3
$block_type and $last_nonblank_type eq "w" and $last_nonblank_i >= 0
$block_type $last_nonblank_type eq "w" $last_nonblank_i >= 0
Truth table75%3/4
A and B and C
A= $block_typeB= $last_nonblank_type eq "w"C= $last_nonblank_i >= 0
ABCresult
0XX0
10X0
1100
1111
3765 && $last_nonblank_type eq 'w'
3766 && $last_nonblank_i >= 0 )
3767 {
3768 36 ▶ if ( $routput_token_type->[$last_nonblank_i] eq 'w' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($routput_token_type->[$last_nonblank_i] eq "w") 36 0 36
3769 $routput_token_type->[$last_nonblank_i] =
3770 36 ▶ $is_grep_alias{$block_type} ? 'k' : 'G';
Branch: 1 branch
BranchTrueFalseTotal
$is_grep_alias{$block_type} ? : 5 31 36
3771 }
3772 }
3773  
3774 # patch for SWITCH/CASE: if we find a stray opening block brace
3775 # where we might accept a 'case' or 'when' block, then take it
3776 1486 ▶ if ( $statement_type eq 'case'
Branch: 1 branch
BranchTrueFalseTotal
if ($statement_type eq "case" or $statement_type eq "when") 48 1438 1486
Condition100%3/3
$statement_type eq "case" or $statement_type eq "when"
l!l&&r!l&&!r
4351438
MC/DC100%2/2
$statement_type eq "case" or $statement_type eq "when"
$statement_type eq "case" $statement_type eq "when"
Truth table100%3/3
A or B
A= $statement_type eq "case"B= $statement_type eq "when"
ABresult
1X1
011
000
3777 || $statement_type eq 'when' )
3778 {
3779 48 ▶ if ( !$block_type || $block_type eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $block_type or $block_type eq "}") 4 44 48
Condition66%2/3
not $block_type or $block_type eq "}"
l!l&&r!l&&!r
4044
MC/DC50%1/2
not $block_type or $block_type eq "}"
not $block_type $block_type eq "}"
Truth table66%2/3
not(A) or B
A= not $block_typeB= $block_type eq "}"
ABresult
1X1
011
000
3780 4 $block_type = $statement_type;
3781 }
3782 }
3783 }
3784  
3785 2082 $rbrace_type->[ ++$brace_depth ] = $block_type;
3786  
3787 # Patch for CLASS BLOCK definitions: do not update the package for the
3788 # current depth if this is a BLOCK type definition.
3789 # TODO: should make 'class' separate from 'package' and only do
3790 # this for 'class'
3791 2082 ▶ $rbrace_package->[$brace_depth] = $current_package
Branch: 1 branch
BranchTrueFalseTotal
if substr($block_type, 0, 8) ne "package " 2072 10 2082
3792 if ( substr( $block_type, 0, 8 ) ne 'package ' );
3793  
3794 2082 $rbrace_structural_type->[$brace_depth] = $type;
3795 2082 $rbrace_context->[$brace_depth] = $context;
3796 2082 ( $type_sequence, $indent_flag ) =
3797 $self->increase_nesting_depth( BRACE, $rtoken_map->[$i_tok] );
3798  
3799 2082 return;
3800 } ## end sub do_LEFT_CURLY_BRACKET
3801  
3802 sub do_RIGHT_CURLY_BRACKET {
3803  
3804 2082 ▶ my $self = shift;
Subroutine do_RIGHT_CURLY_BRACKET: called CC=11 SCAR=24.0
Pod undocumented
3805  
3806 # '}'
3807 2082 $block_type = $rbrace_type->[$brace_depth];
3808 2082 ▶ if ($block_type) { $statement_type = EMPTY_STRING }
Branch: 1 branch
BranchTrueFalseTotal
if ($block_type) 1157 925 2082
3809 2082 ▶ if ( defined( $rbrace_package->[$brace_depth] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rbrace_package->[$brace_depth]) { } 2072 10 2082
3810 2072 $current_package = $rbrace_package->[$brace_depth];
3811 }
3812 else {
3813 ## can happen on brace error (caught elsewhere)
3814 }
3815 2082 ( $type_sequence, $indent_flag ) =
3816 $self->decrease_nesting_depth( BRACE, $rtoken_map->[$i_tok] );
3817  
3818 2082 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) 952 1130 2082
3819 $self->error_if_expecting_TERM()
3820 if (
3821 952 ▶ !$self->[_rsaw_unknown_syntax_in_seqno_]->{$type_sequence}
Branch: 1 branch
BranchTrueFalseTotal
if not $self->[56]{$type_sequence} and $last_nonblank_type ne "%" 950 2 952
Condition66%2/3
not $self->[56]{$type_sequence} and $last_nonblank_type ne "%"
!ll&&!rl&&r
20950
MC/DC50%1/2
not $self->[56]{$type_sequence} and $last_nonblank_type ne "%"
not $self->[56]{$type_sequence} $last_nonblank_type ne "%"
Truth table66%2/3
not(A) and B
A= not $self->[56]{$type_sequence}B= $last_nonblank_type ne "%"
ABresult
0X0
100
111
3822  
3823 # c583: no error check at a possible end-of-macro combo '%}'
3824 && $last_nonblank_type ne '%'
3825 );
3826 }
3827  
3828 2082 ▶ if ( $rbrace_structural_type->[$brace_depth] eq 'L' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rbrace_structural_type->[$brace_depth] eq "L") 588 1494 2082
3829 588 $type = 'R';
3830 }
3831  
3832 # propagate type information for 'do' and 'eval' blocks, and also
3833 # for smartmatch operator. This is necessary to enable us to know
3834 # if an operator or term is expected next.
3835 2082 ▶ if ( $is_block_operator{$block_type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_block_operator{$block_type}) 88 1994 2082
3836 88 $tok = $block_type;
3837 }
3838  
3839 # pop non-indenting brace stack if sequence number matches
3840 2082 ▶ if ( @{ $self->[_rnon_indenting_brace_stack_] }
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->[53];} and $self->[53][-1] eq $type_sequence) 6 2076 2082
Condition100%3/3
@{$self->[53];} and $self->[53][-1] eq $type_sequence
!ll&&!rl&&r
207426
MC/DC100%2/2
@{$self->[53];} and $self->[53][-1] eq $type_sequence
@{$self->[53];} $self->[53][-1] eq $type_sequence
Truth table100%3/3
A and B
A= @{$self->[53];}B= $self->[53][-1] eq $type_sequence
ABresult
0X0
100
111
3841 && $self->[_rnon_indenting_brace_stack_]->[-1] eq $type_sequence )
3842 {
3843 6 pop @{ $self->[_rnon_indenting_brace_stack_] };
3844 }
3845  
3846 2082 $context = $rbrace_context->[$brace_depth];
3847 2082 ▶ if ( $brace_depth > 0 ) { $brace_depth--; }
Branch: 1 branch
BranchTrueFalseTotal
if ($brace_depth > 0) 2082 0 2082
3848 2082 return;
3849 } ## end sub do_RIGHT_CURLY_BRACKET
3850  
3851 sub do_AMPERSAND {
3852  
3853 126 ▶ my $self = shift;
Subroutine do_AMPERSAND: called CC=4 SCAR=13.9
Pod undocumented
3854  
3855 # '&' = maybe sub call? start looking
3856 # We have to check for sub call unless we are sure we
3857 # are expecting an operator. This example from s2p
3858 # got mistaken as a q operator in an early version:
3859 # print BODY &q(<<'EOT');
3860 126 ▶ if ( $expecting != OPERATOR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting != 1) { } 106 20 126
3861  
3862 # But only look for a sub call if we are expecting a term or
3863 # if there is no existing space after the &.
3864 # For example we probably don't want & as sub call here:
3865 # Fcntl::S_IRUSR & $mode;
3866 106 ▶ if ( $expecting == TERM || $next_type ne 'b' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1 or $next_type ne "b") 103 3 106
Condition66%2/3
$expecting == -1 or $next_type ne "b"
l!l&&r!l&&!r
10303
MC/DC50%1/2
$expecting == -1 or $next_type ne "b"
$expecting == -1 $next_type ne "b"
Truth table66%2/3
A or B
A= $expecting == -1B= $next_type ne "b"
ABresult
1X1
011
000
3867 103 $self->scan_simple_identifier();
3868 }
3869 }
3870 else {
3871 ## '&' is an operator
3872 }
3873 126 return;
3874 } ## end sub do_AMPERSAND
3875  
3876 sub do_LESS_THAN_SIGN {
3877  
3878 33 ▶ my $self = shift;
Subroutine do_LESS_THAN_SIGN: called CC=2 SCAR=6.9
Pod undocumented
3879  
3880 # '<' - angle operator or less than?
3881 33 ▶ if ( $expecting != OPERATOR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting != 1) { } 8 25 33
3882 8 ( $i, $type ) = $self->find_angle_operator_termination(
3883  
3884 $input_line,
3885 $i,
3886 $rtoken_map,
3887 $expecting,
3888 $max_token_index,
3889 );
3890 8 if ( DEBUG_GUESS_MODE && $expecting == UNKNOWN ) {
3891 my $msg = "guessing that '<' is ";
3892 $msg .=
3893 $type eq 'Q' ? "an angle operator" : "a less than symbol";
3894 if ( $type eq 'Q' ) {
3895 $self->warning("DEBUG_GUESS_MODE message:\n$msg\n");
3896 }
3897 }
3898 }
3899 else {
3900 ## ok: '<' is less than
3901 }
3902 33 return;
3903 } ## end sub do_LESS_THAN_SIGN
3904  
3905 sub do_QUESTION_MARK {
3906  
3907 193 ▶ my $self = shift;
Subroutine do_QUESTION_MARK: called CC=7 SCAR=20.6
Pod undocumented
3908  
3909 # '?' = conditional or starting pattern?
3910 193 my $is_pattern;
3911  
3912 # Patch for rt #126965
3913 # a pattern cannot follow certain keywords which take optional
3914 # arguments, like 'shift' and 'pop'. See also '/'.
3915 193 ▶ if (
Branch: 3 branches
BranchTrueFalseTotal
if ($last_nonblank_type eq 'k' and $is_keyword_rejecting_question_as_pattern_delimiter{$last_nonblank_token}) { } 1 192 193
elsif ($last_nonblank_type =~ /^[FUY]$/) { } 1 191 192
elsif ($expecting == 0) { } 12 179 191
Condition66%2/3
$last_nonblank_type eq "k" and $is_keyword_rejecting_question_as_pattern_delimiter{$last_nonblank_token}
!ll&&!rl&&r
19201
MC/DC50%1/2
$last_nonblank_type eq "k" and $is_keyword_rejecting_question_as_pattern_delimiter{$last_nonblank_token}
$last_nonblank_type eq "k" $is_keyword_rejecting_question_as_pattern_delimiter{$last_nonblank_token}
Truth table66%2/3
A and B
A= $last_nonblank_type eq "k"B= $is_keyword_rejecting_question_as_pattern_delimiter{$last_nonblank_token}
ABresult
0X0
100
111
3916 $last_nonblank_type eq 'k'
3917 && $is_keyword_rejecting_question_as_pattern_delimiter{
3918 $last_nonblank_token}
3919 )
3920 {
3921 1 $is_pattern = 0;
3922 }
3923  
3924 # patch for RT#131288, user constant function without prototype
3925 # last type is 'U' followed by ?.
3926 elsif ( $last_nonblank_type =~ /^[FUY]$/ ) {
3927 1 $is_pattern = 0;
3928 }
3929 elsif ( $expecting == UNKNOWN ) {
3930  
3931 # In older versions of Perl, a bare ? can be a pattern
3932 # delimiter. In perl version 5.22 this was
3933 # dropped, but we have to support it in order to format
3934 # older programs. See:
3935 ## https://perl.developpez.com/documentations/en/5.22.0/perl5211delta.html
3936 # For example, the following line worked
3937 # at one time:
3938 # ?(.*)? && (print $1,"\n");
3939 # In current versions it would have to be written with slashes:
3940 # /(.*)/ && (print $1,"\n");
3941 (
3942 12 $is_pattern,
3943 my $msg,
3944  
3945 ) = $self->guess_if_pattern_or_conditional(
3946  
3947 $i,
3948 $rtokens,
3949 $rtoken_type,
3950 $rtoken_map,
3951 $max_token_index,
3952 );
3953  
3954 12 ▶ if ($msg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg) 12 0 12
3955 12 $self->write_logfile_entry($msg);
3956 12 if ( DEBUG_GUESS_MODE && $is_pattern ) {
3957 $self->warning("DEBUG_GUESS_MODE message:\n$msg\n");
3958 }
3959 }
3960 }
3961 else {
3962 179 $is_pattern = ( $expecting == TERM );
3963 }
3964  
3965 193 ▶ if ($is_pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_pattern) { } 0 193 193
3966 0 $in_quote = 1;
3967 0 $type = 'Q';
3968 0 $allowed_quote_modifiers = $quote_modifiers{'m'};
3969 0 $quote_starting_tok = 'm';
3970 0 $quote_here_target_2 = undef;
3971 }
3972 else {
3973 193 ( $type_sequence, $indent_flag ) =
3974 $self->increase_nesting_depth( QUESTION_COLON,
3975 $rtoken_map->[$i_tok] );
3976 }
3977 193 return;
3978 } ## end sub do_QUESTION_MARK
3979  
3980 sub do_STAR {
3981  
3982 254 ▶ my $self = shift;
Subroutine do_STAR: called CC=8 SCAR=20.8
Pod undocumented
3983  
3984 # '*' = typeglob, or multiply?
3985  
3986 # Guess based on next token. See also c036, and versions before 2026-
3987 254 ▶ if ( $expecting == UNKNOWN && $next_type ne 'b' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == 0 and $next_type ne "b") 6 248 254
Condition100%3/3
$expecting == 0 and $next_type ne "b"
!ll&&!rl&&r
24266
MC/DC100%2/2
$expecting == 0 and $next_type ne "b"
$expecting == 0 $next_type ne "b"
Truth table100%3/3
A and B
A= $expecting == 0B= $next_type ne "b"
ABresult
0X0
100
111
3988  
3989 # Check for a normal glob, like *OUT:
3990 6 ▶ if ( $next_tok =~ /^[_A-Za-z]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_tok =~ /^[_A-Za-z]/) { } 0 6 6
3991 0 $expecting = TERM;
3992 }
3993 else {
3994 ## Could check for glob of a simple punctuation variable here
3995 ## by looking ahead one more character
3996 }
3997 }
3998  
3999 254 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) { } 21 233 254
4000 21 $self->scan_simple_identifier();
4001 }
4002 else {
4003  
4004 233 ▶ if ( $rtokens->[ $i + 1 ] eq '=' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$rtokens[$i + 1] eq '=') { } 2 231 233
elsif ($$rtokens[$i + 1] eq '*') { } 42 189 231
4005 2 $tok = '*=';
4006 2 $type = $tok;
4007 2 $i++;
4008 }
4009 elsif ( $rtokens->[ $i + 1 ] eq '*' ) {
4010 42 $tok = '**';
4011 42 $type = $tok;
4012 42 $i++;
4013 42 ▶ if ( $rtokens->[ $i + 1 ] eq '=' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$rtokens[$i + 1] eq "=") 2 40 42
4014 2 $tok = '**=';
4015 2 $type = $tok;
4016 2 $i++;
4017 }
4018 }
4019 else {
4020 ## not multiple characters
4021 }
4022 }
4023 254 return;
4024 } ## end sub do_STAR
4025  
4026 sub do_DOT {
4027  
4028 176 ▶ my $self = shift;
Subroutine do_DOT: called CC=2 SCAR=6.9
Pod undocumented
4029  
4030 # '.' = what kind of . ?
4031 176 ▶ if ( $expecting != OPERATOR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting != 1) 10 166 176
4032 10 $self->scan_number();
4033 }
4034 176 return;
4035 } ## end sub do_DOT
4036  
4037 sub do_COLON {
4038  
4039 285 ▶ my $self = shift;
Subroutine do_COLON: called CC=13 SCAR=26.6
Pod undocumented
4040  
4041 # ':' = label, ternary, attribute, ?
4042  
4043 # if this is the first nonblank character, call it a label
4044 # since perl seems to just swallow it
4045 285 ▶ if ( $input_line_number == 1 && $last_nonblank_i == -1 ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($input_line_number == 1 and $last_nonblank_i == -1) { } 0 285 285
elsif ($statement_type =~ /^(sub|package)\b/) { } 22 263 285
elsif ($rparen_type->[$paren_depth] =~ /^sub\b/ and not is_balanced_closing_container(3)) { } 1 262 263
elsif ($is_my_our_state{$statement_type} and $rcurrent_depth->[3] == 0) { } 17 245 262
elsif ($is_case_default{$statement_type} and not is_balanced_closing_container(3)) { } 46 199 245
elsif (not $rcurrent_depth->[3]) { } 6 193 199
Condition66%2/3
$input_line_number == 1 and $last_nonblank_i == -1
!ll&&!rl&&r
274110
MC/DC0%0/2
$input_line_number == 1 and $last_nonblank_i == -1
$input_line_number == 1 $last_nonblank_i == -1
Truth table66%2/3
A and B
A= $input_line_number == 1B= $last_nonblank_i == -1
ABresult
0X0
100
111
4046 0 $type = 'J';
4047 }
4048  
4049 # ATTRS: check for a ':' which introduces an attribute list
4050 # either after a 'sub' keyword or within a paren list
4051 # Added 'package' (can be 'class') for --use-feature=class (rt145706)
4052 elsif ( $statement_type =~ /^(sub|package)\b/ ) {
4053 22 $type = 'A';
4054 22 $self->[_in_attribute_list_] = 1;
4055 }
4056  
4057 # Within a signature, unless we are in a ternary. For example,
4058 # from 't/filter_example.t':
4059 # method foo4 ( $class: $bar ) { $class->bar($bar) }
4060 ▶ elsif ( $rparen_type->[$paren_depth] =~ /^sub\b/
Condition66%2/3
$rparen_type->[$paren_depth] =~ /^sub\b/ and not is_balanced_closing_container(3)
!ll&&!rl&&r
26201
MC/DC50%1/2
$rparen_type->[$paren_depth] =~ /^sub\b/ and not is_balanced_closing_container(3)
$rparen_type->[$paren_depth] =~ /^sub\b/ not is_balanced_closing_container(3)
Truth table66%2/3
A and not(B)
A= $rparen_type->[$paren_depth] =~ /^sub\b/B= not is_balanced_closing_container(3)
ABresult
0X0
100
111
4061 && !is_balanced_closing_container(QUESTION_COLON) )
4062 {
4063 1 $type = 'A';
4064 1 $self->[_in_attribute_list_] = 1;
4065 }
4066  
4067 # check for scalar attribute, such as
4068 # my $foo : shared = 1;
4069 ▶ elsif ($is_my_our_state{$statement_type}
Condition66%2/3
$is_my_our_state{$statement_type} and $rcurrent_depth->[3] == 0
!ll&&!rl&&r
245017
MC/DC50%1/2
$is_my_our_state{$statement_type} and $rcurrent_depth->[3] == 0
$is_my_our_state{$statement_type} $rcurrent_depth->[3] == 0
Truth table66%2/3
A and B
A= $is_my_our_state{$statement_type}B= $rcurrent_depth->[3] == 0
ABresult
0X0
100
111
4070 && $rcurrent_depth->[QUESTION_COLON] == 0 )
4071 {
4072 17 $type = 'A';
4073 17 $self->[_in_attribute_list_] = 1;
4074 }
4075  
4076 # Look for Switch::Plain syntax if an error would otherwise occur
4077 # here. Note that we do not need to check if the extended syntax
4078 # flag is set because otherwise an error would occur, and we would
4079 # then have to output a message telling the user to set the
4080 # extended syntax flag to avoid the error.
4081 # case 1: {
4082 # default: {
4083 # default:
4084 # Note that the line 'default:' will be parsed as a label elsewhere.
4085 ▶ elsif ( $is_case_default{$statement_type}
Condition66%2/3
$is_case_default{$statement_type} and not is_balanced_closing_container(3)
!ll&&!rl&&r
199046
MC/DC50%1/2
$is_case_default{$statement_type} and not is_balanced_closing_container(3)
$is_case_default{$statement_type} not is_balanced_closing_container(3)
Truth table66%2/3
A and not(B)
A= $is_case_default{$statement_type}B= not is_balanced_closing_container(3)
ABresult
0X0
100
111
4086 && !is_balanced_closing_container(QUESTION_COLON) )
4087 {
4088 # mark it as a perltidy label type
4089 46 $type = 'J';
4090 }
4091  
4092 # mark colon as attribute if an error would occur otherwise; git #162
4093 elsif ( !$rcurrent_depth->[QUESTION_COLON] ) {
4094 6 $type = 'A';
4095 6 $self->[_in_attribute_list_] = 1;
4096  
4097 # and set a flag to skip error messages
4098 6 my $seqno = $self->[_rseqno_at_depth_]->[$total_depth];
4099 6 ▶ $self->[_rsaw_unknown_syntax_in_seqno_]->{$seqno} = 1 if ($seqno);
Branch: 1 branch
BranchTrueFalseTotal
if $seqno 6 0 6
4100 }
4101  
4102 # otherwise, it should be part of a ?/: operator
4103 else {
4104 193 ( $type_sequence, $indent_flag ) =
4105 $self->decrease_nesting_depth( QUESTION_COLON,
4106 $rtoken_map->[$i_tok] );
4107 193 ▶ if ( $last_nonblank_token eq '?' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_token eq "?") 0 193 193
4108 0 $self->warning("Syntax error near ? :\n");
4109 }
4110 }
4111 285 return;
4112 } ## end sub do_COLON
4113  
4114 sub do_PLUS_SIGN {
4115  
4116 240 ▶ my $self = shift;
Subroutine do_PLUS_SIGN: called CC=6 SCAR=18.5
Pod undocumented
4117  
4118 # '+' = what kind of plus?
4119 240 ▶ if ( $expecting == TERM ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($expecting == -1) { } 14 226 240
elsif ($expecting == 1) { } 224 2 226
4120 14 my $number = $self->scan_number_fast();
4121  
4122 # unary plus is safest assumption if not a number
4123 14 ▶ if ( !defined($number) ) { $type = 'p'; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $number) 14 0 14
4124 }
4125 elsif ( $expecting == OPERATOR ) {
4126 }
4127 else {
4128 2 ▶ if ( $next_type eq 'w' || $next_type eq '{' ) { $type = 'p' }
Branch: 1 branch
BranchTrueFalseTotal
if ($next_type eq "w" or $next_type eq "{") 2 0 2
Condition33%1/3
$next_type eq "w" or $next_type eq "{"
l!l&&r!l&&!r
200
MC/DC0%0/2
$next_type eq "w" or $next_type eq "{"
$next_type eq "w" $next_type eq "{"
Truth table33%1/3
A or B
A= $next_type eq "w"B= $next_type eq "{"
ABresult
1X1
011
000
4129 }
4130 240 return;
4131 } ## end sub do_PLUS_SIGN
4132  
4133 sub do_AT_SIGN {
4134  
4135 530 ▶ my $self = shift;
Subroutine do_AT_SIGN: called CC=2 SCAR=7.0
Pod undocumented
4136  
4137 # '@' = sigil for array?
4138 530 ▶ $self->error_if_expecting_OPERATOR("Array")
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 530 530
4139 if ( $expecting == OPERATOR );
4140 530 $self->scan_simple_identifier();
4141 530 return;
4142 } ## end sub do_AT_SIGN
4143  
4144 sub do_PERCENT_SIGN {
4145  
4146 218 ▶ my $self = shift;
Subroutine do_PERCENT_SIGN: called CC=5 SCAR=20.9
Pod undocumented
4147  
4148 # '%' = hash or modulo?
4149 # first guess is hash if no following blank or paren
4150 218 ▶ if ( $expecting == UNKNOWN ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == 0) 0 218 218
4151 0 ▶ if ( $next_type ne 'b' && $next_type ne '(' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_type ne "b" and $next_type ne "(") 0 0 0
Condition0%0/3
$next_type ne "b" and $next_type ne "("
!ll&&!rl&&r
000
MC/DC0%0/2
$next_type ne "b" and $next_type ne "("
$next_type ne "b" $next_type ne "("
Truth table0%0/3
A and B
A= $next_type ne "b"B= $next_type ne "("
ABresult
0X0
100
111
4152 0 $expecting = TERM;
4153 }
4154 }
4155 218 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) 208 10 218
4156 208 $self->scan_simple_identifier();
4157 }
4158 218 return;
4159 } ## end sub do_PERCENT_SIGN
4160  
4161 sub do_LEFT_SQUARE_BRACKET {
4162  
4163 817 ▶ my $self = shift;
Subroutine do_LEFT_SQUARE_BRACKET: called CC=2 SCAR=6.9
Pod undocumented
4164  
4165 # '['
4166 817 $rsquare_bracket_type->[ ++$square_bracket_depth ] =
4167 $last_nonblank_token;
4168 817 ( $type_sequence, $indent_flag ) =
4169 $self->increase_nesting_depth( SQUARE_BRACKET,
4170 $rtoken_map->[$i_tok] );
4171  
4172 # It may seem odd, but structural square brackets have
4173 # type '{' and '}'. This simplifies the indentation logic.
4174 817 ▶ if ( !is_non_structural_brace() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_non_structural_brace()) 377 440 817
4175 377 $type = '{';
4176 }
4177 817 $rsquare_bracket_structural_type->[$square_bracket_depth] = $type;
4178 817 return;
4179 } ## end sub do_LEFT_SQUARE_BRACKET
4180  
4181 sub do_RIGHT_SQUARE_BRACKET {
4182  
4183 817 ▶ my $self = shift;
Subroutine do_RIGHT_SQUARE_BRACKET: called CC=6 SCAR=18.0
Pod undocumented
4184  
4185 # ']'
4186 817 ( $type_sequence, $indent_flag ) =
4187 $self->decrease_nesting_depth( SQUARE_BRACKET,
4188 $rtoken_map->[$i_tok] );
4189  
4190 817 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) 91 726 817
4191 $self->error_if_expecting_TERM()
4192 91 ▶ if ( !$self->[_rsaw_unknown_syntax_in_seqno_]->{$type_sequence} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->[56]{$type_sequence} 91 0 91
4193 }
4194  
4195 817 ▶ if ( $rsquare_bracket_structural_type->[$square_bracket_depth] eq '{' )
Branch: 1 branch
BranchTrueFalseTotal
if ($rsquare_bracket_structural_type->[$square_bracket_depth] eq "{") 377 440 817
4196 {
4197 377 $type = '}';
4198 }
4199  
4200 # propagate type information for smartmatch operator. This is
4201 # necessary to enable us to know if an operator or term is expected
4202 # next.
4203 817 ▶ if ( $rsquare_bracket_type->[$square_bracket_depth] eq '~~' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rsquare_bracket_type->[$square_bracket_depth] eq "~~") 20 797 817
4204 20 $tok = $rsquare_bracket_type->[$square_bracket_depth];
4205 }
4206  
4207 817 ▶ if ( $square_bracket_depth > 0 ) { $square_bracket_depth--; }
Branch: 1 branch
BranchTrueFalseTotal
if ($square_bracket_depth > 0) 817 0 817
4208 817 return;
4209 } ## end sub do_RIGHT_SQUARE_BRACKET
4210  
4211 sub do_MINUS_SIGN {
4212  
4213 491 ▶ my $self = shift;
Subroutine do_MINUS_SIGN: called CC=8 SCAR=20.9
Pod undocumented
4214  
4215 # '-' = what kind of minus?
4216 491 ▶ if ( ( $expecting != OPERATOR )
Branch: 3 branches
BranchTrueFalseTotal
if ($expecting != 1 and $is_file_test_operator{$next_tok}) { } 12 479 491
elsif ($expecting == -1) { } 378 101 479
elsif ($expecting == 1) { } 97 4 101
Condition100%3/3
$expecting != 1 and $is_file_test_operator{$next_tok}
!ll&&!rl&&r
9738212
MC/DC100%2/2
$expecting != 1 and $is_file_test_operator{$next_tok}
$expecting != 1 $is_file_test_operator{$next_tok}
Truth table100%3/3
A and B
A= $expecting != 1B= $is_file_test_operator{$next_tok}
ABresult
0X0
100
111
4217 && $is_file_test_operator{$next_tok} )
4218 {
4219 12 my ( $next_nonblank_token, $i_next_uu ) =
4220 $self->find_next_nonblank_token( $i + 1, $rtokens,
4221 $max_token_index );
4222  
4223 # check for a quoted word like "-w=>xx";
4224 # it is sufficient to just check for a following '='
4225 12 ▶ if ( $next_nonblank_token eq '=' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq '=') { } 0 12 12
4226 0 $type = 'm';
4227 }
4228 else {
4229 12 $i++;
4230 12 $tok .= $next_tok;
4231 12 $type = 'F';
4232 }
4233 }
4234 elsif ( $expecting == TERM ) {
4235 378 my $number = $self->scan_number_fast();
4236  
4237 # maybe part of bareword token? unary is safest
4238 378 ▶ if ( !defined($number) ) { $type = 'm'; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $number) 288 90 378
4239  
4240 }
4241 elsif ( $expecting == OPERATOR ) {
4242 }
4243 else {
4244 4 ▶ if ( $next_type eq 'w' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_type eq "w") 4 0 4
4245 4 $type = 'm';
4246 }
4247 }
4248 491 return;
4249 } ## end sub do_MINUS_SIGN
4250  
4251 sub do_CARAT_SIGN {
4252  
4253 12 ▶ my $self = shift;
Subroutine do_CARAT_SIGN: called CC=9 SCAR=25.4
Pod undocumented
4254  
4255 # '^'
4256 # check for special variables like ${^WARNING_BITS}
4257 12 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) 5 7 12
4258  
4259 5 ▶ if ( $last_nonblank_token eq '{'
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_token eq "{" and not $next_tok =~ /^\d/ and $next_tok =~ /^\w/) 5 0 5
Condition33%2/6
$last_nonblank_token eq "{" and not $next_tok =~ /^\d/ and $next_tok =~ /^\w/
!ll&&!rl&&r
005
$last_nonblank_token eq "{" and not $next_tok =~ /^\d/
!ll&&!rl&&r
005
MC/DC0%0/3
$last_nonblank_token eq "{" and not $next_tok =~ /^\d/ and $next_tok =~ /^\w/
$last_nonblank_token eq "{" not $next_tok =~ /^\d/ $next_tok =~ /^\w/
Truth table25%1/4
A and not(B) and C
A= $last_nonblank_token eq "{"B= not $next_tok =~ /^\d/C= $next_tok =~ /^\w/
ABCresult
0XX0
10X0
1100
1111
4260 && ( $next_tok !~ /^\d/ )
4261 && ( $next_tok =~ /^\w/ ) )
4262 {
4263  
4264 5 ▶ if ( $next_tok eq 'W' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_tok eq "W") 1 4 5
4265 1 $self->[_saw_perl_dash_w_] = 1;
4266 }
4267 5 $tok = $tok . $next_tok;
4268 5 $i = $i + 1;
4269 5 $type = 'w';
4270  
4271 # Optional coding to try to catch syntax errors. This can
4272 # be removed if it ever causes incorrect warning messages.
4273 # The '{^' should be preceded by either by a type or '$#'
4274 # Examples:
4275 # $#{^CAPTURE} ok
4276 # *${^LAST_FH}{NAME} ok
4277 # @{^HOWDY} ok
4278 # $hash{^HOWDY} error
4279  
4280 # Note that a type sigil '$' may be tokenized as 'Z'
4281 # after something like 'print', so allow type 'Z'
4282 5 ▶ if ( $last_last_nonblank_type ne 't'
Branch: 1 branch
BranchTrueFalseTotal
if ($last_last_nonblank_type ne "t" and $last_last_nonblank_type ne "Z" and $last_last_nonblank_token ne "\$#") 0 5 5
Condition33%2/6
$last_last_nonblank_type ne "t" and $last_last_nonblank_type ne "Z" and $last_last_nonblank_token ne "\$#"
!ll&&!rl&&r
500
$last_last_nonblank_type ne "t" and $last_last_nonblank_type ne "Z"
!ll&&!rl&&r
500
MC/DC0%0/3
$last_last_nonblank_type ne "t" and $last_last_nonblank_type ne "Z" and $last_last_nonblank_token ne "\$#"
$last_last_nonblank_type ne "t" $last_last_nonblank_type ne "Z" $last_last_nonblank_token ne "\$#"
Truth table25%1/4
A and B and C
A= $last_last_nonblank_type ne "t"B= $last_last_nonblank_type ne "Z"C= $last_last_nonblank_token ne "\$#"
ABCresult
0XX0
10X0
1100
1111
4283 && $last_last_nonblank_type ne 'Z'
4284 && $last_last_nonblank_token ne '$#' )
4285 {
4286 0 $self->warning("Possible syntax error near '{^'\n");
4287 }
4288 }
4289 }
4290 12 return;
4291 } ## end sub do_CARAT_SIGN
4292  
4293 sub do_DOUBLE_COLON {
4294  
4295 9 ▶ my $self = shift;
Subroutine do_DOUBLE_COLON: called CC=1 SCAR=0.0
Pod undocumented
4296  
4297 # '::' = probably a sub call
4298 9 $self->scan_bare_identifier();
4299 9 return;
4300 } ## end sub do_DOUBLE_COLON
4301  
4302 sub do_LEFT_SHIFT {
4303  
4304 25 ▶ my $self = shift;
Subroutine do_LEFT_SHIFT: called CC=9 SCAR=27.7
Pod undocumented
4305  
4306 # '<<' = maybe a here-doc?
4307 25 ▶ if ( $expecting != OPERATOR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting != 1) { } 25 0 25
4308 my (
4309 25 $found_target,
4310 $here_doc_target,
4311 $here_quote_character,
4312 $i_return,
4313 $saw_error,
4314  
4315 ) = $self->find_here_doc(
4316  
4317 $expecting,
4318 $i,
4319 $rtokens,
4320 $rtoken_type,
4321 $rtoken_map,
4322 $max_token_index,
4323 );
4324 25 $i = $i_return;
4325  
4326 25 ▶ if ($found_target) {
Branch: 2 branches
BranchTrueFalseTotal
if ($found_target) { } 23 2 25
elsif ($expecting == -1) { } 0 2 2
4327 23 push @{$rhere_target_list},
4328 [ $here_doc_target, $here_quote_character ];
4329 23 $type = 'h';
4330 23 ▶ if ( length($here_doc_target) > 80 ) {
Branch: 3 branches
BranchTrueFalseTotal
if (length $here_doc_target > 80) { } 0 23 23
elsif (not $here_doc_target) { } 0 23 23
elsif (not $here_doc_target =~ /^[A-Z_]\w+$/) { } 6 17 23
4331 0 my $truncated = substr( $here_doc_target, 0, 80 );
4332 0 $self->complain("Long here-target: '$truncated' ...\n");
4333 }
4334 elsif ( !$here_doc_target ) {
4335 0 ▶ $self->warning(
Branch: 1 branch
BranchTrueFalseTotal
unless $here_quote_character 0 0 0
4336 'Use of bare << to mean <<"" is deprecated' . "\n" )
4337 if ( !$here_quote_character );
4338 }
4339 elsif ( $here_doc_target !~ /^[A-Z_]\w+$/ ) {
4340 6 $self->complain(
4341 "Unconventional here-target: '$here_doc_target'\n");
4342 }
4343 else {
4344 ## nothing to complain about
4345 }
4346 }
4347 elsif ( $expecting == TERM ) {
4348 0 ▶ if ( !$saw_error ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($saw_error) 0 0 0
4349  
4350 # shouldn't happen..arriving here implies an error in
4351 # the logic in sub 'find_here_doc'
4352 0 if (DEVEL_MODE) {
4353 Fault(<<EOM);
4354 Program bug; didn't find here doc target
4355 EOM
4356 }
4357 $self->warning(
4358 0 "Possible program error: didn't find here doc target\n"
4359 );
4360 0 $self->report_definite_bug();
4361 }
4362 }
4363  
4364 # target not found, expecting == UNKNOWN
4365 else {
4366 ## assume it is a shift
4367 }
4368 }
4369 else {
4370 ## '<<' is shift
4371 }
4372 25 return;
4373 } ## end sub do_LEFT_SHIFT
4374  
4375 sub do_NEW_HERE_DOC {
4376  
4377 # '<<~' = a here-doc, new type added in v26
4378  
4379 14 ▶ my $self = shift;
Subroutine do_NEW_HERE_DOC: called CC=8 SCAR=28.2
Pod undocumented
4380  
4381 return
4382 14 ▶ if ( $i >= $max_token_index ); # here-doc not possible if end of line
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $max_token_index 0 14 14
4383 14 ▶ if ( $expecting != OPERATOR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting != 1) { } 14 0 14
4384 my (
4385 14 $found_target,
4386 $here_doc_target,
4387 $here_quote_character,
4388 $i_return,
4389 $saw_error,
4390  
4391 ) = $self->find_here_doc(
4392  
4393 $expecting,
4394 $i,
4395 $rtokens,
4396 $rtoken_type,
4397 $rtoken_map,
4398 $max_token_index,
4399 );
4400 14 $i = $i_return;
4401  
4402 14 ▶ if ($found_target) {
Branch: 2 branches
BranchTrueFalseTotal
if ($found_target) { } 14 0 14
elsif ($expecting == -1) { } 0 0 0
4403  
4404 14 ▶ if ( length($here_doc_target) > 80 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $here_doc_target > 80) { } 0 14 14
elsif (not $here_doc_target =~ /^[A-Z_]\w+$/) { } 0 14 14
4405 0 my $truncated = substr( $here_doc_target, 0, 80 );
4406 0 $self->complain("Long here-target: '$truncated' ...\n");
4407 }
4408 elsif ( $here_doc_target !~ /^[A-Z_]\w+$/ ) {
4409 0 $self->complain(
4410 "Unconventional here-target: '$here_doc_target'\n");
4411 }
4412 else {
4413 ## nothing to complain about
4414 }
4415  
4416 # Note that we put a leading space on the here quote
4417 # character indicate that it may be preceded by spaces
4418 14 $here_quote_character = SPACE . $here_quote_character;
4419 14 push @{$rhere_target_list},
4420 [ $here_doc_target, $here_quote_character ];
4421 14 $type = 'h';
4422 }
4423  
4424 # target not found ..
4425 elsif ( $expecting == TERM ) {
4426 0 ▶ if ( !$saw_error ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($saw_error) 0 0 0
4427  
4428 # shouldn't happen..arriving here implies an error in
4429 # the logic in sub 'find_here_doc'
4430 0 if (DEVEL_MODE) {
4431 Fault(<<EOM);
4432 Program bug; didn't find here doc target
4433 EOM
4434 }
4435 $self->warning(
4436 0 "Possible program error: didn't find here doc target\n"
4437 );
4438 0 $self->report_definite_bug();
4439 }
4440 }
4441  
4442 # Target not found, expecting==UNKNOWN
4443 else {
4444 0 $self->warning("didn't find here doc target after '<<~'\n");
4445 }
4446 }
4447 else {
4448 0 $self->error_if_expecting_OPERATOR();
4449 }
4450 14 return;
4451 } ## end sub do_NEW_HERE_DOC
4452  
4453 sub do_POINTER {
4454  
4455 # '->'
4456 1197 ▶ return;
Subroutine do_POINTER: called CC=1 SCAR=0.0
Pod undocumented
4457 }
4458  
4459 sub do_PLUS_PLUS {
4460  
4461 50 ▶ my $self = shift;
Subroutine do_PLUS_PLUS: called CC=5 SCAR=16.6
Pod undocumented
4462  
4463 # '++'
4464 # type = 'pp' for pre-increment, '++' for post-increment
4465 50 ▶ if ( $expecting == OPERATOR ) { $type = '++' }
Branch: 2 branches
BranchTrueFalseTotal
if ($expecting == 1) { } 41 9 50
elsif ($expecting == -1) { } 7 2 9
4466 7 elsif ( $expecting == TERM ) { $type = 'pp' }
4467  
4468 # handle ( $expecting == UNKNOWN )
4469 else {
4470  
4471 # look ahead ..
4472 2 my ( $next_nonblank_token, $i_next ) =
4473 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
4474  
4475 # Fix for c042: look past a side comment
4476 2 ▶ if ( $next_nonblank_token eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "#") 0 2 2
4477 0 ( $next_nonblank_token, $i_next ) =
4478 $self->find_next_nonblank_token( $max_token_index,
4479 $rtokens, $max_token_index );
4480 }
4481  
4482 2 ▶ if ( $next_nonblank_token eq '$' ) { $type = 'pp' }
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "\$") 0 2 2
4483 }
4484 50 return;
4485 } ## end sub do_PLUS_PLUS
4486  
4487 sub do_FAT_COMMA {
4488  
4489 1117 ▶ my $self = shift;
Subroutine do_FAT_COMMA: called CC=3 SCAR=11.2
Pod undocumented
4490  
4491 # '=>'
4492 1117 ▶ if ( $last_nonblank_type eq $tok ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq $tok) 0 1117 1117
4493 0 $self->complain("Repeated '=>'s \n");
4494 }
4495  
4496 # patch for operator_expected: note if we are in the list (use.t)
4497 # TODO: make version numbers a new token type
4498 1117 ▶ if ( $statement_type eq 'use' ) { $statement_type = '_use' }
Branch: 1 branch
BranchTrueFalseTotal
if ($statement_type eq "use") 20 1097 1117
4499 1117 return;
4500 } ## end sub do_FAT_COMMA
4501  
4502 sub do_MINUS_MINUS {
4503  
4504 2 ▶ my $self = shift;
Subroutine do_MINUS_MINUS: called CC=5 SCAR=25.2
Pod undocumented
4505  
4506 # '--'
4507 # type = 'mm' for pre-decrement, '--' for post-decrement
4508  
4509 2 ▶ if ( $expecting == OPERATOR ) { $type = '--' }
Branch: 2 branches
BranchTrueFalseTotal
if ($expecting == 1) { } 0 2 2
elsif ($expecting == -1) { } 2 0 2
4510 2 elsif ( $expecting == TERM ) { $type = 'mm' }
4511  
4512 # handle ( $expecting == UNKNOWN )
4513 else {
4514  
4515 # look ahead ..
4516 0 my ( $next_nonblank_token, $i_next ) =
4517 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
4518  
4519 # Fix for c042: look past a side comment
4520 0 ▶ if ( $next_nonblank_token eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "#") 0 0 0
4521 0 ( $next_nonblank_token, $i_next ) =
4522 $self->find_next_nonblank_token( $max_token_index,
4523 $rtokens, $max_token_index );
4524 }
4525  
4526 0 ▶ if ( $next_nonblank_token eq '$' ) { $type = 'mm' }
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "\$") 0 0 0
4527 }
4528  
4529 2 return;
4530 } ## end sub do_MINUS_MINUS
4531  
4532 sub do_DIGITS {
4533  
4534 2521 ▶ my $self = shift;
Subroutine do_DIGITS: called CC=3 SCAR=13.0
Pod undocumented
4535  
4536 # 'd' = string of digits
4537 2521 ▶ $self->error_if_expecting_OPERATOR("Number")
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 2521 2521
4538 if ( $expecting == OPERATOR );
4539  
4540 2521 my $number = $self->scan_number_fast();
4541 2521 ▶ if ( !defined($number) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $number) 0 2521 2521
4542  
4543 # shouldn't happen - we should always get a number
4544 0 if (DEVEL_MODE) {
4545 Fault(<<EOM);
4546 non-number beginning with digit--program bug
4547 EOM
4548 }
4549 $self->warning(
4550 0 "Unexpected error condition: non-number beginning with digit\n"
4551 );
4552 0 $self->report_definite_bug();
4553 }
4554 2521 return;
4555 } ## end sub do_DIGITS
4556  
4557 sub do_ATTRIBUTE_LIST {
4558  
4559 45 ▶ my ( $self, $next_nonblank_token ) = @_;
Subroutine do_ATTRIBUTE_LIST: called CC=4 SCAR=13.9
Pod undocumented
4560  
4561 # Called at a bareword encountered while in an attribute list
4562 # returns 'is_attribute':
4563 # true if attribute found
4564 # false if an attribute (continue parsing bareword)
4565  
4566 # treat bare word followed by open paren like qw(
4567 45 ▶ if ( $next_nonblank_token eq '(' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq '(') { } 20 25 45
4568  
4569 # For something like:
4570 # : prototype($$)
4571 # we should let do_scan_sub see it so that it can see
4572 # the prototype. All other attributes get parsed as a
4573 # quoted string.
4574 20 ▶ if ( $tok eq 'prototype' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "prototype") 2 18 20
4575 2 $id_scan_state = 'prototype';
4576  
4577 # start just after the word 'prototype'
4578 2 my $i_beg = $i + 1;
4579 2 ( $i, $tok, $type, $id_scan_state ) = $self->do_scan_sub(
4580 {
4581 input_line => $input_line,
4582 i => $i,
4583 i_beg => $i_beg,
4584 tok => $tok,
4585 type => $type,
4586 rtokens => $rtokens,
4587 rtoken_map => $rtoken_map,
4588 id_scan_state => $id_scan_state,
4589 max_token_index => $max_token_index,
4590 }
4591 );
4592  
4593 # If successful, mark as type 'q' to be consistent
4594 # with other attributes. Type 'w' would also work.
4595 2 ▶ if ( $i > $i_beg ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > $i_beg) 2 0 2
4596 2 $type = 'q';
4597 2 return 1;
4598 }
4599  
4600 # If not successful, continue and parse as a quote.
4601 }
4602  
4603 # All other attribute lists must be parsed as quotes
4604 # (see 'signatures.t' for good examples)
4605 18 $in_quote = $quote_items{'q'};
4606 18 $allowed_quote_modifiers = $quote_modifiers{'q'};
4607 18 $quote_starting_tok = 'q';
4608 18 $type = 'q';
4609 18 $quote_type = 'q';
4610 18 $quote_here_target_2 = undef;
4611 18 return 1;
4612 }
4613  
4614 # handle bareword not followed by open paren
4615 else {
4616 25 $type = 'w';
4617 25 return 1;
4618 }
4619  
4620 # attribute not found
4621 0 return;
4622 } ## end sub do_ATTRIBUTE_LIST
4623  
4624 sub do_X_OPERATOR {
4625  
4626 17 ▶ my $self = shift;
Subroutine do_X_OPERATOR: called CC=4 SCAR=14.7
Pod undocumented
4627  
4628 # We are at a pretoken starting with 'x' where an operator is expected
4629  
4630 17 ▶ if ( $tok eq 'x' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq 'x') { } 15 2 17
4631 15 ▶ if ( $rtokens->[ $i + 1 ] eq '=' ) { # x=
Branch: 1 branch
BranchTrueFalseTotal
if ($$rtokens[$i + 1] eq '=') { } 0 15 15
4632 0 $tok = 'x=';
4633 0 $type = $tok;
4634 0 $i++;
4635 }
4636 else {
4637 15 $type = 'x';
4638 }
4639 }
4640 else {
4641  
4642 # Split a pretoken like 'x10' into 'x' and '10'.
4643 # Note: In previous versions of perltidy it was marked
4644 # as a number, $type = 'n', and fixed downstream by the
4645 # Formatter.
4646 2 $type = 'n';
4647 2 ▶ if ( $self->split_pretoken(1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->split_pretoken(1)) 2 0 2
4648 2 $type = 'x';
4649 2 $tok = 'x';
4650 }
4651 }
4652 17 return;
4653 } ## end sub do_X_OPERATOR
4654  
4655 sub do_USE_CONSTANT {
4656  
4657 18 ▶ my $self = shift;
Subroutine do_USE_CONSTANT: called CC=3 SCAR=11.0
Pod undocumented
4658  
4659 # We just saw 'use constant' and must look ahead
4660  
4661 18 $self->scan_bare_identifier();
4662 18 my ( $next_nonblank_tok2, $i_next2_uu ) =
4663 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
4664  
4665 18 ▶ if ($next_nonblank_tok2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_tok2) 18 0 18
4666  
4667 18 ▶ if ( $is_keyword{$next_nonblank_tok2} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_keyword{$next_nonblank_tok2}) { } 1 17 18
4668  
4669 # Assume qw is used as a quote and okay, as in:
4670 # use constant qw{ DEBUG 0 };
4671 # Not worth trying to parse for just a warning
4672  
4673 # NOTE: This warning is deactivated because recent
4674 # versions of perl do not complain here, but
4675 # the coding is retained for reference.
4676 1 if ( 0 && $next_nonblank_tok2 ne 'qw' ) {
4677 $self->warning(
4678 "Attempting to define constant '$next_nonblank_tok2' which is a perl keyword\n"
4679 );
4680 }
4681 }
4682  
4683 else {
4684 17 $ris_constant->{$current_package}->{$next_nonblank_tok2} = 1;
4685 }
4686 }
4687 18 return;
4688 } ## end sub do_USE_CONSTANT
4689  
4690 sub do_KEYWORD {
4691  
4692 3136 ▶ my $self = shift;
Subroutine do_KEYWORD: called CC=23 SCAR=34.7
Pod undocumented
4693  
4694 # found a keyword - set any associated flags
4695 3136 $type = 'k';
4696  
4697 # Since for and foreach may not be followed immediately
4698 # by an opening paren, we have to remember which keyword
4699 # is associated with the next '('
4700 # Previously, before update c230 : if ( $is_for_foreach{$tok} ) {
4701 ##(if elsif unless while until for foreach switch case given when catch)
4702 3136 ▶ if ( $is_blocktype_with_paren{$tok} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_blocktype_with_paren{$tok}) 501 2635 3136
4703 501 ▶ if ( new_statement_ok() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (new_statement_ok()) 362 139 501
4704 362 $want_paren = $tok;
4705 }
4706 }
4707  
4708 # Catch unexpected keywords (c517, c613).
4709 3136 ▶ if ( $expecting == TERM ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($expecting == -1) { } 2765 371 3136
elsif ($expecting == 1) { } 337 34 371
4710 $self->error_if_expecting_TERM()
4711 2765 ▶ if ( $is_OPERATOR_keyword{$tok} );
Branch: 1 branch
BranchTrueFalseTotal
if $is_OPERATOR_keyword{$tok} 0 2765 2765
4712 }
4713 elsif ( $expecting == OPERATOR ) {
4714 $self->error_if_expecting_OPERATOR()
4715 337 ▶ if ( $is_TERM_keyword{$tok} );
Branch: 1 branch
BranchTrueFalseTotal
if $is_TERM_keyword{$tok} 0 337 337
4716 }
4717 else {
4718 ## expecting == UNKNOWN
4719 }
4720  
4721 # recognize 'use' statements, which are special
4722 3136 ▶ if ( $is_use_require{$tok} ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($is_use_require{$tok}) { } 180 2956 3136
elsif ($is_my_our_state{$tok}) { } 769 2187 2956
elsif ($tok eq 'elsif') { } 35 2152 2187
elsif ($tok eq 'else') { } 53 2099 2152
elsif ($tok eq 'when' or $tok eq 'case' or $tok eq 'default') { } 70 2029 2099
elsif ($tok eq 'err') { } 1 2028 2029
4723 180 $statement_type = $tok;
4724 }
4725  
4726 # remember my and our to check for trailing ": shared"
4727 elsif ( $is_my_our_state{$tok} ) {
4728 769 $statement_type = $tok;
4729 }
4730  
4731 # Check for unexpected 'elsif'
4732 elsif ( $tok eq 'elsif' ) {
4733 35 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_if_elsif_unless{$last_nonblank_block_type} or $last_nonblank_token eq ";" and $next_sequence_number == 2) 0 35 35
Condition16%1/6
$is_if_elsif_unless{$last_nonblank_block_type} or $last_nonblank_token eq ";" and $next_sequence_number == 2
l!l&&r!l&&!r
3500
$last_nonblank_token eq ";" and $next_sequence_number == 2
!ll&&!rl&&r
000
MC/DC0%0/3
$is_if_elsif_unless{$last_nonblank_block_type} or $last_nonblank_token eq ";" and $next_sequence_number == 2
$is_if_elsif_unless{$last_nonblank_block_type} $last_nonblank_token eq ";" $next_sequence_number == 2
Truth table25%1/4
A or B and C
A= $is_if_elsif_unless{$last_nonblank_block_type}B= $last_nonblank_token eq ";"C= $next_sequence_number == 2
ABCresult
1XX1
0111
00X0
0100
4734  
4735 !$is_if_elsif_unless{$last_nonblank_block_type}
4736  
4737 # Allow isolated blocks of any kind during editing
4738 # by checking for a last noblank token of ';' and no
4739 # sequence numbers having been issued (c272). The check
4740 # on sequence number is not perfect but good enough.
4741 && !(
4742 $last_nonblank_token eq ';'
4743 && $next_sequence_number == SEQ_ROOT + 1
4744 )
4745  
4746 )
4747 {
4748 ## prevent formatting and avoid instability (b1553)
4749 0 $self->warning_do_not_format(
4750 "expecting '$tok' to follow one of 'if|elsif|unless'\n");
4751 }
4752 }
4753  
4754 # Check for unexpected 'else'
4755 elsif ( $tok eq 'else' ) {
4756  
4757 # patched for SWITCH/CASE
4758 53 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_if_elsif_unless_case_when{$last_nonblank_block_type} or $is_if_elsif_unless_case_when{$statement_type} or $last_nonblank_token eq ";" and $next_sequence_number == 2) 0 53 53
Condition33%3/9
$is_if_elsif_unless_case_when{$last_nonblank_block_type} or $is_if_elsif_unless_case_when{$statement_type} or $last_nonblank_token eq ";" and $next_sequence_number == 2
l!l&&r!l&&!r
5300
$is_if_elsif_unless_case_when{$last_nonblank_block_type} or $is_if_elsif_unless_case_when{$statement_type}
l!l&&r!l&&!r
5210
$last_nonblank_token eq ";" and $next_sequence_number == 2
!ll&&!rl&&r
000
MC/DC0%0/4
$is_if_elsif_unless_case_when{$last_nonblank_block_type} or $is_if_elsif_unless_case_when{$statement_type} or $last_nonblank_token eq ";" and $next_sequence_number == 2
$is_if_elsif_unless_case_when{$last_nonblank_block_type} $is_if_elsif_unless_case_when{$statement_type} $last_nonblank_token eq ";" $next_sequence_number == 2
Truth table40%2/5
A or B or C and D
A= $is_if_elsif_unless_case_when{$last_nonblank_block_type}B= $is_if_elsif_unless_case_when{$statement_type}C= $last_nonblank_token eq ";"D= $next_sequence_number == 2
ABCDresult
1XXX1
01XX1
00111
000X0
00100
4759  
4760 !$is_if_elsif_unless_case_when{$last_nonblank_block_type}
4761  
4762 # patch to avoid an unwanted error message for
4763 # the case of a parenless 'case' (RT 105484):
4764 # switch ( 1 ) { case x { 2 } else { } }
4765 && !$is_if_elsif_unless_case_when{$statement_type}
4766  
4767 # Allow isolated blocks of any kind during editing (c272)
4768 && !(
4769 $last_nonblank_token eq ';'
4770 && $next_sequence_number == SEQ_ROOT + 1
4771 )
4772  
4773 )
4774 {
4775 ## prevent formatting and avoid instability (b1553)
4776 0 $self->warning_do_not_format(
4777 "expecting '$tok' to follow one of 'if|elsif|unless|case|when'\n"
4778 );
4779 }
4780 }
4781  
4782 # patch for SWITCH/CASE if 'case' and 'when are
4783 # treated as keywords. Also 'default' for Switch::Plain
4784 ▶ elsif ($tok eq 'when'
Condition100%6/6
$tok eq "when" or $tok eq "case" or $tok eq "default"
l!l&&r!l&&!r
6822029
$tok eq "when" or $tok eq "case"
l!l&&r!l&&!r
4642031
MC/DC100%3/3
$tok eq "when" or $tok eq "case" or $tok eq "default"
$tok eq "when" $tok eq "case" $tok eq "default"
Truth table100%4/4
A or B or C
A= $tok eq "when"B= $tok eq "case"C= $tok eq "default"
ABCresult
1XX1
01X1
0011
0000
4785 || $tok eq 'case'
4786 || $tok eq 'default' )
4787 {
4788 70 $statement_type = $tok; # next '{' is block
4789 }
4790  
4791 # feature 'err' was removed in Perl 5.10. So mark this as
4792 # a bareword unless an operator is expected (see c158).
4793 elsif ( $tok eq 'err' ) {
4794 1 ▶ if ( $expecting != OPERATOR ) { $type = 'w' }
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting != 1) 1 0 1
4795 }
4796 else {
4797 ## no special treatment needed
4798 }
4799  
4800 3136 return;
4801 } ## end sub do_KEYWORD
4802  
4803 sub do_QUOTE_OPERATOR {
4804  
4805 237 ▶ my $self = shift;
Subroutine do_QUOTE_OPERATOR: called CC=7 SCAR=25.2
Pod undocumented
4806  
4807 # We have arrived at a quote operator: q, qq, qw, qx, qr, s, y, tr, m
4808  
4809 237 ▶ if ( $expecting == OPERATOR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == 1) 0 237 237
4810  
4811 # Be careful not to call an error for a qw quote
4812 # where a parenthesized list is allowed. For example,
4813 # it could also be a for/foreach construct such as
4814 #
4815 # foreach my $key qw\Uno Due Tres Quadro\ {
4816 # print "Set $key\n";
4817 # }
4818 #
4819  
4820 # Or it could be a function call.
4821 # NOTE: Braces in something like &{ xxx } are not
4822 # marked as a block, we might have a method call.
4823 # &method(...), $method->(..), &{method}(...),
4824 # $ref[2](list) is ok & short for $ref[2]->(list)
4825 #
4826 # See notes in 'sub code_block_type' and
4827 # 'sub is_non_structural_brace'
4828  
4829 my $paren_list_possible = $tok eq 'qw'
4830 && ( $last_nonblank_token =~ /^([\]\}\&]|\-\>)/
4831 0 ▶ || $is_for_foreach{$want_paren} );
Condition0%0/6
$tok eq 'qw' && ($last_nonblank_token =~ /^([\]\}\&]|\-\>)/ || $is_for_foreach{$want_paren})
!ll&&!rl&&r
000
$last_nonblank_token =~ /^([\]\}\&]|\-\>)/ or $is_for_foreach{$want_paren}
l!l&&r!l&&!r
000
MC/DC0%0/3
$tok eq 'qw' && ($last_nonblank_token =~ /^([\]\}\&]|\-\>)/ || $is_for_foreach{$want_paren})
$tok eq 'qw' $last_nonblank_token =~ /^([\]\}\&]|\-\>)/ $is_for_foreach{$want_paren}
Truth table0%0/4
A && B or C
A= $tok eq 'qw'B= $last_nonblank_token =~ /^([\]\}\&]|\-\>)/C= $is_for_foreach{$want_paren}
ABCresult
0XX0
1000
11X1
1011
4832  
4833 0 ▶ if ( !$paren_list_possible ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($paren_list_possible) 0 0 0
4834 0 $self->error_if_expecting_OPERATOR();
4835 }
4836 }
4837 237 $in_quote = $quote_items{$tok};
4838 237 $allowed_quote_modifiers = $quote_modifiers{$tok};
4839 237 $quote_starting_tok = $tok;
4840 237 $quote_here_target_2 = undef;
4841  
4842 # All quote types are 'Q' except possibly qw quotes.
4843 # qw quotes are special in that they may generally be trimmed
4844 # of leading and trailing whitespace. So they are given a
4845 # separate type, 'q', unless requested otherwise.
4846 237 ▶ $type =
Branch: 1 branch
BranchTrueFalseTotal
$tok eq 'qw' && $rOpts_trim_qw ? : 140 97 237
Condition66%2/3
$tok eq "qw" and $rOpts_trim_qw
!ll&&!rl&&r
970140
MC/DC50%1/2
$tok eq "qw" and $rOpts_trim_qw
$tok eq "qw" $rOpts_trim_qw
Truth table66%2/3
A and B
A= $tok eq "qw"B= $rOpts_trim_qw
ABresult
0X0
100
111
4847 ( $tok eq 'qw' && $rOpts_trim_qw )
4848 ? 'q'
4849 : 'Q';
4850 237 $quote_type = $type;
4851 237 return;
4852 } ## end sub do_QUOTE_OPERATOR
4853  
4854 sub do_UNKNOWN_BAREWORD {
4855  
4856 1036 ▶ my ( $self, $next_nonblank_token ) = @_;
Subroutine do_UNKNOWN_BAREWORD: called CC=27 SCAR=45.8
Pod undocumented
4857  
4858 # We have encountered a bareword which needs more work to classify
4859  
4860 1036 $self->scan_bare_identifier();
4861  
4862 1036 ▶ if ( $statement_type eq 'use'
Branch: 1 branch
BranchTrueFalseTotal
if ($statement_type eq "use" and $last_nonblank_token eq "use") 111 925 1036
Condition100%3/3
$statement_type eq "use" and $last_nonblank_token eq "use"
!ll&&!rl&&r
9232111
MC/DC100%2/2
$statement_type eq "use" and $last_nonblank_token eq "use"
$statement_type eq "use" $last_nonblank_token eq "use"
Truth table100%3/3
A and B
A= $statement_type eq "use"B= $last_nonblank_token eq "use"
ABresult
0X0
100
111
4863 && $last_nonblank_token eq 'use' )
4864 {
4865 111 $rsaw_use_module->{$current_package}->{$tok} = 1;
4866 }
4867  
4868 1036 ▶ if ( $type eq 'w' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "w") 1009 27 1036
4869  
4870 1009 ▶ if ( $expecting == OPERATOR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == 1) 2 1007 1009
4871  
4872 # Patch to avoid error message for RPerl overloaded
4873 # operator functions: use overload
4874 # '+' => \&sse_add,
4875 # '-' => \&sse_sub,
4876 # '*' => \&sse_mul,
4877 # '/' => \&sse_div;
4878 # TODO: this could eventually be generalized
4879 2 ▶ if ( $rsaw_use_module->{$current_package}->{'RPerl'}
Branch: 4 branches
BranchTrueFalseTotal
if ($rsaw_use_module->{$current_package}{'RPerl'} and $tok =~ /^sse_(mul|div|add|sub)$/) { } 0 2 2
elsif ($tok eq 'in' and $next_nonblank_token eq ':') { } 2 0 2
elsif ($last_nonblank_type eq '->') { } 0 0 0
elsif ($last_nonblank_type eq 'C') { } 0 0 0
Condition33%1/3
$rsaw_use_module->{$current_package}{"RPerl"} and $tok =~ /^sse_(mul|div|add|sub)$/
!ll&&!rl&&r
200
MC/DC0%0/2
$rsaw_use_module->{$current_package}{"RPerl"} and $tok =~ /^sse_(mul|div|add|sub)$/
$rsaw_use_module->{$current_package}{"RPerl"} $tok =~ /^sse_(mul|div|add|sub)$/
Truth table33%1/3
A and B
A= $rsaw_use_module->{$current_package}{"RPerl"}B= $tok =~ /^sse_(mul|div|add|sub)$/
ABresult
0X0
100
111
4880 && $tok =~ /^sse_(mul|div|add|sub)$/ )
4881 {
4882  
4883 }
4884  
4885 # patch for Syntax::Operator::In, git #162
4886 ▶ elsif ( $tok eq 'in' && $next_nonblank_token eq ':' ) {
Condition33%1/3
$tok eq "in" and $next_nonblank_token eq ":"
!ll&&!rl&&r
002
MC/DC0%0/2
$tok eq "in" and $next_nonblank_token eq ":"
$tok eq "in" $next_nonblank_token eq ":"
Truth table33%1/3
A and B
A= $tok eq "in"B= $next_nonblank_token eq ":"
ABresult
0X0
100
111
4887  
4888 }
4889  
4890 # Fix part 1 for git #63 in which a comment falls
4891 # between an -> and the following word. An
4892 # alternate fix would be to change operator_expected
4893 # to return an UNKNOWN for this type.
4894 elsif ( $last_nonblank_type eq '->' ) {
4895  
4896 }
4897  
4898 # don't complain about possible indirect object
4899 # notation.
4900 # For example:
4901 # package main;
4902 # sub new($) { ... }
4903 # $b = new A::; # calls A::new
4904 # $c = new A; # same thing but suspicious
4905 # This will call A::new but we have a 'new' in
4906 # main:: which looks like a constant.
4907 #
4908 elsif ( $last_nonblank_type eq 'C' ) {
4909 0 ▶ if ( $tok !~ /::$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tok =~ /::$/) 0 0 0
4910 0 $self->complain(<<EOM);
4911 Expecting operator after '$last_nonblank_token' but found bare word '$tok'
4912 Maybe indirect object notation?
4913 EOM
4914 }
4915 }
4916 else {
4917 0 $self->error_if_expecting_OPERATOR("bareword");
4918 }
4919 }
4920  
4921 # mark bare words immediately followed by a paren as
4922 # functions
4923 1009 $next_tok = $rtokens->[ $i + 1 ];
4924 1009 ▶ if ( $next_tok eq '(' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_tok eq "(") 298 711 1009
4925  
4926 # Patch for issue c151, where we are processing a snippet and
4927 # have not seen that SPACE is a constant. In this case 'x' is
4928 # probably an operator. The only disadvantage with an incorrect
4929 # guess is that the space after it may be incorrect. For example
4930 # $str .= SPACE x ( 16 - length($str) ); See also b1410.
4931 298 ▶ if ( $tok eq 'x' && $last_nonblank_type eq 'w' ) { $type = 'x' }
Branch: 2 branches
BranchTrueFalseTotal
if ($tok eq 'x' and $last_nonblank_type eq 'w') { } 0 298 298
elsif ($last_nonblank_type ne '->') { } 298 0 298
Condition33%1/3
$tok eq "x" and $last_nonblank_type eq "w"
!ll&&!rl&&r
29800
MC/DC0%0/2
$tok eq "x" and $last_nonblank_type eq "w"
$tok eq "x" $last_nonblank_type eq "w"
Truth table33%1/3
A and B
A= $tok eq "x"B= $last_nonblank_type eq "w"
ABresult
0X0
100
111
4932  
4933 # Fix part 2 for git #63. Leave type as 'w' to keep
4934 # the type the same as if the -> were not separated
4935 298 elsif ( $last_nonblank_type ne '->' ) { $type = 'U' }
4936  
4937 # not a special case
4938 else { }
4939  
4940 }
4941  
4942 # underscore after file test operator is file handle
4943 1009 ▶ if ( $tok eq '_' && $last_nonblank_type eq 'F' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "_" and $last_nonblank_type eq "F") 0 1009 1009
Condition66%2/3
$tok eq "_" and $last_nonblank_type eq "F"
!ll&&!rl&&r
100540
MC/DC0%0/2
$tok eq "_" and $last_nonblank_type eq "F"
$tok eq "_" $last_nonblank_type eq "F"
Truth table66%2/3
A and B
A= $tok eq "_"B= $last_nonblank_type eq "F"
ABresult
0X0
100
111
4944 0 $type = 'Z';
4945 }
4946  
4947 # patch for SWITCH/CASE if 'case' and 'when are
4948 # not treated as keywords:
4949 1009 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "case" and $rbrace_type->[$brace_depth] eq "switch" or $tok eq "when" and $rbrace_type->[$brace_depth] eq "given") 0 1009 1009
Condition33%3/9
$tok eq "case" and $rbrace_type->[$brace_depth] eq "switch" or $tok eq "when" and $rbrace_type->[$brace_depth] eq "given"
l!l&&r!l&&!r
001009
$tok eq "case" and $rbrace_type->[$brace_depth] eq "switch"
!ll&&!rl&&r
100900
$tok eq "when" and $rbrace_type->[$brace_depth] eq "given"
!ll&&!rl&&r
100900
MC/DC0%0/4
$tok eq "case" and $rbrace_type->[$brace_depth] eq "switch" or $tok eq "when" and $rbrace_type->[$brace_depth] eq "given"
$tok eq "case" $rbrace_type->[$brace_depth] eq "switch" $tok eq "when" $rbrace_type->[$brace_depth] eq "given"
Truth table0%0/7
A and B or C and D
A= $tok eq "case"B= $rbrace_type->[$brace_depth] eq "switch"C= $tok eq "when"D= $rbrace_type->[$brace_depth] eq "given"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
4950 ( $tok eq 'case' && $rbrace_type->[$brace_depth] eq 'switch' )
4951 || ( $tok eq 'when'
4952 && $rbrace_type->[$brace_depth] eq 'given' )
4953 )
4954 {
4955 0 $statement_type = $tok; # next '{' is block
4956 0 $type = 'k'; # for keyword syntax coloring
4957 }
4958 1009 ▶ if ( $next_nonblank_token eq '(' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "(") 263 746 1009
4959  
4960 # patch for SWITCH/CASE if switch and given not keywords
4961 # Switch is not a perl 5 keyword, but we will gamble
4962 # and mark switch followed by paren as a keyword. This
4963 # is only necessary to get html syntax coloring nice,
4964 # and does not commit this as being a switch/case.
4965 263 ▶ if ( $tok eq 'switch' || $tok eq 'given' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tok eq 'switch' or $tok eq 'given') { } 0 263 263
elsif ($tok eq 'x' and $last_nonblank_type eq 'w') { } 0 263 263
Condition33%1/3
$tok eq "switch" or $tok eq "given"
l!l&&r!l&&!r
00263
MC/DC0%0/2
$tok eq "switch" or $tok eq "given"
$tok eq "switch" $tok eq "given"
Truth table33%1/3
A or B
A= $tok eq "switch"B= $tok eq "given"
ABresult
1X1
011
000
4966 0 $type = 'k'; # for keyword syntax coloring
4967 }
4968  
4969 # mark 'x' as operator for something like this (see b1410)
4970 # my $line = join( LD_X, map { LD_H x ( $_ + 2 ) } @$widths );
4971 ▶ elsif ( $tok eq 'x' && $last_nonblank_type eq 'w' ) {
Condition33%1/3
$tok eq "x" and $last_nonblank_type eq "w"
!ll&&!rl&&r
26300
MC/DC0%0/2
$tok eq "x" and $last_nonblank_type eq "w"
$tok eq "x" $last_nonblank_type eq "w"
Truth table33%1/3
A and B
A= $tok eq "x"B= $last_nonblank_type eq "w"
ABresult
0X0
100
111
4972 0 $type = 'x';
4973 }
4974 else {
4975 ## not a special case
4976 }
4977 }
4978 }
4979 1036 return;
4980 } ## end sub do_UNKNOWN_BAREWORD
4981  
4982 sub sub_attribute_ok_here {
4983  
4984 37 ▶ my ( $self, $tok_kw, $next_nonblank_token, $i_next ) = @_;
Subroutine sub_attribute_ok_here: called CC=6 SCAR=18.4
Pod undocumented
4985  
4986 # Decide if a ':' can introduce an attribute. For example,
4987 # something like 'sub :'
4988  
4989 # Given:
4990 # $tok_kw = a bareword token
4991 # $next_nonblank_token = a following ':' being examined
4992 # $i_next = the index of the following ':'
4993  
4994 # We will decide based on if the colon is followed by a bareword
4995 # which is not a keyword. Changed inext+1 to inext to fixed case
4996 # b1190.
4997 37 my $sub_attribute_ok_here;
4998 37 ▶ if ( $is_sub{$tok_kw}
Branch: 1 branch
BranchTrueFalseTotal
if ($is_sub{$tok_kw} and $expecting != 1 and $next_nonblank_token eq ":") 3 34 37
Condition66%4/6
$is_sub{$tok_kw} and $expecting != 1 and $next_nonblank_token eq ":"
!ll&&!rl&&r
3403
$is_sub{$tok_kw} and $expecting != 1
!ll&&!rl&&r
3403
MC/DC33%1/3
$is_sub{$tok_kw} and $expecting != 1 and $next_nonblank_token eq ":"
$is_sub{$tok_kw} $expecting != 1 $next_nonblank_token eq ":"
Truth table50%2/4
A and B and C
A= $is_sub{$tok_kw}B= $expecting != 1C= $next_nonblank_token eq ":"
ABCresult
0XX0
10X0
1100
1111
4999 && $expecting != OPERATOR
5000 && $next_nonblank_token eq ':' )
5001 {
5002 3 my ( $nn_nonblank_token, $i_nn_uu ) =
5003 $self->find_next_nonblank_token( $i_next, $rtokens,
5004 $max_token_index );
5005 $sub_attribute_ok_here =
5006 $nn_nonblank_token =~ /^\w/
5007 && $nn_nonblank_token !~ /^\d/
5008 3 ▶ && !$is_keyword{$nn_nonblank_token};
Condition66%4/6
$nn_nonblank_token =~ /^\w/ && !($nn_nonblank_token =~ /^\d/) && !$is_keyword{$nn_nonblank_token}
!ll&&!rl&&r
102
$nn_nonblank_token =~ /^\w/ and not $nn_nonblank_token =~ /^\d/
!ll&&!rl&&r
102
MC/DC33%1/3
$nn_nonblank_token =~ /^\w/ && !($nn_nonblank_token =~ /^\d/) && !$is_keyword{$nn_nonblank_token}
$nn_nonblank_token =~ /^\w/ not $nn_nonblank_token =~ /^\d/ !$is_keyword{$nn_nonblank_token}
Truth table50%2/4
A and not(B) && not(C)
A= $nn_nonblank_token =~ /^\w/B= not $nn_nonblank_token =~ /^\d/C= !$is_keyword{$nn_nonblank_token}
ABCresult
0XX0
10X0
1100
1111
5009 }
5010 37 return $sub_attribute_ok_here;
5011 } ## end sub sub_attribute_ok_here
5012  
5013 45 ▶ use constant DEBUG_BAREWORD => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5014  
5015 sub saw_bareword_function {
5016 961 ▶ my ( $self, $bareword ) = @_;
Subroutine saw_bareword_function: called CC=1 SCAR=0.0
Pod undocumented
5017 $self->[_rbareword_info_]->{$current_package}->{$bareword}
5018 961 ->{function_count}++;
5019 961 return;
5020 } ## end sub saw_bareword_function
5021  
5022 sub saw_bareword_constant {
5023 182 ▶ my ( $self, $bareword ) = @_;
Subroutine saw_bareword_constant: called CC=1 SCAR=0.0
Pod undocumented
5024 $self->[_rbareword_info_]->{$current_package}->{$bareword}
5025 182 ->{constant_count}++;
5026 182 return;
5027 } ## end sub saw_bareword_constant
5028  
5029 sub get_bareword_counts {
5030 0 ▶ my ( $self, $bareword ) = @_;
Subroutine get_bareword_counts: not called CC=6 SCAR=37.4
Pod undocumented
5031  
5032 # Given:
5033 # $bareword = a bareword
5034 # Return:
5035 # $function_count = number of times seen as function taking >0 args
5036 # $constant_count = number of times seen as function taking 0 args
5037 # Note:
5038 # $function_count > 0 implies that a TERM should come next
5039 # $constant_count > 0 implies that an OPERATOR **may** come next,
5040 # but this can be incorrect if $bareword can take 0 or more args.
5041 # This is used to help guess tokenization around unknown barewords.
5042 0 my $function_count;
5043 my $constant_count;
5044 0 my $rbareword_info_tok = $self->[_rbareword_info_]->{$current_package};
5045 0 ▶ if ($rbareword_info_tok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rbareword_info_tok) 0 0 0
5046 0 $rbareword_info_tok = $rbareword_info_tok->{$bareword};
5047 0 ▶ if ($rbareword_info_tok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rbareword_info_tok) 0 0 0
5048 0 $function_count = $rbareword_info_tok->{function_count};
5049 0 $constant_count = $rbareword_info_tok->{constant_count};
5050  
5051 # a positive function count overrides a constant count
5052 0 ▶ if ($function_count) { $constant_count = 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($function_count) 0 0 0
5053 }
5054 }
5055 0 ▶ if ( !defined($function_count) ) { $function_count = 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $function_count) 0 0 0
5056 0 ▶ if ( !defined($constant_count) ) { $constant_count = 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $constant_count) 0 0 0
5057 0 return ( $function_count, $constant_count );
5058 } ## end sub get_bareword_counts
5059  
5060 # hashes used to help determine a bareword type
5061 45 my %is_wiUC;
5062 45 my %is_function_follower;
5063 45 my %is_constant_follower;
5064 45 my %is_use_require_no;
5065  
5066 BEGIN {
5067 45 ▶ my @qz = qw( w i U C );
Subroutine BEGIN: called CC=5 SCAR=16.1
5068 45 $is_wiUC{$_} = 1 for @qz;
5069  
5070 45 @qz = qw( use require no );
5071 45 $is_use_require_no{$_} = 1 for @qz;
5072  
5073 # These pre-token types after a bareword imply that it
5074 # is not a constant, except when '(' is followed by ')'.
5075 45 @qz = qw# ( [ { $ @ " ' m #;
5076 45 $is_function_follower{$_} = 1 for @qz;
5077  
5078 # These pre-token types after a bareword imply that it
5079 # MIGHT be a constant, but it also might be a function taking
5080 # 0 or more call args.
5081 45 @qz = qw# ; ) ] } if unless #;
5082 45 push @qz, COMMA;
5083 45 $is_constant_follower{$_} = 1 for @qz;
5084 }
5085  
5086 sub do_BAREWORD {
5087  
5088 6739 ▶ my ($self) = @_;
Subroutine do_BAREWORD: called CC=106 SCAR=54.2
Pod undocumented
5089  
5090 # handle a bareword token:
5091 # returns
5092 # true if this token ends the current line
5093 # false otherwise
5094  
5095 6739 my $next_nonblank_token;
5096 6739 my $i_next = $i + 1;
5097 6739 ▶ if ( $i_next <= $max_token_index && $rtoken_type->[$i_next] eq 'b' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_next <= $max_token_index and $rtoken_type->[$i_next] eq "b") 4105 2634 6739
Condition100%3/3
$i_next <= $max_token_index and $rtoken_type->[$i_next] eq "b"
!ll&&!rl&&r
7825564105
MC/DC100%2/2
$i_next <= $max_token_index and $rtoken_type->[$i_next] eq "b"
$i_next <= $max_token_index $rtoken_type->[$i_next] eq "b"
Truth table100%3/3
A and B
A= $i_next <= $max_token_indexB= $rtoken_type->[$i_next] eq "b"
ABresult
0X0
100
111
5098 4105 $i_next++;
5099 }
5100 6739 ▶ if ( $i_next <= $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_next <= $max_token_index) { } 6655 84 6739
5101 6655 $next_nonblank_token = $rtokens->[$i_next];
5102 }
5103 else {
5104 84 ( $next_nonblank_token, $i_next ) =
5105 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
5106 }
5107  
5108 # Fix for git #182: If --use-feature=class is set, then
5109 # a colon between words 'ADJUST' and 'params', and on the same line,
5110 # does not form the label 'ADJUST:'. It will get marked as type 'A'.
5111 6739 my $is_not_label;
5112 6739 ▶ if ( $tok eq 'ADJUST'
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "ADJUST" and $is_code_block_token{$tok} and $rtokens->[$i_next] eq ":" and $i_next < $max_token_index) 2 6737 6739
Condition77%7/9
$tok eq "ADJUST" and $is_code_block_token{$tok} and $rtokens->[$i_next] eq ":" and $i_next < $max_token_index
!ll&&!rl&&r
673702
$tok eq "ADJUST" and $is_code_block_token{$tok} and $rtokens->[$i_next] eq ":"
!ll&&!rl&&r
673612
$tok eq "ADJUST" and $is_code_block_token{$tok}
!ll&&!rl&&r
673603
MC/DC50%2/4
$tok eq "ADJUST" and $is_code_block_token{$tok} and $rtokens->[$i_next] eq ":" and $i_next < $max_token_index
$tok eq "ADJUST" $is_code_block_token{$tok} $rtokens->[$i_next] eq ":" $i_next < $max_token_index
Truth table60%3/5
A and B and C and D
A= $tok eq "ADJUST"B= $is_code_block_token{$tok}C= $rtokens->[$i_next] eq ":"D= $i_next < $max_token_index
ABCDresult
0XXX0
10XX0
110X0
11100
11111
5113 && $is_code_block_token{$tok}
5114 && $rtokens->[$i_next] eq ':'
5115 && $i_next < $max_token_index )
5116 {
5117 2 ▶ my $i_next2 =
Branch: 1 branch
BranchTrueFalseTotal
$$rtoken_type[$i_next + 1] eq 'b' ? : 0 2 2
5118 $rtoken_type->[ $i_next + 1 ] eq 'b' ? $i_next + 2 : $i_next + 1;
5119 2 ▶ $is_not_label =
Condition33%2/6
$i_next2 <= $max_token_index && $rtoken_type->[$i_next2] eq 'w' && $rtokens->[$i_next2] eq 'params'
!ll&&!rl&&r
002
$i_next2 <= $max_token_index and $rtoken_type->[$i_next2] eq "w"
!ll&&!rl&&r
002
MC/DC0%0/3
$i_next2 <= $max_token_index && $rtoken_type->[$i_next2] eq 'w' && $rtokens->[$i_next2] eq 'params'
$i_next2 <= $max_token_index $rtoken_type->[$i_next2] eq "w" $rtokens->[$i_next2] eq 'params'
Truth table25%1/4
A and B && C
A= $i_next2 <= $max_token_indexB= $rtoken_type->[$i_next2] eq "w"C= $rtokens->[$i_next2] eq 'params'
ABCresult
0XX0
10X0
1100
1111
5120 ( $i_next2 <= $max_token_index
5121 && $rtoken_type->[$i_next2] eq 'w'
5122 && $rtokens->[$i_next2] eq 'params' );
5123 }
5124  
5125 # a bare word immediately followed by :: is not a keyword;
5126 # use $tok_kw when testing for keywords to avoid a mistake
5127 6739 my $tok_kw = $tok;
5128 6739 ▶ if ( $rtokens->[ $i + 1 ] eq ':'
Branch: 1 branch
BranchTrueFalseTotal
if ($$rtokens[$i + 1] eq ":" and $$rtokens[$i + 2] eq ":") 272 6467 6739
Condition100%3/3
$$rtokens[$i + 1] eq ":" and $$rtokens[$i + 2] eq ":"
!ll&&!rl&&r
643433272
MC/DC100%2/2
$$rtokens[$i + 1] eq ":" and $$rtokens[$i + 2] eq ":"
$$rtokens[$i + 1] eq ":" $$rtokens[$i + 2] eq ":"
Truth table100%3/3
A and B
A= $$rtokens[$i + 1] eq ":"B= $$rtokens[$i + 2] eq ":"
ABresult
0X0
100
111
5129 && $rtokens->[ $i + 2 ] eq ':' )
5130 {
5131 272 $tok_kw .= '::';
5132 }
5133  
5134 6739 ▶ if ( $self->[_in_attribute_list_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[15]) 45 6694 6739
5135 45 my $is_attribute = $self->do_ATTRIBUTE_LIST($next_nonblank_token);
5136 45 ▶ return if ($is_attribute);
Branch: 1 branch
BranchTrueFalseTotal
if $is_attribute 45 0 45
5137 }
5138  
5139 #-----------------------------------------
5140 # Preliminary check for a lexical sub name
5141 #-----------------------------------------
5142 6694 my $is_lexical_sub_type;
5143  
5144 # Has this name been seen as a lexical sub?
5145 6694 ▶ if ( my $rseqno_hash = $ris_lexical_sub->{$tok_kw} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rseqno_hash = $ris_lexical_sub->{$tok_kw}) 0 6694 6694
5146  
5147 # Look back up the stack to see if it is still in scope.
5148 # Use the deepest we find if there are multiple versions.
5149 0 my @seqno_tested;
5150 0 my $cd_aa = $rcurrent_depth->[BRACE];
5151 0 foreach my $cd ( reverse( 0 .. $cd_aa ) ) {
5152 0 ▶ my $p_seqno =
Branch: 1 branch
BranchTrueFalseTotal
$cd ? : 0 0 0
5153 $cd
5154 ? $rcurrent_sequence_number->[BRACE]->[$cd]
5155 : SEQ_ROOT;
5156  
5157 0 push @seqno_tested, $p_seqno;
5158  
5159 # Lexical subs use their containing sequence number as package
5160 0 ▶ if ( my $seqno_brace = $rseqno_hash->{$p_seqno} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $seqno_brace = $rseqno_hash->{$p_seqno}) 0 0 0
5161  
5162 # This sub is in scope .. lookup its type
5163 $is_lexical_sub_type =
5164 $ris_constant->{$p_seqno}->{$tok_kw} ? 'C'
5165 : $ris_block_function->{$p_seqno}->{$tok_kw} ? 'G'
5166 : $ris_block_list_function->{$p_seqno}->{$tok_kw} ? 'G'
5167 0 ▶ : $ris_user_function->{$p_seqno}->{$tok_kw} ? 'U'
Branch: 4 branches
BranchTrueFalseTotal
$ris_constant->{$p_seqno}{$tok_kw} ? : 0 0 0
$ris_block_function->{$p_seqno}{$tok_kw} ? : 0 0 0
$ris_block_list_function->{$p_seqno}{$tok_kw} ? : 0 0 0
$ris_user_function->{$p_seqno}{$tok_kw} ? : 0 0 0
5168 : 'U';
5169  
5170 # But lexical subs do not apply within their defining code
5171 0 foreach (@seqno_tested) {
5172 0 ▶ next if ( $_ != $seqno_brace );
Branch: 1 branch
BranchTrueFalseTotal
if $_ != $seqno_brace 0 0 0
5173 0 $is_lexical_sub_type = undef;
5174 0 last;
5175 }
5176  
5177 0 last;
5178 }
5179 }
5180 }
5181  
5182 #----------------------------------------
5183 # Starting final if-elsif- chain of tests
5184 #----------------------------------------
5185  
5186 # This is the return flag:
5187 # true => this is the last token on the line
5188 # false => keep tokenizing the line
5189 6694 my $is_last;
5190  
5191 # The following blocks of code must update these vars:
5192 # $type - the final token type, must always be set
5193  
5194 # In addition, if additional pretokens are added:
5195 # $tok - the final token
5196 # $i - the index of the last pretoken
5197  
5198 # They may also need to check and set various flags
5199  
5200 # Scan a bare word following a -> as an identifier; it could
5201 # have a long package name. Fixes c037, c041.
5202 6694 ▶ if ( $last_nonblank_token eq '->' ) {
Branch: 19 branches
BranchTrueFalseTotal
if ($last_nonblank_token eq '->') { } 786 5908 6694
elsif ($next_nonblank_token eq '=' and $$rtokens[$i_next + 1] eq '>' and not defined $is_END_DATA{$tok_kw} && $input_line =~ /^\s*__(?:END|DATA)__\s*$/) { } 826 5082 5908
elsif ($next_nonblank_token eq '}' and $last_nonblank_type eq 'L' || $last_nonblank_type eq 'm' && $last_last_nonblank_type eq 'L') { } 138 4944 5082
elsif ($expecting == 1 and substr($tok, 0, 1) eq 'x' and length $tok == 1 || substr($tok, 1, 1) =~ /^\d/) { } 17 4927 4944
elsif ($tok_kw eq 'CORE::') { } 3 4924 4927
elsif ($tok eq 'strict' and $last_nonblank_token eq 'use') { } 14 4910 4924
elsif ($tok eq 'warnings' and $last_nonblank_token eq 'use') { } 7 4903 4910
elsif ($tok eq 'AutoLoader' and $self->[27] and $last_nonblank_token eq 'use' || $input_line =~ /^\s*(use|require)\s+AutoLoader\b/ || $input_line =~ /\bISA\s*=.*\bAutoLoader\b/) { } 0 4903 4903
elsif ($tok eq 'SelfLoader' and $self->[28] and $last_nonblank_token eq 'use' || $input_line =~ /^\s*(use|require)\s+SelfLoader\b/ || $input_line =~ /\bISA\s*=.*\bSelfLoader\b/) { } 0 4903 4903
elsif ($tok eq 'constant' and $last_nonblank_token eq 'use') { } 18 4885 4903
elsif ($is_lexical_sub_type) { } 0 4885 4885
elsif ($is_q_qq_qw_qx_qr_s_y_tr_m{$tok}) { } 237 4648 4885
elsif ($next_nonblank_token eq ':' and not $is_not_label and $$rtokens[$i_next + 1] ne ':' and $i_next <= $max_token_index and not $self->sub_attribute_ok_here($tok_kw, $next_nonblank_token, $i_next) and new_statement_ok()) { } 33 4615 4648
elsif ($is_sub{$tok_kw}) { } 372 4243 4615
elsif ($is_package{$tok_kw}) { } 54 4189 4243
elsif ($tok_kw eq 'format' and new_statement_ok()) { } 1 4188 4189
elsif (defined $is_END_DATA{$tok_kw}) { } 8 4180 4188
elsif ($is_keyword{$tok_kw}) { } 3136 1044 4180
elsif ($last_nonblank_type eq 'k' and $is_redo_last_next_goto{$last_nonblank_token}) { } 19 1025 1044
5203 786 $self->scan_bare_identifier();
5204  
5205 # a bareward after '->' gets type 'i'
5206 786 $type = 'i';
5207 }
5208  
5209 # Quote a word followed by => operator
5210 ▶ elsif (
Condition88%8/9
$next_nonblank_token eq "=" and $$rtokens[$i_next + 1] eq ">" and not defined $is_END_DATA{$tok_kw} && $input_line =~ /^\s*__(?:END|DATA)__\s*$/
!ll&&!rl&&r
50811826
$next_nonblank_token eq "=" and $$rtokens[$i_next + 1] eq ">"
!ll&&!rl&&r
507011827
defined $is_END_DATA{$tok_kw} && $input_line =~ /^\s*__(?:END|DATA)__\s*$/
!ll&&!rl&&r
82601
MC/DC75%3/4
$next_nonblank_token eq "=" and $$rtokens[$i_next + 1] eq ">" and not defined $is_END_DATA{$tok_kw} && $input_line =~ /^\s*__(?:END|DATA)__\s*$/
$next_nonblank_token eq "=" $$rtokens[$i_next + 1] eq ">" defined $is_END_DATA{$tok_kw} $input_line =~ /^\s*__(?:END|DATA)__\s*$/
Truth table80%4/5
A and B and not(C && D)
A= $next_nonblank_token eq "="B= $$rtokens[$i_next + 1] eq ">"C= defined $is_END_DATA{$tok_kw}D= $input_line =~ /^\s*__(?:END|DATA)__\s*$/
ABCDresult
0XXX0
10XX0
11110
110X1
11101
5211 ( $next_nonblank_token eq '=' && $rtokens->[ $i_next + 1 ] eq '>' )
5212  
5213 # unless the word is __END__ or __DATA__ and is the only word on
5214 # the line.
5215 && ( !defined( $is_END_DATA{$tok_kw} )
5216 || $input_line !~ /^\s*__(?:END|DATA)__\s*$/ )
5217 )
5218 {
5219 # Bareword followed by a fat comma - see 'git18.in'
5220 # This code was previously sub do_QUOTED_BAREWORD: see c316, c317
5221  
5222 # Older perl:
5223 # 'v25=>1' is a v-string key!
5224 # '-v25=>1' is also a v-string key!
5225 # Deactivated: this is no longer true; see git #165
5226 826 ▶ if ( 0 && $tok =~ /^v\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (do { $expecting == 1 and substr($tok, 0, 1) eq 'x' and length $tok == 1 || substr($tok, 1, 1) =~ /^\d/ }) { } 3 823 826
5227 $type = 'v';
5228 $self->complain("v-string used as hash key\n");
5229 $self->report_v_string($tok);
5230 }
5231  
5232 # If tok is something like 'x17' then it could
5233 # actually be operator x followed by number 17.
5234 # For example, here:
5235 # 123x17 => [ 792, 1224 ],
5236 # (a key of 123 repeated 17 times, perhaps not
5237 # what was intended). We will mark x17 as type
5238 # 'n' and it will be split. If the previous token
5239 # was also a bareword then it is not very clear is
5240 # going on. In this case we will not be sure that
5241 # an operator is expected, so we just mark it as a
5242 # bareword. Perl is a little murky in what it does
5243 # with stuff like this, and its behavior can change
5244 # over time. Something like
5245 # a x18 => [792, 1224], will compile as
5246 # a key with 18 a's. But something like
5247 # push @array, a x18;
5248 # is a syntax error.
5249 ▶ elsif (
Condition55%5/9
$expecting == 1 and substr($tok, 0, 1) eq "x" and length $tok == 1 || substr($tok, 1, 1) =~ /^\d/
!ll&&!rl&&r
82303
$expecting == 1 and substr($tok, 0, 1) eq "x"
!ll&&!rl&&r
82303
length $tok == 1 or substr($tok, 1, 1) =~ /^\d/
l!l&&r!l&&!r
030
MC/DC25%1/4
$expecting == 1 and substr($tok, 0, 1) eq "x" and length $tok == 1 || substr($tok, 1, 1) =~ /^\d/
$expecting == 1 substr($tok, 0, 1) eq "x" length $tok == 1 substr($tok, 1, 1) =~ /^\d/
Truth table40%2/5
A and B and C or D
A= $expecting == 1B= substr($tok, 0, 1) eq "x"C= length $tok == 1D= substr($tok, 1, 1) =~ /^\d/
ABCDresult
0XXX0
10XX0
11000
111X1
11011
5250 $expecting == OPERATOR
5251 && substr( $tok, 0, 1 ) eq 'x'
5252 && ( length($tok) == 1
5253 || substr( $tok, 1, 1 ) =~ /^\d/ )
5254 )
5255 {
5256 3 $type = 'n';
5257 3 ▶ if ( $self->split_pretoken(1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->split_pretoken(1)) 3 0 3
5258 3 $type = 'x';
5259 3 $tok = 'x';
5260 }
5261 3 $self->complain("x operator in hash key\n");
5262 }
5263 else {
5264  
5265 # git #18
5266 823 $type = 'w';
5267 823 $self->error_if_expecting_OPERATOR();
5268 }
5269 }
5270  
5271 # quote a bare word within braces..like xxx->{s}; note that we
5272 # must be sure this is not a structural brace, to avoid
5273 # mistaking {s} in the following for a quoted bare word:
5274 # for(@[){s}bla}BLA}
5275 # Also treat q in something like var{-q} as a bare word, not
5276 # a quote operator
5277 ▶ elsif (
Condition100%9/9
$next_nonblank_token eq "}" and $last_nonblank_type eq "L" || $last_nonblank_type eq "m" && $last_last_nonblank_type eq "L"
!ll&&!rl&&r
491529138
$last_nonblank_type eq "L" or $last_nonblank_type eq "m" and $last_last_nonblank_type eq "L"
l!l&&r!l&&!r
136229
$last_nonblank_type eq "m" and $last_last_nonblank_type eq "L"
!ll&&!rl&&r
2812
MC/DC100%4/4
$next_nonblank_token eq "}" and $last_nonblank_type eq "L" || $last_nonblank_type eq "m" && $last_last_nonblank_type eq "L"
$next_nonblank_token eq "}" $last_nonblank_type eq "L" $last_nonblank_type eq "m" $last_last_nonblank_type eq "L"
Truth table100%5/5
A and B or C and D
A= $next_nonblank_token eq "}"B= $last_nonblank_type eq "L"C= $last_nonblank_type eq "m"D= $last_last_nonblank_type eq "L"
ABCDresult
0XXX0
100X0
10100
11XX1
10111
5278 $next_nonblank_token eq '}'
5279 && (
5280 $last_nonblank_type eq 'L'
5281 || ( $last_nonblank_type eq 'm'
5282 && $last_last_nonblank_type eq 'L' )
5283 )
5284 )
5285 {
5286 138 $type = 'w';
5287 }
5288  
5289 # handle operator x (now we know it isn't $x=)
5290 ▶ elsif (
Condition77%7/9
$expecting == 1 and substr($tok, 0, 1) eq "x" and length $tok == 1 || substr($tok, 1, 1) =~ /^\d/
!ll&&!rl&&r
4927017
$expecting == 1 and substr($tok, 0, 1) eq "x"
!ll&&!rl&&r
458833917
length $tok == 1 or substr($tok, 1, 1) =~ /^\d/
l!l&&r!l&&!r
1520
MC/DC50%2/4
$expecting == 1 and substr($tok, 0, 1) eq "x" and length $tok == 1 || substr($tok, 1, 1) =~ /^\d/
$expecting == 1 substr($tok, 0, 1) eq "x" length $tok == 1 substr($tok, 1, 1) =~ /^\d/
Truth table80%4/5
A and B and C or D
A= $expecting == 1B= substr($tok, 0, 1) eq "x"C= length $tok == 1D= substr($tok, 1, 1) =~ /^\d/
ABCDresult
0XXX0
10XX0
11000
111X1
11011
5291 $expecting == OPERATOR
5292 && substr( $tok, 0, 1 ) eq 'x'
5293 && ( length($tok) == 1
5294 || substr( $tok, 1, 1 ) =~ /^\d/ )
5295 )
5296 {
5297 17 $self->do_X_OPERATOR();
5298 }
5299 elsif ( $tok_kw eq 'CORE::' ) {
5300 3 $type = $tok = $tok_kw;
5301 3 $i += 2;
5302 }
5303 ▶ elsif ( ( $tok eq 'strict' )
Condition100%3/3
$tok eq "strict" and $last_nonblank_token eq "use"
!ll&&!rl&&r
4908214
MC/DC100%2/2
$tok eq "strict" and $last_nonblank_token eq "use"
$tok eq "strict" $last_nonblank_token eq "use"
Truth table100%3/3
A and B
A= $tok eq "strict"B= $last_nonblank_token eq "use"
ABresult
0X0
100
111
5304 and ( $last_nonblank_token eq 'use' ) )
5305 {
5306 14 $self->[_saw_use_strict_] = 1;
5307 14 $self->scan_bare_identifier();
5308 }
5309  
5310 ▶ elsif ( ( $tok eq 'warnings' )
Condition100%3/3
$tok eq "warnings" and $last_nonblank_token eq "use"
!ll&&!rl&&r
490127
MC/DC100%2/2
$tok eq "warnings" and $last_nonblank_token eq "use"
$tok eq "warnings" $last_nonblank_token eq "use"
Truth table100%3/3
A and B
A= $tok eq "warnings"B= $last_nonblank_token eq "use"
ABresult
0X0
100
111
5311 and ( $last_nonblank_token eq 'use' ) )
5312 {
5313 7 $self->[_saw_perl_dash_w_] = 1;
5314  
5315 # scan as identifier, so that we pick up something like:
5316 # use warnings::register
5317 7 $self->scan_bare_identifier();
5318 }
5319  
5320 ▶ elsif (
Condition16%2/12
$tok eq "AutoLoader" and $self->[27] and $last_nonblank_token eq "use" || $input_line =~ /^\s*(use|require)\s+AutoLoader\b/ || $input_line =~ /\bISA\s*=.*\bAutoLoader\b/
!ll&&!rl&&r
490300
$tok eq "AutoLoader" and $self->[27]
!ll&&!rl&&r
490300
$last_nonblank_token eq "use" or $input_line =~ /^\s*(use|require)\s+AutoLoader\b/ or $input_line =~ /\bISA\s*=.*\bAutoLoader\b/
l!l&&r!l&&!r
000
$last_nonblank_token eq "use" or $input_line =~ /^\s*(use|require)\s+AutoLoader\b/
l!l&&r!l&&!r
000
MC/DC0%0/5
$tok eq "AutoLoader" and $self->[27] and $last_nonblank_token eq "use" || $input_line =~ /^\s*(use|require)\s+AutoLoader\b/ || $input_line =~ /\bISA\s*=.*\bAutoLoader\b/
$tok eq "AutoLoader" $self->[27] $last_nonblank_token eq "use" $input_line =~ /^\s*(use|require)\s+AutoLoader\b/ $input_line =~ /\bISA\s*=.*\bAutoLoader\b/
Truth table16%1/6
A and B and C or D or E
A= $tok eq "AutoLoader"B= $self->[27]C= $last_nonblank_token eq "use"D= $input_line =~ /^\s*(use|require)\s+AutoLoader\b/E= $input_line =~ /\bISA\s*=.*\bAutoLoader\b/
ABCDEresult
0XXXX0
10XXX0
110000
111XX1
1101X1
110011
5321 $tok eq 'AutoLoader'
5322 && $self->[_look_for_autoloader_]
5323 && (
5324 $last_nonblank_token eq 'use'
5325  
5326 # these regexes are from AutoSplit.pm, which we want
5327 # to mimic
5328 || $input_line =~ /^\s*(use|require)\s+AutoLoader\b/
5329 || $input_line =~ /\bISA\s*=.*\bAutoLoader\b/
5330 )
5331 )
5332 {
5333 0 $self->write_logfile_entry("AutoLoader seen, -nlal deactivates\n");
5334 0 $self->[_saw_autoloader_] = 1;
5335 0 $self->[_look_for_autoloader_] = 0;
5336 0 $self->scan_bare_identifier();
5337 }
5338  
5339 ▶ elsif (
Condition16%2/12
$tok eq "SelfLoader" and $self->[28] and $last_nonblank_token eq "use" || $input_line =~ /^\s*(use|require)\s+SelfLoader\b/ || $input_line =~ /\bISA\s*=.*\bSelfLoader\b/
!ll&&!rl&&r
490300
$tok eq "SelfLoader" and $self->[28]
!ll&&!rl&&r
490300
$last_nonblank_token eq "use" or $input_line =~ /^\s*(use|require)\s+SelfLoader\b/ or $input_line =~ /\bISA\s*=.*\bSelfLoader\b/
l!l&&r!l&&!r
000
$last_nonblank_token eq "use" or $input_line =~ /^\s*(use|require)\s+SelfLoader\b/
l!l&&r!l&&!r
000
MC/DC0%0/5
$tok eq "SelfLoader" and $self->[28] and $last_nonblank_token eq "use" || $input_line =~ /^\s*(use|require)\s+SelfLoader\b/ || $input_line =~ /\bISA\s*=.*\bSelfLoader\b/
$tok eq "SelfLoader" $self->[28] $last_nonblank_token eq "use" $input_line =~ /^\s*(use|require)\s+SelfLoader\b/ $input_line =~ /\bISA\s*=.*\bSelfLoader\b/
Truth table16%1/6
A and B and C or D or E
A= $tok eq "SelfLoader"B= $self->[28]C= $last_nonblank_token eq "use"D= $input_line =~ /^\s*(use|require)\s+SelfLoader\b/E= $input_line =~ /\bISA\s*=.*\bSelfLoader\b/
ABCDEresult
0XXXX0
10XXX0
110000
111XX1
1101X1
110011
5340 $tok eq 'SelfLoader'
5341 && $self->[_look_for_selfloader_]
5342 && ( $last_nonblank_token eq 'use'
5343 || $input_line =~ /^\s*(use|require)\s+SelfLoader\b/
5344 || $input_line =~ /\bISA\s*=.*\bSelfLoader\b/ )
5345 )
5346 {
5347 0 $self->write_logfile_entry("SelfLoader seen, -nlsl deactivates\n");
5348 0 $self->[_saw_selfloader_] = 1;
5349 0 $self->[_look_for_selfloader_] = 0;
5350 0 $self->scan_bare_identifier();
5351 }
5352  
5353 ▶ elsif ( ( $tok eq 'constant' )
Condition66%2/3
$tok eq "constant" and $last_nonblank_token eq "use"
!ll&&!rl&&r
4885018
MC/DC50%1/2
$tok eq "constant" and $last_nonblank_token eq "use"
$tok eq "constant" $last_nonblank_token eq "use"
Truth table66%2/3
A and B
A= $tok eq "constant"B= $last_nonblank_token eq "use"
ABresult
0X0
100
111
5354 and ( $last_nonblank_token eq 'use' ) )
5355 {
5356 18 $self->do_USE_CONSTANT();
5357 }
5358  
5359 # Lexical sub names override keywords, labels. Based on testing,
5360 # this seems to be the correct location for this check.
5361 elsif ($is_lexical_sub_type) {
5362 0 $type = $is_lexical_sub_type;
5363 }
5364  
5365 # various quote operators
5366 elsif ( $is_q_qq_qw_qx_qr_s_y_tr_m{$tok} ) {
5367 237 $self->do_QUOTE_OPERATOR();
5368 }
5369  
5370 # check for a statement label
5371 ▶ elsif (
Condition100%15/15
$next_nonblank_token eq ":" and not $is_not_label and $$rtokens[$i_next + 1] ne ":" and $i_next <= $max_token_index and not $self->sub_attribute_ok_here($tok_kw, $next_nonblank_token, $i_next) and new_statement_ok()
!ll&&!rl&&r
4613233
$next_nonblank_token eq ":" and not $is_not_label and $$rtokens[$i_next + 1] ne ":" and $i_next <= $max_token_index and not $self->sub_attribute_ok_here($tok_kw, $next_nonblank_token, $i_next)
!ll&&!rl&&r
4611235
$next_nonblank_token eq ":" and not $is_not_label and $$rtokens[$i_next + 1] ne ":" and $i_next <= $max_token_index
!ll&&!rl&&r
4608337
$next_nonblank_token eq ":" and not $is_not_label and $$rtokens[$i_next + 1] ne ":"
!ll&&!rl&&r
433527340
$next_nonblank_token eq ":" and not $is_not_label
!ll&&!rl&&r
43332313
MC/DC100%6/6
$next_nonblank_token eq ":" and not $is_not_label and $$rtokens[$i_next + 1] ne ":" and $i_next <= $max_token_index and not $self->sub_attribute_ok_here($tok_kw, $next_nonblank_token, $i_next) and new_statement_ok()
$next_nonblank_token eq ":" not $is_not_label $$rtokens[$i_next + 1] ne ":" $i_next <= $max_token_index not $self->sub_attribute_ok_here($tok_kw, $next_nonblank_token, $i_next) new_statement_ok()
Truth table100%7/7
A and not(B) and C and D and not(E) and F
A= $next_nonblank_token eq ":"B= not $is_not_labelC= $$rtokens[$i_next + 1] ne ":"D= $i_next <= $max_token_indexE= not $self->sub_attribute_ok_here($tok_kw, $next_nonblank_token, $i_next)F= new_statement_ok()
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
5372 ( $next_nonblank_token eq ':' )
5373 && !$is_not_label
5374 && ( $rtokens->[ $i_next + 1 ] ne ':' )
5375 && ( $i_next <= $max_token_index ) # colon on same line
5376  
5377 # like 'sub : lvalue' ?
5378 && !$self->sub_attribute_ok_here( $tok_kw, $next_nonblank_token,
5379 $i_next )
5380 && new_statement_ok()
5381 )
5382 {
5383 33 ▶ if ( $tok !~ /[A-Z]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tok =~ /[A-Z]/) 15 18 33
5384 15 push @{ $self->[_rlower_case_labels_at_] }, $input_line_number;
5385 }
5386 33 $type = 'J';
5387 33 $tok .= ':';
5388 33 $i = $i_next;
5389 }
5390  
5391 # 'sub' or other sub alias
5392 elsif ( $is_sub{$tok_kw} ) {
5393  
5394 # Guess what to do for unknown word 'method':
5395 # Updated for --use-feature=class (rt145706):
5396 372 ▶ if ( $tok_kw eq 'method'
Branch: 1 branch
BranchTrueFalseTotal
if ($tok_kw eq 'method' and $guess_if_method and not $self->method_ok_here($next_nonblank_token)) { } 7 365 372
Condition100%6/6
$tok_kw eq "method" and $guess_if_method and not $self->method_ok_here($next_nonblank_token)
!ll&&!rl&&r
35877
$tok_kw eq "method" and $guess_if_method
!ll&&!rl&&r
356214
MC/DC100%3/3
$tok_kw eq "method" and $guess_if_method and not $self->method_ok_here($next_nonblank_token)
$tok_kw eq "method" $guess_if_method not $self->method_ok_here($next_nonblank_token)
Truth table100%4/4
A and B and not(C)
A= $tok_kw eq "method"B= $guess_if_methodC= not $self->method_ok_here($next_nonblank_token)
ABCresult
0XX0
10X0
1100
1111
5397 && $guess_if_method
5398 && !$self->method_ok_here($next_nonblank_token) )
5399 {
5400 7 $self->do_UNKNOWN_BAREWORD($next_nonblank_token);
5401 }
5402 else {
5403 365 ▶ $self->error_if_expecting_OPERATOR()
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 365 365
5404 if ( $expecting == OPERATOR );
5405 365 initialize_subname();
5406 365 $self->scan_id();
5407 }
5408 }
5409  
5410 # 'package'
5411 elsif ( $is_package{$tok_kw} ) {
5412  
5413 # Update for --use-feature=class (rt145706):
5414 # We have to be extra careful because 'class' may be used for other
5415 # purposes on older code; i.e.
5416 # class($x) - valid sub call
5417 # package($x) - error
5418 54 ▶ if ( $tok_kw eq 'class' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok_kw eq 'class') { } 14 40 54
5419 14 ▶ if ( $expecting == OPERATOR
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == 1 or not $next_nonblank_token =~ /^[\w\:]/ or not $self->class_ok_here) { } 4 10 14
Condition83%5/6
$expecting == 1 or not $next_nonblank_token =~ /^[\w\:]/ or not $self->class_ok_here
l!l&&r!l&&!r
2210
$expecting == 1 or not $next_nonblank_token =~ /^[\w\:]/
l!l&&r!l&&!r
0212
MC/DC66%2/3
$expecting == 1 or not $next_nonblank_token =~ /^[\w\:]/ or not $self->class_ok_here
$expecting == 1 not $next_nonblank_token =~ /^[\w\:]/ not $self->class_ok_here
Truth table75%3/4
A or not(B) or not(C)
A= $expecting == 1B= not $next_nonblank_token =~ /^[\w\:]/C= not $self->class_ok_here
ABCresult
1XX1
01X1
0011
0000
5420 || $next_nonblank_token !~ /^[\w\:]/
5421 || !$self->class_ok_here() )
5422 {
5423 4 $self->do_UNKNOWN_BAREWORD($next_nonblank_token);
5424 }
5425 10 else { $self->scan_id() }
5426 }
5427 else {
5428 40 ▶ $self->error_if_expecting_OPERATOR()
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 40 40
5429 if ( $expecting == OPERATOR );
5430 40 $self->scan_id();
5431 }
5432 }
5433  
5434 # Fix for c035: split 'format' from 'is_format_END_DATA' to be
5435 # more restrictive. Require a new statement to be ok here.
5436 ▶ elsif ( $tok_kw eq 'format' && new_statement_ok() ) {
Condition66%2/3
$tok_kw eq "format" and new_statement_ok()
!ll&&!rl&&r
418801
MC/DC50%1/2
$tok_kw eq "format" and new_statement_ok()
$tok_kw eq "format" new_statement_ok()
Truth table66%2/3
A and B
A= $tok_kw eq "format"B= new_statement_ok()
ABresult
0X0
100
111
5437 1 $type = ';'; # make tokenizer look for TERM next
5438 1 $self->[_in_format_] = 1;
5439 1 $is_last = 1; ## is last token on this line
5440 }
5441  
5442 # Note on token types for format, __DATA__, __END__:
5443 # It simplifies things to give these type ';', so that when we
5444 # start rescanning we will be expecting a token of type TERM.
5445 # We will switch to type 'k' before outputting the tokens.
5446 elsif ( defined( $is_END_DATA{$tok_kw} ) ) {
5447  
5448 # Warn if this follows an operator expecting a term (c565)
5449 8 ▶ $self->error_if_expecting_TERM()
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == -1 8 0 8
5450 if ( $expecting == TERM );
5451  
5452 8 $type = ';'; # make tokenizer look for TERM next
5453  
5454 # Remember that we are in one of these three sections
5455 8 $self->[ $is_END_DATA{$tok_kw} ] = 1;
5456 8 $is_last = 1; ## is last token on this line
5457 }
5458 elsif ( $is_keyword{$tok_kw} ) {
5459 3136 $self->do_KEYWORD();
5460 }
5461  
5462 # check for inline label following
5463 # /^(redo|last|next|goto)$/
5464 ▶ elsif (( $last_nonblank_type eq 'k' )
Condition100%3/3
$last_nonblank_type eq "k" and $is_redo_last_next_goto{$last_nonblank_token}
!ll&&!rl&&r
80721819
MC/DC100%2/2
$last_nonblank_type eq "k" and $is_redo_last_next_goto{$last_nonblank_token}
$last_nonblank_type eq "k" $is_redo_last_next_goto{$last_nonblank_token}
Truth table100%3/3
A and B
A= $last_nonblank_type eq "k"B= $is_redo_last_next_goto{$last_nonblank_token}
ABresult
0X0
100
111
5465 && ( $is_redo_last_next_goto{$last_nonblank_token} ) )
5466 {
5467 19 $type = 'j';
5468 }
5469  
5470 # something else --
5471 else {
5472 1025 $self->do_UNKNOWN_BAREWORD($next_nonblank_token);
5473 }
5474  
5475 #----------------------------------------------------------------
5476 # Save info for use in later guessing. Even for types 'i' and 'U'
5477 # because those may be marked as type 'w' (barewords) elsewhere.
5478 #----------------------------------------------------------------
5479 6694 ▶ if ( $is_wiUC{$type}
Branch: 1 branch
BranchTrueFalseTotal
if ($is_wiUC{$type} and $statement_type ne "use" and $statement_type ne "_use") 2644 4050 6694
Condition100%6/6
$is_wiUC{$type} and $statement_type ne "use" and $statement_type ne "_use"
!ll&&!rl&&r
404822644
$is_wiUC{$type} and $statement_type ne "use"
!ll&&!rl&&r
38781702646
MC/DC100%3/3
$is_wiUC{$type} and $statement_type ne "use" and $statement_type ne "_use"
$is_wiUC{$type} $statement_type ne "use" $statement_type ne "_use"
Truth table100%4/4
A and B and C
A= $is_wiUC{$type}B= $statement_type ne "use"C= $statement_type ne "_use"
ABCresult
0XX0
10X0
1100
1111
5480 && $statement_type ne 'use'
5481 && $statement_type ne '_use' )
5482 {
5483 2644 my $result = "unknown";
5484  
5485 # Words are marked 'function' if they appear in a role which
5486 # is not consistent with a constant value. Typically they are
5487 # function calls.
5488 2644 ▶ if ( $type eq 'U'
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'U' or $is_function_follower{$next_nonblank_token}) { } 1019 1625 2644
elsif ($type eq 'C' or $is_constant_follower{$next_nonblank_token}) { } 445 1180 1625
Condition100%3/3
$type eq "U" or $is_function_follower{$next_nonblank_token}
l!l&&r!l&&!r
2987211625
MC/DC100%2/2
$type eq "U" or $is_function_follower{$next_nonblank_token}
$type eq "U" $is_function_follower{$next_nonblank_token}
Truth table100%3/3
A or B
A= $type eq "U"B= $is_function_follower{$next_nonblank_token}
ABresult
1X1
011
000
5489 || $is_function_follower{$next_nonblank_token} )
5490 {
5491  
5492 1019 my $empty_parens = 0;
5493 1019 ▶ if ( $next_nonblank_token eq '(' && $i_next < $max_token_index )
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "(" and $i_next < $max_token_index) 594 425 1019
Condition100%3/3
$next_nonblank_token eq "(" and $i_next < $max_token_index
!ll&&!rl&&r
151274594
MC/DC100%2/2
$next_nonblank_token eq "(" and $i_next < $max_token_index
$next_nonblank_token eq "(" $i_next < $max_token_index
Truth table100%3/3
A and B
A= $next_nonblank_token eq "("B= $i_next < $max_token_index
ABresult
0X0
100
111
5494 {
5495 594 my $tok_next_p1 = $rtokens->[ $i_next + 1 ];
5496 594 ▶ if ( substr( $tok_next_p1, 0, 1 ) eq SPACE
Branch: 1 branch
BranchTrueFalseTotal
if (substr($tok_next_p1, 0, 1) eq " " and $i_next + 2 <= $max_token_index) 284 310 594
Condition100%3/3
substr($tok_next_p1, 0, 1) eq " " and $i_next + 2 <= $max_token_index
!ll&&!rl&&r
3082284
MC/DC100%2/2
substr($tok_next_p1, 0, 1) eq " " and $i_next + 2 <= $max_token_index
substr($tok_next_p1, 0, 1) eq " " $i_next + 2 <= $max_token_index
Truth table100%3/3
A and B
A= substr($tok_next_p1, 0, 1) eq " "B= $i_next + 2 <= $max_token_index
ABresult
0X0
100
111
5497 && $i_next + 2 <= $max_token_index )
5498 {
5499 284 $tok_next_p1 = $rtokens->[ $i_next + 2 ];
5500 }
5501 594 $empty_parens = $tok_next_p1 eq ')';
5502 }
5503  
5504 1019 ▶ if ( !$empty_parens ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($empty_parens) 961 58 1019
5505  
5506 # not a constant term - probably a function
5507 961 $result = "function";
5508 961 $self->saw_bareword_function($tok);
5509 }
5510 }
5511  
5512 # Words are marked 'constant' if they appear in a role
5513 # consistent with a constant value. However, they may simply
5514 # be functions which optionally take zero args. So if a word
5515 # appears as both constant and function, it is not a constant.
5516 ▶ elsif ($type eq 'C'
Condition100%3/3
$type eq "C" or $is_constant_follower{$next_nonblank_token}
l!l&&r!l&&!r
124331180
MC/DC100%2/2
$type eq "C" or $is_constant_follower{$next_nonblank_token}
$type eq "C" $is_constant_follower{$next_nonblank_token}
Truth table100%3/3
A or B
A= $type eq "C"B= $is_constant_follower{$next_nonblank_token}
ABresult
1X1
011
000
5517 || $is_constant_follower{$next_nonblank_token} )
5518 {
5519  
5520 445 ▶ my $is_hash_key = $next_nonblank_token eq '}'
Condition100%9/9
$next_nonblank_token eq '}' && ($last_nonblank_type eq 'L' || $last_nonblank_type eq 'm' && $last_last_nonblank_type eq 'L')
!ll&&!rl&&r
27037138
$last_nonblank_type eq "L" or $last_nonblank_type eq "m" and $last_last_nonblank_type eq "L"
l!l&&r!l&&!r
136237
$last_nonblank_type eq "m" and $last_last_nonblank_type eq "L"
!ll&&!rl&&r
3612
MC/DC100%4/4
$next_nonblank_token eq '}' && ($last_nonblank_type eq 'L' || $last_nonblank_type eq 'm' && $last_last_nonblank_type eq 'L')
$next_nonblank_token eq '}' $last_nonblank_type eq "L" $last_nonblank_type eq "m" $last_last_nonblank_type eq "L"
Truth table100%5/5
A && B or C and D
A= $next_nonblank_token eq '}'B= $last_nonblank_type eq "L"C= $last_nonblank_type eq "m"D= $last_last_nonblank_type eq "L"
ABCDresult
0XXX0
100X0
10100
11XX1
10111
5521 && (
5522 $last_nonblank_type eq 'L'
5523 || ( $last_nonblank_type eq 'm'
5524 && $last_last_nonblank_type eq 'L' )
5525 );
5526  
5527 445 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_hash_key and $last_nonblank_type ne 'k' || !$is_use_require_no{$last_nonblank_token} and $last_nonblank_token ne '->') { } 182 263 445
Condition100%9/9
not $is_hash_key and $last_nonblank_type ne "k" || !$is_use_require_no{$last_nonblank_token} and $last_nonblank_token ne "->"
!ll&&!rl&&r
154109182
not $is_hash_key and $last_nonblank_type ne "k" || !$is_use_require_no{$last_nonblank_token}
!ll&&!rl&&r
13816291
$last_nonblank_type ne "k" or not $is_use_require_no{$last_nonblank_token}
l!l&&r!l&&!r
282916
MC/DC100%4/4
not $is_hash_key and $last_nonblank_type ne "k" || !$is_use_require_no{$last_nonblank_token} and $last_nonblank_token ne "->"
not $is_hash_key $last_nonblank_type ne "k" not $is_use_require_no{$last_nonblank_token} $last_nonblank_token ne "->"
Truth table83%5/6
not(A) and B or not(C) and D
A= not $is_hash_keyB= $last_nonblank_type ne "k"C= not $is_use_require_no{$last_nonblank_token}D= $last_nonblank_token ne "->"
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
5528  
5529 # not a hash key like {bareword} or {-bareword}
5530 !$is_hash_key
5531  
5532 # not a package name, etc
5533 && ( $last_nonblank_type ne 'k'
5534 || !$is_use_require_no{$last_nonblank_token} )
5535  
5536 # skip arrow calls, which can go either way
5537 && $last_nonblank_token ne '->'
5538 )
5539 {
5540 # possibly a constant or constant function
5541 182 $result = "constant";
5542 182 $self->saw_bareword_constant($tok);
5543 }
5544 else {
5545 263 $result = "other bareword";
5546 }
5547 }
5548 else {
5549 ## something else
5550 }
5551  
5552 2644 if ( DEBUG_BAREWORD && $result ne 'other bareword' ) {
5553 print
5554 "$input_line_number: $result: $tok: type=$type : last_tok=$last_nonblank_token : next_tok='$next_nonblank_token'\n";
5555 }
5556 }
5557 6694 return $is_last;
5558  
5559 } ## end sub do_BAREWORD
5560  
5561 # Table of quote types checked for interpolated here targets.
5562 # Issue 310 has extensive test cases.
5563 45 my %is_interpolated_quote = (
5564 q{'} => 0,
5565 q{`} => 1,
5566 q{"} => 1,
5567 qq => 1,
5568 qx => 1,
5569 m => 1,
5570 qr => 1,
5571 q => 0,
5572 qw => 0,
5573 s => 1,
5574 y => 0,
5575 tr => 0,
5576 );
5577  
5578 sub push_here_targets {
5579 2 ▶ my ($rht) = @_;
Subroutine push_here_targets: called CC=2 SCAR=6.9
Pod undocumented
5580  
5581 # Push here targets found in a quote onto the here target list
5582 2 push @{$rhere_target_list}, @{$rht};
5583  
5584 # Change type from 'Q' to 'h' for quotes with here-doc targets so that
5585 # the formatter (see sub process_line_of_CODE) will not make any line
5586 # breaks after this point.
5587 2 $type = 'h';
5588 2 ▶ if ( $i_tok < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_tok < 0) 1 1 2
5589 1 my $ilast = $routput_token_list->[-1];
5590 1 $routput_token_type->[$ilast] = $type;
5591 }
5592 2 return;
5593 } ## end sub push_here_targets
5594  
5595 sub do_FOLLOW_QUOTE {
5596  
5597 3233 ▶ my $self = shift;
Subroutine do_FOLLOW_QUOTE: called CC=28 SCAR=34.9
Pod undocumented
5598  
5599 # Continue following a quote on a new line
5600 3233 $type = $quote_type;
5601  
5602 # initialize if continuation line
5603 3233 ▶ if ( !@{$routput_token_list} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$routput_token_list;}) 245 2988 3233
5604 245 push @{$routput_token_list}, $i;
5605 245 $routput_token_type->[$i] = $type;
5606 }
5607  
5608 # Save starting lengths for here target search
5609 3233 my $len_qs1 = length($quoted_string_1);
5610 3233 my $len_qs2 = length($quoted_string_2);
5611 3233 my $in_quote_start = $in_quote;
5612  
5613 # scan for the end of the quote or pattern
5614 (
5615 3233 $i,
5616 $in_quote,
5617 $quote_character,
5618 $quote_pos,
5619 $quote_depth,
5620 $quoted_string_1,
5621 $quoted_string_2,
5622  
5623 ) = $self->do_quote(
5624  
5625 $i,
5626 $in_quote,
5627 $quote_character,
5628 $quote_pos,
5629 $quote_depth,
5630 $quoted_string_1,
5631 $quoted_string_2,
5632 $rtokens,
5633 $rtoken_type,
5634 $rtoken_map,
5635 $max_token_index,
5636  
5637 );
5638  
5639 # Save pattern and replacement text for rescanning for /e
5640 3233 my $qs1_for_e_scan = $quoted_string_1;
5641  
5642 # Check for possible here targets in an interpolated quote
5643 3233 ▶ if ( $is_interpolated_quote{$quote_starting_tok}
Branch: 1 branch
BranchTrueFalseTotal
if ($is_interpolated_quote{$quote_starting_tok} and $in_quote < $in_quote_start) 1478 1755 3233
Condition100%3/3
$is_interpolated_quote{$quote_starting_tok} and $in_quote < $in_quote_start
!ll&&!rl&&r
1725301478
MC/DC100%2/2
$is_interpolated_quote{$quote_starting_tok} and $in_quote < $in_quote_start
$is_interpolated_quote{$quote_starting_tok} $in_quote < $in_quote_start
Truth table100%3/3
A and B
A= $is_interpolated_quote{$quote_starting_tok}B= $in_quote < $in_quote_start
ABresult
0X0
100
111
5644 && $in_quote < $in_quote_start )
5645 {
5646  
5647 # post any saved target of a 2-part quote if the end is reached
5648 1478 ▶ if ( !$in_quote && defined($quote_here_target_2) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $in_quote and defined $quote_here_target_2) 1 1477 1478
Condition100%3/3
not $in_quote and defined $quote_here_target_2
!ll&&!rl&&r
214751
MC/DC100%2/2
not $in_quote and defined $quote_here_target_2
not $in_quote defined $quote_here_target_2
Truth table100%3/3
not(A) and B
A= not $in_quoteB= defined $quote_here_target_2
ABresult
0X0
100
111
5649  
5650 # Safety check
5651 1 ▶ if ( $quote_items{$quote_starting_tok} == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote_items{$quote_starting_tok} == 2) { } 1 0 1
5652 1 push_here_targets($quote_here_target_2);
5653 }
5654 else {
5655 0 DEVEL_MODE
5656 && Fault(
5657 "unexpected saved here target near line $input_line_number\n"
5658 );
5659 }
5660 1 $quote_here_target_2 = undef;
5661 }
5662  
5663 # Single part quotes: use $quoted_string_1, and
5664 # $in_quote drops from 1 to 0 when the end is found
5665 # Dual part quotes ('s'): first part is in $quoted_string_2, and
5666 # $in_quote:
5667 # drops from 2 to 1 when the the first part is found
5668 # drops 1 to 0 when the the second part is found
5669 # drops from 2 to 0 if both parts are found in this call
5670 # The tricky part is that we must search for here targets whenever
5671 # $in_quote drops, but we can only post here targets after the end
5672 # of the last part is found (in_quote==0). See test 'here4.in'.
5673 # Update c310 added interpolated here docs and has many test cases.
5674  
5675 # Initialize for the normal case of a single quote
5676 1478 my $qs = $quoted_string_1;
5677 1478 my $len_qs = $len_qs1;
5678 1478 my $num_quotes = $in_quote_start - $in_quote;
5679  
5680 # Dual part quotes (type 's') have first part in $quoted_string_2
5681 1478 ▶ if ( $in_quote_start == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote_start == 2) 31 1447 1478
5682 31 $qs = $quoted_string_2;
5683 31 $len_qs = $len_qs2;
5684 }
5685  
5686 # Loop to search 1 or 2 quotes for here targets
5687 1478 foreach ( 1 .. $num_quotes ) {
5688  
5689 # Perform quick tests to avoid a sub call:
5690 1507 my $pos_shift = rindex( $qs, '<<' );
5691 1507 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($pos_shift >= $len_qs and rindex($qs, "}") >= $len_qs and rindex($qs, "\$", $pos_shift) != -1 || rindex($qs, "\@", $pos_shift) != -1) 2 1505 1507
Condition66%6/9
$pos_shift >= $len_qs and rindex($qs, "}") >= $len_qs and rindex($qs, "\$", $pos_shift) != -1 || rindex($qs, "\@", $pos_shift) != -1
!ll&&!rl&&r
150520
$pos_shift >= $len_qs and rindex($qs, "}") >= $len_qs
!ll&&!rl&&r
150412
rindex($qs, "\$", $pos_shift) != -1 or rindex($qs, "\@", $pos_shift) != -1
l!l&&r!l&&!r
200
MC/DC0%0/4
$pos_shift >= $len_qs and rindex($qs, "}") >= $len_qs and rindex($qs, "\$", $pos_shift) != -1 || rindex($qs, "\@", $pos_shift) != -1
$pos_shift >= $len_qs rindex($qs, "}") >= $len_qs rindex($qs, "\$", $pos_shift) != -1 rindex($qs, "\@", $pos_shift) != -1
Truth table40%2/5
A and B and C or D
A= $pos_shift >= $len_qsB= rindex($qs, "}") >= $len_qsC= rindex($qs, "\$", $pos_shift) != -1D= rindex($qs, "\@", $pos_shift) != -1
ABCDresult
0XXX0
10XX0
11000
111X1
11011
5692  
5693 # a '<<' in the last line
5694 $pos_shift >= $len_qs
5695  
5696 # and a '}' in the last line (c598: updated to allow
5697 # for the possibility of an extra '<<' after a here doc)
5698 && rindex( $qs, '}' ) >= $len_qs
5699  
5700 # and a '<<' preceded by '$' or '@'
5701 && ( rindex( $qs, '$', $pos_shift ) >= 0
5702 || rindex( $qs, '@', $pos_shift ) >= 0 )
5703 )
5704 {
5705  
5706 # scan the quote for here targets
5707 2 my ( $rht, $qs_mod ) =
5708 $self->find_interpolated_here_targets( $qs, $len_qs );
5709 2 ▶ if ($rht) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rht) 2 0 2
5710  
5711 # only post here targets when end of quote is found
5712 2 ▶ if ($in_quote) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote) { } 1 1 2
5713 1 $quote_here_target_2 = $rht;
5714 }
5715 else {
5716 1 push_here_targets($rht);
5717  
5718 # Replace the string with the modified version
5719 # in case it is re-scanned due to a /e modifier
5720 1 $qs1_for_e_scan = $qs_mod;
5721 }
5722 }
5723 }
5724  
5725 # re-initialize for next pass
5726 1507 $qs = $quoted_string_1;
5727 1507 $len_qs = $len_qs1;
5728 } ## end while ( $num_quotes-- > 0)
5729 }
5730  
5731 3233 ▶ if ($in_quote) { return }
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote) 244 2989 3233
5732  
5733 # All done with this quote...
5734  
5735 # re-initialize for next search
5736 2989 $quote_character = EMPTY_STRING;
5737 2989 $quote_pos = 0;
5738 2989 $quote_type = 'Q';
5739 2989 $quoted_string_1 = EMPTY_STRING;
5740 2989 $quoted_string_2 = EMPTY_STRING;
5741 2989 ▶ if ( ++$i > $max_token_index ) { return }
Branch: 1 branch
BranchTrueFalseTotal
if (++$i > $max_token_index) 126 2863 2989
5742  
5743 # look for any modifiers
5744 2863 ▶ if ($allowed_quote_modifiers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allowed_quote_modifiers) 165 2698 2863
5745  
5746 # check for exact quote modifiers
5747 165 ▶ if ( $rtokens->[$i] =~ /^[A-Za-z_]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rtokens->[$i] =~ /^[A-Za-z_]/) 31 134 165
5748 31 my $str = $rtokens->[$i];
5749 31 my $saw_modifier_e;
5750 31 ▶ while ( $str =~ /\G$allowed_quote_modifiers/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\G$allowed_quote_modifiers/cg) 49 31 80
5751 49 my $pos = pos($str);
5752 49 my $char = substr( $str, $pos - 1, 1 );
5753 49 ▶ $saw_modifier_e ||= ( $char eq 'e' );
Condition100%3/3
$saw_modifier_e ||= $char eq "e"
l!l&&r!l&&!r
1246
MC/DC100%2/2
$saw_modifier_e ||= $char eq "e"
$saw_modifier_e $char eq "e"
Truth table100%3/3
A ||= B
A= $saw_modifier_eB= $char eq "e"
ABresult
1X1
011
000
5754 }
5755  
5756 # For an 'e' quote modifier we must scan the replacement
5757 # text for here-doc targets...
5758 # but if the modifier starts a new line we must skip
5759 # this because either the here doc will be fully
5760 # contained in the replacement text (so we can
5761 # ignore it) or Perl will not find it. The modifier will have a
5762 # pretoken index $i=1 if it starts a new line, so we only look
5763 # for a here doc if $i>1. See test 'here2.in'.
5764 31 ▶ if ( $saw_modifier_e && $i > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($saw_modifier_e and $i > 1) 0 31 31
Condition66%2/3
$saw_modifier_e and $i > 1
!ll&&!rl&&r
2920
MC/DC0%0/2
$saw_modifier_e and $i > 1
$saw_modifier_e $i > 1
Truth table66%2/3
A and B
A= $saw_modifier_eB= $i > 1
ABresult
0X0
100
111
5765 0 my $rht = $self->scan_replacement_text($qs1_for_e_scan);
5766 0 ▶ if ($rht) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rht) 0 0 0
5767 0 push_here_targets($rht);
5768 }
5769 }
5770  
5771 31 ▶ if ( defined( pos($str) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined pos $str) { } 31 0 31
5772  
5773 # matched
5774 31 ▶ if ( pos($str) == length($str) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $str == length $str) { } 31 0 31
5775 31 ▶ if ( ++$i > $max_token_index ) { return }
Branch: 1 branch
BranchTrueFalseTotal
if (++$i > $max_token_index) 0 31 31
5776 }
5777  
5778 # Looks like a joined quote modifier
5779 # and keyword, maybe something like
5780 # s/xxx/yyy/gefor @k=...
5781 # Example is "galgen.pl". Would have to split
5782 # the word and insert a new token in the
5783 # pre-token list. This is so rare that I haven't
5784 # done it. Will just issue a warning citation.
5785  
5786 # This error might also be triggered if my quote
5787 # modifier characters are incomplete
5788 else {
5789 0 $self->warning(<<EOM);
5790  
5791 Partial match to quote modifier $allowed_quote_modifiers at word: '$str'
5792 Please put a space between quote modifiers and trailing keywords.
5793 EOM
5794  
5795 # print "token $rtokens->[$i]\n";
5796 # my $num = length($str) - pos($str);
5797 # $rtokens->[$i]=substr($rtokens->[$i],pos($str),$num);
5798 # print "continuing with new token $rtokens->[$i]\n";
5799  
5800 # skipping past this token does least damage
5801 0 ▶ if ( ++$i > $max_token_index ) { return }
Branch: 1 branch
BranchTrueFalseTotal
if (++$i > $max_token_index) 0 0 0
5802 }
5803 }
5804 else {
5805  
5806 # example file: rokicki4.pl
5807 # This error might also be triggered if my quote
5808 # modifier characters are incomplete
5809 0 $self->write_logfile_entry(
5810 "Note: found word $str at quote modifier location\n");
5811 }
5812 }
5813  
5814 # re-initialize
5815 165 $allowed_quote_modifiers = EMPTY_STRING;
5816 }
5817 2863 return;
5818 } ## end sub do_FOLLOW_QUOTE
5819  
5820 # ------------------------------------------------------------
5821 # begin hash of code for handling most token types
5822 # ------------------------------------------------------------
5823 45 my $tokenization_code = {
5824  
5825 '$' => \&do_DOLLAR_SIGN,
5826 '(' => \&do_LEFT_PARENTHESIS,
5827 ')' => \&do_RIGHT_PARENTHESIS,
5828 ',' => \&do_COMMA,
5829 ';' => \&do_SEMICOLON,
5830 '"' => \&do_QUOTATION_MARK,
5831 "'" => \&do_APOSTROPHE,
5832 '`' => \&do_BACKTICK,
5833 '/' => \&do_SLASH,
5834 '{' => \&do_LEFT_CURLY_BRACKET,
5835 '}' => \&do_RIGHT_CURLY_BRACKET,
5836 '&' => \&do_AMPERSAND,
5837 '<' => \&do_LESS_THAN_SIGN,
5838 '?' => \&do_QUESTION_MARK,
5839 '*' => \&do_STAR,
5840 '.' => \&do_DOT,
5841 ':' => \&do_COLON,
5842 '+' => \&do_PLUS_SIGN,
5843 '@' => \&do_AT_SIGN,
5844 '%' => \&do_PERCENT_SIGN,
5845 '[' => \&do_LEFT_SQUARE_BRACKET,
5846 ']' => \&do_RIGHT_SQUARE_BRACKET,
5847 '-' => \&do_MINUS_SIGN,
5848 '^' => \&do_CARAT_SIGN,
5849 '::' => \&do_DOUBLE_COLON,
5850 '<<' => \&do_LEFT_SHIFT,
5851 '<<~' => \&do_NEW_HERE_DOC,
5852 '->' => \&do_POINTER,
5853 '++' => \&do_PLUS_PLUS,
5854 '=>' => \&do_FAT_COMMA,
5855 '--' => \&do_MINUS_MINUS,
5856  
5857 # No special code for these types yet, but syntax checks
5858 # could be added.
5859 ## '&&' => \&do_LOGICAL_AND,
5860 ## '||' => \&do_LOGICAL_OR,
5861 ## '>' => \&do_GREATER_THAN_SIGN,
5862 ## '|' => \&do_VERTICAL_LINE,
5863 ## '//' => \&do_SLASH_SLASH,
5864 ## '!' => undef,
5865 ## '!=' => undef,
5866 ## '!~' => undef,
5867 ## '%=' => undef,
5868 ## '&&=' => undef,
5869 ## '&=' => undef,
5870 ## '+=' => undef,
5871 ## '-=' => undef,
5872 ## '..' => undef,
5873 ## '..' => undef,
5874 ## '...' => undef,
5875 ## '.=' => undef,
5876 ## '<<=' => undef,
5877 ## '<=' => undef,
5878 ## '<=>' => undef,
5879 ## '<>' => undef,
5880 ## '=' => undef,
5881 ## '==' => undef,
5882 ## '=~' => undef,
5883 ## '>=' => undef,
5884 ## '>>' => undef,
5885 ## '>>=' => undef,
5886 ## '\\' => undef,
5887 ## '^=' => undef,
5888 ## '|=' => undef,
5889 ## '||=' => undef,
5890 ## '//=' => undef,
5891 ## '~' => undef,
5892 ## '~~' => undef,
5893 ## '!~~' => undef,
5894  
5895 };
5896  
5897 # ------------------------------------------------------------
5898 # end hash of code for handling individual token types
5899 # ------------------------------------------------------------
5900  
5901 45 ▶ use constant DEBUG_TOKENIZE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5902  
5903 45 my %is_arrow_or_Z;
5904  
5905 BEGIN {
5906 45 ▶ my @qZ = qw( -> Z );
Subroutine BEGIN: called CC=2 SCAR=6.9
5907 45 $is_arrow_or_Z{$_} = 1 for @qZ;
5908 }
5909  
5910 sub tokenize_this_line {
5911  
5912 8951 ▶ my ( $self, $line_of_tokens, $trimmed_input_line ) = @_;
Subroutine tokenize_this_line: called CC=31 SCAR=34.8
Pod undocumented
5913  
5914 # This routine tokenizes one line. The results are stored in
5915 # the hash ref '$line_of_tokens'.
5916  
5917 # Given:
5918 # $line_of_tokens = ref to hash of values being filled for this line
5919 # $trimmed_input_line
5920 # = the input line without leading whitespace, OR
5921 # = undef if not available
5922 # Returns:
5923 # nothing
5924  
5925 8951 my $untrimmed_input_line = $line_of_tokens->{_line_text};
5926  
5927 # Extract line number for use in error messages
5928 8951 $input_line_number = $line_of_tokens->{_line_number};
5929  
5930 #-------------------------------------
5931 # Check for start of pod documentation
5932 #-------------------------------------
5933 8951 ▶ if ( !$in_quote
Branch: 1 branch
BranchTrueFalseTotal
if (not $in_quote and substr($untrimmed_input_line, 0, 1) eq "=" and $untrimmed_input_line =~ /^=[A-Za-z_]/) 15 8936 8951
Condition83%5/6
not $in_quote and substr($untrimmed_input_line, 0, 1) eq "=" and $untrimmed_input_line =~ /^=[A-Za-z_]/
!ll&&!rl&&r
8936015
not $in_quote and substr($untrimmed_input_line, 0, 1) eq "="
!ll&&!rl&&r
247868915
MC/DC66%2/3
not $in_quote and substr($untrimmed_input_line, 0, 1) eq "=" and $untrimmed_input_line =~ /^=[A-Za-z_]/
not $in_quote substr($untrimmed_input_line, 0, 1) eq "=" $untrimmed_input_line =~ /^=[A-Za-z_]/
Truth table75%3/4
not(A) and B and C
A= not $in_quoteB= substr($untrimmed_input_line, 0, 1) eq "="C= $untrimmed_input_line =~ /^=[A-Za-z_]/
ABCresult
0XX0
10X0
1100
1111
5934 && substr( $untrimmed_input_line, 0, 1 ) eq '='
5935 && $untrimmed_input_line =~ /^=[A-Za-z_]/ )
5936 {
5937  
5938 # Must not be in an equation where an '=' could be expected.
5939 # Perl has additional restrictions which are not checked here.
5940 15 my $blank_after_Z = 1;
5941 15 $expecting = $self->operator_expected( '=', 'b', $blank_after_Z );
5942 15 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) 15 0 15
5943 15 $self->[_in_pod_] = 1;
5944 15 return;
5945 }
5946 }
5947  
5948 #--------------------------
5949 # Trim leading whitespace ?
5950 #--------------------------
5951 # Use untrimmed line if we are continuing in a type 'Q' quote
5952 8936 ▶ if ( $in_quote && $quote_type eq 'Q' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote and $quote_type eq 'Q') { } 58 8878 8936
Condition100%3/3
$in_quote and $quote_type eq "Q"
!ll&&!rl&&r
868918958
MC/DC100%2/2
$in_quote and $quote_type eq "Q"
$in_quote $quote_type eq "Q"
Truth table100%3/3
A and B
A= $in_quoteB= $quote_type eq "Q"
ABresult
0X0
100
111
5953 58 $line_of_tokens->{_starting_in_quote} = 1;
5954 58 $input_line = $untrimmed_input_line;
5955 58 chomp $input_line;
5956 }
5957  
5958 # Trim start of this line if we are not continuing a quoted line.
5959 # Do not trim end because we might end in a quote (test: deken4.pl)
5960 # Perl::Tidy::Formatter will delete needless trailing blanks
5961 else {
5962 8878 $line_of_tokens->{_starting_in_quote} = 0;
5963  
5964 # Use the pre-computed trimmed line if defined (most efficient)
5965 8878 $input_line = $trimmed_input_line;
5966  
5967 # otherwise trim the raw input line (much less efficient)
5968 8878 ▶ if ( !defined($input_line) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $input_line) 0 8878 8878
5969 0 $input_line = $untrimmed_input_line;
5970 0 $input_line =~ s/^\s+//;
5971 }
5972  
5973 8878 chomp $input_line;
5974  
5975 # define 'guessed_indentation_level' if logfile will be saved
5976 8878 ▶ if ( $self->[_save_logfile_] && length($input_line) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[39] and length $input_line) 3 8875 8878
Condition100%3/3
$self->[39] and length $input_line
!ll&&!rl&&r
887413
MC/DC100%2/2
$self->[39] and length $input_line
$self->[39] length $input_line
Truth table100%3/3
A and B
A= $self->[39]B= length $input_line
ABresult
0X0
100
111
5977 3 my $guess =
5978 $self->guess_old_indentation_level($untrimmed_input_line);
5979 3 $line_of_tokens->{_guessed_indentation_level} = $guess;
5980 }
5981 }
5982  
5983 #------------
5984 # Blank lines
5985 #------------
5986 8936 ▶ if ( !length($input_line) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $input_line) 1057 7879 8936
5987 1057 $line_of_tokens->{_line_type} = 'CODE';
5988 1057 $line_of_tokens->{_rtokens} = [];
5989 1057 $line_of_tokens->{_rtoken_type} = [];
5990 1057 $line_of_tokens->{_rlevels} = [];
5991 1057 $line_of_tokens->{_rblock_type} = [];
5992 1057 $line_of_tokens->{_nesting_tokens_0} = $nesting_token_string;
5993 1057 $line_of_tokens->{_nesting_blocks_0} = $nesting_block_string;
5994 1057 return;
5995 }
5996  
5997 #---------
5998 # Comments
5999 #---------
6000 7879 ▶ if ( !$in_quote && substr( $input_line, 0, 1 ) eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $in_quote and substr($input_line, 0, 1) eq "#") 896 6983 7879
Condition100%3/3
not $in_quote and substr($input_line, 0, 1) eq "#"
!ll&&!rl&&r
2456738896
MC/DC100%2/2
not $in_quote and substr($input_line, 0, 1) eq "#"
not $in_quote substr($input_line, 0, 1) eq "#"
Truth table100%3/3
not(A) and B
A= not $in_quoteB= substr($input_line, 0, 1) eq "#"
ABresult
0X0
100
111
6001  
6002 # and check for skipped section
6003 896 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (substr($input_line, 0, 4) eq "#<<V" || $rOpts_code_skipping_begin and $rOpts_code_skipping and ($input_line . ' ') =~ /$code_skipping_pattern_begin/) 2 894 896
Condition66%6/9
substr($input_line, 0, 4) eq "#<<V" || $rOpts_code_skipping_begin and $rOpts_code_skipping and ($input_line . ' ') =~ /$code_skipping_pattern_begin/
!ll&&!rl&&r
89402
substr($input_line, 0, 4) eq "#<<V" || $rOpts_code_skipping_begin and $rOpts_code_skipping
!ll&&!rl&&r
89402
substr($input_line, 0, 4) eq "#<<V" or $rOpts_code_skipping_begin
l!l&&r!l&&!r
20894
MC/DC25%1/4
substr($input_line, 0, 4) eq "#<<V" || $rOpts_code_skipping_begin and $rOpts_code_skipping and ($input_line . ' ') =~ /$code_skipping_pattern_begin/
substr($input_line, 0, 4) eq "#<<V" $rOpts_code_skipping_begin $rOpts_code_skipping ($input_line . ' ') =~ /$code_skipping_pattern_begin/
Truth table28%2/7
A or B and C and D
A= substr($input_line, 0, 4) eq "#<<V"B= $rOpts_code_skipping_beginC= $rOpts_code_skippingD= ($input_line . ' ') =~ /$code_skipping_pattern_begin/
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
6004 (
6005 substr( $input_line, 0, 4 ) eq '#<<V'
6006 || $rOpts_code_skipping_begin
6007 )
6008 && $rOpts_code_skipping
6009  
6010 # note that the code_skipping_patterns require a newline
6011 && ( $input_line . SPACE ) =~ /$code_skipping_pattern_begin/
6012 )
6013 {
6014 2 $self->[_in_code_skipping_] = $self->[_last_line_number_];
6015 2 return;
6016 }
6017  
6018 # Look for format skipping tags, but just normal mode.
6019 # It will be used for these purposes:
6020 # - to inform the formatter of an end token with no begin token
6021 # - for making a hint when a brace error is detected
6022 894 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if (substr($input_line, 0, 4) eq '#<<<' || $rOpts_format_skipping_begin and $rOpts_format_skipping and ($input_line . ' ') =~ /$format_skipping_pattern_begin/ and !$self->[13] || $format_skipping_pattern_begin ne $format_skipping_pattern_end) { } 17 877 894
elsif (substr($input_line, 0, 4) eq '#>>>' || $rOpts_format_skipping_end and $rOpts_format_skipping and ($input_line . ' ') =~ /$format_skipping_pattern_end/) { } 20 857 877
Condition80%12/15
substr($input_line, 0, 4) eq "#<<<" || $rOpts_format_skipping_begin and $rOpts_format_skipping and ($input_line . ' ') =~ /$format_skipping_pattern_begin/ and !$self->[13] || $format_skipping_pattern_begin ne $format_skipping_pattern_end
!ll&&!rl&&r
877017
substr($input_line, 0, 4) eq "#<<<" || $rOpts_format_skipping_begin and $rOpts_format_skipping and ($input_line . ' ') =~ /$format_skipping_pattern_begin/
!ll&&!rl&&r
8572017
substr($input_line, 0, 4) eq "#<<<" || $rOpts_format_skipping_begin and $rOpts_format_skipping
!ll&&!rl&&r
855237
substr($input_line, 0, 4) eq "#<<<" or $rOpts_format_skipping_begin
l!l&&r!l&&!r
1821855
not $self->[13] or $format_skipping_pattern_begin ne $format_skipping_pattern_end
l!l&&r!l&&!r
1700
MC/DC66%4/6
substr($input_line, 0, 4) eq "#<<<" || $rOpts_format_skipping_begin and $rOpts_format_skipping and ($input_line . ' ') =~ /$format_skipping_pattern_begin/ and !$self->[13] || $format_skipping_pattern_begin ne $format_skipping_pattern_end
substr($input_line, 0, 4) eq "#<<<" $rOpts_format_skipping_begin $rOpts_format_skipping ($input_line . ' ') =~ /$format_skipping_pattern_begin/ not $self->[13] $format_skipping_pattern_begin ne $format_skipping_pattern_end
Truth table45%5/11
A or B and C and D and not(E) or F
A= substr($input_line, 0, 4) eq "#<<<"B= $rOpts_format_skipping_beginC= $rOpts_format_skippingD= ($input_line . ' ') =~ /$format_skipping_pattern_begin/E= not $self->[13]F= $format_skipping_pattern_begin ne $format_skipping_pattern_end
ABCDEFresult
00XXXX0
1X0XXX0
010XXX0
1X10XX0
0110XX0
1X11000
0111000
1X111X1
1X11011
01111X1
0111011
6023 (
6024 substr( $input_line, 0, 4 ) eq '#<<<'
6025 || $rOpts_format_skipping_begin
6026 )
6027 && $rOpts_format_skipping
6028  
6029 # note that the format_skipping_patterns require a space
6030 && ( $input_line . SPACE ) =~ /$format_skipping_pattern_begin/
6031  
6032 # allow same token for begin and end
6033 && (
6034 !$self->[_in_format_skipping_]
6035 || ( $format_skipping_pattern_begin ne
6036 $format_skipping_pattern_end )
6037 )
6038 )
6039 {
6040 17 my $on_off = 1;
6041 17 my $lno = $self->[_last_line_number_];
6042 17 my $rformat_skipping_list = $self->[_rformat_skipping_list_];
6043  
6044 # format markers must alternate between on and off
6045 17 ▶ if ( @{$rformat_skipping_list}
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rformat_skipping_list;} and $rformat_skipping_list->[-1][0] == $on_off) 0 17 17
Condition66%2/3
@{$rformat_skipping_list;} and $rformat_skipping_list->[-1][0] == $on_off
!ll&&!rl&&r
1070
MC/DC0%0/2
@{$rformat_skipping_list;} and $rformat_skipping_list->[-1][0] == $on_off
@{$rformat_skipping_list;} $rformat_skipping_list->[-1][0] == $on_off
Truth table66%2/3
A and B
A= @{$rformat_skipping_list;}B= $rformat_skipping_list->[-1][0] == $on_off
ABresult
0X0
100
111
6046 && $rformat_skipping_list->[-1]->[0] == $on_off )
6047 {
6048 0 my $lno_last = $rformat_skipping_list->[-1]->[1];
6049 0 $self->warning_do_not_format(
6050 "consecutive format-skipping start markers - see line $lno_last\n"
6051 );
6052 }
6053 17 push @{$rformat_skipping_list}, [ $on_off, $lno, $input_line ];
6054 17 $self->[_in_format_skipping_] = $lno;
6055 }
6056 ▶ elsif (
Condition100%9/9
substr($input_line, 0, 4) eq "#>>>" || $rOpts_format_skipping_end and $rOpts_format_skipping and ($input_line . ' ') =~ /$format_skipping_pattern_end/
!ll&&!rl&&r
8401720
substr($input_line, 0, 4) eq "#>>>" || $rOpts_format_skipping_end and $rOpts_format_skipping
!ll&&!rl&&r
838237
substr($input_line, 0, 4) eq "#>>>" or $rOpts_format_skipping_end
l!l&&r!l&&!r
2118838
MC/DC100%4/4
substr($input_line, 0, 4) eq "#>>>" || $rOpts_format_skipping_end and $rOpts_format_skipping and ($input_line . ' ') =~ /$format_skipping_pattern_end/
substr($input_line, 0, 4) eq "#>>>" $rOpts_format_skipping_end $rOpts_format_skipping ($input_line . ' ') =~ /$format_skipping_pattern_end/
Truth table71%5/7
A or B and C and D
A= substr($input_line, 0, 4) eq "#>>>"B= $rOpts_format_skipping_endC= $rOpts_format_skippingD= ($input_line . ' ') =~ /$format_skipping_pattern_end/
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
6057 (
6058 substr( $input_line, 0, 4 ) eq '#>>>'
6059 || $rOpts_format_skipping_end
6060 )
6061 && $rOpts_format_skipping
6062  
6063 # note that the format_skipping_patterns require a newline
6064 && ( $input_line . SPACE ) =~ /$format_skipping_pattern_end/
6065 )
6066 {
6067 20 my $lno = $self->[_last_line_number_];
6068 20 my $rformat_skipping_list = $self->[_rformat_skipping_list_];
6069 20 my $on_off = -1;
6070  
6071 # markers must alternate between on and off
6072 20 ▶ if ( @{$rformat_skipping_list}
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rformat_skipping_list;} and $rformat_skipping_list->[-1][0] == $on_off) 0 20 20
Condition66%2/3
@{$rformat_skipping_list;} and $rformat_skipping_list->[-1][0] == $on_off
!ll&&!rl&&r
3170
MC/DC0%0/2
@{$rformat_skipping_list;} and $rformat_skipping_list->[-1][0] == $on_off
@{$rformat_skipping_list;} $rformat_skipping_list->[-1][0] == $on_off
Truth table66%2/3
A and B
A= @{$rformat_skipping_list;}B= $rformat_skipping_list->[-1][0] == $on_off
ABresult
0X0
100
111
6073 && $rformat_skipping_list->[-1]->[0] == $on_off )
6074 {
6075 0 my $lno_last = $rformat_skipping_list->[-1]->[1];
6076 0 $self->warning_do_not_format(
6077 "consecutive format-skipping end markers - see line $lno_last\n"
6078 );
6079 }
6080  
6081 20 push @{$rformat_skipping_list}, [ $on_off, $lno, $input_line ];
6082 20 $self->[_in_format_skipping_] = 0;
6083 }
6084 else {
6085 ## not a format skipping comment
6086 }
6087  
6088 # Optional fast processing of a block comment
6089 894 $line_of_tokens->{_line_type} = 'CODE';
6090 894 $line_of_tokens->{_rtokens} = [$input_line];
6091 894 $line_of_tokens->{_rtoken_type} = ['#'];
6092 894 $line_of_tokens->{_rlevels} = [$level_in_tokenizer];
6093 894 $line_of_tokens->{_rblock_type} = [EMPTY_STRING];
6094 894 $line_of_tokens->{_nesting_tokens_0} = $nesting_token_string;
6095 894 $line_of_tokens->{_nesting_blocks_0} = $nesting_block_string;
6096 894 return;
6097 }
6098  
6099 #-------------------------------------
6100 # Loop to find all tokens on this line
6101 #-------------------------------------
6102  
6103 # Update the copy of the line for use in error messages
6104 # This must be exactly what we give the pre_tokenizer
6105 6983 $self->[_line_of_text_] = $input_line;
6106  
6107 # re-initialize for the main loop
6108 6983 $routput_token_list = []; # stack of output token indexes
6109 6983 $routput_token_type = []; # token types
6110 6983 $routput_block_type = []; # types of code block
6111 6983 $routput_type_sequence = []; # nesting sequential number
6112  
6113 6983 $rhere_target_list = [];
6114  
6115 6983 $tok = $last_nonblank_token;
6116 6983 $type = $last_nonblank_type;
6117 6983 $prototype = $last_nonblank_prototype;
6118 6983 $last_nonblank_i = -1;
6119 6983 $block_type = $last_nonblank_block_type;
6120 6983 $container_type = $last_nonblank_container_type;
6121 6983 $type_sequence = $last_nonblank_type_sequence;
6122 6983 $indent_flag = 0;
6123 6983 $peeked_ahead = 0;
6124  
6125 6983 $self->tokenizer_main_loop();
6126  
6127 #-------------------------------------------------
6128 # Done tokenizing this line ... package the result
6129 #-------------------------------------------------
6130 6983 $self->tokenizer_wrapup_line($line_of_tokens);
6131  
6132 6983 return;
6133 } ## end sub tokenize_this_line
6134  
6135 sub tokenizer_main_loop {
6136  
6137 6983 ▶ my ($self) = @_;
Subroutine tokenizer_main_loop: called CC=81 SCAR=45.3
Pod undocumented
6138  
6139 # Break one input line into tokens
6140 # We are working on closure variables.
6141  
6142 # Start by breaking the line into pre-tokens
6143 6983 ( $rtokens, $rtoken_map, $rtoken_type ) = pre_tokenize($input_line);
6144  
6145 # Verify that all leading whitespace has been trimmed
6146 # except for quotes of type 'Q' (c273).
6147 6983 ▶ if ( @{$rtokens}
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rtokens;} and $rtoken_type->[0] eq "b" and not $in_quote && $quote_type eq "Q") 0 6983 6983
Condition55%5/9
@{$rtokens;} and $rtoken_type->[0] eq "b" and not $in_quote && $quote_type eq "Q"
!ll&&!rl&&r
6947360
@{$rtokens;} and $rtoken_type->[0] eq "b"
!ll&&!rl&&r
0694736
$in_quote && $quote_type eq 'Q'
!ll&&!rl&&r
0036
MC/DC0%0/4
@{$rtokens;} and $rtoken_type->[0] eq "b" and not $in_quote && $quote_type eq "Q"
@{$rtokens;} $rtoken_type->[0] eq "b" $in_quote $quote_type eq 'Q'
Truth table40%2/5
A and B and not(C && D)
A= @{$rtokens;}B= $rtoken_type->[0] eq "b"C= $in_quoteD= $quote_type eq 'Q'
ABCDresult
0XXX0
10XX0
11110
110X1
11101
6148 && $rtoken_type->[0] eq 'b'
6149 && !( $in_quote && $quote_type eq 'Q' ) )
6150 {
6151  
6152 # Shouldn't happen if calling sub did trim operation correctly.
6153 0 DEVEL_MODE && Fault(<<EOM);
6154 leading blank at line
6155 $input_line
6156 EOM
6157  
6158 # Fix by removing the leading blank token. This fix has been
6159 # tested and works correctly even if no whitespaces was trimmed.
6160 # But it is an inefficient way to do things because, for example,
6161 # it forces all comments to be processed by sub pre_tokenize.
6162 # And it may cause indented code-skipping comments to be missed.
6163 0 shift @{$rtokens};
6164 0 shift @{$rtoken_map};
6165 0 shift @{$rtoken_type};
6166 }
6167  
6168 6983 $max_token_index = scalar( @{$rtokens} ) - 1;
6169  
6170 # add extra spaces to simplify logic - they shouldn't be referenced
6171 6983 push @{$rtokens}, ( SPACE, SPACE, SPACE );
6172 6983 push @{$rtoken_map}, qw( 0 0 0 );
6173 6983 push @{$rtoken_type}, qw( b b b );
6174  
6175 # initialize for main loop
6176 6983 if (0) { #<<< this is not necessary
6177 foreach my $ii ( 0 .. $max_token_index + 3 ) {
6178 $routput_token_type->[$ii] = EMPTY_STRING;
6179 $routput_block_type->[$ii] = EMPTY_STRING;
6180 $routput_type_sequence->[$ii] = EMPTY_STRING;
6181 $routput_indent_flag->[$ii] = 0;
6182 }
6183 }
6184  
6185 6983 $i = -1;
6186 6983 $i_tok = -1;
6187  
6188 #-----------------------
6189 # main tokenization loop
6190 #-----------------------
6191  
6192 # we are looking at each pre-token of one line and combining them
6193 # into tokens
6194 6983 ▶ while ( ++$i <= $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$i <= $max_token_index) 57814 6241 64055
6195  
6196 # continue looking for the end of a quote
6197 60548 ▶ if ($in_quote) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote) 3233 57315 60548
6198 3233 $self->do_FOLLOW_QUOTE();
6199 3233 ▶ last if ( $in_quote || $i > $max_token_index );
Branch: 1 branch
BranchTrueFalseTotal
if $in_quote or $i > $max_token_index 370 2863 3233
Condition100%3/3
$in_quote or $i > $max_token_index
l!l&&r!l&&!r
2441262863
MC/DC100%2/2
$in_quote or $i > $max_token_index
$in_quote $i > $max_token_index
Truth table100%3/3
A or B
A= $in_quoteB= $i > $max_token_index
ABresult
1X1
011
000
6200 }
6201  
6202 60178 ▶ if ( $type ne 'b' && $type ne 'CORE::' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type ne "b" and $type ne "CORE::") 42154 18024 60178
Condition100%3/3
$type ne "b" and $type ne "CORE::"
!ll&&!rl&&r
18021342154
MC/DC100%2/2
$type ne "b" and $type ne "CORE::"
$type ne "b" $type ne "CORE::"
Truth table100%3/3
A and B
A= $type ne "b"B= $type ne "CORE::"
ABresult
0X0
100
111
6203  
6204 # try to catch some common errors
6205 42154 ▶ if ( ( $type eq 'n' ) && ( $tok ne '0' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "n" and $tok ne 0) 2075 40079 42154
Condition100%3/3
$type eq "n" and $tok ne 0
!ll&&!rl&&r
395335462075
MC/DC100%2/2
$type eq "n" and $tok ne 0
$type eq "n" $tok ne 0
Truth table100%3/3
A and B
A= $type eq "n"B= $tok ne 0
ABresult
0X0
100
111
6206  
6207 2075 ▶ if ( $last_nonblank_token eq 'eq' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($last_nonblank_token eq 'eq') { } 9 2066 2075
elsif ($last_nonblank_token eq 'ne') { } 0 2066 2066
6208 9 $self->complain("Should 'eq' be '==' here ?\n");
6209 }
6210 elsif ( $last_nonblank_token eq 'ne' ) {
6211 0 $self->complain("Should 'ne' be '!=' here ?\n");
6212 }
6213 else {
6214 ## that's all
6215 }
6216 }
6217  
6218 # fix c090, only rotate vars if a new token will be stored
6219 42154 ▶ if ( $i_tok >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_tok >= 0) 35360 6794 42154
6220  
6221 35360 $last_last_nonblank_token = $last_nonblank_token;
6222 35360 $last_last_nonblank_type = $last_nonblank_type;
6223  
6224 35360 $last_nonblank_prototype = $prototype;
6225 35360 $last_nonblank_block_type = $block_type;
6226 35360 $last_nonblank_container_type = $container_type;
6227 35360 $last_nonblank_type_sequence = $type_sequence;
6228 35360 $last_nonblank_i = $i_tok;
6229 35360 $last_nonblank_token = $tok;
6230 35360 $last_nonblank_type = $type;
6231 }
6232  
6233 # Check for patches
6234 42154 ▶ if ( $is_arrow_or_Z{$last_last_nonblank_type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_arrow_or_Z{$last_last_nonblank_type}) 1244 40910 42154
6235  
6236 # Patch for c030: Fix things in case a '->' got separated
6237 # from the subsequent identifier by a side comment. We
6238 # need the last_nonblank_token to have a leading -> to
6239 # avoid triggering an operator expected error message at
6240 # the next '('. See also fix for git #63.
6241 1244 ▶ if ( $last_last_nonblank_type eq '->' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($last_last_nonblank_type eq '->') { } 1196 48 1244
elsif ($last_last_nonblank_type eq 'Z') { } 48 0 48
6242 1196 ▶ if ( $last_nonblank_type eq 'w'
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq "w" or $last_nonblank_type eq "i") 793 403 1196
Condition66%2/3
$last_nonblank_type eq "w" or $last_nonblank_type eq "i"
l!l&&r!l&&!r
0793403
MC/DC50%1/2
$last_nonblank_type eq "w" or $last_nonblank_type eq "i"
$last_nonblank_type eq "w" $last_nonblank_type eq "i"
Truth table66%2/3
A or B
A= $last_nonblank_type eq "w"B= $last_nonblank_type eq "i"
ABresult
1X1
011
000
6243 || $last_nonblank_type eq 'i' )
6244 {
6245 793 $last_nonblank_token = '->' . $last_nonblank_token;
6246 793 $last_nonblank_type = 'i';
6247 }
6248 }
6249  
6250 # Fix part #3 for git82: propagate type 'Z' though L-R pair
6251 elsif ( $last_last_nonblank_type eq 'Z' ) {
6252 48 ▶ if ( $last_nonblank_type eq 'R' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq "R") 1 47 48
6253 1 $last_nonblank_type = $last_last_nonblank_type;
6254 1 $last_nonblank_token = $last_last_nonblank_token;
6255 }
6256 }
6257 else {
6258 ## No other patches
6259 }
6260 }
6261 }
6262  
6263 # store previous token type
6264 60178 ▶ if ( $i_tok >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_tok >= 0) 53384 6794 60178
6265 53384 $routput_token_type->[$i_tok] = $type;
6266 53384 $routput_block_type->[$i_tok] = $block_type;
6267 53384 $routput_type_sequence->[$i_tok] = $type_sequence;
6268 53384 $routput_indent_flag->[$i_tok] = $indent_flag;
6269 }
6270  
6271 # get the next pre-token and type
6272 # $tok and $type will be modified to make the output token
6273 60178 my $pre_tok = $tok = $rtokens->[$i]; # get the next pre-token
6274 60178 my $pre_type = $type = $rtoken_type->[$i]; # and type
6275  
6276 # re-initialize various flags for the next output token
6277 (
6278  
6279 # remember the starting index of this token; we will update $i
6280 60178 $i_tok,
6281 $block_type,
6282 $container_type,
6283 $type_sequence,
6284 $indent_flag,
6285 $prototype,
6286 )
6287 = (
6288  
6289 $i,
6290 EMPTY_STRING,
6291 EMPTY_STRING,
6292 EMPTY_STRING,
6293 0,
6294 EMPTY_STRING,
6295 );
6296  
6297 # this pre-token will start an output token
6298 60178 push @{$routput_token_list}, $i_tok;
6299  
6300 #---------------------------------------------------
6301 # The token search leads to one of 5 main END NODES:
6302 #---------------------------------------------------
6303  
6304 #-----------------------
6305 # END NODE 1: whitespace
6306 #-----------------------
6307 60178 ▶ next if ( $pre_type eq 'b' );
Branch: 1 branch
BranchTrueFalseTotal
if $pre_type eq "b" 18169 42009 60178
6308  
6309 #----------------------
6310 # END NODE 2: a comment
6311 #----------------------
6312 42009 ▶ if ( $pre_type eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre_type eq "#") 363 41646 42009
6313  
6314 # push non-indenting brace stack Look for a possible
6315 # non-indenting brace. This is only used to give a hint in
6316 # case the file is unbalanced.
6317 # Hardwired to '#<<<' for efficiency. We will not use the
6318 # result later if the pattern has been changed (very unusual).
6319 363 ▶ if ( $last_nonblank_token eq '{'
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_token eq "{" and $last_nonblank_block_type and $last_nonblank_type_sequence and not $self->[13] and $rOpts_non_indenting_braces) 46 317 363
Condition75%9/12
$last_nonblank_token eq "{" and $last_nonblank_block_type and $last_nonblank_type_sequence and not $self->[13] and $rOpts_non_indenting_braces
!ll&&!rl&&r
311646
$last_nonblank_token eq "{" and $last_nonblank_block_type and $last_nonblank_type_sequence and not $self->[13]
!ll&&!rl&&r
311052
$last_nonblank_token eq "{" and $last_nonblank_block_type and $last_nonblank_type_sequence
!ll&&!rl&&r
311052
$last_nonblank_token eq "{" and $last_nonblank_block_type
!ll&&!rl&&r
311052
MC/DC40%2/5
$last_nonblank_token eq "{" and $last_nonblank_block_type and $last_nonblank_type_sequence and not $self->[13] and $rOpts_non_indenting_braces
$last_nonblank_token eq "{" $last_nonblank_block_type $last_nonblank_type_sequence not $self->[13] $rOpts_non_indenting_braces
Truth table50%3/6
A and B and C and not(D) and E
A= $last_nonblank_token eq "{"B= $last_nonblank_block_typeC= $last_nonblank_type_sequenceD= not $self->[13]E= $rOpts_non_indenting_braces
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
6320 && $last_nonblank_block_type
6321 && $last_nonblank_type_sequence
6322 && !$self->[_in_format_skipping_]
6323 && $rOpts_non_indenting_braces )
6324 {
6325 46 my $offset = $rtoken_map->[$i_tok];
6326 46 my $text = substr( $input_line, $offset, 5 );
6327 46 my $len = length($text);
6328 46 ▶ if ( $len == 4 && $text eq '#<<<'
Branch: 1 branch
BranchTrueFalseTotal
if ($len == 4 and $text eq "#<<<" or $len > 4 and $text eq "#<<< ") 6 40 46
Condition66%6/9
$len == 4 and $text eq "#<<<" or $len > 4 and $text eq "#<<< "
l!l&&r!l&&!r
6040
$len == 4 and $text eq "#<<<"
!ll&&!rl&&r
4006
$len > 4 and $text eq "#<<< "
!ll&&!rl&&r
13270
MC/DC25%1/4
$len == 4 and $text eq "#<<<" or $len > 4 and $text eq "#<<< "
$len == 4 $text eq "#<<<" $len > 4 $text eq "#<<< "
Truth table28%2/7
A and B or C and D
A= $len == 4B= $text eq "#<<<"C= $len > 4D= $text eq "#<<< "
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
6329 || $len > 4 && $text eq '#<<< ' )
6330 {
6331 6 push @{ $self->[_rnon_indenting_brace_stack_] },
6332 $last_nonblank_type_sequence;
6333 }
6334 }
6335 363 last;
6336 }
6337  
6338 # continue gathering identifier if necessary
6339 41646 ▶ if ($id_scan_state) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state) 17 41629 41646
6340  
6341 17 ▶ if ( $is_sub{$id_scan_state} || $is_package{$id_scan_state} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_sub{$id_scan_state} or $is_package{$id_scan_state}) { } 10 7 17
Condition66%2/3
$is_sub{$id_scan_state} or $is_package{$id_scan_state}
l!l&&r!l&&!r
1007
MC/DC50%1/2
$is_sub{$id_scan_state} or $is_package{$id_scan_state}
$is_sub{$id_scan_state} $is_package{$id_scan_state}
Truth table66%2/3
A or B
A= $is_sub{$id_scan_state}B= $is_package{$id_scan_state}
ABresult
1X1
011
000
6342 10 $self->scan_id();
6343 }
6344 else {
6345 7 $self->scan_identifier();
6346 }
6347  
6348 17 ▶ if ($id_scan_state) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state) 1 16 17
6349  
6350 # Still scanning ...
6351 # Check for side comment between sub and prototype (c061)
6352  
6353 # done if nothing left to scan on this line
6354 1 ▶ last if ( $i > $max_token_index );
Branch: 1 branch
BranchTrueFalseTotal
if $i > $max_token_index 0 1 1
6355  
6356 1 my ( $next_nonblank_token_uu, $i_next ) =
6357 find_next_nonblank_token_on_this_line( $i, $rtokens,
6358 $max_token_index );
6359  
6360 # done if it was just some trailing space
6361 1 ▶ last if ( $i_next > $max_token_index );
Branch: 1 branch
BranchTrueFalseTotal
if $i_next > $max_token_index 0 1 1
6362  
6363 # something remains on the line ... must be a side comment
6364 1 next;
6365 }
6366  
6367 16 ▶ next if ( ( $i > 0 ) || $type );
Branch: 1 branch
BranchTrueFalseTotal
if $i > 0 or $type 9 7 16
Condition100%3/3
$i > 0 or $type
l!l&&r!l&&!r
367
MC/DC100%2/2
$i > 0 or $type
$i > 0 $type
Truth table100%3/3
A or B
A= $i > 0B= $type
ABresult
1X1
011
000
6368  
6369 # didn't find any token; start over
6370 7 $type = $pre_type;
6371 7 $tok = $pre_tok;
6372 }
6373  
6374 #-----------------------------------------------------------
6375 # Combine pre-tokens into digraphs and trigraphs if possible
6376 #-----------------------------------------------------------
6377  
6378 # See if we can make a digraph...
6379 # The following tokens are excluded and handled specially:
6380 # '/=' is excluded because the / might start a pattern.
6381 # 'x=' is excluded since it might be $x=, with $ on previous line
6382 # '**' and *= might be typeglobs of punctuation variables
6383 # I have allowed tokens starting with <, such as <=,
6384 # because I don't think these could be valid angle operators.
6385 # test file: storrs4.pl
6386 41636 ▶ if ( $can_start_digraph{$tok}
Branch: 1 branch
BranchTrueFalseTotal
if ($can_start_digraph{$tok} and $i < $max_token_index and $is_digraph{$tok . $$rtokens[$i + 1]}) 3121 38515 41636
Condition100%6/6
$can_start_digraph{$tok} and $i < $max_token_index and $is_digraph{$tok . $$rtokens[$i + 1]}
!ll&&!rl&&r
3514033753121
$can_start_digraph{$tok} and $i < $max_token_index
!ll&&!rl&&r
350101306496
MC/DC100%3/3
$can_start_digraph{$tok} and $i < $max_token_index and $is_digraph{$tok . $$rtokens[$i + 1]}
$can_start_digraph{$tok} $i < $max_token_index $is_digraph{$tok . $$rtokens[$i + 1]}
Truth table100%4/4
A and B and C
A= $can_start_digraph{$tok}B= $i < $max_token_indexC= $is_digraph{$tok . $$rtokens[$i + 1]}
ABCresult
0XX0
10X0
1100
1111
6387 && $i < $max_token_index
6388 && $is_digraph{ $tok . $rtokens->[ $i + 1 ] } )
6389 {
6390  
6391 3121 my $combine_ok = 1;
6392 3121 my $test_tok = $tok . $rtokens->[ $i + 1 ];
6393  
6394 # check for special cases which cannot be combined
6395  
6396 # Smartmatch is being deprecated, but may exist in older
6397 # scripts.
6398 3121 ▶ if ( $test_tok eq '~~' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($test_tok eq '~~') { } 111 3010 3121
elsif ($test_tok eq '//') { } 16 2994 3010
elsif ($test_tok eq '**') { } 45 2949 2994
6399  
6400 # Do not combine if a TERM is required
6401 111 ▶ if ( $self->operator_expected( $tok, '~', undef ) == TERM )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->operator_expected($tok, "~", undef) == -1) 1 110 111
6402 {
6403  
6404 # block types ';' may actually be hash refs, c567
6405 1 ▶ if ( $last_nonblank_type eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq '}') { } 1 0 1
6406 1 my $blk = $rbrace_type->[ $brace_depth + 1 ];
6407 1 ▶ if ( !$blk || $blk ne ';' ) { $combine_ok = 0 }
Branch: 1 branch
BranchTrueFalseTotal
if (not $blk or $blk ne ";") 0 1 1
Condition33%1/3
not $blk or $blk ne ";"
l!l&&r!l&&!r
001
MC/DC0%0/2
not $blk or $blk ne ";"
not $blk $blk ne ";"
Truth table33%1/3
not(A) or B
A= not $blkB= $blk ne ";"
ABresult
1X1
011
000
6408 }
6409 else {
6410 0 $combine_ok = 0;
6411 }
6412 }
6413 }
6414  
6415 # '//' must be defined_or operator if an operator is expected.
6416 # TODO: Code for other ambiguous digraphs (/=, x=, **, *=)
6417 # could be migrated here for clarity
6418  
6419 # Patch for RT#102371, misparsing a // in the following snippet:
6420 # state $b //= ccc();
6421 # The solution is to always accept the digraph (or trigraph)
6422 # after type 'Z' (possible file handle). The reason is that
6423 # sub operator_expected gives TERM expected here, which is
6424 # wrong in this case.
6425 elsif ( $test_tok eq '//' ) {
6426 16 ▶ if ( $last_nonblank_type ne 'Z' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type ne "Z") 16 0 16
6427  
6428 # note that here $tok = '/' and the next tok and type
6429 # is '/'
6430 16 my $blank_after_Z;
6431 16 $expecting =
6432 $self->operator_expected( $tok, '/', $blank_after_Z );
6433  
6434 # Patched for RT#101547, was
6435 # 'unless ($expecting==OPERATOR)'
6436 16 ▶ $combine_ok = 0 if ( $expecting == TERM );
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == -1 4 12 16
6437 }
6438 }
6439  
6440 # Patch for RT #114359: mis-parsing of "print $x ** 0.5;
6441 # Accept the digraphs '**' only after type 'Z'
6442 # Otherwise postpone the decision.
6443 elsif ( $test_tok eq '**' ) {
6444 45 ▶ if ( $last_nonblank_type ne 'Z' ) { $combine_ok = 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type ne "Z") 43 2 45
6445 }
6446 else {
6447 ## no other special cases
6448 }
6449  
6450 3121 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($combine_ok and $test_tok ne "/=" and $test_tok ne "x=" and $test_tok ne "*=") 3068 53 3121
Condition88%8/9
$combine_ok and $test_tok ne "/=" and $test_tok ne "x=" and $test_tok ne "*="
!ll&&!rl&&r
5123068
$combine_ok and $test_tok ne "/=" and $test_tok ne "x="
!ll&&!rl&&r
5103070
$combine_ok and $test_tok ne "/="
!ll&&!rl&&r
4743070
MC/DC75%3/4
$combine_ok and $test_tok ne "/=" and $test_tok ne "x=" and $test_tok ne "*="
$combine_ok $test_tok ne "/=" $test_tok ne "x=" $test_tok ne "*="
Truth table80%4/5
A and B and C and D
A= $combine_okB= $test_tok ne "/="C= $test_tok ne "x="D= $test_tok ne "*="
ABCDresult
0XXX0
10XX0
110X0
11100
11111
6451  
6452 # still ok to combine?
6453 $combine_ok
6454  
6455 && ( $test_tok ne '/=' ) # might be pattern
6456 && ( $test_tok ne 'x=' ) # might be $x
6457 && ( $test_tok ne '*=' ) # typeglob?
6458  
6459 # Moved above as part of fix for
6460 # RT #114359: Missparsing of "print $x ** 0.5;
6461 # && ( $test_tok ne '**' ) # typeglob?
6462 )
6463 {
6464 3068 $tok = $test_tok;
6465 3068 $i++;
6466  
6467 # Now try to assemble trigraphs. Note that all possible
6468 # perl trigraphs can be constructed by appending a character
6469 # to a digraph.
6470 3068 $test_tok = $tok . $rtokens->[ $i + 1 ];
6471  
6472 3068 ▶ if ( $is_trigraph{$test_tok} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_trigraph{$test_tok}) { } 105 2963 3068
6473 105 $tok = $test_tok;
6474 105 $i++;
6475 }
6476  
6477 # The only current tetragraph is the double diamond operator
6478 # and its first three characters are NOT a trigraph, so
6479 # we do can do a special test for it
6480 else {
6481 2963 ▶ if ( $test_tok eq '<<>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test_tok eq "<<>") 1 2962 2963
6482 1 $test_tok .= $rtokens->[ $i + 2 ];
6483 1 ▶ if ( $is_tetragraph{$test_tok} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_tetragraph{$test_tok}) 1 0 1
6484 1 $tok = $test_tok;
6485 1 $i += 2;
6486 }
6487 }
6488 }
6489 }
6490 }
6491  
6492 41636 $type = $tok;
6493 41636 $next_tok = $rtokens->[ $i + 1 ];
6494 41636 $next_type = $rtoken_type->[ $i + 1 ];
6495  
6496 # expecting an operator here? first try table lookup, then function
6497 41636 $expecting = $op_expected_table{$last_nonblank_type};
6498 41636 ▶ if ( !defined($expecting) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $expecting) 11872 29764 41636
6499 11872 ▶ my $blank_after_Z = $last_nonblank_type eq 'Z'
Condition83%5/6
$last_nonblank_type eq 'Z' && ($i == 0 || $$rtoken_type[$i - 1] eq 'b')
!ll&&!rl&&r
118253413
$i == 0 or $$rtoken_type[$i - 1] eq "b"
l!l&&r!l&&!r
01334
MC/DC66%2/3
$last_nonblank_type eq 'Z' && ($i == 0 || $$rtoken_type[$i - 1] eq 'b')
$last_nonblank_type eq 'Z' $i == 0 $$rtoken_type[$i - 1] eq "b"
Truth table75%3/4
A && B or C
A= $last_nonblank_type eq 'Z'B= $i == 0C= $$rtoken_type[$i - 1] eq "b"
ABCresult
0XX0
1000
11X1
1011
6500 && ( $i == 0 || $rtoken_type->[ $i - 1 ] eq 'b' );
6501 11872 $expecting =
6502 $self->operator_expected( $tok, $next_type, $blank_after_Z );
6503 }
6504  
6505 41636 DEBUG_TOKENIZE && do {
6506 local $LIST_SEPARATOR = ')(';
6507 my @debug_list = (
6508 $last_nonblank_token, $tok,
6509 $next_tok, $brace_depth,
6510 $rbrace_type->[$brace_depth], $paren_depth,
6511 $rparen_type->[$paren_depth],
6512 );
6513 print {*STDOUT} "TOKENIZE:(@debug_list)\n";
6514 };
6515  
6516 # The next token is '$tok'.
6517 # Now we have to define its '$type'
6518  
6519 #------------------------
6520 # END NODE 3: a bare word
6521 #------------------------
6522 41636 ▶ if ( $pre_type eq 'w' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre_type eq "w") 6739 34897 41636
6523 6739 my $is_last = $self->do_BAREWORD();
6524 6739 ▶ last if ($is_last);
Branch: 1 branch
BranchTrueFalseTotal
if $is_last 9 6730 6739
6525 6730 next;
6526 }
6527  
6528 # Turn off attribute list on first non-blank, non-bareword,
6529 # and non-comment (added to fix c038)
6530 34897 $self->[_in_attribute_list_] = 0;
6531  
6532 #-------------------------------
6533 # END NODE 4: a string of digits
6534 #-------------------------------
6535 34897 ▶ if ( $pre_type eq 'd' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre_type eq "d") 2521 32376 34897
6536 2521 $self->do_DIGITS();
6537 2521 next;
6538 }
6539  
6540 #------------------------------------------
6541 # END NODE 5: everything else (punctuation)
6542 #------------------------------------------
6543 32376 my $code = $tokenization_code->{$tok};
6544 32376 ▶ if ($code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code) 30102 2274 32376
6545 30102 $code->($self);
6546 30102 ▶ redo if ($in_quote);
Branch: 1 branch
BranchTrueFalseTotal
if $in_quote 2734 27368 30102
6547 }
6548  
6549 # Check for a non-TERM where a TERM is expected. Note that this
6550 # checks all symbols, even those without a $code (update c566)
6551 29642 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) 11902 17740 29642
6552 my $is_not_term =
6553 $type eq ';'
6554 || $type eq ','
6555 11902 ▶ || $is_binary_operator_type{$type};
Condition100%6/6
$type eq ';' || $type eq ',' || $is_binary_operator_type{$type}
l!l&&r!l&&!r
2611611625
$type eq ";" or $type eq ","
l!l&&r!l&&!r
2154611641
MC/DC100%3/3
$type eq ';' || $type eq ',' || $is_binary_operator_type{$type}
$type eq ";" $type eq "," $is_binary_operator_type{$type}
Truth table100%4/4
A or B || C
A= $type eq ";"B= $type eq ","C= $is_binary_operator_type{$type}
ABCresult
1XX1
01X1
0011
0000
6556 11902 ▶ if ($is_not_term) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_not_term) 277 11625 11902
6557 277 $self->error_if_expecting_TERM();
6558 }
6559 }
6560 } ## End main tokenizer loop
6561  
6562 # Store the final token
6563 6983 ▶ if ( $i_tok >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_tok >= 0) 6794 189 6983
6564 6794 $routput_token_type->[$i_tok] = $type;
6565 6794 $routput_block_type->[$i_tok] = $block_type;
6566 6794 $routput_type_sequence->[$i_tok] = $type_sequence;
6567 6794 $routput_indent_flag->[$i_tok] = $indent_flag;
6568 }
6569  
6570 # Remember last nonblank values
6571 6983 ▶ if ( $type ne 'b' && $type ne '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type ne "b" and $type ne "#") 6472 511 6983
Condition100%3/3
$type ne "b" and $type ne "#"
!ll&&!rl&&r
1483636472
MC/DC100%2/2
$type ne "b" and $type ne "#"
$type ne "b" $type ne "#"
Truth table100%3/3
A and B
A= $type ne "b"B= $type ne "#"
ABresult
0X0
100
111
6572  
6573 6472 $last_last_nonblank_token = $last_nonblank_token;
6574 6472 $last_last_nonblank_type = $last_nonblank_type;
6575  
6576 6472 $last_nonblank_prototype = $prototype;
6577 6472 $last_nonblank_block_type = $block_type;
6578 6472 $last_nonblank_container_type = $container_type;
6579 6472 $last_nonblank_type_sequence = $type_sequence;
6580 6472 $last_nonblank_token = $tok;
6581 6472 $last_nonblank_type = $type;
6582 }
6583  
6584 # reset indentation level if necessary at a sub or package
6585 # in an attempt to recover from a nesting error
6586 6983 ▶ if ( $level_in_tokenizer < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level_in_tokenizer < 0) 0 6983 6983
6587 0 ▶ if ( $input_line =~ /^\s*(sub|package)\s+(\w+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^\s*(sub|package)\s+(\w+)/) 0 0 0
6588 0 reset_indentation_level(0);
6589 0 $self->brace_warning("resetting level to 0 at $1 $2\n");
6590 }
6591 }
6592  
6593 6983 $self->[_in_quote_] = $in_quote;
6594 $self->[_quote_target_] =
6595 $in_quote
6596 ? (
6597 $matching_end_token{$quote_character}
6598 6983 ▶ ? $matching_end_token{$quote_character}
Branch: 2 branches
BranchTrueFalseTotal
$in_quote ? : 245 6738 6983
$matching_end_token{$quote_character} ? : 187 58 245
6599 : $quote_character
6600 )
6601 : EMPTY_STRING;
6602 6983 $self->[_rhere_target_list_] = $rhere_target_list;
6603  
6604 6983 return;
6605 } ## end sub tokenizer_main_loop
6606  
6607 sub tokenizer_wrapup_line {
6608 6983 ▶ my ( $self, $line_of_tokens ) = @_;
Subroutine tokenizer_wrapup_line: called CC=43 SCAR=38.7
Pod undocumented
6609  
6610 #---------------------------------------------------------
6611 # Package a line of tokens for shipping back to the caller
6612 #---------------------------------------------------------
6613  
6614 # Arrays to hold token values for this line:
6615 my (
6616 6983 @output_levels, @output_block_type, @output_type_sequence,
6617 @output_token_type, @output_tokens,
6618 );
6619  
6620 6983 $line_of_tokens->{_nesting_tokens_0} = $nesting_token_string;
6621  
6622 # Remember starting nesting block string
6623 6983 my $nesting_block_string_0 = $nesting_block_string;
6624  
6625 #-----------------
6626 # Loop over tokens
6627 #-----------------
6628 # $i is the index of the pretoken which starts this full token
6629 6983 foreach my $ii ( @{$routput_token_list} ) {
6630  
6631 60423 my $type_i = $routput_token_type->[$ii];
6632  
6633 #----------------------------------------
6634 # Section 1. Handle a non-sequenced token
6635 #----------------------------------------
6636 60423 ▶ if ( !$routput_type_sequence->[$ii] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $routput_type_sequence->[$ii]) { } 49349 11074 60423
6637  
6638 #-------------------------------
6639 # Section 1.1. types ';' and 't'
6640 #-------------------------------
6641 # - output anonymous 'sub' as keyword (type 'k')
6642 # - output __END__, __DATA__, and format as type 'k' instead
6643 # of ';' to make html colors correct, etc.
6644 49349 ▶ if ( $is_semicolon_or_t{$type_i} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_semicolon_or_t{$type_i}) { } 3226 46123 49349
elsif (not $is_valid_token_type{$type_i}) { } 0 46123 46123
6645 3226 my $tok_i = $rtokens->[$ii];
6646 3226 ▶ if ( $is_END_DATA_format_sub{$tok_i} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_END_DATA_format_sub{$tok_i}) 189 3037 3226
6647 189 $type_i = 'k';
6648 }
6649 }
6650  
6651 #----------------------------------------------
6652 # Section 1.2. Check for an invalid token type.
6653 #----------------------------------------------
6654 # This can happen by running perltidy on non-scripts although
6655 # it could also be bug introduced by programming change. Perl
6656 # silently accepts a 032 (^Z) and takes it as the end
6657 elsif ( !$is_valid_token_type{$type_i} ) {
6658 0 ▶ if ( !$self->[_in_error_] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[7]) 0 0 0
6659 0 my $val = ord($type_i);
6660 0 $self->warning(
6661 "unexpected character decimal $val ($type_i) in script\n"
6662 );
6663 0 $self->[_in_error_] = 1;
6664 }
6665 }
6666 else {
6667 ## valid token type other than ; and t
6668 }
6669  
6670 #----------------------------------------------------
6671 # Section 1.3. Store values for a non-sequenced token
6672 #----------------------------------------------------
6673 49349 push @output_levels, $level_in_tokenizer;
6674 49349 push @output_block_type, EMPTY_STRING;
6675 49349 push @output_type_sequence, EMPTY_STRING;
6676 49349 push @output_token_type, $type_i;
6677  
6678 }
6679  
6680 #------------------------------------
6681 # Section 2. Handle a sequenced token
6682 # One of { [ ( ? : ) ] }
6683 #------------------------------------
6684 else {
6685  
6686 # $level_i is the level we will store. Levels of braces are
6687 # set so that the leading braces have a HIGHER level than their
6688 # CONTENTS, which is convenient for indentation.
6689 11074 my $level_i = $level_in_tokenizer;
6690  
6691 # $tok_i is the PRE-token. It only equals the token for symbols
6692 11074 my $tok_i = $rtokens->[$ii];
6693  
6694 # $routput_indent_flag->[$ii] indicates that we need a change
6695 # in level at a nested ternary, as follows
6696 # 1 => at a nested ternary ?
6697 # -1 => at a nested ternary :
6698 # 0 => otherwise
6699  
6700 #--------------------------------------------
6701 # Section 2.1 Handle a level-increasing token
6702 #--------------------------------------------
6703 11074 ▶ if ( $is_opening_or_ternary_type{$type_i} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_opening_or_ternary_type{$type_i}) { } 5537 5537 11074
elsif ($is_closing_or_ternary_type{$type_i}) { } 5537 0 5537
6704  
6705 5537 ▶ if ( $type_i eq '?' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_i eq '?') { } 193 5344 5537
6706  
6707 193 ▶ if ( $routput_indent_flag->[$ii] > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($routput_indent_flag->[$ii] > 0) 8 185 193
6708 8 $level_in_tokenizer++;
6709  
6710 # break BEFORE '?' in a nested ternary
6711 8 $level_i = $level_in_tokenizer;
6712 8 $nesting_block_string .= "$nesting_block_flag";
6713  
6714 }
6715 }
6716 else {
6717  
6718 5344 $nesting_token_string .= $tok_i;
6719  
6720 5344 ▶ if ( $type_i eq '{' || $type_i eq 'L' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_i eq "{" or $type_i eq "L") 4904 440 5344
Condition100%3/3
$type_i eq "{" or $type_i eq "L"
l!l&&r!l&&!r
4316588440
MC/DC100%2/2
$type_i eq "{" or $type_i eq "L"
$type_i eq "{" $type_i eq "L"
Truth table100%3/3
A or B
A= $type_i eq "{"B= $type_i eq "L"
ABresult
1X1
011
000
6721  
6722 4904 $level_in_tokenizer++;
6723  
6724 4904 ▶ if ( $routput_block_type->[$ii] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($routput_block_type->[$ii]) { } 1157 3747 4904
6725 1157 $nesting_block_flag = 1;
6726 1157 $nesting_block_string .= '1';
6727 }
6728 else {
6729 3747 $nesting_block_flag = 0;
6730 3747 $nesting_block_string .= '0';
6731 }
6732 }
6733 }
6734 }
6735  
6736 #---------------------------------------------
6737 # Section 2.2. Handle a level-decreasing token
6738 #---------------------------------------------
6739 elsif ( $is_closing_or_ternary_type{$type_i} ) {
6740  
6741 5537 ▶ if ( $type_i ne ':' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_i ne ":") 5344 193 5537
6742 5344 my $char = chop $nesting_token_string;
6743 5344 ▶ if ( $char ne $matching_start_token{$tok_i} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char ne $matching_start_token{$tok_i}) 0 5344 5344
6744 0 $nesting_token_string .= $char . $tok_i;
6745 }
6746 }
6747  
6748 5537 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($type_i eq "}" or $type_i eq "R" or $type_i eq ":" and $routput_indent_flag->[$ii] < 0) 596 625 1221
Condition100%9/9
$type_i eq "}" or $type_i eq "R" or $type_i eq ":" and $routput_indent_flag->[$ii] < 0
l!l&&r!l&&!r
49048625
$type_i eq "}" or $type_i eq "R"
l!l&&r!l&&!r
4316588633
$type_i eq ":" and $routput_indent_flag->[$ii] < 0
!ll&&!rl&&r
4401858
MC/DC75%3/4
$type_i eq "}" or $type_i eq "R" or $type_i eq ":" and $routput_indent_flag->[$ii] < 0
$type_i eq "}" $type_i eq "R" $type_i eq ":" $routput_indent_flag->[$ii] < 0
Truth table80%4/5
A or B or C and D
A= $type_i eq "}"B= $type_i eq "R"C= $type_i eq ":"D= $routput_indent_flag->[$ii] < 0
ABCDresult
1XXX1
01XX1
00111
000X0
00100
6749 $type_i eq '}'
6750 || $type_i eq 'R'
6751  
6752 # only the second and higher ? : have levels
6753 || $type_i eq ':' && $routput_indent_flag->[$ii] < 0
6754 )
6755 {
6756  
6757 4912 $level_i = --$level_in_tokenizer;
6758  
6759 4912 ▶ if ( $level_in_tokenizer < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level_in_tokenizer < 0) 0 4912 4912
6760 0 ▶ if ( !$self->[_saw_negative_indentation_] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[34]) 0 0 0
6761 0 $self->[_saw_negative_indentation_] = 1;
6762 0 $self->warning(
6763 "Starting negative indentation\n");
6764 }
6765 }
6766  
6767 # restore previous level values
6768 4912 ▶ if ( length($nesting_block_string) > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (length $nesting_block_string > 1) 4912 0 4912
6769 { # true for valid script
6770 4912 chop $nesting_block_string;
6771 4912 $nesting_block_flag =
6772 substr( $nesting_block_string, -1 ) eq '1';
6773 }
6774  
6775 }
6776 }
6777  
6778 #-----------------------------------------------------
6779 # Section 2.3. Unexpected sequenced token type - error
6780 #-----------------------------------------------------
6781 else {
6782  
6783 # The tokenizer should only be assigning sequence numbers
6784 # to types { [ ( ? ) ] } :
6785 0 DEVEL_MODE && Fault(<<EOM);
6786 unexpected sequence number on token type $type_i with pre-tok=$tok_i
6787 EOM
6788 }
6789  
6790 #------------------------------------------------
6791 # Section 2.4. Store values for a sequenced token
6792 #------------------------------------------------
6793  
6794 # The starting nesting block string, which is used in any .LOG
6795 # output, should include the first token of the line
6796 11074 ▶ if ( !@output_levels ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@output_levels) 1805 9269 11074
6797 1805 $nesting_block_string_0 = $nesting_block_string;
6798 }
6799  
6800 # Store values for a sequenced token
6801 11074 push @output_levels, $level_i;
6802 11074 push @output_block_type, $routput_block_type->[$ii];
6803 11074 push @output_type_sequence, $routput_type_sequence->[$ii];
6804 11074 push @output_token_type, $type_i;
6805  
6806 }
6807 } ## End loop to over tokens
6808  
6809 #---------------------
6810 # Post-loop operations
6811 #---------------------
6812  
6813 6983 $line_of_tokens->{_nesting_blocks_0} = $nesting_block_string_0;
6814  
6815 # Form and store the tokens
6816 6983 ▶ if (@output_levels) {
Branch: 1 branch
BranchTrueFalseTotal
if (@output_levels) 6983 0 6983
6817  
6818 6983 my $im = shift @{$routput_token_list};
6819 6983 my $offset = $rtoken_map->[$im];
6820 6983 foreach my $ii ( @{$routput_token_list} ) {
6821 53440 my $numc = $rtoken_map->[$ii] - $offset;
6822 53440 push @output_tokens, substr( $input_line, $offset, $numc );
6823 53440 $offset += $numc;
6824  
6825 # programming note: it seems most efficient to 'next' out of
6826 # a critical loop like this as early as possible. So instead
6827 # of 'if ( DEVEL_MODE && $numc < 0 )' we write:
6828 53440 next unless (DEVEL_MODE);
6829 0 ▶ next if ( $numc > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $numc > 0 0 0 0
6830  
6831 # Should not happen unless @{$rtoken_map} is corrupted
6832 0 Fault("number of characters is '$numc' but should be >0\n");
6833 }
6834  
6835 # Form and store the final token of this line
6836 6983 my $numc = length($input_line) - $offset;
6837 6983 push @output_tokens, substr( $input_line, $offset, $numc );
6838  
6839 6983 if (DEVEL_MODE) {
6840 if ( $numc <= 0 ) {
6841  
6842 # check '$rtoken_map' and '$routput_token_list'
6843 Fault("Number of Characters is '$numc' but should be >0\n");
6844 }
6845  
6846 # Make sure we didn't gain or lose any characters
6847 my $test_line = join( EMPTY_STRING, @output_tokens );
6848 if ( $test_line ne $input_line ) {
6849 my $len_input = length($input_line);
6850 my $len_test = length($test_line);
6851  
6852 # check '$rtoken_map' and '$routput_token_list'
6853 Fault(<<EOM);
6854 Reconstructed line difers from input; input_length=$len_input test_length=$len_test
6855 input:'$input_line'
6856 test :'$test_line'
6857 EOM
6858 }
6859 }
6860 }
6861  
6862 # Wrap up this line of tokens for shipping to the Formatter
6863 6983 $line_of_tokens->{_rtoken_type} = \@output_token_type;
6864 6983 $line_of_tokens->{_rtokens} = \@output_tokens;
6865 6983 $line_of_tokens->{_rblock_type} = \@output_block_type;
6866 6983 $line_of_tokens->{_rtype_sequence} = \@output_type_sequence;
6867 6983 $line_of_tokens->{_rlevels} = \@output_levels;
6868  
6869 #-----------------------------------------------------------------
6870 # Compare input indentation with computed levels at closing braces
6871 #-----------------------------------------------------------------
6872 # This may provide a useful hint for error location if the file
6873 # is not balanced in braces. Closing braces are used because they
6874 # have a well-defined indentation and can be processed efficiently.
6875 6983 ▶ if ( $output_tokens[0] eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($output_tokens[0] eq "}") 758 6225 6983
6876  
6877 758 my $blk = $output_block_type[0];
6878 758 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($is_zero_continuation_block_type{$blk} || substr($blk, 0, 4) eq "sub " and not $self->[13]) 415 343 758
Condition83%5/6
$is_zero_continuation_block_type{$blk} || substr($blk, 0, 4) eq "sub " and not $self->[13]
!ll&&!rl&&r
3430415
$is_zero_continuation_block_type{$blk} or substr($blk, 0, 4) eq "sub "
l!l&&r!l&&!r
32095343
MC/DC66%2/3
$is_zero_continuation_block_type{$blk} || substr($blk, 0, 4) eq "sub " and not $self->[13]
$is_zero_continuation_block_type{$blk} substr($blk, 0, 4) eq "sub " not $self->[13]
Truth table60%3/5
A or B and not(C)
A= $is_zero_continuation_block_type{$blk}B= substr($blk, 0, 4) eq "sub "C= not $self->[13]
ABCresult
00X0
1X00
0100
1X11
0111
6879 (
6880 # builtin block types without continuation indentation
6881 $is_zero_continuation_block_type{$blk}
6882  
6883 # or a named sub, but skip sub aliases for efficiency,
6884 # since this is just for diagnostic info
6885 || substr( $blk, 0, 4 ) eq 'sub '
6886 )
6887  
6888 # and we are not in format skipping
6889 && !$self->[_in_format_skipping_]
6890 )
6891 {
6892  
6893 # subtract 1 space for newline in untrimmed line
6894 415 my $untrimmed_input_line = $line_of_tokens->{_line_text};
6895 415 my $space_count =
6896 length($untrimmed_input_line) - length($input_line) - 1;
6897  
6898 # check for tabs
6899 415 ▶ if ( $space_count
Branch: 1 branch
BranchTrueFalseTotal
if ($space_count and ord substr($untrimmed_input_line, 0, 1) == 9) 15 400 415
Condition100%3/3
$space_count and ord substr($untrimmed_input_line, 0, 1) == 9
!ll&&!rl&&r
22517515
MC/DC100%2/2
$space_count and ord substr($untrimmed_input_line, 0, 1) == 9
$space_count ord substr($untrimmed_input_line, 0, 1) == 9
Truth table100%3/3
A and B
A= $space_countB= ord substr($untrimmed_input_line, 0, 1) == 9
ABresult
0X0
100
111
6900 && ord( substr( $untrimmed_input_line, 0, 1 ) ) == ORD_TAB )
6901 {
6902 15 ▶ if ( $untrimmed_input_line =~ /^(\t+)?(\s+)?/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($untrimmed_input_line =~ /^(\t+)?(\s+)?/) 15 0 15
6903 15 ▶ if ($1) { $space_count += length($1) * $tabsize }
Branch: 1 branch
BranchTrueFalseTotal
if ($1) 15 0 15
6904 15 ▶ if ($2) { $space_count += length($2) }
Branch: 1 branch
BranchTrueFalseTotal
if ($2) 1 14 15
6905 }
6906 }
6907  
6908 # '$guess' = the level according to indentation
6909 415 my $guess = int( $space_count / $rOpts_indent_columns );
6910  
6911 # subtract 1 level from guess for --indent-closing-brace
6912 415 ▶ $guess -= 1 if ($rOpts_indent_closing_brace);
Branch: 1 branch
BranchTrueFalseTotal
if $rOpts_indent_closing_brace 3 412 415
6913  
6914 # subtract 1 from $level for each non-indenting brace level
6915 415 my $adjust = @{ $self->[_rnon_indenting_brace_stack_] };
6916  
6917 415 my $level = $output_levels[0];
6918  
6919 # find the difference between expected and indentation guess
6920 415 my $level_diff = $level - $adjust - $guess;
6921  
6922 415 my $rhash = $self->[_rclosing_brace_indentation_hash_];
6923  
6924 # results are only valid if we guess correctly at the
6925 # first spaced brace
6926 415 ▶ if ( $space_count && !defined( $rhash->{valid} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($space_count and not defined $rhash->{"valid"}) 83 332 415
Condition100%3/3
$space_count and not defined $rhash->{"valid"}
!ll&&!rl&&r
22510783
MC/DC100%2/2
$space_count and not defined $rhash->{"valid"}
$space_count not defined $rhash->{"valid"}
Truth table100%3/3
A and not(B)
A= $space_countB= not defined $rhash->{"valid"}
ABresult
0X0
100
111
6927 83 $rhash->{valid} = !$level_diff;
6928 }
6929  
6930 # save the result
6931 415 my $rhistory_line_number = $rhash->{rhistory_line_number};
6932 415 my $rhistory_level_diff = $rhash->{rhistory_level_diff};
6933 415 my $rhistory_anchor_point = $rhash->{rhistory_anchor_point};
6934  
6935 415 ▶ if ( $rhistory_level_diff->[-1] != $level_diff ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rhistory_level_diff->[-1] != $level_diff) { } 55 360 415
6936  
6937 # Patch for non-indenting-braces: if we guess zero and
6938 # match before all non-indenting braces have been found,
6939 # it means that we would need negative indentation to
6940 # match if/when the brace is found. So we have a problem
6941 # from here on. We indicate this with a value 2 instead
6942 # of 1 as a signal to stop outputting the table here.
6943 55 my $anchor = 1;
6944 55 ▶ if ( $guess == 0 && $adjust > 0 ) { $anchor = 2 }
Branch: 1 branch
BranchTrueFalseTotal
if ($guess == 0 and $adjust > 0) 0 55 55
Condition66%2/3
$guess == 0 and $adjust > 0
!ll&&!rl&&r
9460
MC/DC0%0/2
$guess == 0 and $adjust > 0
$guess == 0 $adjust > 0
Truth table66%2/3
A and B
A= $guess == 0B= $adjust > 0
ABresult
0X0
100
111
6945  
6946 # add an anchor point
6947 55 push @{$rhistory_level_diff}, $level_diff;
6948 55 push @{$rhistory_line_number}, $input_line_number;
6949 55 push @{$rhistory_anchor_point}, $anchor;
6950 }
6951 else {
6952  
6953 # add a movable point following an anchor point
6954 360 ▶ if ( $rhistory_anchor_point->[-1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rhistory_anchor_point->[-1]) { } 162 198 360
6955 162 push @{$rhistory_level_diff}, $level_diff;
6956 162 push @{$rhistory_line_number}, $input_line_number;
6957 162 push @{$rhistory_anchor_point}, 0;
6958 }
6959  
6960 # extend a movable point
6961 else {
6962 198 $rhistory_line_number->[-1] = $input_line_number;
6963 }
6964 }
6965 }
6966 }
6967  
6968 6983 return;
6969 } ## end sub tokenizer_wrapup_line
6970  
6971 } ## end tokenize_this_line
6972  
6973 #######################################################################
6974 # Tokenizer routines which assist in identifying token types
6975 #######################################################################
6976  
6977 # Define Global '%op_expected_table'
6978 # = hash table of operator expected values based on last nonblank token
6979  
6980 # exceptions to perl's weird parsing rules after type 'Z'
6981 45 my %is_weird_parsing_rule_exception;
6982  
6983 my %is_paren_dollar;
6984  
6985 45 my %is_n_v;
6986  
6987 BEGIN {
6988  
6989 # Always expecting TERM following these types:
6990 # note: this is identical to '@value_requestor_type' defined later.
6991 # Fix for c250: add new type 'P' for package (expecting VERSION or {}
6992 # after package NAMESPACE, so expecting TERM)
6993 # Fix for c250: add new type 'S' for sub (not expecting operator)
6994 45 ▶ my @q = qw#
Subroutine BEGIN: called CC=6 SCAR=17.9
6995 ; ! + x & ? F J - p / Y : % f U ~ A G j L P S * . | ^ < = [ m { > t
6996 || >= != mm *= => .. !~ == && |= .= pp -= =~ += <= %= ^= x= ~~ ** << /=
6997 &= // >> ~. &. |. ^.
6998 ... **= <<= >>= &&= ||= //= <=> !~~ &.= |.= ^.= <<~
6999 #;
7000 45 push @q, BACKSLASH;
7001 45 push @q, COMMA;
7002 45 push @q, '('; # for completeness, not currently a token type
7003 45 push @q, '->'; # was previously in UNKNOWN
7004 45 $op_expected_table{$_} = TERM for @q;
7005  
7006 # No UNKNOWN table types:
7007 # removed '->' for c030, now always TERM
7008 # removed 'w' for c392 to allow use of 'function_count' info in the sub
7009  
7010 # Always expecting OPERATOR ...
7011 # 'n' and 'v' are currently excluded because they might be VERSION numbers
7012 # 'i' is currently excluded because it might be a package
7013 # 'q' is currently excluded because it might be a prototype
7014 # Fix for c030: removed '->' from this list:
7015 # Fix for c250: added 'i' because new type 'P' was added
7016 45 @q = qw( -- C h R ++ ] Q <> i );
7017 45 push @q, ')';
7018 45 $op_expected_table{$_} = OPERATOR for @q;
7019  
7020 # Fix for git #62: added '*' and '%'
7021 45 @q = qw( < ? * % );
7022 45 $is_weird_parsing_rule_exception{$_} = 1 for @q;
7023  
7024 45 @q = qw<) $>;
7025 45 $is_paren_dollar{$_} = 1 for @q;
7026  
7027 45 @q = qw( n v );
7028 45 $is_n_v{$_} = 1 for @q;
7029  
7030 } ## end BEGIN
7031  
7032 45 ▶use constant DEBUG_OPERATOR_EXPECTED => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
7033  
7034 sub operator_expected {
7035  
7036 12014 ▶ my ( $self, $tok, $next_type, $blank_after_Z ) = @_;
Subroutine operator_expected: called CC=46 SCAR=38.6
Pod undocumented
7037  
7038 # Returns a parameter indicating what types of tokens can occur next
7039  
7040 # Call format:
7041 # $op_expected =
7042 # $self->operator_expected( $tok, $next_type, $blank_after_Z );
7043 # where
7044 # $tok is the current token
7045 # $next_type is the type of the next token (blank or not)
7046 # $blank_after_Z = flag for guessing after a type 'Z':
7047 # true if $tok follows type 'Z' with intermediate blank
7048 # false if $tok follows type 'Z' with no intermediate blank
7049 # ignored if $tok does not follow type 'Z'
7050  
7051 # Many perl symbols have two or more meanings. For example, '<<'
7052 # can be a shift operator or a here-doc operator. The
7053 # interpretation of these symbols depends on the current state of
7054 # the tokenizer, which may either be expecting a term or an
7055 # operator. For this example, a << would be a shift if an OPERATOR
7056 # is expected, and a here-doc if a TERM is expected. This routine
7057 # is called to make this decision for any current token. It returns
7058 # one of three possible values:
7059 #
7060 # OPERATOR - operator expected (or at least, not a term)
7061 # UNKNOWN - can't tell
7062 # TERM - a term is expected (or at least, not an operator)
7063 #
7064 # The decision is based on what has been seen so far. This
7065 # information is stored in the "$last_nonblank_type" and
7066 # "$last_nonblank_token" variables. For example, if the
7067 # $last_nonblank_type is '=~', then we are expecting a TERM, whereas
7068 # if $last_nonblank_type is 'n' (numeric), we are expecting an
7069 # OPERATOR.
7070 #
7071 # If a UNKNOWN is returned, the calling routine must guess. A major
7072 # goal of this tokenizer is to minimize the possibility of returning
7073 # UNKNOWN, because a wrong guess can spoil the formatting of a
7074 # script.
7075 #
7076 # Adding NEW_TOKENS: it is critically important that this routine be
7077 # updated to allow it to determine if an operator or term is to be
7078 # expected after the new token. Doing this simply involves adding
7079 # the new token character to one of the regexes in this routine or
7080 # to one of the hash lists
7081 # that it uses, which are initialized in the BEGIN section.
7082 # USES GLOBAL VARIABLES: $last_nonblank_type, $last_nonblank_token,
7083 # $statement_type
7084  
7085 # When possible, token types should be selected such that we can determine
7086 # the 'operator_expected' value by a simple hash lookup. If there are
7087 # exceptions, that is an indication that a new type is needed.
7088  
7089 #--------------------------------------------
7090 # Section 1: Table lookup will get most cases
7091 #--------------------------------------------
7092  
7093 # Many types are can be obtained by a table lookup. This typically handles
7094 # more than half of the calls. For speed, the caller may try table lookup
7095 # first before calling this sub.
7096 12014 my $op_expected = $op_expected_table{$last_nonblank_type};
7097 12014 ▶ if ( defined($op_expected) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $op_expected) 78 11936 12014
7098 DEBUG_OPERATOR_EXPECTED
7099 78 && print {*STDOUT}
7100 "OPERATOR_EXPECTED: Table Lookup; returns $op_expected for last type $last_nonblank_type token $last_nonblank_token\n";
7101 78 return $op_expected;
7102 }
7103  
7104 DEBUG_OPERATOR_EXPECTED
7105 11936 && print {*STDOUT}
7106 "OPERATOR_EXPECTED: in hardwired table for last type $last_nonblank_type token $last_nonblank_token\n";
7107  
7108 #---------------------------------------------
7109 # Section 2: Handle special cases if necessary
7110 #---------------------------------------------
7111  
7112 # Types 'k', '}' and 'Z' depend on context
7113 # Types 'n', 'v', 'q' also depend on context.
7114  
7115 # identifier...
7116 # Fix for c250: removed coding for type 'i' because 'i' and new type 'P'
7117 # are now done by hash table lookup
7118  
7119 #--------------------
7120 # Section 2A: keyword
7121 #--------------------
7122 11936 ▶ if ( $last_nonblank_type eq 'k' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq "k") 3139 8797 11936
7123  
7124 # keywords expecting TERM:
7125 3139 ▶ if ( $expecting_term_token{$last_nonblank_token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting_term_token{$last_nonblank_token}) 3016 123 3139
7126  
7127 # Exceptions from TERM:
7128  
7129 # // may follow perl functions which may be unary operators
7130 # see test file dor.t (defined or);
7131 3016 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "/" and $next_type eq "/" and $is_keyword_rejecting_slash_as_pattern_delimiter{$last_nonblank_token}) 1 3015 3016
Condition100%6/6
$tok eq "/" and $next_type eq "/" and $is_keyword_rejecting_slash_as_pattern_delimiter{$last_nonblank_token}
!ll&&!rl&&r
301321
$tok eq "/" and $next_type eq "/"
!ll&&!rl&&r
3002113
MC/DC100%3/3
$tok eq "/" and $next_type eq "/" and $is_keyword_rejecting_slash_as_pattern_delimiter{$last_nonblank_token}
$tok eq "/" $next_type eq "/" $is_keyword_rejecting_slash_as_pattern_delimiter{$last_nonblank_token}
Truth table100%4/4
A and B and C
A= $tok eq "/"B= $next_type eq "/"C= $is_keyword_rejecting_slash_as_pattern_delimiter{$last_nonblank_token}
ABCresult
0XX0
10X0
1100
1111
7132 $tok eq '/'
7133 && $next_type eq '/'
7134 && $is_keyword_rejecting_slash_as_pattern_delimiter{
7135 $last_nonblank_token}
7136 )
7137 {
7138 1 return OPERATOR;
7139 }
7140  
7141 # Patch to allow a ? following 'split' to be a deprecated pattern
7142 # delimiter. This patch is coordinated with the omission of split
7143 # from the list
7144 # %is_keyword_rejecting_question_as_pattern_delimiter. This patch
7145 # will force perltidy to guess.
7146 3015 ▶ if ( $tok eq '?'
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "?" and $last_nonblank_token eq "split") 0 3015 3015
Condition66%2/3
$tok eq "?" and $last_nonblank_token eq "split"
!ll&&!rl&&r
301410
MC/DC0%0/2
$tok eq "?" and $last_nonblank_token eq "split"
$tok eq "?" $last_nonblank_token eq "split"
Truth table66%2/3
A and B
A= $tok eq "?"B= $last_nonblank_token eq "split"
ABresult
0X0
100
111
7147 && $last_nonblank_token eq 'split' )
7148 {
7149 0 return UNKNOWN;
7150 }
7151  
7152 3015 return TERM;
7153 }
7154  
7155 # keywords expecting OPERATOR:
7156 123 ▶ if ( $expecting_operator_token{$last_nonblank_token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting_operator_token{$last_nonblank_token}) 7 116 123
7157 7 return OPERATOR;
7158 }
7159  
7160 116 return TERM;
7161  
7162 } ## end type 'k'
7163  
7164 #------------------------------------
7165 # Section 2B: Closing container token
7166 #------------------------------------
7167  
7168 # Note that the actual token for type '}' may also be a ')'.
7169  
7170 # Also note that $last_nonblank_token is not the token corresponding to
7171 # $last_nonblank_type when the type is a closing container. In that
7172 # case it is the token before the corresponding opening container token.
7173 # So for example, for this snippet
7174 # $a = do { BLOCK } / 2;
7175 # the $last_nonblank_token is 'do' when $last_nonblank_type eq '}'.
7176  
7177 8797 ▶ if ( $last_nonblank_type eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq "}") 4198 4599 8797
7178  
7179 #-------------------------------------------
7180 # Section 2B1: Closing structural ')' or ']'
7181 #-------------------------------------------
7182 4198 ▶ if ( $last_nonblank_token eq ')' || $last_nonblank_token eq ']' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_token eq ")" or $last_nonblank_token eq "]") 2819 1379 4198
Condition100%3/3
$last_nonblank_token eq ")" or $last_nonblank_token eq "]"
l!l&&r!l&&!r
24443751379
MC/DC100%2/2
$last_nonblank_token eq ")" or $last_nonblank_token eq "]"
$last_nonblank_token eq ")" $last_nonblank_token eq "]"
Truth table100%3/3
A or B
A= $last_nonblank_token eq ")"B= $last_nonblank_token eq "]"
ABresult
1X1
011
000
7183 2819 return OPERATOR;
7184 }
7185  
7186 #-------------------------------------
7187 # Section 2B2: Closing block brace '}'
7188 #-------------------------------------
7189 1379 my $blk = $rbrace_type->[ $brace_depth + 1 ];
7190  
7191 # Non-blocks
7192 1379 ▶ if ( !defined($blk) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $blk) 2 1377 1379
7193 2 return OPERATOR;
7194 }
7195  
7196 # Unidentified block type
7197 1377 ▶ if ( !$blk ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($blk) 367 1010 1377
7198 367 return UNKNOWN;
7199 }
7200  
7201 # Blocks followed by a TERM
7202 1010 ▶ if ( $is_zero_continuation_block_type{$blk}
Branch: 1 branch
BranchTrueFalseTotal
if ($is_zero_continuation_block_type{$blk} or $is_sort_map_grep{$blk} or $is_grep_alias{$blk} or substr($blk, -1, 1) eq ":" and $blk =~ /^\w+:$/ or substr($blk, 0, 3) eq "sub" and $blk =~ /^sub\s/ or substr($blk, 0, 7) eq "package" and $blk =~ /^package\s/) 116 349 465
Condition95%23/24
$is_zero_continuation_block_type{$blk} or $is_sort_map_grep{$blk} or $is_grep_alias{$blk} or substr($blk, -1, 1) eq ":" and $blk =~ /^\w+:$/ or substr($blk, 0, 3) eq "sub" and $blk =~ /^sub\s/ or substr($blk, 0, 7) eq "package" and $blk =~ /^package\s/
l!l&&r!l&&!r
65527328
$is_zero_continuation_block_type{$blk} or $is_sort_map_grep{$blk} or $is_grep_alias{$blk} or substr($blk, -1, 1) eq ":" and $blk =~ /^\w+:$/ or substr($blk, 0, 3) eq "sub" and $blk =~ /^sub\s/
l!l&&r!l&&!r
545110355
$is_zero_continuation_block_type{$blk} or $is_sort_map_grep{$blk} or $is_grep_alias{$blk} or substr($blk, -1, 1) eq ":" and $blk =~ /^\w+:$/
l!l&&r!l&&!r
52619465
$is_zero_continuation_block_type{$blk} or $is_sort_map_grep{$blk} or $is_grep_alias{$blk}
l!l&&r!l&&!r
5215484
$is_zero_continuation_block_type{$blk} or $is_sort_map_grep{$blk}
l!l&&r!l&&!r
42695489
substr($blk, -1, 1) eq ":" and $blk =~ /^\w+:$/
!ll&&!rl&&r
4521319
substr($blk, 0, 3) eq "sub" and $blk =~ /^sub\s/
!ll&&!rl&&r
163192110
substr($blk, 0, 7) eq "package" and $blk =~ /^package\s/
!ll&&!rl&&r
34906
MC/DC0%0/9
$is_zero_continuation_block_type{$blk} or $is_sort_map_grep{$blk} or $is_grep_alias{$blk} or substr($blk, -1, 1) eq ":" and $blk =~ /^\w+:$/ or substr($blk, 0, 3) eq "sub" and $blk =~ /^sub\s/ or substr($blk, 0, 7) eq "package" and $blk =~ /^package\s/
$is_zero_continuation_block_type{$blk} $is_sort_map_grep{$blk} $is_grep_alias{$blk} substr($blk, -1, 1) eq ":" $blk =~ /^\w+:$/ substr($blk, 0, 3) eq "sub" $blk =~ /^sub\s/ substr($blk, 0, 7) eq "package" $blk =~ /^package\s/
Truth table33%6/18
A or B or C or D and E or F and G or H and I
A= $is_zero_continuation_block_type{$blk}B= $is_sort_map_grep{$blk}C= $is_grep_alias{$blk}D= substr($blk, -1, 1) eq ":"E= $blk =~ /^\w+:$/F= substr($blk, 0, 3) eq "sub"G= $blk =~ /^sub\s/H= substr($blk, 0, 7) eq "package"I= $blk =~ /^package\s/
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
00011XXXX1
0000X11XX1
0001011XX1
0000X0X111
0000X10111
000100X111
0001010111
0000X0X0X0
0000X0X100
0000X100X0
0000X10100
000100X0X0
000100X100
00010100X0
0001010100
7203 || $is_sort_map_grep{$blk}
7204 || $is_grep_alias{$blk}
7205 || substr( $blk, -1, 1 ) eq ':' && $blk =~ /^\w+:$/
7206 || substr( $blk, 0, 3 ) eq 'sub' && $blk =~ /^sub\s/
7207 || substr( $blk, 0, 7 ) eq 'package' && $blk =~ /^package\s/ )
7208 {
7209 661 return TERM;
7210 }
7211  
7212 # Blocks followed by an OPERATOR
7213 # do eval sub
7214 349 ▶ if ( $is_block_operator{$blk}
Branch: 1 branch
BranchTrueFalseTotal
if ($is_block_operator{$blk} or $is_sub{$blk}) 279 70 349
Condition100%3/3
$is_block_operator{$blk} or $is_sub{$blk}
l!l&&r!l&&!r
8719270
MC/DC100%2/2
$is_block_operator{$blk} or $is_sub{$blk}
$is_block_operator{$blk} $is_sub{$blk}
Truth table100%3/3
A or B
A= $is_block_operator{$blk}B= $is_sub{$blk}
ABresult
1X1
011
000
7215 || $is_sub{$blk} )
7216 {
7217 279 return OPERATOR;
7218 }
7219  
7220 # Any other block type is marked UNKNOWN to be safe (c566).
7221 # For example, a block type marked ';' could be a hash ref:
7222 # { map { $_ => 'x' } keys %main:: } ~~ \%main::;
7223 # The tokenizer would have to analyze the contents to distinguish
7224 # between a block closure and a hash ref brace in this case. So mark
7225 # this as UNKNOWN and let the lower level routines figure it out.
7226 70 return UNKNOWN;
7227 }
7228  
7229 #-------------------------------
7230 # Section 2C: number or v-string
7231 #-------------------------------
7232 # An exception is for VERSION numbers a 'use' statement. It has the format
7233 # use Module VERSION LIST
7234 # We could avoid this exception by writing a special sub to parse 'use'
7235 # statements and perhaps mark these numbers with a new type V (for VERSION)
7236 4599 ▶ if ( $is_n_v{$last_nonblank_type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_n_v{$last_nonblank_type}) 2634 1965 4599
7237 2634 ▶ if ( $statement_type eq 'use' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($statement_type eq "use") 11 2623 2634
7238 11 return UNKNOWN;
7239 }
7240 2623 return OPERATOR;
7241 }
7242  
7243 #---------------------
7244 # Section 2D: qw quote
7245 #---------------------
7246 # TODO: labeled prototype words would better be given type 'A' or maybe
7247 # 'J'; not 'q'; or maybe mark as type 'Y'?
7248 1965 ▶ if ( $last_nonblank_type eq 'q' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq "q") 160 1805 1965
7249 160 ▶ if ( $last_nonblank_token eq 'prototype' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_token eq "prototype") 0 160 160
7250 0 return TERM;
7251 }
7252  
7253 # update for --use-feature=class (rt145706):
7254 # Look for class VERSION after possible attribute, as in
7255 # class Example::Subclass : isa(Example::Base) 1.345 { ... }
7256 160 ▶ if ( $statement_type =~ /^package\b/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($statement_type =~ /^package\b/) 3 157 160
7257 3 return TERM;
7258 }
7259  
7260 # everything else
7261 157 return OPERATOR;
7262 }
7263  
7264 #---------------------
7265 # Section 2E: bareword
7266 #---------------------
7267 1805 ▶ if ( $last_nonblank_type eq 'w' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq "w") 1754 51 1805
7268  
7269 # It is safest to return UNKNOWN if a possible ? pattern delimiter may
7270 # follow (git #32, c469) and let the guess algorithm handle it.
7271 1754 ▶ if ( $tok eq '?' ) { return UNKNOWN }
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "?") 7 1747 1754
7272  
7273 # see if this has been seen in the role of a function taking args
7274 1747 my $rinfo = $self->[_rbareword_info_]->{$current_package};
7275 1747 ▶ if ($rinfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rinfo) 1228 519 1747
7276 1228 $rinfo = $rinfo->{$last_nonblank_token};
7277 1228 ▶ if ($rinfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rinfo) 317 911 1228
7278 317 my $function_count = $rinfo->{function_count};
7279 317 ▶ if ( $function_count && $function_count > 0 ) { return TERM }
Branch: 1 branch
BranchTrueFalseTotal
if ($function_count and $function_count > 0) 135 182 317
Condition66%2/3
$function_count and $function_count > 0
!ll&&!rl&&r
1820135
MC/DC50%1/2
$function_count and $function_count > 0
$function_count $function_count > 0
Truth table66%2/3
A and B
A= $function_countB= $function_count > 0
ABresult
0X0
100
111
7280 }
7281 }
7282 1612 return UNKNOWN;
7283 }
7284  
7285 #-----------------------------------
7286 # Section 2F: file handle or similar
7287 #-----------------------------------
7288 51 ▶ if ( $last_nonblank_type eq 'Z' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq "Z") 47 4 51
7289  
7290 # angle.t
7291 47 ▶ if ( $last_nonblank_token =~ /^\w/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_token =~ /^\w/) 2 45 47
7292 2 return UNKNOWN;
7293 }
7294  
7295 # Exception to weird parsing rules for 'x(' ... see case b1205:
7296 # In something like 'print $vv x(...' the x is an operator;
7297 # Likewise in 'print $vv x$ww' the x is an operator (case b1207)
7298 # otherwise x follows the weird parsing rules.
7299 45 ▶ if ( $tok eq 'x' && $next_type =~ /^[\(\$\@\%]$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "x" and $next_type =~ /^[\(\$\@\%]$/) 0 45 45
Condition33%1/3
$tok eq "x" and $next_type =~ /^[\(\$\@\%]$/
!ll&&!rl&&r
4500
MC/DC0%0/2
$tok eq "x" and $next_type =~ /^[\(\$\@\%]$/
$tok eq "x" $next_type =~ /^[\(\$\@\%]$/
Truth table33%1/3
A and B
A= $tok eq "x"B= $next_type =~ /^[\(\$\@\%]$/
ABresult
0X0
100
111
7300 0 return OPERATOR;
7301 }
7302  
7303 # The 'weird parsing rules' of next section do not work for '<' and '?'
7304 # It is best to mark them as unknown. Test case:
7305 # print $fh <DATA>;
7306 45 ▶ if ( $is_weird_parsing_rule_exception{$tok} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_weird_parsing_rule_exception{$tok}) 4 41 45
7307 4 return UNKNOWN;
7308 }
7309  
7310 # For possible file handle like "$a", Perl uses weird parsing rules.
7311 # For example:
7312 # print $a/2,"/hi"; - division
7313 # print $a / 2,"/hi"; - division
7314 # print $a/ 2,"/hi"; - division
7315 # print $a /2,"/hi"; - pattern (and error)!
7316 # Some examples where this logic works okay, for '&','*','+':
7317 # print $fh &xsi_protos(@mods);
7318 # my $x = new $CompressClass *FH;
7319 # print $OUT +( $count % 15 ? ", " : "\n\t" );
7320 41 ▶ if ( $blank_after_Z
Branch: 1 branch
BranchTrueFalseTotal
if ($blank_after_Z and $next_type ne "b") 0 41 41
Condition66%2/3
$blank_after_Z and $next_type ne "b"
!ll&&!rl&&r
3380
MC/DC0%0/2
$blank_after_Z and $next_type ne "b"
$blank_after_Z $next_type ne "b"
Truth table66%2/3
A and B
A= $blank_after_ZB= $next_type ne "b"
ABresult
0X0
100
111
7321 && $next_type ne 'b' )
7322 {
7323 0 return TERM;
7324 }
7325  
7326 # Note that '?' and '<' have been moved above
7327 # ( $tok =~ /^([x\/\+\-\*\%\&\.\?\<]|\>\>)$/ ) {
7328 41 ▶ if ( $tok =~ /^([x\/\+\-\*\%\&\.]|\>\>)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok =~ m[^([x/\+\-\*\%\&\.]|\>\>)$]) 9 32 41
7329  
7330 # Do not complain in 'use' statements, which have special syntax.
7331 # For example, from RT#130344:
7332 # use lib $FindBin::Bin . '/lib';
7333 9 ▶ if ( $statement_type ne 'use' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($statement_type ne "use") 9 0 9
7334 9 $self->complain(
7335 "operator in possible indirect object location not recommended\n"
7336 );
7337 }
7338 9 return OPERATOR;
7339 }
7340  
7341 # all other cases
7342  
7343 32 return UNKNOWN;
7344 }
7345  
7346 #--------------------------
7347 # Section 2F: anything else
7348 #--------------------------
7349 4 return UNKNOWN;
7350  
7351 } ## end sub operator_expected
7352  
7353 sub new_statement_ok {
7354  
7355 # Returns:
7356 # true if a new statement can begin here
7357 # false otherwise
7358  
7359 # USES GLOBAL VARIABLES: $last_nonblank_token, $last_nonblank_type,
7360 # $brace_depth, $rbrace_type
7361  
7362 # Uses:
7363 # - See if a 'class' statement can occur here
7364 # - See if a keyword begins at a new statement; i.e. is an 'if' a
7365 # block if or a trailing if? Also see if 'format' starts a statement.
7366 # - Decide if a ':' is part of a statement label (not a ternary)
7367  
7368 # Curly braces are tricky because some small blocks do not get marked as
7369 # blocks..
7370  
7371 # if it follows an opening curly brace..
7372 551 ▶ if ( $last_nonblank_token eq '{' ) {
Subroutine new_statement_ok: called CC=6 SCAR=17.9
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
if ($last_nonblank_token eq '{') { } 70 481 551
elsif ($last_nonblank_token eq '}' and $last_nonblank_type eq $last_nonblank_token) { } 117 364 481
7373  
7374 # The safe thing is to return true in all cases because:
7375 # - a ternary ':' cannot occur here
7376 # - an 'if' here, for example, cannot be a trailing if
7377 # See test case c231 for an example.
7378 # This works but could be improved, if necessary, by returning
7379 # 'false' at obvious non-blocks.
7380 70 return 1;
7381 }
7382  
7383 # if it follows a closing code block curly brace..
7384 ▶ elsif ($last_nonblank_token eq '}'
Condition100%3/3
$last_nonblank_token eq "}" and $last_nonblank_type eq $last_nonblank_token
!ll&&!rl&&r
3622117
MC/DC100%2/2
$last_nonblank_token eq "}" and $last_nonblank_type eq $last_nonblank_token
$last_nonblank_token eq "}" $last_nonblank_type eq $last_nonblank_token
Truth table100%3/3
A and B
A= $last_nonblank_token eq "}"B= $last_nonblank_type eq $last_nonblank_token
ABresult
0X0
100
111
7385 && $last_nonblank_type eq $last_nonblank_token )
7386 {
7387  
7388 # A new statement can follow certain closing block braces ...
7389 # Previously, a true was always returned, and this worked ok.
7390 # Update c443: now we return false for certain blocks which must be
7391 # followed by a ';'. See comments elsewhere on
7392 # '%is_zero_continuation_block_type'. The value of $brace_depth has
7393 # also been corrected, it was off by 1.
7394 117 my $block_type = $rbrace_type->[ $brace_depth + 1 ];
7395 return $block_type
7396 117 ▶ && !$is_sort_map_grep_eval_do_sub{$block_type};
Condition66%2/3
$block_type && !$is_sort_map_grep_eval_do_sub{$block_type}
!ll&&!rl&&r
20115
MC/DC50%1/2
$block_type && !$is_sort_map_grep_eval_do_sub{$block_type}
$block_type !$is_sort_map_grep_eval_do_sub{$block_type}
Truth table66%2/3
A && not(B)
A= $block_typeB= !$is_sort_map_grep_eval_do_sub{$block_type}
ABresult
0X0
100
111
7397 }
7398  
7399 # otherwise, it is a label if and only if it follows a ';' (real or fake)
7400 # or another label
7401 else {
7402 364 ▶ return ( $last_nonblank_type eq ';' || $last_nonblank_type eq 'J' );
Condition100%3/3
$last_nonblank_type eq ';' || $last_nonblank_type eq 'J'
l!l&&r!l&&!r
18342139
MC/DC100%2/2
$last_nonblank_type eq ';' || $last_nonblank_type eq 'J'
$last_nonblank_type eq ';' $last_nonblank_type eq 'J'
Truth table100%3/3
A || B
A= $last_nonblank_type eq ';'B= $last_nonblank_type eq 'J'
ABresult
1X1
011
000
7403 }
7404 } ## end sub new_statement_ok
7405  
7406 sub code_block_type {
7407  
7408 1486 ▶ my ( $self, $i, $rtokens, $rtoken_type, $max_token_index ) = @_;
Subroutine code_block_type: called CC=26 SCAR=34.6
Pod undocumented
7409  
7410 # Decide if this is a block of code, and its type.
7411 # Must be called only when $type = $token = '{'
7412 # The problem is to distinguish between the start of a block of code
7413 # and the start of an anonymous hash reference
7414 # Returns "" if not code block, otherwise returns 'last_nonblank_token'
7415 # to indicate the type of code block. (For example, 'last_nonblank_token'
7416 # might be 'if' for an if block, 'else' for an else block, etc).
7417 # USES GLOBAL VARIABLES: $last_nonblank_token, $last_nonblank_type,
7418 # $last_nonblank_block_type, $brace_depth, $rbrace_type
7419  
7420 # handle case of multiple '{'s
7421  
7422 #print "BLOCK_TYPE EXAMINING: type=$last_nonblank_type tok=$last_nonblank_token\n";
7423  
7424 1486 ▶ if ( $last_nonblank_token eq '{'
Branch: 11 branches
BranchTrueFalseTotal
if ($last_nonblank_token eq '{' and $last_nonblank_type eq $last_nonblank_token) { } 98 1388 1486
elsif ($last_nonblank_token eq ';') { } 55 1333 1388
elsif ($last_nonblank_token eq '}' and $last_nonblank_type eq $last_nonblank_token) { } 10 1323 1333
elsif ($last_nonblank_type eq 'J') { } 34 1289 1323
elsif ($is_code_block_token{$last_nonblank_token} or $is_grep_alias{$last_nonblank_token}) { } 563 726 1289
elsif ($last_nonblank_type eq 'P' or $last_nonblank_type eq 'S' or $last_nonblank_type eq 't' and substr($last_nonblank_token, 0, 3) eq 'sub') { } 366 360 726
elsif ($statement_type =~ /^(sub|package)\b/) { } 0 360 360
elsif ($last_nonblank_type eq 'G') { } 0 360 360
elsif ($last_nonblank_type eq 'w') { } 24 336 360
elsif ($last_nonblank_token eq '(') { } 89 247 336
elsif ($last_nonblank_token =~ /\(\)$/) { } 16 231 247
Condition66%2/3
$last_nonblank_token eq "{" and $last_nonblank_type eq $last_nonblank_token
!ll&&!rl&&r
1388098
MC/DC50%1/2
$last_nonblank_token eq "{" and $last_nonblank_type eq $last_nonblank_token
$last_nonblank_token eq "{" $last_nonblank_type eq $last_nonblank_token
Truth table66%2/3
A and B
A= $last_nonblank_token eq "{"B= $last_nonblank_type eq $last_nonblank_token
ABresult
0X0
100
111
7425 && $last_nonblank_type eq $last_nonblank_token )
7426 {
7427  
7428 # opening brace where a statement may appear is probably
7429 # a code block but might be and anonymous hash reference
7430 98 ▶ if ( $rbrace_type->[$brace_depth] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rbrace_type->[$brace_depth]) { } 98 0 98
7431 98 return $self->decide_if_code_block( $i, $rtokens, $rtoken_type,
7432 $max_token_index );
7433 }
7434  
7435 # cannot start a code block within an anonymous hash
7436 else {
7437 0 return EMPTY_STRING;
7438 }
7439 }
7440  
7441 elsif ( $last_nonblank_token eq ';' ) {
7442  
7443 # an opening brace where a statement may appear is probably
7444 # a code block but might be and anonymous hash reference
7445 55 return $self->decide_if_code_block( $i, $rtokens, $rtoken_type,
7446 $max_token_index );
7447 }
7448  
7449 # handle case of '}{'
7450 ▶ elsif ($last_nonblank_token eq '}'
Condition66%2/3
$last_nonblank_token eq "}" and $last_nonblank_type eq $last_nonblank_token
!ll&&!rl&&r
1323010
MC/DC50%1/2
$last_nonblank_token eq "}" and $last_nonblank_type eq $last_nonblank_token
$last_nonblank_token eq "}" $last_nonblank_type eq $last_nonblank_token
Truth table66%2/3
A and B
A= $last_nonblank_token eq "}"B= $last_nonblank_type eq $last_nonblank_token
ABresult
0X0
100
111
7451 && $last_nonblank_type eq $last_nonblank_token )
7452 {
7453  
7454 # a } { situation ...
7455 # could be hash reference after code block..(blktype1.t)
7456 10 ▶ if ($last_nonblank_block_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_block_type) { } 10 0 10
7457 10 return $self->decide_if_code_block( $i, $rtokens, $rtoken_type,
7458 $max_token_index );
7459 }
7460  
7461 # must be a block if it follows a closing hash reference
7462 else {
7463 0 return $last_nonblank_token;
7464 }
7465 }
7466  
7467 #--------------------------------------------------------------
7468 # NOTE: braces after type characters start code blocks, but for
7469 # simplicity these are not identified as such. See also
7470 # sub is_non_structural_brace.
7471 #--------------------------------------------------------------
7472  
7473 ## elsif ( $last_nonblank_type eq 't' ) {
7474 ## return $last_nonblank_token;
7475 ## }
7476  
7477 # brace after label:
7478 elsif ( $last_nonblank_type eq 'J' ) {
7479 34 return $last_nonblank_token;
7480 }
7481  
7482 # otherwise, see if a block must follow the previous token (such as 'if'):
7483 ▶ elsif ($is_code_block_token{$last_nonblank_token}
Condition100%3/3
$is_code_block_token{$last_nonblank_token} or $is_grep_alias{$last_nonblank_token}
l!l&&r!l&&!r
5585726
MC/DC100%2/2
$is_code_block_token{$last_nonblank_token} or $is_grep_alias{$last_nonblank_token}
$is_code_block_token{$last_nonblank_token} $is_grep_alias{$last_nonblank_token}
Truth table100%3/3
A or B
A= $is_code_block_token{$last_nonblank_token}B= $is_grep_alias{$last_nonblank_token}
ABresult
1X1
011
000
7484 || $is_grep_alias{$last_nonblank_token} )
7485 {
7486  
7487 # Bug Patch: Note that the opening brace after the 'if' in the following
7488 # snippet is an anonymous hash ref and not a code block!
7489 # print 'hi' if { x => 1, }->{x};
7490 # We can identify this situation because the last nonblank type
7491 # will be a keyword (instead of a closing paren)
7492 563 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq 'k' and $last_nonblank_token eq 'if' || $last_nonblank_token eq 'unless') { } 0 563 563
Condition50%3/6
$last_nonblank_type eq "k" and $last_nonblank_token eq "if" || $last_nonblank_token eq "unless"
!ll&&!rl&&r
3012620
$last_nonblank_token eq "if" or $last_nonblank_token eq "unless"
l!l&&r!l&&!r
00262
MC/DC0%0/3
$last_nonblank_type eq "k" and $last_nonblank_token eq "if" || $last_nonblank_token eq "unless"
$last_nonblank_type eq "k" $last_nonblank_token eq "if" $last_nonblank_token eq "unless"
Truth table50%2/4
A and B or C
A= $last_nonblank_type eq "k"B= $last_nonblank_token eq "if"C= $last_nonblank_token eq "unless"
ABCresult
0XX0
1000
11X1
1011
7493 $last_nonblank_type eq 'k'
7494 && ( $last_nonblank_token eq 'if'
7495 || $last_nonblank_token eq 'unless' )
7496 )
7497 {
7498 0 return EMPTY_STRING;
7499 }
7500 else {
7501 563 return $last_nonblank_token;
7502 }
7503 }
7504  
7505 # or a sub or package BLOCK
7506 # Fixed for c250 to include new package type 'P', and change 'i' to 'S'
7507 ▶ elsif (
Condition88%8/9
$last_nonblank_type eq "P" or $last_nonblank_type eq "S" or $last_nonblank_type eq "t" and substr($last_nonblank_token, 0, 3) eq "sub"
l!l&&r!l&&!r
198168360
$last_nonblank_type eq "P" or $last_nonblank_type eq "S"
l!l&&r!l&&!r
10188528
$last_nonblank_type eq "t" and substr($last_nonblank_token, 0, 3) eq "sub"
!ll&&!rl&&r
3600168
MC/DC75%3/4
$last_nonblank_type eq "P" or $last_nonblank_type eq "S" or $last_nonblank_type eq "t" and substr($last_nonblank_token, 0, 3) eq "sub"
$last_nonblank_type eq "P" $last_nonblank_type eq "S" $last_nonblank_type eq "t" substr($last_nonblank_token, 0, 3) eq "sub"
Truth table80%4/5
A or B or C and D
A= $last_nonblank_type eq "P"B= $last_nonblank_type eq "S"C= $last_nonblank_type eq "t"D= substr($last_nonblank_token, 0, 3) eq "sub"
ABCDresult
1XXX1
01XX1
00111
000X0
00100
7508 $last_nonblank_type eq 'P'
7509 || $last_nonblank_type eq 'S'
7510 || ( $last_nonblank_type eq 't'
7511 && substr( $last_nonblank_token, 0, 3 ) eq 'sub' )
7512 )
7513 {
7514 366 return $last_nonblank_token;
7515 }
7516  
7517 elsif ( $statement_type =~ /^(sub|package)\b/ ) {
7518 0 return $statement_type;
7519 }
7520  
7521 # user-defined subs with block parameters (like grep/map/eval)
7522 elsif ( $last_nonblank_type eq 'G' ) {
7523 0 return $last_nonblank_token;
7524 }
7525  
7526 # check bareword
7527 elsif ( $last_nonblank_type eq 'w' ) {
7528  
7529 # check for syntax 'use MODULE LIST'
7530 # This fixes b1022 b1025 b1027 b1028 b1029 b1030 b1031
7531 24 ▶ return EMPTY_STRING if ( $statement_type eq 'use' );
Branch: 1 branch
BranchTrueFalseTotal
if $statement_type eq "use" 1 23 24
7532  
7533 23 return $self->decide_if_code_block( $i, $rtokens, $rtoken_type,
7534 $max_token_index );
7535 }
7536  
7537 # Patch for bug # RT #94338 reported by Daniel Trizen
7538 # for-loop in a parenthesized block-map triggering an error message:
7539 # map( { foreach my $item ( '0', '1' ) { print $item} } qw(a b c) );
7540 # Check for a code block within a parenthesized function call
7541 elsif ( $last_nonblank_token eq '(' ) {
7542 89 my $paren_type = $rparen_type->[$paren_depth];
7543  
7544 # /^(map|grep|sort)$/
7545 89 ▶ if ( $paren_type && $is_sort_map_grep{$paren_type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($paren_type and $is_sort_map_grep{$paren_type}) { } 3 86 89
Condition66%2/3
$paren_type and $is_sort_map_grep{$paren_type}
!ll&&!rl&&r
0863
MC/DC50%1/2
$paren_type and $is_sort_map_grep{$paren_type}
$paren_type $is_sort_map_grep{$paren_type}
Truth table66%2/3
A and B
A= $paren_typeB= $is_sort_map_grep{$paren_type}
ABresult
0X0
100
111
7546  
7547 # We will mark this as a code block but use type 't' instead
7548 # of the name of the containing function. This will allow for
7549 # correct parsing but will usually produce better formatting.
7550 # Braces with block type 't' are not broken open automatically
7551 # in the formatter as are other code block types, and this usually
7552 # works best.
7553 3 return 't'; # (Not $paren_type)
7554 }
7555 else {
7556 86 return EMPTY_STRING;
7557 }
7558 }
7559  
7560 # handle unknown syntax ') {'
7561 # we previously appended a '()' to mark this case
7562 elsif ( $last_nonblank_token =~ /\(\)$/ ) {
7563 16 return $last_nonblank_token;
7564 }
7565  
7566 # anything else must be anonymous hash reference
7567 else {
7568 231 return EMPTY_STRING;
7569 }
7570 } ## end sub code_block_type
7571  
7572 sub decide_if_code_block {
7573  
7574 # USES GLOBAL VARIABLES: $last_nonblank_token
7575 186 ▶ my ( $self, $i, $rtokens, $rtoken_type, $max_token_index ) = @_;
Subroutine decide_if_code_block: called CC=22 SCAR=31.4
Pod undocumented
7576  
7577 186 my ( $next_nonblank_token, $i_next_uu ) =
7578 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
7579  
7580 # we are at a '{' where a statement may appear.
7581 # We must decide if this brace starts an anonymous hash or a code
7582 # block.
7583 # return "" if anonymous hash, and $last_nonblank_token otherwise
7584  
7585 # initialize to be code BLOCK
7586 186 my $code_block_type = $last_nonblank_token;
7587  
7588 # Check for the common case of an empty anonymous hash reference:
7589 # Maybe something like sub { { } }
7590 186 ▶ if ( $next_nonblank_token eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq '}') { } 5 181 186
7591 5 $code_block_type = EMPTY_STRING;
7592 }
7593  
7594 else {
7595  
7596 # To guess if this '{' is an anonymous hash reference, look ahead
7597 # and test as follows:
7598 #
7599 # it is a hash reference if next come:
7600 # - a string or digit followed by a comma or =>
7601 # - bareword followed by =>
7602 # otherwise it is a code block
7603 #
7604 # Examples of anonymous hash ref:
7605 # {'aa',};
7606 # {1,2}
7607 #
7608 # Examples of code blocks:
7609 # {1; print "hello\n", 1;}
7610 # {$a,1};
7611  
7612 # We are only going to look ahead one more (nonblank/comment) line.
7613 # Strange formatting could cause a bad guess, but that's unlikely.
7614 181 my @pre_types;
7615 my @pre_tokens;
7616  
7617 # Ignore the rest of this line if it is a side comment
7618 181 ▶ if ( $next_nonblank_token ne '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token ne "#") 156 25 181
7619 156 @pre_types = @{$rtoken_type}[ $i + 1 .. $max_token_index ];
7620 156 @pre_tokens = @{$rtokens}[ $i + 1 .. $max_token_index ];
7621 }
7622  
7623 # Here 20 is arbitrary but generous, and prevents wasting lots of time
7624 # in mangled files
7625 181 my ( $rpre_tokens, $rpre_types ) =
7626 $self->peek_ahead_for_n_nonblank_pre_tokens(20);
7627 181 ▶ if ( defined($rpre_types) && @{$rpre_types} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rpre_types and @{$rpre_types;}) 173 8 181
Condition66%2/3
defined $rpre_types and @{$rpre_types;}
!ll&&!rl&&r
80173
MC/DC50%1/2
defined $rpre_types and @{$rpre_types;}
defined $rpre_types @{$rpre_types;}
Truth table66%2/3
A and B
A= defined $rpre_typesB= @{$rpre_types;}
ABresult
0X0
100
111
7628 173 push @pre_types, @{$rpre_types};
7629 173 push @pre_tokens, @{$rpre_tokens};
7630 }
7631  
7632 # put a sentinel token to simplify stopping the search
7633 181 push @pre_types, '}';
7634 181 push @pre_types, '}';
7635  
7636 181 my $jbeg = 0;
7637 181 ▶ $jbeg = 1 if ( $pre_types[0] eq 'b' );
Branch: 1 branch
BranchTrueFalseTotal
if $pre_types[0] eq "b" 64 117 181
7638  
7639 # first look for one of these
7640 # - bareword
7641 # - bareword with leading -
7642 # - digit
7643 # - quoted string
7644 181 my $j = $jbeg;
7645 181 ▶ if ( $pre_types[$j] =~ /^[\'\"]/ ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($pre_types[$j] =~ /^[\'\"]/) { } 1 180 181
elsif ($pre_types[$j] eq 'd') { } 8 172 180
elsif ($pre_types[$j] eq 'w') { } 78 94 172
elsif ($pre_types[$j] eq '-' and $pre_types[++$j] eq 'w') { } 0 94 94
7646  
7647 # find the closing quote; don't worry about escapes
7648 1 my $quote_mark = $pre_types[$j];
7649 1 foreach my $k ( $j + 1 .. @pre_types - 2 ) {
7650 1 ▶ if ( $pre_types[$k] eq $quote_mark ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre_types[$k] eq $quote_mark) 1 0 1
7651 1 $j = $k + 1;
7652 1 last;
7653 }
7654 }
7655 }
7656 elsif ( $pre_types[$j] eq 'd' ) {
7657 8 $j++;
7658 }
7659 elsif ( $pre_types[$j] eq 'w' ) {
7660 78 $j++;
7661 }
7662 ▶ elsif ( $pre_types[$j] eq '-' && $pre_types[ ++$j ] eq 'w' ) {
Condition33%1/3
$pre_types[$j] eq "-" and $pre_types[++$j] eq "w"
!ll&&!rl&&r
9400
MC/DC0%0/2
$pre_types[$j] eq "-" and $pre_types[++$j] eq "w"
$pre_types[$j] eq "-" $pre_types[++$j] eq "w"
Truth table33%1/3
A and B
A= $pre_types[$j] eq "-"B= $pre_types[++$j] eq "w"
ABresult
0X0
100
111
7663 0 $j++;
7664 }
7665 else {
7666 ## none of the above
7667 }
7668 181 ▶ if ( $j > $jbeg ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j > $jbeg) 87 94 181
7669  
7670 87 ▶ $j++ if ( $pre_types[$j] eq 'b' );
Branch: 1 branch
BranchTrueFalseTotal
if $pre_types[$j] eq "b" 80 7 87
7671  
7672 # Patched for RT #95708
7673 87 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($pre_types[$j] eq "," and not $is_q_qq_qx_qr_s_y_tr_m{$pre_tokens[$jbeg]} or $pre_types[$j] eq "=" and $pre_types[++$j] eq ">") 18 69 87
Condition55%5/9
$pre_types[$j] eq "," and not $is_q_qq_qx_qr_s_y_tr_m{$pre_tokens[$jbeg]} or $pre_types[$j] eq "=" and $pre_types[++$j] eq ">"
l!l&&r!l&&!r
02364
$pre_types[$j] eq "," and not $is_q_qq_qx_qr_s_y_tr_m{$pre_tokens[$jbeg]}
!ll&&!rl&&r
8700
$pre_types[$j] eq "=" and $pre_types[++$j] eq ">"
!ll&&!rl&&r
69018
MC/DC0%0/4
$pre_types[$j] eq "," and not $is_q_qq_qx_qr_s_y_tr_m{$pre_tokens[$jbeg]} or $pre_types[$j] eq "=" and $pre_types[++$j] eq ">"
$pre_types[$j] eq "," not $is_q_qq_qx_qr_s_y_tr_m{$pre_tokens[$jbeg]} $pre_types[$j] eq "=" $pre_types[++$j] eq ">"
Truth table14%1/7
A and not(B) or C and D
A= $pre_types[$j] eq ","B= not $is_q_qq_qx_qr_s_y_tr_m{$pre_tokens[$jbeg]}C= $pre_types[$j] eq "="D= $pre_types[++$j] eq ">"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
7674  
7675 # it is a comma which is not a pattern delimiter except for qw
7676 (
7677 $pre_types[$j] eq COMMA
7678 && !$is_q_qq_qx_qr_s_y_tr_m{ $pre_tokens[$jbeg] }
7679 )
7680  
7681 # or a =>
7682 || ( $pre_types[$j] eq '=' && $pre_types[ ++$j ] eq '>' )
7683 )
7684 {
7685 18 $code_block_type = EMPTY_STRING;
7686 }
7687 }
7688  
7689 181 ▶ if ($code_block_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code_block_type) 163 18 181
7690  
7691 # Patch for cases b1085 b1128: It is uncertain if this is a block.
7692 # If this brace follows a bareword, then append a space as a signal
7693 # to the formatter that this may not be a block brace. To find the
7694 # corresponding code in Formatter.pm search for 'b1085'.
7695 # But not for the word 'method': fixes c534; this will cause the
7696 # formatter to mark an asub block instead of a sub block.
7697 163 ▶ if ( $code_block_type =~ /^\w/ && $code_block_type ne 'method' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code_block_type =~ /^\w/ and $code_block_type ne "method") 20 143 163
Condition66%2/3
$code_block_type =~ /^\w/ and $code_block_type ne "method"
!ll&&!rl&&r
143020
MC/DC50%1/2
$code_block_type =~ /^\w/ and $code_block_type ne "method"
$code_block_type =~ /^\w/ $code_block_type ne "method"
Truth table66%2/3
A and B
A= $code_block_type =~ /^\w/B= $code_block_type ne "method"
ABresult
0X0
100
111
7698 20 $code_block_type .= SPACE;
7699 }
7700 }
7701 }
7702  
7703 186 return $code_block_type;
7704 } ## end sub decide_if_code_block
7705  
7706 sub report_unexpected {
7707  
7708 # report unexpected token type and show where it is
7709 # USES GLOBAL VARIABLES: (none)
7710 0 ▶ my ( $self, $rcall_hash ) = @_;
Subroutine report_unexpected: not called CC=6 SCAR=37.4
Pod undocumented
7711  
7712 0 my $found = $rcall_hash->{found};
7713 0 my $expecting = $rcall_hash->{expecting};
7714 0 my $i_tok = $rcall_hash->{i_tok};
7715 0 my $last_nonblank_i = $rcall_hash->{last_nonblank_i};
7716 0 my $rpretoken_map = $rcall_hash->{rpretoken_map};
7717 0 my $rpretoken_type = $rcall_hash->{rpretoken_type};
7718 0 my $input_line = $rcall_hash->{input_line};
7719  
7720 0 ▶ if ( ++$self->[_unexpected_error_count_] <= MAX_NAG_MESSAGES ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$self->[40] <= 6) 0 0 0
7721 0 my $msg = "found $found where $expecting expected";
7722 0 my $pos = $rpretoken_map->[$i_tok];
7723 0 $self->interrupt_logfile();
7724 0 my $input_line_number = $self->[_last_line_number_];
7725 0 my ( $offset, $numbered_line, $underline ) =
7726 make_numbered_line( $input_line_number, $input_line, $pos );
7727 0 $underline = write_on_underline( $underline, $pos - $offset, '^' );
7728  
7729 0 my $trailer = EMPTY_STRING;
7730 0 ▶ if ( ( $i_tok > 0 ) && ( $last_nonblank_i >= 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_tok > 0 and $last_nonblank_i >= 0) 0 0 0
Condition0%0/3
$i_tok > 0 and $last_nonblank_i >= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$i_tok > 0 and $last_nonblank_i >= 0
$i_tok > 0 $last_nonblank_i >= 0
Truth table0%0/3
A and B
A= $i_tok > 0B= $last_nonblank_i >= 0
ABresult
0X0
100
111
7731 0 my $pos_prev = $rpretoken_map->[$last_nonblank_i];
7732 0 my $num;
7733 0 ▶ if ( $rpretoken_type->[ $i_tok - 1 ] eq 'b' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$rpretoken_type[$i_tok - 1] eq 'b') { } 0 0 0
7734 0 $num = $rpretoken_map->[ $i_tok - 1 ] - $pos_prev;
7735 }
7736 else {
7737 0 $num = $pos - $pos_prev;
7738 }
7739 0 ▶ if ( $num > 40 ) { $num = 40; $pos_prev = $pos - 40; }
Branch: 1 branch
BranchTrueFalseTotal
if ($num > 40) 0 0 0
7740  
7741 $underline =
7742 0 write_on_underline( $underline, $pos_prev - $offset, '-' x $num );
7743 0 $trailer = " (previous token underlined)";
7744 }
7745 0 $underline =~ s/\s+$//;
7746 0 $self->warning( $numbered_line . "\n" );
7747 0 $self->warning( $underline . "\n" );
7748 0 $self->warning( $msg . $trailer . "\n" );
7749 0 $self->resume_logfile();
7750 }
7751 0 return;
7752 } ## end sub report_unexpected
7753  
7754 45 my %is_sigil_or_paren;
7755 45 my %is_R_closing_sb;
7756  
7757 BEGIN {
7758  
7759 45 ▶ my @q = qw< $ & % * @ ) >;
Subroutine BEGIN: called CC=3 SCAR=11.0
7760 45 $is_sigil_or_paren{$_} = 1 for @q;
7761  
7762 45 @q = qw( R ] );
7763 45 $is_R_closing_sb{$_} = 1 for @q;
7764 } ## end BEGIN
7765  
7766 sub is_non_structural_brace {
7767  
7768 # Decide if a brace or bracket is structural or non-structural
7769 # by looking at the previous token and type
7770 # USES GLOBAL VARIABLES: $last_nonblank_type, $last_nonblank_token
7771  
7772 # EXPERIMENTAL: Mark slices as structural; idea was to improve formatting.
7773 # Tentatively deactivated because it caused the wrong operator expectation
7774 # for this code:
7775 # $user = @vars[1] / 100;
7776 # Must update sub operator_expected before re-implementing.
7777 # if ( $last_nonblank_type eq 'i' && $last_nonblank_token =~ /^@/ ) {
7778 # return 0;
7779 # }
7780  
7781 #--------------------------------------------------------------
7782 # NOTE: braces after type characters start code blocks, but for
7783 # simplicity these are not identified as such. See also
7784 # sub code_block_type
7785 #--------------------------------------------------------------
7786  
7787 ##if ($last_nonblank_type eq 't') {return 0}
7788  
7789 # otherwise, it is non-structural if it is decorated
7790 # by type information.
7791 # For example, the '{' here is non-structural: ${xxx}
7792 # Removed '::' to fix c074
7793 ## $last_nonblank_token =~ /^([\$\@\*\&\%\)]|->|::)/
7794 return (
7795 ## $last_nonblank_token =~ /^([\$\@\*\&\%\)]|->)/
7796 $is_sigil_or_paren{ substr( $last_nonblank_token, 0, 1 ) }
7797 || substr( $last_nonblank_token, 0, 2 ) eq '->'
7798  
7799 # or if we follow a hash or array closing curly brace or bracket
7800 # For example, the second '{' in this is non-structural: $a{'x'}{'y'}
7801 # because the first '}' would have been given type 'R'
7802 ##|| $last_nonblank_type =~ /^([R\]])$/
7803 2891 ▶ || $is_R_closing_sb{$last_nonblank_type}
Subroutine is_non_structural_brace: called CC=3 SCAR=11.0
Pod undocumented
Condition100%6/6
$is_sigil_or_paren{substr($last_nonblank_token, 0, 1)} || substr($last_nonblank_token, 0, 2) eq '->' || $is_R_closing_sb{$last_nonblank_type}
l!l&&r!l&&!r
9091191863
$is_sigil_or_paren{substr($last_nonblank_token, 0, 1)} or substr($last_nonblank_token, 0, 2) eq "->"
l!l&&r!l&&!r
5153941982
MC/DC100%3/3
$is_sigil_or_paren{substr($last_nonblank_token, 0, 1)} || substr($last_nonblank_token, 0, 2) eq '->' || $is_R_closing_sb{$last_nonblank_type}
$is_sigil_or_paren{substr($last_nonblank_token, 0, 1)} substr($last_nonblank_token, 0, 2) eq "->" $is_R_closing_sb{$last_nonblank_type}
Truth table100%4/4
A or B || C
A= $is_sigil_or_paren{substr($last_nonblank_token, 0, 1)}B= substr($last_nonblank_token, 0, 2) eq "->"C= $is_R_closing_sb{$last_nonblank_type}
ABCresult
1XX1
01X1
0011
0000
7804 );
7805 } ## end sub is_non_structural_brace
7806  
7807 #######################################################################
7808 # Tokenizer routines for tracking container nesting depths
7809 #######################################################################
7810  
7811 # The following routines keep track of nesting depths of the nesting
7812 # types, ( [ { and ?. This is necessary for determining the indentation
7813 # level, and also for debugging programs. Not only do they keep track of
7814 # nesting depths of the individual brace types, but they check that each
7815 # of the other brace types is balanced within matching pairs. For
7816 # example, if the program sees this sequence:
7817 #
7818 # { ( ( ) }
7819 #
7820 # then it can determine that there is an extra left paren somewhere
7821 # between the { and the }. And so on with every other possible
7822 # combination of outer and inner brace types. For another
7823 # example:
7824 #
7825 # ( [ ..... ] ] )
7826 #
7827 # which has an extra ] within the parens.
7828 #
7829 # The brace types have indexes 0 .. 3 which are indexes into
7830 # the matrices.
7831 #
7832 # The pair ? : are treated as just another nesting type, with ? acting
7833 # as the opening brace and : acting as the closing brace.
7834 #
7835 # The matrix
7836 #
7837 # $rdepth_array->[$a][$b][ $rcurrent_depth->[$a] ] = $rcurrent_depth->[$b];
7838 #
7839 # saves the nesting depth of brace type $b (where $b is either of the other
7840 # nesting types) when brace type $a enters a new depth. When this depth
7841 # decreases, a check is made that the current depth of brace types $b is
7842 # unchanged, or otherwise there must have been an error. This can
7843 # be very useful for localizing errors, particularly when perl runs to
7844 # the end of a large file (such as this one) and announces that there
7845 # is a problem somewhere.
7846 #
7847 # A numerical sequence number is maintained for every nesting type,
7848 # so that each matching pair can be uniquely identified in a simple
7849 # way.
7850  
7851 sub increase_nesting_depth {
7852 5537 ▶ my ( $self, $aa, $pos ) = @_;
Subroutine increase_nesting_depth: called CC=8 SCAR=20.8
Pod undocumented
7853  
7854 # Given:
7855 # $aa = integer code of container type, 0-3
7856 # $pos = position of character, for error message
7857  
7858 # USES GLOBAL VARIABLES: $rcurrent_depth,
7859 # $rcurrent_sequence_number, $rdepth_array,
7860 # $rstarting_line_of_current_depth, $statement_type
7861 5537 my $cd_aa = ++$rcurrent_depth->[$aa];
7862 5537 $total_depth++;
7863 5537 $rtotal_depth->[$aa]->[$cd_aa] = $total_depth;
7864 5537 my $input_line_number = $self->[_last_line_number_];
7865 5537 my $input_line = $self->[_line_of_text_];
7866  
7867 # Sequence numbers increment by number of items. This keeps
7868 # a unique set of numbers but still allows the relative location
7869 # of any type to be determined.
7870  
7871 # make a new unique sequence number
7872 5537 my $seqno = $next_sequence_number++;
7873  
7874 # Remember the type sequence number at the current depth,
7875 # but do not overwrite the root sequence number.
7876 5537 ▶ if ( $total_depth > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($total_depth > 0) 5537 0 5537
7877 5537 $self->[_rseqno_at_depth_]->[$total_depth] = $seqno;
7878 }
7879  
7880 5537 $rcurrent_sequence_number->[$aa]->[$cd_aa] = $seqno;
7881  
7882 5537 $rstarting_line_of_current_depth->[$aa]->[$cd_aa] =
7883 [ $input_line_number, $input_line, $pos ];
7884  
7885 5537 for my $bb ( 0 .. @closing_brace_names - 1 ) {
7886 22148 ▶ next if ( $bb == $aa );
Branch: 1 branch
BranchTrueFalseTotal
if $bb == $aa 5537 16611 22148
7887 16611 $rdepth_array->[$aa]->[$bb]->[$cd_aa] = $rcurrent_depth->[$bb];
7888 }
7889  
7890 # set a flag for indenting a nested ternary statement
7891 5537 my $indent = 0;
7892 5537 ▶ if ( $aa == QUESTION_COLON ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aa == 3) 193 5344 5537
7893 193 $rnested_ternary_flag->[$cd_aa] = 0;
7894 193 ▶ if ( $cd_aa > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cd_aa > 1) 17 176 193
7895 17 ▶ if ( $rnested_ternary_flag->[ $cd_aa - 1 ] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$rnested_ternary_flag[$cd_aa - 1] == 0) 16 1 17
7896 16 my $pdepth = $rtotal_depth->[$aa]->[ $cd_aa - 1 ];
7897 16 ▶ if ( $pdepth == $total_depth - 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pdepth == $total_depth - 1) 8 8 16
7898 8 $indent = 1;
7899 8 $rnested_ternary_flag->[ $cd_aa - 1 ] = -1;
7900 }
7901 }
7902 }
7903 }
7904  
7905 # Fix part #1 for git82: save last token type for propagation of type 'Z'
7906 5537 $rnested_statement_type->[$aa]->[$cd_aa] =
7907 [ $statement_type, $last_nonblank_type, $last_nonblank_token ];
7908 5537 $statement_type = EMPTY_STRING;
7909 5537 return ( $seqno, $indent );
7910 } ## end sub increase_nesting_depth
7911  
7912 sub is_balanced_closing_container {
7913  
7914 47 ▶ my ($aa) = @_;
Subroutine is_balanced_closing_container: called CC=5 SCAR=16.7
Pod undocumented
7915  
7916 # Return true if a closing container can go here without error
7917 # Return false if not
7918 # Given:
7919 # $aa = integer code of container type, 0-3
7920  
7921 # cannot close if there was no opening
7922 47 my $cd_aa = $rcurrent_depth->[$aa];
7923 47 ▶ return if ( $cd_aa <= 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $cd_aa <= 0 39 8 47
7924  
7925 # check that any other brace types $bb contained within would be balanced
7926 8 for my $bb ( 0 .. @closing_brace_names - 1 ) {
7927 8 ▶ next if ( $bb == $aa );
Branch: 1 branch
BranchTrueFalseTotal
if $bb == $aa 0 8 8
7928 return
7929 if (
7930 8 ▶ $rdepth_array->[$aa]->[$bb]->[$cd_aa] != $rcurrent_depth->[$bb] );
Branch: 1 branch
BranchTrueFalseTotal
if $rdepth_array->[$aa][$bb][$cd_aa] != $rcurrent_depth->[$bb] 8 0 8
7931 }
7932  
7933 # OK, everything will be balanced
7934 0 return 1;
7935 } ## end sub is_balanced_closing_container
7936  
7937 sub decrease_nesting_depth {
7938  
7939 5537 ▶ my ( $self, $aa, $pos ) = @_;
Subroutine decrease_nesting_depth: called CC=21 SCAR=49.7
Pod undocumented
7940  
7941 # Given:
7942 # $aa = integer code of container type, 0-3
7943 # $pos = position of character, for error message
7944  
7945 # USES GLOBAL VARIABLES: $rcurrent_depth,
7946 # $rcurrent_sequence_number, $rdepth_array, $rstarting_line_of_current_depth
7947 # $statement_type
7948 5537 my $seqno = 0;
7949 5537 my $input_line_number = $self->[_last_line_number_];
7950 5537 my $input_line = $self->[_line_of_text_];
7951  
7952 5537 my $outdent = 0;
7953 5537 $total_depth--;
7954 5537 my $cd_aa = $rcurrent_depth->[$aa];
7955 5537 ▶ if ( $cd_aa > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cd_aa > 0) { } 5537 0 5537
7956  
7957 # set a flag for un-indenting after seeing a nested ternary statement
7958 5537 $seqno = $rcurrent_sequence_number->[$aa]->[$cd_aa];
7959 5537 ▶ if ( $aa == QUESTION_COLON ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aa == 3) 193 5344 5537
7960 193 $outdent = $rnested_ternary_flag->[$cd_aa];
7961 }
7962  
7963 # Fix part #2 for git82: use saved type for propagation of type 'Z'
7964 # through type L-R braces. Perl seems to allow ${bareword}
7965 # as an indirect object, but nothing much more complex than that.
7966 ( $statement_type, my $saved_type, my $saved_token_uu ) =
7967 5537 @{ $rnested_statement_type->[$aa]->[ $rcurrent_depth->[$aa] ] };
7968 5537 ▶ if ( $aa == BRACE
Branch: 1 branch
BranchTrueFalseTotal
if ($aa == 0 and $saved_type eq "Z" and $last_nonblank_type eq "w" and $rbrace_structural_type->[$brace_depth] eq "L") 1 5536 5537
Condition77%7/9
$aa == 0 and $saved_type eq "Z" and $last_nonblank_type eq "w" and $rbrace_structural_type->[$brace_depth] eq "L"
!ll&&!rl&&r
553601
$aa == 0 and $saved_type eq "Z" and $last_nonblank_type eq "w"
!ll&&!rl&&r
553601
$aa == 0 and $saved_type eq "Z"
!ll&&!rl&&r
345520811
MC/DC50%2/4
$aa == 0 and $saved_type eq "Z" and $last_nonblank_type eq "w" and $rbrace_structural_type->[$brace_depth] eq "L"
$aa == 0 $saved_type eq "Z" $last_nonblank_type eq "w" $rbrace_structural_type->[$brace_depth] eq "L"
Truth table60%3/5
A and B and C and D
A= $aa == 0B= $saved_type eq "Z"C= $last_nonblank_type eq "w"D= $rbrace_structural_type->[$brace_depth] eq "L"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
7969 && $saved_type eq 'Z'
7970 && $last_nonblank_type eq 'w'
7971 && $rbrace_structural_type->[$brace_depth] eq 'L' )
7972 {
7973 1 $last_nonblank_type = $saved_type;
7974 }
7975  
7976 # check that any brace types $bb contained within are balanced
7977 5537 for my $bb ( 0 .. @closing_brace_names - 1 ) {
7978 22148 ▶ next if ( $bb == $aa );
Branch: 1 branch
BranchTrueFalseTotal
if $bb == $aa 5537 16611 22148
7979  
7980 16611 ▶ if ( $rdepth_array->[$aa]->[$bb]->[$cd_aa] !=
Branch: 1 branch
BranchTrueFalseTotal
if ($rdepth_array->[$aa][$bb][$cd_aa] != $rcurrent_depth->[$bb]) 0 16611 16611
7981 $rcurrent_depth->[$bb] )
7982 {
7983 0 my $diff =
7984 $rcurrent_depth->[$bb] -
7985 $rdepth_array->[$aa]->[$bb]->[$cd_aa];
7986  
7987 # don't whine too many times
7988 0 my $saw_brace_error = $self->get_saw_brace_error();
7989 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($saw_brace_error <= 6 and $diff > 0 || $saw_brace_error <= 0) 0 0 0
Condition0%0/6
$saw_brace_error <= 6 and $diff > 0 || $saw_brace_error <= 0
!ll&&!rl&&r
000
$diff > 0 or $saw_brace_error <= 0
l!l&&r!l&&!r
000
MC/DC0%0/3
$saw_brace_error <= 6 and $diff > 0 || $saw_brace_error <= 0
$saw_brace_error <= 6 $diff > 0 $saw_brace_error <= 0
Truth table0%0/4
A and B or C
A= $saw_brace_error <= 6B= $diff > 0C= $saw_brace_error <= 0
ABCresult
0XX0
1000
11X1
1011
7990 $saw_brace_error <= MAX_NAG_MESSAGES
7991  
7992 # if too many closing types have occurred, we probably
7993 # already caught this error
7994 && ( ( $diff > 0 ) || ( $saw_brace_error <= 0 ) )
7995 )
7996 {
7997 0 $self->interrupt_logfile();
7998 0 my $rsl = $rstarting_line_of_current_depth->[$aa]->[$cd_aa];
7999 0 my $sl = $rsl->[0];
8000 0 my $rel = [ $input_line_number, $input_line, $pos ];
8001 0 my $el = $rel->[0];
8002 0 my ($ess);
8003  
8004 0 ▶ if ( $diff == 1 || $diff == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diff == 1 or $diff == -1) { } 0 0 0
Condition0%0/3
$diff == 1 or $diff == -1
l!l&&r!l&&!r
000
MC/DC0%0/2
$diff == 1 or $diff == -1
$diff == 1 $diff == -1
Truth table0%0/3
A or B
A= $diff == 1B= $diff == -1
ABresult
1X1
011
000
8005 0 $ess = EMPTY_STRING;
8006 }
8007 else {
8008 0 $ess = 's';
8009 }
8010 0 ▶ my $bname =
Branch: 1 branch
BranchTrueFalseTotal
$diff > 0 ? : 0 0 0
8011 ( $diff > 0 )
8012 ? $opening_brace_names[$bb]
8013 : $closing_brace_names[$bb];
8014 0 $self->write_error_indicator_pair( @{$rsl}, '^' );
8015 0 my $msg = <<"EOM";
8016 Found $diff extra $bname$ess between $opening_brace_names[$aa] on line $sl and $closing_brace_names[$aa] on line $el
8017 EOM
8018  
8019 0 ▶ if ( $diff > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diff > 0) 0 0 0
8020 0 my $rml =
8021 $rstarting_line_of_current_depth->[$bb]
8022 ->[ $rcurrent_depth->[$bb] ];
8023 0 my $ml = $rml->[0];
8024 0 $msg .=
8025 " The most recent un-matched $bname is on line $ml\n";
8026 0 $self->write_error_indicator_pair( @{$rml}, '^' );
8027 }
8028 0 $self->write_error_indicator_pair( @{$rel}, '^' );
8029 0 $self->warning($msg);
8030 0 $self->resume_logfile();
8031 }
8032 0 $self->increment_brace_error();
8033 0 ▶ if ( $bb eq BRACE ) { $self->[_show_indentation_table_] = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($bb eq 0) 0 0 0
8034 }
8035 }
8036 5537 $rcurrent_depth->[$aa]--;
8037 }
8038 else {
8039  
8040 0 my $saw_brace_error = $self->get_saw_brace_error();
8041 0 ▶ if ( $saw_brace_error <= MAX_NAG_MESSAGES ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($saw_brace_error <= 6) 0 0 0
8042 0 my $msg = <<"EOM";
8043 There is no previous $opening_brace_names[$aa] to match a $closing_brace_names[$aa] on line $input_line_number
8044 EOM
8045 0 $self->indicate_error( $msg, $input_line_number, $input_line, $pos,
8046 '^' );
8047 }
8048 0 $self->increment_brace_error();
8049 0 ▶ if ( $aa eq BRACE ) { $self->[_show_indentation_table_] = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($aa eq 0) 0 0 0
8050  
8051 # keep track of errors in braces alone (ignoring ternary nesting errors)
8052 0 ▶ $self->[_true_brace_error_count_]++
Branch: 1 branch
BranchTrueFalseTotal
if $closing_brace_names[$aa] ne "':'" 0 0 0
8053 if ( $closing_brace_names[$aa] ne "':'" );
8054 }
8055 5537 return ( $seqno, $outdent );
8056 } ## end sub decrease_nesting_depth
8057  
8058 sub check_final_nesting_depths {
8059  
8060 # USES GLOBAL VARIABLES: $rcurrent_depth, $rstarting_line_of_current_depth
8061 662 ▶ my $self = shift;
Subroutine check_final_nesting_depths: called CC=5 SCAR=26.8
Pod undocumented
8062  
8063 662 for my $aa ( 0 .. @closing_brace_names - 1 ) {
8064  
8065 2648 my $cd_aa = $rcurrent_depth->[$aa];
8066 2648 ▶ if ($cd_aa) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cd_aa) 0 2648 2648
8067 0 my $rsl = $rstarting_line_of_current_depth->[$aa]->[$cd_aa];
8068 0 my $sl = $rsl->[0];
8069  
8070 # Add hint for something like a missing terminal ':' of a ternary
8071 0 my $hint = EMPTY_STRING;
8072 0 ▶ if ( $cd_aa == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cd_aa == 1) 0 0 0
8073 0 $hint =
8074 " .. did not find its closing $closing_brace_names[$aa]";
8075 }
8076 0 my $msg = <<"EOM";
8077 Final nesting depth of $opening_brace_names[$aa]s is $cd_aa
8078 The most recent un-matched $opening_brace_names[$aa] is on line $sl$hint
8079 EOM
8080 0 $self->indicate_error( $msg, @{$rsl}, '^' );
8081 0 $self->increment_brace_error();
8082 0 ▶ if ( $aa eq BRACE ) { $self->[_show_indentation_table_] = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($aa eq 0) 0 0 0
8083 }
8084 }
8085 662 return;
8086 } ## end sub check_final_nesting_depths
8087  
8088 #######################################################################
8089 # Tokenizer routines for looking ahead in input stream
8090 #######################################################################
8091  
8092 sub peek_ahead_for_n_nonblank_pre_tokens {
8093  
8094 188 ▶ my ( $self, $max_pretokens ) = @_;
Subroutine peek_ahead_for_n_nonblank_pre_tokens: called CC=4 SCAR=13.9
Pod undocumented
8095  
8096 # Given:
8097 # $max_pretokens = number of pretokens wanted
8098 # Return:
8099 # next $max_pretokens pretokens if they exist
8100 # undef's if hits eof without seeing any pretokens
8101  
8102 # USES GLOBAL VARIABLES: (none)
8103 188 my $line;
8104 188 my $i = 0;
8105 188 my ( $rpre_tokens, $rmap, $rpre_types );
8106  
8107 188 ▶ while ( defined( $line = $self->peek_ahead( $i++ ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->peek_ahead($i++))) 206 8 214
8108 206 $line =~ s/^\s+//; # trim leading blanks
8109 206 ▶ next if ( length($line) <= 0 ); # skip blank
Branch: 1 branch
BranchTrueFalseTotal
if length $line <= 0 6 200 206
8110 200 ▶ next if ( $line =~ /^#/ ); # skip comment
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^#/ 20 180 200
8111 180 ( $rpre_tokens, $rmap, $rpre_types ) =
8112 pre_tokenize( $line, $max_pretokens );
8113 180 last;
8114 } ## end while ( defined( $line = ...))
8115 188 return ( $rpre_tokens, $rpre_types );
8116 } ## end sub peek_ahead_for_n_nonblank_pre_tokens
8117  
8118 # look ahead for next non-blank, non-comment line of code
8119 sub peek_ahead_for_nonblank_token {
8120  
8121 143 ▶ my ( $self, $rtokens, $max_token_index ) = @_;
Subroutine peek_ahead_for_nonblank_token: called CC=6 SCAR=17.9
Pod undocumented
8122  
8123 # Given:
8124 # $rtokens = ref to token array
8125 # $max_token_index = index of last token in $rtokens
8126 # Task:
8127 # Update $rtokens with next nonblank token
8128  
8129 # USES GLOBAL VARIABLES: (none)
8130 143 my $line;
8131 143 my $i = 0;
8132  
8133 143 ▶ while ( defined( $line = $self->peek_ahead( $i++ ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->peek_ahead($i++))) 194 2 196
8134 194 $line =~ s/^\s+//; # trim leading blanks
8135 194 ▶ next if ( length($line) <= 0 ); # skip blank
Branch: 1 branch
BranchTrueFalseTotal
if length $line <= 0 29 165 194
8136 165 ▶ next if ( $line =~ /^#/ ); # skip comment
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^#/ 24 141 165
8137  
8138 # Updated from 2 to 3 to get trigraphs, added for case b1175
8139 141 my ( $rtok, $rmap_uu, $rtype_uu ) = pre_tokenize( $line, 3 );
8140 141 my $j = $max_token_index + 1;
8141  
8142 141 foreach my $tok ( @{$rtok} ) {
8143 406 ▶ last if ( $tok =~ "\n" );
Branch: 1 branch
BranchTrueFalseTotal
if $tok =~ / / 43 363 406
8144 363 $rtokens->[ ++$j ] = $tok;
8145 }
8146 141 last;
8147 } ## end while ( defined( $line = ...))
8148 143 return;
8149 } ## end sub peek_ahead_for_nonblank_token
8150  
8151 #######################################################################
8152 # Tokenizer guessing routines for ambiguous situations
8153 #######################################################################
8154  
8155 45 my %is_non_ternary_pretok;
8156  
8157 BEGIN {
8158  
8159 # Some pre-tokens which cannot immediately follow a ternary '?'
8160 45 ▶ my @q = qw# ; ? : ) } ] = > #;
Subroutine BEGIN: called CC=1 SCAR=0.0
8161 45 push @q, COMMA;
8162 45 %is_non_ternary_pretok = map { $_ => 1 } @q;
8163 }
8164  
8165 sub guess_if_pattern_or_conditional {
8166  
8167 12 ▶ my ( $self, $i, $rtokens, $rtoken_type, $rtoken_map_uu, $max_token_index )
Subroutine guess_if_pattern_or_conditional: called CC=14 SCAR=48.1
Pod undocumented
8168 = @_;
8169  
8170 # This routine is called when we have encountered a ? following an
8171 # unknown bareword, and we must decide if it starts a pattern or not
8172 # Given:
8173 # $i - token index of the ? starting possible pattern
8174 # $rtokens ... = the token arrays
8175 # Return:
8176 # $is_pattern = 0 if probably not pattern, =1 if probably a pattern
8177 # msg = a warning or diagnostic message
8178  
8179 # USES GLOBAL VARIABLES: $last_nonblank_token
8180  
8181 12 my $is_pattern = 0;
8182 12 my $msg =
8183 "guessing that ? after type='$last_nonblank_type' token='$last_nonblank_token' starts a ";
8184  
8185 12 ▶ if ( $i >= $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $max_token_index) 0 12 12
8186 0 $msg .= "conditional (no end to pattern found on the line)\n";
8187 0 $is_pattern = 0;
8188 0 return ( $is_pattern, $msg );
8189 }
8190  
8191 # See if we can rule out a ternary operator here before proceeding. c547.
8192 12 my ( $next_nonblank_token, $i_next_uu ) =
8193 find_next_nonblank_token_on_this_line( $i, $rtokens, $max_token_index );
8194 12 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_non_ternary_pretok{$next_nonblank_token} or $last_nonblank_type eq "k" and $last_nonblank_token eq "split") 12 0 12
Condition33%2/6
$is_non_ternary_pretok{$next_nonblank_token} or $last_nonblank_type eq "k" and $last_nonblank_token eq "split"
l!l&&r!l&&!r
0012
$last_nonblank_type eq "k" and $last_nonblank_token eq "split"
!ll&&!rl&&r
1200
MC/DC0%0/3
$is_non_ternary_pretok{$next_nonblank_token} or $last_nonblank_type eq "k" and $last_nonblank_token eq "split"
$is_non_ternary_pretok{$next_nonblank_token} $last_nonblank_type eq "k" $last_nonblank_token eq "split"
Truth table0%0/4
A or B and C
A= $is_non_ternary_pretok{$next_nonblank_token}B= $last_nonblank_type eq "k"C= $last_nonblank_token eq "split"
ABCresult
1XX1
0111
00X0
0100
8195 !(
8196 $is_non_ternary_pretok{$next_nonblank_token}
8197 || ( $last_nonblank_type eq 'k' && $last_nonblank_token eq 'split' )
8198 )
8199 )
8200 {
8201 # A ternary cannot be ruled out here. We will assume this is a ternary
8202 # operator since '?' as pattern delimiter is deprecated.
8203 12 $is_pattern = 0;
8204 12 $msg .= "conditional (cannot rule it out)";
8205 12 return ( $is_pattern, $msg );
8206 }
8207  
8208 # If we get here, then we either have a ternary with a syntax error or some
8209 # ancient code which uses ? as a pattern delimiter. We will only select the
8210 # pattern delimiter if we can find its matching closing delimiter.
8211  
8212 0 my $ibeg = $i;
8213 0 $i = $ibeg + 1;
8214 ##my $next_token = $rtokens->[$i]; # first token after ?
8215  
8216 # look for a possible ending ? on this line..
8217 0 my $in_quote = 1;
8218 0 my $quote_depth = 0;
8219 0 my $quote_character = EMPTY_STRING;
8220 0 my $quote_pos = 0;
8221 0 my $quoted_string;
8222 (
8223  
8224 0 $i,
8225 $in_quote,
8226 $quote_character,
8227 $quote_pos,
8228 $quote_depth,
8229 $quoted_string,
8230  
8231 ) = $self->follow_quoted_string(
8232  
8233 $ibeg,
8234 $in_quote,
8235 $rtokens,
8236 $rtoken_type,
8237 $quote_character,
8238 $quote_pos,
8239 $quote_depth,
8240 $max_token_index,
8241  
8242 );
8243  
8244 0 ▶ if ($in_quote) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote) 0 0 0
8245  
8246 # we didn't find an ending ? on this line,
8247 # so we bias towards conditional
8248 0 $is_pattern = 0;
8249 0 $msg .= "conditional (no ending ? on this line)\n";
8250 0 return ( $is_pattern, $msg );
8251 }
8252  
8253 # we found an ending ?, so we bias towards a pattern
8254  
8255 # Watch out for an ending ? in quotes, like this
8256 # my $case_flag = File::Spec->case_tolerant ? '(?i)' : '';
8257 0 my $s_quote = 0;
8258 0 my $d_quote = 0;
8259 0 my $colons = 0;
8260 0 foreach my $ii ( $ibeg + 1 .. $i - 1 ) {
8261 0 my $tok = $rtokens->[$ii];
8262 0 ▶ if ( $tok eq ":" ) { $colons++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq ":") 0 0 0
8263 0 ▶ if ( $tok eq "'" ) { $s_quote++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "'") 0 0 0
8264 0 ▶ if ( $tok eq '"' ) { $d_quote++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "\"") 0 0 0
8265 }
8266 0 ▶ if ( $s_quote % 2 || $d_quote % 2 || $colons ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s_quote % 2 or $d_quote % 2 or $colons) 0 0 0
Condition0%0/6
$s_quote % 2 or $d_quote % 2 or $colons
l!l&&r!l&&!r
000
$s_quote % 2 or $d_quote % 2
l!l&&r!l&&!r
000
MC/DC0%0/3
$s_quote % 2 or $d_quote % 2 or $colons
$s_quote % 2 $d_quote % 2 $colons
Truth table0%0/4
A or B or C
A= $s_quote % 2B= $d_quote % 2C= $colons
ABCresult
1XX1
01X1
0011
0000
8267 0 $is_pattern = 0;
8268 0 $msg .= "conditional: found ending ? but unbalanced quote chars\n";
8269 0 return ( $is_pattern, $msg );
8270 }
8271 0 ▶ if ( $self->pattern_expected( $i, $rtokens, $max_token_index ) >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->pattern_expected($i, $rtokens, $max_token_index) >= 0) 0 0 0
8272 0 $is_pattern = 1;
8273 0 $msg .= "pattern (found ending ? and pattern expected)\n";
8274 0 return ( $is_pattern, $msg );
8275 }
8276  
8277 # NOTE: An ultimate decision could be made on version, since ? is a ternary
8278 # after version 5.22. But we may be formatting an ancient script with a
8279 # newer perl, and it might run on an older perl, so we cannot be certain.
8280 # if ($] >=5.022) {$is_pattern=0} else { ... not sure
8281  
8282 0 $msg .= "conditional (but uncertain)\n";
8283 0 return ( $is_pattern, $msg );
8284 } ## end sub guess_if_pattern_or_conditional
8285  
8286 45 my %is_known_constant;
8287 45 my %is_known_function;
8288  
8289 BEGIN {
8290  
8291 # Constants like 'pi' in Trig.pm are common
8292 45 ▶ my @q = qw( pi pi2 pi4 pip2 pip4 );
Subroutine BEGIN: called CC=3 SCAR=11.0
8293 45 $is_known_constant{$_} = 1 for @q;
8294  
8295 # parenless calls of 'ok' are common
8296 45 @q = qw( ok );
8297 45 $is_known_function{$_} = 1 for @q;
8298 } ## end BEGIN
8299  
8300 sub guess_if_pattern_or_division {
8301  
8302 0 ▶ my ( $self, $i, $rtokens, $rtoken_type, $rtoken_map, $max_token_index ) =
Subroutine guess_if_pattern_or_division: not called CC=13 SCAR=52.0
Pod undocumented
8303 @_;
8304  
8305 # This routine is called when we have encountered a / following an
8306 # unknown bareword, and we must decide if it starts a pattern or is a
8307 # division.
8308 # Given:
8309 # $i - token index of the / starting possible pattern
8310 # $rtokens ... = the token arrays
8311 # Return:
8312 # $is_pattern = 0 if probably division, =1 if probably a pattern
8313 # msg = a warning or diagnostic message
8314 # USES GLOBAL VARIABLES: $last_nonblank_token
8315 0 my $msg = "guessing that / after '$last_nonblank_token' starts a ";
8316 0 my $ibeg = $i;
8317 0 my $is_pattern = 0;
8318  
8319 0 my $divide_possible =
8320 $self->is_possible_numerator( $i, $rtokens, $max_token_index );
8321  
8322 0 ▶ if ( $divide_possible < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($divide_possible < 0) 0 0 0
8323 0 $msg .= "pattern (division not possible here)\n";
8324 0 $is_pattern = 1;
8325 0 $self->saw_bareword_function($last_nonblank_token);
8326 0 return ( $is_pattern, $msg );
8327 }
8328 0 ▶ if ( $divide_possible == 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($divide_possible == 4) 0 0 0
8329 0 $msg .= "division (pattern not possible here)\n";
8330 0 $is_pattern = 0;
8331 0 return ( $is_pattern, $msg );
8332 }
8333  
8334 # anything left on line?
8335 0 ▶ if ( $i >= $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $max_token_index) 0 0 0
8336 0 $msg .= "division (line ends with this /)\n";
8337 0 $is_pattern = 0;
8338 0 return ( $is_pattern, $msg );
8339 }
8340  
8341 # quick check for no pattern-ending slash on this line
8342 0 my $pos_beg = $rtoken_map->[$ibeg];
8343 0 my $input_line = $self->[_line_of_text_];
8344 0 ▶ if ( index( $input_line, '/', $pos_beg + 1 ) < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($input_line, "/", $pos_beg + 1) == -1) 0 0 0
8345 0 $msg .= "division (no ending / on this line)\n";
8346 0 $is_pattern = 0;
8347 0 return ( $is_pattern, $msg );
8348 }
8349  
8350 # Setup spacing rule before we change $i below..
8351 0 $i = $ibeg + 1;
8352 0 my $next_token = $rtokens->[$i]; # first token after slash
8353  
8354 # There are four possible spacings around the first slash:
8355 #
8356 # return pi/two;#/; -/-
8357 # return pi/ two;#/; -/+
8358 # return pi / two;#/; +/+
8359 # return pi /two;#/; +/- <-- possible pattern
8360 #
8361 # Spacing rule: a space before the slash but not after the slash
8362 # usually indicates a pattern. We can use this to break ties.
8363 # Note: perl seems to take a newline as a space in this rule (c243)
8364 0 ▶ my $space_before = $i < 2 || $rtokens->[ $i - 2 ] =~ m/^\s/;
Condition0%0/3
$i < 2 || $$rtokens[$i - 2] =~ /^\s/
l!l&&r!l&&!r
000
MC/DC0%0/2
$i < 2 || $$rtokens[$i - 2] =~ /^\s/
$i < 2 $$rtokens[$i - 2] =~ /^\s/
Truth table0%0/3
A || B
A= $i < 2B= $$rtokens[$i - 2] =~ /^\s/
ABresult
1X1
011
000
8365 0 my $space_after = $next_token =~ m/^\s/;
8366 0 ▶ my $is_pattern_by_spacing = $space_before && !$space_after;
Condition0%0/3
$space_before && !$space_after
!ll&&!rl&&r
000
MC/DC0%0/2
$space_before && !$space_after
$space_before !$space_after
Truth table0%0/3
A && not(B)
A= $space_beforeB= !$space_after
ABresult
0X0
100
111
8367  
8368 # Make an accurate search for a possible terminating / on this line..
8369 0 my $in_quote = 1;
8370 0 my $quote_depth = 0;
8371 0 my $quote_character = EMPTY_STRING;
8372 0 my $quote_pos = 0;
8373 0 my $quoted_string;
8374 (
8375  
8376 0 $i,
8377 $in_quote,
8378 $quote_character,
8379 $quote_pos,
8380 $quote_depth,
8381 $quoted_string,
8382 )
8383 = $self->follow_quoted_string(
8384  
8385 $ibeg,
8386 $in_quote,
8387 $rtokens,
8388 $rtoken_type,
8389 $quote_character,
8390 $quote_pos,
8391 $quote_depth,
8392 $max_token_index,
8393 );
8394  
8395 # if we didn't find an ending / on this line ..
8396 0 ▶ if ($in_quote) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote) 0 0 0
8397 0 $is_pattern = 0;
8398 0 $msg .= "division (no ending / on this line)\n";
8399 0 return ( $is_pattern, $msg );
8400 }
8401  
8402 # we found an ending /, see if it might terminate a pattern
8403 0 my $pattern_expected =
8404 $self->pattern_expected( $i, $rtokens, $max_token_index );
8405  
8406 0 ▶ if ( $pattern_expected < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern_expected < 0) 0 0 0
8407 0 $is_pattern = 0;
8408 0 $msg .= "division (pattern not possible)\n";
8409 0 return ( $is_pattern, $msg );
8410 }
8411  
8412 # Both pattern and divide can work here...
8413 # Check for known constants in the numerator, like 'pi'
8414 0 ▶ if ( $is_known_constant{$last_nonblank_token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_known_constant{$last_nonblank_token}) 0 0 0
8415 0 $msg .=
8416 "division (pattern works too but saw known constant '$last_nonblank_token')\n";
8417 0 $is_pattern = 0;
8418 0 return ( $is_pattern, $msg );
8419 }
8420  
8421 # Check for known functions like 'ok'
8422 0 ▶ if ( $is_known_function{$last_nonblank_token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_known_function{$last_nonblank_token}) 0 0 0
8423 0 $msg .= "pattern (division works too but saw '$last_nonblank_token')\n";
8424 0 $is_pattern = 1;
8425 0 return ( $is_pattern, $msg );
8426 }
8427  
8428 # If one rule is more probable, use it
8429 0 ▶ if ( $divide_possible > $pattern_expected ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($divide_possible > $pattern_expected) 0 0 0
8430 0 $msg .= "division (more likely based on following tokens)\n";
8431 0 $is_pattern = 0;
8432 0 return ( $is_pattern, $msg );
8433 }
8434  
8435 # finally, we have to use the spacing rule
8436 0 ▶ if ($is_pattern_by_spacing) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_pattern_by_spacing) { } 0 0 0
8437 0 $msg .= "pattern (guess on spacing, but division possible too)\n";
8438 0 $is_pattern = 1;
8439 }
8440 else {
8441 0 $msg .= "division (guess on spacing, but pattern is possible too)\n";
8442 0 $is_pattern = 0;
8443 }
8444  
8445 0 return ( $is_pattern, $msg );
8446 } ## end sub guess_if_pattern_or_division
8447  
8448 sub guess_if_here_doc {
8449  
8450 0 ▶ my ( $self, $next_token ) = @_;
Subroutine guess_if_here_doc: not called CC=7 SCAR=40.3
Pod undocumented
8451  
8452 # Try to resolve here-doc vs. shift by looking ahead for
8453 # non-code or the end token (currently only looks for end token)
8454  
8455 # Given:
8456 # $next_token = the next token after '<<'
8457  
8458 # Return:
8459 # 1 if it is probably a here doc
8460 # 0 if not
8461  
8462 # USES GLOBAL VARIABLES: $current_package $ris_constant,
8463  
8464 # This is how many lines we will search for a target as part of the
8465 # guessing strategy. There is probably little reason to change it.
8466 0 my $HERE_DOC_WINDOW = 40;
8467  
8468 0 my $here_doc_expected = 0;
8469 0 my $line;
8470 0 my $k = 0;
8471 0 my $msg = "checking <<";
8472  
8473 0 ▶ while ( defined( $line = $self->peek_ahead( $k++ ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->peek_ahead($k++))) 0 0 0
8474 0 chomp $line;
8475 0 ▶ if ( $line eq $next_token ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq $next_token) 0 0 0
8476 0 $msg .= " -- found target $next_token ahead $k lines\n";
8477 0 $here_doc_expected = 1; # got it
8478 0 last;
8479 }
8480 0 ▶ last if ( $k >= $HERE_DOC_WINDOW );
Branch: 1 branch
BranchTrueFalseTotal
if $k >= $HERE_DOC_WINDOW 0 0 0
8481 } ## end while ( defined( $line = ...))
8482  
8483 0 ▶ if ( !$here_doc_expected ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($here_doc_expected) 0 0 0
8484  
8485 0 ▶ if ( !defined($line) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $line) { } 0 0 0
8486 0 $here_doc_expected = -1; # hit eof without seeing target
8487 0 $msg .= " -- must be shift; target $next_token not in file\n";
8488 }
8489 else { # still unsure..taking a wild guess
8490  
8491 0 ▶ if ( !$ris_constant->{$current_package}->{$next_token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ris_constant->{$current_package}{$next_token}) { } 0 0 0
8492 0 $here_doc_expected = 1;
8493 0 $msg .=
8494 " -- guessing it's a here-doc ($next_token not a constant)\n";
8495 }
8496 else {
8497 0 $msg .=
8498 " -- guessing it's a shift ($next_token is a constant)\n";
8499 }
8500 0 if (DEBUG_GUESS_MODE) {
8501 $self->warning("DEBUG_GUESS_MODE message:\n$msg\n");
8502 }
8503 }
8504 }
8505 0 $self->write_logfile_entry($msg);
8506 0 return $here_doc_expected;
8507 } ## end sub guess_if_here_doc
8508  
8509 #######################################################################
8510 # Tokenizer Routines for scanning identifiers and related items
8511 #######################################################################
8512  
8513 sub scan_bare_identifier_do {
8514  
8515 my (
8516  
8517 1870 ▶ $self,
Subroutine scan_bare_identifier_do: called CC=33 SCAR=37.2
Pod undocumented
8518  
8519 $input_line,
8520 $i,
8521 $tok,
8522 $type,
8523 $prototype,
8524 $rtoken_map,
8525 $max_token_index,
8526  
8527 ) = @_;
8528  
8529 # This routine is called to scan a token starting with an alphanumeric
8530 # variable or package separator, :: or '.
8531  
8532 # Given:
8533 # current scan state variables
8534  
8535 # USES GLOBAL VARIABLES: $current_package, $last_nonblank_token,
8536 # $last_nonblank_type, $rparen_type, $paren_depth
8537  
8538 1870 my $package = undef;
8539  
8540 1870 my $i_beg = $i;
8541  
8542 # we have to back up one pretoken at a :: since each : is one pretoken
8543 1870 ▶ if ( $tok eq '::' ) { $i_beg-- }
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "::") 9 1861 1870
8544 1870 my $pos_beg = $rtoken_map->[$i_beg];
8545 1870 pos($input_line) = $pos_beg;
8546  
8547 # Examples:
8548 # A::B::C
8549 # A::
8550 # ::A
8551 # A'B
8552 1870 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ / \G\s* # start at pos ( (?:\w*(?:'|::))* ) # $1 = maybe package name like A:: A::B:: or A' (\w+)? # $2 = maybe followed by sub name /cgx) { } 1870 0 1870
8553 $input_line =~ m{
8554 \G\s* # start at pos
8555 ( (?:\w*(?:'|::))* ) # $1 = maybe package name like A:: A::B:: or A'
8556 (\w+)? # $2 = maybe followed by sub name
8557 }gcx
8558 )
8559 {
8560 1870 my $pos = pos($input_line);
8561 1870 my $numc = $pos - $pos_beg;
8562 1870 $tok = substr( $input_line, $pos_beg, $numc );
8563  
8564 # type 'w' includes anything without leading type info
8565 # ($,%,@,*) including something like abc::def::ghi
8566 1870 $type = 'w';
8567  
8568 1870 my $sub_name = EMPTY_STRING;
8569 1870 ▶ if ( defined($2) ) { $sub_name = $2; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $2) 1865 5 1870
8570 1870 ▶ if ( defined($1) && length($1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $1 and length $1) { } 280 1590 1870
Condition66%2/3
defined $1 and length $1
!ll&&!rl&&r
01590280
MC/DC50%1/2
defined $1 and length $1
defined $1 length $1
Truth table66%2/3
A and B
A= defined $1B= length $1
ABresult
0X0
100
111
8571 280 $package = $1;
8572  
8573 # patch: check for package call A::B::C->
8574 # in this case, C is part of the package name
8575 280 ▶ if ($sub_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub_name) 275 5 280
8576 275 ▶ if ( $input_line =~ m{ \G\s*(?:->) }gcx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ / \G\s*(?:->) /cgx) 117 158 275
8577 117 $package .= $sub_name;
8578 117 $sub_name = EMPTY_STRING;
8579 }
8580 275 pos($input_line) = $pos;
8581 }
8582  
8583 # patch: don't allow isolated package name which just ends
8584 # in the old style package separator (single quote). Example:
8585 # use CGI':all';
8586 280 ▶ if ( !($sub_name) && substr( $package, -1, 1 ) eq '\'' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $sub_name and substr($package, -1, 1) eq "'") 0 280 280
Condition66%2/3
not $sub_name and substr($package, -1, 1) eq "'"
!ll&&!rl&&r
1581220
MC/DC0%0/2
not $sub_name and substr($package, -1, 1) eq "'"
not $sub_name substr($package, -1, 1) eq "'"
Truth table66%2/3
not(A) and B
A= not $sub_nameB= substr($package, -1, 1) eq "'"
ABresult
0X0
100
111
8587 0 $pos--;
8588 }
8589  
8590 280 $package =~ s/\'/::/g;
8591 280 ▶ if ( $package =~ /^\:/ ) { $package = 'main' . $package }
Branch: 1 branch
BranchTrueFalseTotal
if ($package =~ /^\:/) 9 271 280
8592 280 $package =~ s/::$//;
8593 }
8594 else {
8595 1590 $package = $current_package;
8596  
8597 # patched for c043, part 1: keyword does not follow '->'
8598 1590 ▶ if ( $is_keyword{$tok} && $last_nonblank_type ne '->' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_keyword{$tok} and $last_nonblank_type ne "->") 0 1590 1590
Condition66%2/3
$is_keyword{$tok} and $last_nonblank_type ne "->"
!ll&&!rl&&r
1533570
MC/DC0%0/2
$is_keyword{$tok} and $last_nonblank_type ne "->"
$is_keyword{$tok} $last_nonblank_type ne "->"
Truth table66%2/3
A and B
A= $is_keyword{$tok}B= $last_nonblank_type ne "->"
ABresult
0X0
100
111
8599 0 $type = 'k';
8600 }
8601 }
8602  
8603 # if it is a bareword.. patched for c043, part 2: not following '->'
8604 1870 ▶ if ( $type eq 'w' && $last_nonblank_type ne '->' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "w" and $last_nonblank_type ne "->") 1084 786 1870
Condition66%2/3
$type eq "w" and $last_nonblank_type ne "->"
!ll&&!rl&&r
07861084
MC/DC50%1/2
$type eq "w" and $last_nonblank_type ne "->"
$type eq "w" $last_nonblank_type ne "->"
Truth table66%2/3
A and B
A= $type eq "w"B= $last_nonblank_type ne "->"
ABresult
0X0
100
111
8605  
8606 # check for v-string with leading 'v' type character
8607 # (This seems to have precedence over filehandle, type 'Y')
8608 1084 ▶ if ( substr( $tok, 0, 1 ) eq 'v' && $tok =~ /^v\d[_\d]*$/ ) {
Branch: 7 branches
BranchTrueFalseTotal
if (substr($tok, 0, 1) eq 'v' and $tok =~ /^v\d[_\d]*$/) { } 2 1082 1084
elsif ($last_nonblank_token eq 'sort' and $last_nonblank_type eq 'k') { } 1 1081 1082
elsif ($ris_constant->{$package}{$sub_name}) { } 14 1067 1081
elsif ($ris_block_function->{$package}{$sub_name}) { } 0 1067 1067
elsif ($ris_block_list_function->{$package}{$sub_name}) { } 0 1067 1067
elsif ($ris_user_function->{$package}{$sub_name}) { } 6 1061 1067
elsif (not $input_line =~ /\G\(/cg and $is_indirect_object_taker{$last_nonblank_token} || $last_nonblank_token eq '(' && $is_indirect_object_taker{$rparen_type->[$paren_depth]}) { } 4 1057 1061
Condition100%3/3
substr($tok, 0, 1) eq "v" and $tok =~ /^v\d[_\d]*$/
!ll&&!rl&&r
1053292
MC/DC100%2/2
substr($tok, 0, 1) eq "v" and $tok =~ /^v\d[_\d]*$/
substr($tok, 0, 1) eq "v" $tok =~ /^v\d[_\d]*$/
Truth table100%3/3
A and B
A= substr($tok, 0, 1) eq "v"B= $tok =~ /^v\d[_\d]*$/
ABresult
0X0
100
111
8609  
8610 # we only have the first part - something like 'v101' -
8611 # look for more
8612 2 ▶ if ( $input_line =~ m/\G(\.\d[_\d]*)+/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /\G(\.\d[_\d]*)+/cg) 2 0 2
8613 2 $pos = pos($input_line);
8614 2 $numc = $pos - $pos_beg;
8615 2 $tok = substr( $input_line, $pos_beg, $numc );
8616 }
8617 2 $type = 'v';
8618 2 $self->report_v_string($tok);
8619 }
8620  
8621 # bareword after sort has implied empty prototype; for example:
8622 # @sorted = sort numerically ( 53, 29, 11, 32, 7 );
8623 # This has priority over whatever the user has specified.
8624 ▶ elsif ($last_nonblank_token eq 'sort'
Condition66%2/3
$last_nonblank_token eq "sort" and $last_nonblank_type eq "k"
!ll&&!rl&&r
108101
MC/DC50%1/2
$last_nonblank_token eq "sort" and $last_nonblank_type eq "k"
$last_nonblank_token eq "sort" $last_nonblank_type eq "k"
Truth table66%2/3
A and B
A= $last_nonblank_token eq "sort"B= $last_nonblank_type eq "k"
ABresult
0X0
100
111
8625 && $last_nonblank_type eq 'k' )
8626 {
8627 1 $type = 'Z';
8628 }
8629  
8630 # issue c382: this elsif statement moved from above because
8631 # previous check for type 'Z' after sort has priority.
8632 elsif ( $ris_constant->{$package}->{$sub_name} ) {
8633 14 $type = 'C';
8634 }
8635  
8636 # Note: strangely, perl does not seem to really let you create
8637 # functions which act like eval and do, in the sense that eval
8638 # and do may have operators following the final }, but any operators
8639 # that you create with prototype (&) apparently do not allow
8640 # trailing operators, only terms. This seems strange.
8641 # If this ever changes, here is the update
8642 # to make perltidy behave accordingly:
8643  
8644 # elsif ( $ris_block_function->{$package}{$tok} ) {
8645 # $tok='eval'; # patch to do braces like eval - doesn't work
8646 # $type = 'k';
8647 #}
8648 # TODO: This could become a separate type to allow for different
8649 # future behavior:
8650 elsif ( $ris_block_function->{$package}->{$sub_name} ) {
8651 0 $type = 'G';
8652 }
8653 elsif ( $ris_block_list_function->{$package}->{$sub_name} ) {
8654 0 $type = 'G';
8655 }
8656 elsif ( $ris_user_function->{$package}->{$sub_name} ) {
8657 6 $type = 'U';
8658 6 $prototype = $ruser_function_prototype->{$package}->{$sub_name};
8659 }
8660  
8661 # check for indirect object
8662 ▶ elsif (
Condition77%7/9
not $input_line =~ /\G\(/cg and $is_indirect_object_taker{$last_nonblank_token} || $last_nonblank_token eq "(" && $is_indirect_object_taker{$rparen_type->[$paren_depth]}
!ll&&!rl&&r
3027554
$is_indirect_object_taker{$last_nonblank_token} or $last_nonblank_token eq "(" and $is_indirect_object_taker{$rparen_type->[$paren_depth]}
l!l&&r!l&&!r
40755
$last_nonblank_token eq "(" and $is_indirect_object_taker{$rparen_type->[$paren_depth]}
!ll&&!rl&&r
706490
MC/DC50%2/4
not $input_line =~ /\G\(/cg and $is_indirect_object_taker{$last_nonblank_token} || $last_nonblank_token eq "(" && $is_indirect_object_taker{$rparen_type->[$paren_depth]}
not $input_line =~ /\G\(/cg $is_indirect_object_taker{$last_nonblank_token} $last_nonblank_token eq "(" $is_indirect_object_taker{$rparen_type->[$paren_depth]}
Truth table80%4/5
not(A) and B or C and D
A= not $input_line =~ /\G\(/cgB= $is_indirect_object_taker{$last_nonblank_token}C= $last_nonblank_token eq "("D= $is_indirect_object_taker{$rparen_type->[$paren_depth]}
ABCDresult
0XXX0
100X0
10100
11XX1
10111
8663  
8664 # added 2001-03-27: must not be followed immediately by '('
8665 # see fhandle.t
8666 ( $input_line !~ m/\G\(/gc )
8667  
8668 # and
8669 && (
8670  
8671 # preceded by keyword like 'print', 'printf' and friends
8672 $is_indirect_object_taker{$last_nonblank_token}
8673  
8674 # or preceded by something like 'print(' or 'printf('
8675 || (
8676 ( $last_nonblank_token eq '(' )
8677 && $is_indirect_object_taker{
8678 $rparen_type->[$paren_depth]
8679 }
8680  
8681 )
8682 )
8683 )
8684 {
8685  
8686 # may not be indirect object unless followed by a space;
8687 # updated 2021-01-16 to consider newline to be a space.
8688 # updated for case b990 to look for either ';' or space
8689 4 ▶ if ( pos($input_line) == length($input_line)
Branch: 1 branch
BranchTrueFalseTotal
if (pos $input_line == length $input_line or $input_line =~ /\G[;\s]/cg) { } 4 0 4
Condition33%1/3
pos $input_line == length $input_line or $input_line =~ /\G[;\s]/cg
l!l&&r!l&&!r
040
MC/DC0%0/2
pos $input_line == length $input_line or $input_line =~ /\G[;\s]/cg
pos $input_line == length $input_line $input_line =~ /\G[;\s]/cg
Truth table33%1/3
A or B
A= pos $input_line == length $input_lineB= $input_line =~ /\G[;\s]/cg
ABresult
1X1
011
000
8690 || $input_line =~ m/\G[;\s]/gc )
8691 {
8692 4 $type = 'Y';
8693  
8694 # Abandon Hope ...
8695 # Perl's indirect object notation is a very bad
8696 # thing and can cause subtle bugs, especially for
8697 # beginning programmers. And I haven't even been
8698 # able to figure out a sane warning scheme which
8699 # doesn't get in the way of good scripts.
8700  
8701 # Complain if a filehandle has any lower case
8702 # letters. This is suggested good practice.
8703 # Use 'sub_name' because something like
8704 # main::MYHANDLE is ok for filehandle
8705 4 ▶ if ( $sub_name =~ /[a-z]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub_name =~ /[a-z]/) 1 3 4
8706  
8707 # could be bug caused by older perltidy if
8708 # followed by '('
8709 1 ▶ if ( $input_line =~ m/\G\s*\(/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /\G\s*\(/cg) 1 0 1
8710 1 $self->complain(
8711 "Caution: unknown word '$tok' in indirect object slot\n"
8712 );
8713 }
8714 }
8715 }
8716  
8717 # bareword not followed by a space -- may not be filehandle
8718 # (may be function call defined in a 'use' statement)
8719 else {
8720 0 $type = 'Z';
8721 }
8722 }
8723 else {
8724 ## none of the above special types
8725 }
8726 }
8727  
8728 # Now we must convert back from character position
8729 # to pre_token index.
8730 # I don't think an error flag can occur here ..but who knows
8731 1870 my $error;
8732 1870 ( $i, $error ) =
8733 inverse_pretoken_map( $i, $pos, $rtoken_map, $max_token_index );
8734 1870 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 1870 1870
8735 0 $self->warning(
8736 "scan_bare_identifier: Possibly invalid tokenization\n");
8737 }
8738 }
8739  
8740 # no match but line not blank - could be syntax error
8741 # perl will take '::' alone without complaint
8742 else {
8743 0 $type = 'w';
8744  
8745 # change this warning to log message if it becomes annoying
8746 0 $self->warning("didn't find identifier after leading ::\n");
8747 }
8748 1870 return ( $i, $tok, $type, $prototype );
8749 } ## end sub scan_bare_identifier_do
8750  
8751 sub scan_id_do {
8752  
8753 my (
8754  
8755 425 ▶ $self,
Subroutine scan_id_do: called CC=16 SCAR=29.2
Pod undocumented
8756  
8757 $input_line,
8758 $i,
8759 $tok,
8760 $rtokens,
8761 $rtoken_map,
8762 $id_scan_state,
8763 $max_token_index,
8764  
8765 ) = @_;
8766  
8767 # Scan identifier following a type token.
8768 # Given:
8769 # current scan state variables
8770  
8771 # This is the new scanner and may eventually replace scan_identifier.
8772 # Only type 'sub' and 'package' are implemented.
8773 # Token types $ * % @ & -> are not yet implemented.
8774 #
8775 # The type of call depends on $id_scan_state: $id_scan_state = ''
8776 # for starting call, in which case $tok must be the token defining
8777 # the type.
8778 #
8779 # If the type token is the last nonblank token on the line, a value
8780 # of $id_scan_state = $tok is returned, indicating that further
8781 # calls must be made to get the identifier. If the type token is
8782 # not the last nonblank token on the line, the identifier is
8783 # scanned and handled and a value of '' is returned.
8784  
8785 45 ▶ use constant DEBUG_NSCAN => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
8786 425 my $type = EMPTY_STRING;
8787 425 my $i_beg;
8788  
8789 #print "NSCAN:entering i=$i, tok=$tok, type=$type, state=$id_scan_state\n";
8790 #my ($a,$b,$c) = caller;
8791 #print "NSCAN: scan_id called with tok=$tok $a $b $c\n";
8792  
8793 # on re-entry, start scanning at first token on the line
8794 425 ▶ if ($id_scan_state) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state) { } 10 415 425
8795 10 $i_beg = $i;
8796 10 $type = EMPTY_STRING;
8797 }
8798  
8799 # on initial entry, start scanning just after type token
8800 else {
8801 415 $i_beg = $i + 1;
8802 415 $id_scan_state = $tok;
8803 415 $type = 't';
8804 }
8805  
8806 # find $i_beg = index of next nonblank token,
8807 # and handle empty lines
8808 425 my $blank_line = 0;
8809 425 my $is_lexical_method = 0;
8810 425 my $next_nonblank_token = $rtokens->[$i_beg];
8811 425 ▶ if ( $i_beg > $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_beg > $max_token_index) { } 2 423 425
8812 2 $blank_line = 1;
8813 }
8814 else {
8815  
8816 # only a '#' immediately after a '$' is not a comment
8817 423 ▶ if ( $next_nonblank_token eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "#") 0 423 423
8818 0 ▶ if ( $tok ne '$' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok ne "\$") 0 0 0
8819 0 $blank_line = 1;
8820 }
8821 }
8822  
8823 423 ▶ if ( $next_nonblank_token =~ /^\s/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token =~ /^\s/) 403 20 423
8824 403 ( $next_nonblank_token, $i_beg ) =
8825 find_next_nonblank_token_on_this_line( $i_beg, $rtokens,
8826 $max_token_index );
8827 403 ▶ if ( $next_nonblank_token =~ /(^#|^\s*$)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token =~ /(^#|^\s*$)/) 4 399 403
8828 4 $blank_line = 1;
8829 }
8830 }
8831  
8832 # Patch for Object::Pad lexical method like 'method $var {':
8833 # Skip past a '$'
8834 423 ▶ if ( !$blank_line
Branch: 1 branch
BranchTrueFalseTotal
if (not $blank_line and $next_nonblank_token eq "\$" and $id_scan_state eq "method") 2 421 423
Condition83%5/6
not $blank_line and $next_nonblank_token eq "\$" and $id_scan_state eq "method"
!ll&&!rl&&r
42102
not $blank_line and $next_nonblank_token eq "\$"
!ll&&!rl&&r
44172
MC/DC66%2/3
not $blank_line and $next_nonblank_token eq "\$" and $id_scan_state eq "method"
not $blank_line $next_nonblank_token eq "\$" $id_scan_state eq "method"
Truth table75%3/4
not(A) and B and C
A= not $blank_lineB= $next_nonblank_token eq "\$"C= $id_scan_state eq "method"
ABCresult
0XX0
10X0
1100
1111
8835 && $next_nonblank_token eq '$'
8836 && $id_scan_state eq 'method' )
8837 {
8838 2 ( $next_nonblank_token, $i_beg ) =
8839 find_next_nonblank_token_on_this_line( $i_beg, $rtokens,
8840 $max_token_index );
8841 2 $is_lexical_method = 1;
8842 }
8843 }
8844  
8845 # handle non-blank line; identifier, if any, must follow
8846 425 ▶ if ( !$blank_line ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($blank_line) 419 6 425
8847  
8848 419 ▶ if ( $is_sub{$id_scan_state} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_sub{$id_scan_state}) { } 369 50 419
elsif ($is_package{$id_scan_state}) { } 50 0 50
8849 369 ( $i, $tok, $type, $id_scan_state ) = $self->do_scan_sub(
8850 {
8851 input_line => $input_line,
8852 i => $i,
8853 i_beg => $i_beg,
8854 tok => $tok,
8855 type => $type,
8856 rtokens => $rtokens,
8857 rtoken_map => $rtoken_map,
8858 id_scan_state => $id_scan_state,
8859 max_token_index => $max_token_index,
8860 is_lexical_method => $is_lexical_method,
8861 }
8862 );
8863 }
8864  
8865 elsif ( $is_package{$id_scan_state} ) {
8866 50 ( $i, $tok, $type ) = $self->do_scan_package(
8867 {
8868 input_line => $input_line,
8869 i => $i,
8870 i_beg => $i_beg,
8871 tok => $tok,
8872 type => $type,
8873 rtokens => $rtokens,
8874 rtoken_map => $rtoken_map,
8875 max_token_index => $max_token_index,
8876 }
8877 );
8878 50 $id_scan_state = EMPTY_STRING;
8879 }
8880  
8881 else {
8882 0 $self->warning("invalid token in scan_id: $tok\n");
8883 0 $id_scan_state = EMPTY_STRING;
8884 }
8885 }
8886  
8887 425 ▶ if ( $id_scan_state && ( !defined($type) || !$type ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state and not defined $type && $type) 0 425 425
Condition50%3/6
$id_scan_state and not defined $type && $type
!ll&&!rl&&r
415100
defined $type && $type
!ll&&!rl&&r
0010
MC/DC0%0/3
$id_scan_state and not defined $type && $type
$id_scan_state defined $type $type
Truth table50%2/4
A and not(B && C)
A= $id_scan_stateB= defined $typeC= $type
ABCresult
0XX0
1110
10X1
1101
8888  
8889 # shouldn't happen:
8890 0 if (DEVEL_MODE) {
8891 Fault(<<EOM);
8892 Program bug in scan_id: undefined type but scan_state=$id_scan_state
8893 EOM
8894 }
8895 $self->warning(
8896 0 "Possible program bug in sub scan_id: undefined type but scan_state=$id_scan_state\n"
8897 );
8898 0 $self->report_definite_bug();
8899 }
8900  
8901 425 DEBUG_NSCAN && do {
8902 print {*STDOUT}
8903 "NSCAN: returns i=$i, tok=$tok, type=$type, state=$id_scan_state\n";
8904 };
8905 425 return ( $i, $tok, $type, $id_scan_state );
8906 } ## end sub scan_id_do
8907  
8908 sub check_prototype {
8909 191 ▶ my ( $proto, $package, $subname ) = @_;
Subroutine check_prototype: called CC=7 SCAR=19.7
Pod undocumented
8910  
8911 # Classify a sub based on its prototype
8912 191 ▶ return if ( !defined($package) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $package 0 191 191
8913 191 ▶ return if ( !defined($subname) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $subname 0 191 191
8914 191 ▶ if ( defined($proto) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $proto) { } 34 157 191
8915 34 $proto =~ s/^\s*\(\s*//;
8916 34 $proto =~ s/\s*\)$//;
8917 34 ▶ if ($proto) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proto) { } 5 29 34
8918 5 $ris_user_function->{$package}->{$subname} = 1;
8919 5 $ruser_function_prototype->{$package}->{$subname} = "($proto)";
8920  
8921 # prototypes containing '&' must be treated specially..
8922 5 ▶ if ( $proto =~ /\&/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proto =~ /\&/) 1 4 5
8923  
8924 # right curly braces of prototypes ending in
8925 # '&' may be followed by an operator
8926 1 ▶ if ( $proto =~ /\&$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proto =~ /\&$/) { } 0 1 1
8927 0 $ris_block_function->{$package}->{$subname} = 1;
8928 }
8929  
8930 # right curly braces of prototypes NOT ending in
8931 # '&' may NOT be followed by an operator
8932 else {
8933 1 $ris_block_list_function->{$package}->{$subname} = 1;
8934 }
8935 }
8936 }
8937 else {
8938 29 $ris_constant->{$package}->{$subname} = 1;
8939 }
8940 }
8941 else {
8942 157 $ris_user_function->{$package}->{$subname} = 1;
8943 }
8944 191 return;
8945 } ## end sub check_prototype
8946  
8947 sub do_scan_package {
8948  
8949 50 ▶ my ( $self, $rcall_hash ) = @_;
Subroutine do_scan_package: called CC=7 SCAR=20.3
Pod undocumented
8950  
8951 # Parse a package name.
8952  
8953 50 my $input_line = $rcall_hash->{input_line};
8954 50 my $i = $rcall_hash->{i};
8955 50 my $i_beg = $rcall_hash->{i_beg};
8956 50 my $tok = $rcall_hash->{tok};
8957 50 my $type = $rcall_hash->{type};
8958 50 my $rtokens = $rcall_hash->{rtokens};
8959 50 my $rtoken_map = $rcall_hash->{rtoken_map};
8960 50 my $max_token_index = $rcall_hash->{max_token_index};
8961  
8962 # This is called with $i_beg equal to the index of the first nonblank
8963 # token following a 'package' token.
8964 # USES GLOBAL VARIABLES: $current_package,
8965  
8966 # package NAMESPACE
8967 # package NAMESPACE VERSION
8968 # package NAMESPACE BLOCK
8969 # package NAMESPACE VERSION BLOCK
8970 #
8971 # If VERSION is provided, package sets the $VERSION variable in the given
8972 # namespace to a version object with the VERSION provided. VERSION must be
8973 # a "strict" style version number as defined by the version module: a
8974 # positive decimal number (integer or decimal-fraction) without
8975 # exponentiation or else a dotted-decimal v-string with a leading 'v'
8976 # character and at least three components.
8977 # reference http://perldoc.perl.org/functions/package.html
8978  
8979 50 my $package = undef;
8980 50 my $pos_beg = $rtoken_map->[$i_beg];
8981 50 pos($input_line) = $pos_beg;
8982  
8983 # handle non-blank line; package name, if any, must follow
8984 50 ▶ if ( $input_line =~ m/\G\s*((?:\w*(?:'|::))*\w*)/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /\G\s*((?:\w*(?:'|::))*\w*)/cg) { } 50 0 50
8985 50 $package = $1;
8986 50 ▶ $package = ( defined($1) && $1 ) ? $1 : 'main';
Branch: 1 branch
BranchTrueFalseTotal
defined $1 && $1 ? : 50 0 50
Condition33%1/3
defined $1 and $1
!ll&&!rl&&r
0050
MC/DC0%0/2
defined $1 and $1
defined $1 $1
Truth table33%1/3
A and B
A= defined $1B= $1
ABresult
0X0
100
111
8987 50 $package =~ s/\'/::/g;
8988 50 ▶ if ( $package =~ /^\:/ ) { $package = 'main' . $package }
Branch: 1 branch
BranchTrueFalseTotal
if ($package =~ /^\:/) 0 50 50
8989 50 $package =~ s/::$//;
8990 50 my $pos = pos($input_line);
8991 50 my $numc = $pos - $pos_beg;
8992 50 $tok = 'package ' . substr( $input_line, $pos_beg, $numc );
8993 50 $type = 'P'; # Fix for c250, previously 'i'
8994  
8995 # Now we must convert back from character position
8996 # to pre_token index.
8997 # I don't think an error flag can occur here ..but ?
8998 50 my $error;
8999 50 ( $i, $error ) =
9000 inverse_pretoken_map( $i, $pos, $rtoken_map, $max_token_index );
9001 50 ▶ if ($error) { $self->warning("Possibly invalid package\n") }
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 50 50
9002 50 $current_package = $package;
9003  
9004 # we should now have package NAMESPACE
9005 # now expecting VERSION, BLOCK, or ; to follow ...
9006 # package NAMESPACE VERSION
9007 # package NAMESPACE BLOCK
9008 # package NAMESPACE VERSION BLOCK
9009 50 my ( $next_nonblank_token, $i_next_uu ) =
9010 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
9011  
9012 # check that something recognizable follows, but do not parse.
9013 # A VERSION number will be parsed later as a number or v-string in the
9014 # normal way. What is important is to set the statement type if
9015 # everything looks okay so that the operator_expected() routine
9016 # knows that the number is in a package statement.
9017 # Examples of valid primitive tokens that might follow are:
9018 # 1235 . ; { } v3 v
9019 # FIX: added a '#' since a side comment may also follow
9020 # Added ':' for class attributes (for --use-feature=class, rt145706)
9021 50 ▶ if ( $next_nonblank_token =~ /^([v\.\d;\{\}\#\:])|v\d|\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token =~ /^([v\.\d;\{\}\#\:])|v\d|\d+$/) { } 50 0 50
9022 50 $statement_type = $tok;
9023 }
9024 else {
9025 0 $self->warning(
9026 "Unexpected '$next_nonblank_token' after package name '$tok'\n"
9027 );
9028 }
9029 }
9030  
9031 # no match but line not blank --
9032 # could be a label with name package, like package: , for example.
9033 else {
9034 0 $type = 'k';
9035 }
9036  
9037 50 return ( $i, $tok, $type );
9038 } ## end sub do_scan_package
9039  
9040 { ## begin closure for sub scan_complex_identifier
9041  
9042 45 ▶ use constant DEBUG_SCAN_ID => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
9043  
9044 # Constant hash:
9045 45 my %is_special_variable_char;
9046  
9047 BEGIN {
9048  
9049 # These are the only characters which can (currently) form special
9050 # variables, like $^W: (issue c066).
9051 45 ▶ my @q = qw{
Subroutine BEGIN: called CC=2 SCAR=6.9
9052 ? A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ ] ^ _
9053 };
9054 45 push @q, BACKSLASH;
9055 45 $is_special_variable_char{$_} = 1 for @q;
9056 } ## end BEGIN
9057  
9058 # These are the possible states for this scanner:
9059 45 my $scan_state_SIGIL = '$';
9060 45 my $scan_state_ALPHA = 'A';
9061 45 my $scan_state_COLON = ':';
9062 45 my $scan_state_LPAREN = '(';
9063 45 my $scan_state_RPAREN = ')';
9064 45 my $scan_state_AMPERSAND = '&';
9065 45 my $scan_state_SPLIT = '^';
9066  
9067 # Only these non-blank states may be returned to caller:
9068 45 my %is_returnable_scan_state = (
9069 $scan_state_SIGIL => 1,
9070 $scan_state_AMPERSAND => 1,
9071 );
9072  
9073 # USES GLOBAL VARIABLES:
9074 # $context, $last_nonblank_token, $last_nonblank_type
9075  
9076 #-----------
9077 # call args:
9078 #-----------
9079 45 my ( $i, $id_scan_state, $identifier, $rtokens, $max_token_index,
9080 $expecting, $container_type );
9081  
9082 #-------------------------------------------
9083 # my variables, re-initialized on each call:
9084 #-------------------------------------------
9085 45 my $i_begin; # starting index $i
9086 45 my $type; # returned identifier type
9087 45 my $tok_begin; # starting token
9088 45 my $tok; # returned token
9089 45 my $id_scan_state_begin; # starting scan state
9090 45 my $identifier_begin; # starting identifier
9091 45 my $i_save; # a last good index, in case of error
9092 45 my $message; # hold error message for log file
9093 45 my $tok_is_blank;
9094 45 my $last_tok_is_blank;
9095 45 my $in_prototype_or_signature;
9096 45 my $saw_alpha;
9097 45 my $saw_type;
9098 45 my $allow_tick;
9099  
9100 sub initialize_my_scan_id_vars {
9101  
9102 # Initialize all 'my' vars on entry
9103 557 ▶ $i_begin = $i;
Subroutine initialize_my_scan_id_vars: called CC=3 SCAR=11.0
Pod undocumented
9104 557 $type = EMPTY_STRING;
9105 557 $tok_begin = $rtokens->[$i_begin];
9106 557 $tok = $tok_begin;
9107 557 ▶ if ( $tok_begin eq ':' ) { $tok_begin = '::' }
Branch: 1 branch
BranchTrueFalseTotal
if ($tok_begin eq ":") 0 557 557
9108 557 $id_scan_state_begin = $id_scan_state;
9109 557 $identifier_begin = $identifier;
9110 557 $i_save = undef;
9111  
9112 557 $message = EMPTY_STRING;
9113 557 $tok_is_blank = undef; # a flag to speed things up
9114 557 $last_tok_is_blank = undef;
9115  
9116 557 ▶ $in_prototype_or_signature =
Condition100%3/3
$container_type && $container_type =~ /^sub\b/
!ll&&!rl&&r
33421013
MC/DC100%2/2
$container_type && $container_type =~ /^sub\b/
$container_type $container_type =~ /^sub\b/
Truth table100%3/3
A && B
A= $container_typeB= $container_type =~ /^sub\b/
ABresult
0X0
100
111
9117 $container_type && $container_type =~ /^sub\b/;
9118  
9119 # these flags will be used to help figure out the type:
9120 557 $saw_alpha = undef;
9121 557 $saw_type = undef;
9122  
9123 # allow old package separator (') except in 'use' statement
9124 557 $allow_tick = ( $last_nonblank_token ne 'use' );
9125 557 return;
9126 } ## end sub initialize_my_scan_id_vars
9127  
9128 #----------------------------------
9129 # Routines for handling scan states
9130 #----------------------------------
9131 sub do_id_scan_state_dollar {
9132  
9133 621 ▶ my $self = shift;
Subroutine do_id_scan_state_dollar: called CC=54 SCAR=49.9
Pod undocumented
9134  
9135 # We saw a sigil, now looking to start a variable name
9136 621 ▶ if ( $tok eq '$' ) {
Branch: 9 branches
BranchTrueFalseTotal
if ($tok eq '$') { } 65 556 621
elsif ($tok =~ /^\w/) { } 316 240 556
elsif ($tok eq '::') { } 16 224 240
elsif ($tok =~ /^[\@\%\&\*]$/ and $identifier =~ /\-\>$/) { } 0 224 224
elsif ($tok eq q['] and $allow_tick) { } 0 224 224
elsif ($tok eq '#') { } 100 124 224
elsif ($tok eq '{') { } 47 77 124
elsif ($tok =~ /^\s*$/) { } 20 57 77
elsif ($tok eq '^') { } 11 46 57
9137  
9138 65 $identifier .= $tok;
9139  
9140 # we've got a punctuation variable if end of line (punct.t)
9141 65 ▶ if ( $i == $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $max_token_index) 0 65 65
9142 0 $type = 'i';
9143 0 $id_scan_state = EMPTY_STRING;
9144 }
9145 }
9146 elsif ( $tok =~ /^\w/ ) { # alphanumeric ..
9147 316 $saw_alpha = 1;
9148 316 $identifier .= $tok;
9149  
9150 # now need :: except for special digit vars like '$1' (c208)
9151 316 ▶ $id_scan_state = $tok =~ /^\d/ ? EMPTY_STRING : $scan_state_COLON;
Branch: 1 branch
BranchTrueFalseTotal
$tok =~ /^\d/ ? : 51 265 316
9152 }
9153 elsif ( $tok eq '::' ) {
9154 16 $id_scan_state = $scan_state_ALPHA;
9155 16 $identifier .= $tok;
9156 }
9157  
9158 # POSTDEFREF ->@ ->% ->& ->*
9159 ▶ elsif ( ( $tok =~ /^[\@\%\&\*]$/ ) && $identifier =~ /\-\>$/ ) {
Condition66%2/3
$tok =~ /^[\@\%\&\*]$/ and $identifier =~ /\-\>$/
!ll&&!rl&&r
198260
MC/DC0%0/2
$tok =~ /^[\@\%\&\*]$/ and $identifier =~ /\-\>$/
$tok =~ /^[\@\%\&\*]$/ $identifier =~ /\-\>$/
Truth table66%2/3
A and B
A= $tok =~ /^[\@\%\&\*]$/B= $identifier =~ /\-\>$/
ABresult
0X0
100
111
9160 0 $identifier .= $tok;
9161 }
9162 ▶ elsif ( $tok eq "'" && $allow_tick ) { # alphanumeric ..
Condition33%1/3
$tok eq "'" and $allow_tick
!ll&&!rl&&r
22400
MC/DC0%0/2
$tok eq "'" and $allow_tick
$tok eq "'" $allow_tick
Truth table33%1/3
A and B
A= $tok eq "'"B= $allow_tick
ABresult
0X0
100
111
9163 0 $saw_alpha = 1;
9164 0 $id_scan_state = $scan_state_COLON; # now need ::
9165 0 $identifier .= $tok;
9166  
9167 # Perl will accept leading digits in identifiers,
9168 # although they may not always produce useful results.
9169 # Something like $main::0 is ok. But this also works:
9170 #
9171 # sub howdy::123::bubba{ print "bubba $54321!\n" }
9172 # howdy::123::bubba();
9173 #
9174 }
9175 elsif ( $tok eq '#' ) {
9176  
9177 100 my $is_punct_var = $identifier eq '$$';
9178  
9179 # side comment or identifier?
9180 100 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $last_tok_is_blank || $in_prototype_or_signature and $identifier =~ /^[\%\@\$\*]$/ || $identifier =~ /\$$/ and not $is_punct_var) { } 96 4 100
Condition66%8/12
not $last_tok_is_blank || $in_prototype_or_signature and $identifier =~ /^[\%\@\$\*]$/ || $identifier =~ /\$$/ and not $is_punct_var
!ll&&!rl&&r
4096
not $last_tok_is_blank || $in_prototype_or_signature and $identifier =~ /^[\%\@\$\*]$/ || $identifier =~ /\$$/
!ll&&!rl&&r
4096
$last_tok_is_blank || $in_prototype_or_signature
l!l&&r!l&&!r
4096
$identifier =~ /^[\%\@\$\*]$/ or $identifier =~ /\$$/
l!l&&r!l&&!r
9510
MC/DC20%1/5
not $last_tok_is_blank || $in_prototype_or_signature and $identifier =~ /^[\%\@\$\*]$/ || $identifier =~ /\$$/ and not $is_punct_var
$last_tok_is_blank $in_prototype_or_signature $identifier =~ /^[\%\@\$\*]$/ $identifier =~ /\$$/ not $is_punct_var
Truth table42%3/7
not(A || B) and C or D and not(E)
A= $last_tok_is_blankB= $in_prototype_or_signatureC= $identifier =~ /^[\%\@\$\*]$/D= $identifier =~ /\$$/E= not $is_punct_var
ABCDEresult
1XXXX0
01XXX0
0000X0
001X00
000100
001X11
000111
9181  
9182 # A '#' starts a comment if it follows a space. For example,
9183 # the following is equivalent to $ans=40.
9184 # my $ #
9185 # ans = 40;
9186 !$last_tok_is_blank
9187  
9188 # a # inside a prototype or signature can only start a
9189 # comment
9190 && !$in_prototype_or_signature
9191  
9192 # these are valid punctuation vars: *# %# @# $#
9193 # May also be '$#array' or POSTDEFREF ->$#
9194 && ( $identifier =~ /^[\%\@\$\*]$/
9195 || $identifier =~ /\$$/ )
9196  
9197 # but a '#' after '$$' is a side comment; see c147
9198 && !$is_punct_var
9199  
9200 )
9201 {
9202 96 $identifier .= $tok; # keep same state, a $ could follow
9203 }
9204 else {
9205  
9206 # otherwise it is a side comment
9207 4 ▶ if ( $identifier eq '->' ) { }
Branch: 3 branches
BranchTrueFalseTotal
if ($identifier eq '->') { } 0 4 4
elsif ($is_punct_var) { } 0 4 4
elsif ($id_scan_state eq $scan_state_SIGIL) { } 4 0 4
9208 0 elsif ($is_punct_var) { $type = 'i' }
9209 4 elsif ( $id_scan_state eq $scan_state_SIGIL ) { $type = 't' }
9210 0 else { $type = 'i' }
9211 4 $i = $i_save;
9212 4 $id_scan_state = EMPTY_STRING;
9213 }
9214 }
9215  
9216 elsif ( $tok eq '{' ) {
9217  
9218 # check for something like ${#} or ${?}, where ? is a special char
9219 47 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($identifier eq '$' || $identifier eq '@' || $identifier eq '$#' and $i + 2 <= $max_token_index and $$rtokens[$i + 2] eq '}' and not $$rtokens[$i + 1] =~ /[\s\w]/) { } 1 46 47
Condition86%13/15
$identifier eq "\$" || $identifier eq "\@" || $identifier eq "\$#" and $i + 2 <= $max_token_index and $$rtokens[$i + 2] eq "}" and not $$rtokens[$i + 1] =~ /[\s\w]/
!ll&&!rl&&r
36101
$identifier eq "\$" || $identifier eq "\@" || $identifier eq "\$#" and $i + 2 <= $max_token_index and $$rtokens[$i + 2] eq "}"
!ll&&!rl&&r
102611
$identifier eq "\$" || $identifier eq "\@" || $identifier eq "\$#" and $i + 2 <= $max_token_index
!ll&&!rl&&r
10037
$identifier eq "\$" or $identifier eq "\@" or $identifier eq "\$#"
l!l&&r!l&&!r
31610
$identifier eq "\$" or $identifier eq "\@"
l!l&&r!l&&!r
31016
MC/DC33%2/6
$identifier eq "\$" || $identifier eq "\@" || $identifier eq "\$#" and $i + 2 <= $max_token_index and $$rtokens[$i + 2] eq "}" and not $$rtokens[$i + 1] =~ /[\s\w]/
$identifier eq "\$" $identifier eq "\@" $identifier eq "\$#" $i + 2 <= $max_token_index $$rtokens[$i + 2] eq "}" not $$rtokens[$i + 1] =~ /[\s\w]/
Truth table38%5/13
A or B or C and D and E and not(F)
A= $identifier eq "\$"B= $identifier eq "\@"C= $identifier eq "\$#"D= $i + 2 <= $max_token_indexE= $$rtokens[$i + 2] eq "}"F= not $$rtokens[$i + 1] =~ /[\s\w]/
ABCDEFresult
000XXX0
1XX0XX0
01X0XX0
0010XX0
1XX10X0
01X10X0
00110X0
1XX1100
01X1100
0011100
1XX1111
01X1111
0011111
9220 (
9221 $identifier eq '$'
9222 || $identifier eq '@'
9223 || $identifier eq '$#'
9224 )
9225 && $i + 2 <= $max_token_index
9226 && $rtokens->[ $i + 2 ] eq '}'
9227 && $rtokens->[ $i + 1 ] !~ /[\s\w]/
9228 )
9229 {
9230 1 my $next2 = $rtokens->[ $i + 2 ];
9231 1 my $next1 = $rtokens->[ $i + 1 ];
9232 1 $identifier .= $tok . $next1 . $next2;
9233 1 $i += 2;
9234 1 $id_scan_state = EMPTY_STRING;
9235 }
9236 else {
9237  
9238 # skip something like ${xxx} or ->{
9239 46 $id_scan_state = EMPTY_STRING;
9240  
9241 # if this is the first token of a line, any tokens for this
9242 # identifier have already been accumulated
9243 46 ▶ if ( $identifier eq '$' || $i == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($identifier eq "\$" or $i == 0) 31 15 46
Condition66%2/3
$identifier eq "\$" or $i == 0
l!l&&r!l&&!r
31015
MC/DC50%1/2
$identifier eq "\$" or $i == 0
$identifier eq "\$" $i == 0
Truth table66%2/3
A or B
A= $identifier eq "\$"B= $i == 0
ABresult
1X1
011
000
9244 31 $identifier = EMPTY_STRING;
9245 }
9246 46 $i = $i_save;
9247 }
9248 }
9249  
9250 # space ok after leading $ % * & @
9251 elsif ( $tok =~ /^\s*$/ ) {
9252  
9253 20 $tok_is_blank = 1;
9254  
9255 # note: an id with a leading '&' does not actually come this way
9256 20 ▶ if ( $identifier =~ /^[\$\%\*\&\@]/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($identifier =~ /^[\$\%\*\&\@]/) { } 20 0 20
elsif ($identifier eq '->') { } 0 0 0
9257  
9258 20 ▶ if ( length($identifier) > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $identifier > 1) { } 8 12 20
9259 8 $id_scan_state = EMPTY_STRING;
9260 8 $i = $i_save;
9261 8 $type = 'i'; # probably punctuation variable
9262 }
9263 else {
9264  
9265 # fix c139: trim line-ending type 't'
9266 12 ▶ if ( $i == $max_token_index ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i == $max_token_index) { } 1 11 12
elsif (not $identifier =~ /^[\@\$]$/) { } 1 10 11
9267 1 $i = $i_save;
9268 1 $type = 't';
9269 }
9270  
9271 # spaces after $'s are common, and space after @
9272 # is harmless, so only complain about space
9273 # after other type characters. Space after $ and
9274 # @ will be removed in formatting. Report space
9275 # after % and * because they might indicate a
9276 # parsing error. In other words '% ' might be a
9277 # modulo operator. Delete this warning if it
9278 # gets annoying.
9279 elsif ( $identifier !~ /^[\@\$]$/ ) {
9280 1 $message =
9281 "Space in identifier, following $identifier\n";
9282 }
9283 else {
9284 ## silently accept space after '$' and '@' sigils
9285 }
9286 }
9287 }
9288  
9289 elsif ( $identifier eq '->' ) {
9290  
9291 # space after '->' is ok except at line end ..
9292 # so trim line-ending in type '->' (fixes c139)
9293 0 ▶ if ( $i == $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $max_token_index) 0 0 0
9294 0 $i = $i_save;
9295 0 $type = '->';
9296 }
9297 }
9298  
9299 # stop at space after something other than -> or sigil
9300 # Example of what can arrive here:
9301 # eval { $MyClass->$$ };
9302 else {
9303 0 $id_scan_state = EMPTY_STRING;
9304 0 $i = $i_save;
9305 0 $type = 'i';
9306 }
9307 }
9308 elsif ( $tok eq '^' ) {
9309  
9310 # check for some special variables like $^ $^W
9311 11 ▶ if ( $identifier =~ /^[\$\*\@\%]$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($identifier =~ /^[\$\*\@\%]$/) { } 11 0 11
9312 11 $identifier .= $tok;
9313 11 $type = 'i';
9314  
9315 # There may be one more character, not a space, after the ^
9316 11 my $next1 = $rtokens->[ $i + 1 ];
9317 11 my $chr = substr( $next1, 0, 1 );
9318 11 ▶ if ( $is_special_variable_char{$chr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_special_variable_char{$chr}) { } 9 2 11
9319  
9320 # It is something like $^W
9321 # Test case (c066) : $^Oeq'linux'
9322 9 $i++;
9323 9 $identifier .= $next1;
9324  
9325 # If pretoken $next1 is more than one character long,
9326 # set a flag indicating that it needs to be split.
9327 9 ▶ $id_scan_state =
Branch: 1 branch
BranchTrueFalseTotal
length $next1 > 1 ? : 3 6 9
9328 ( length($next1) > 1 ) ? $scan_state_SPLIT : EMPTY_STRING;
9329 }
9330 else {
9331  
9332 # it is just $^
9333 # Simple test case (c065): '$aa=$^if($bb)';
9334 2 $id_scan_state = EMPTY_STRING;
9335 }
9336 }
9337 else {
9338 0 $id_scan_state = EMPTY_STRING;
9339 0 $i = $i_save;
9340 }
9341 }
9342 else { # something else
9343  
9344 46 ▶ if ( $in_prototype_or_signature && $tok =~ /^[\),=#]/ ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($in_prototype_or_signature and $tok =~ /^[\),=#]/) { } 3 43 46
elsif ($identifier =~ /^[\$\*\@\%]$/) { } 35 8 43
elsif ($tok eq '*' and $identifier =~ /\-\>([\@\%\$\*\&]|\$\#)$/) { } 6 2 8
elsif ($identifier eq '$#') { } 2 0 2
elsif ($identifier eq '$$') { } 0 0 0
elsif ($identifier eq '->') { } 0 0 0
Condition66%2/3
$in_prototype_or_signature and $tok =~ /^[\),=#]/
!ll&&!rl&&r
4303
MC/DC50%1/2
$in_prototype_or_signature and $tok =~ /^[\),=#]/
$in_prototype_or_signature $tok =~ /^[\),=#]/
Truth table66%2/3
A and B
A= $in_prototype_or_signatureB= $tok =~ /^[\),=#]/
ABresult
0X0
100
111
9345  
9346 # We might be in an extrusion of
9347 # sub foo2 ( $first, $, $third ) {
9348 # looking at a line starting with a comma, like
9349 # $
9350 # ,
9351 # in this case the comma ends the signature variable
9352 # '$' which will have been previously marked type 't'
9353 # rather than 'i'.
9354 3 ▶ if ( $i == $i_begin ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $i_begin) { } 1 2 3
9355 1 $identifier = EMPTY_STRING;
9356 1 $type = EMPTY_STRING;
9357 }
9358  
9359 # at a # we have to mark as type 't' because more may
9360 # follow, otherwise, in a signature we can let '$' be an
9361 # identifier here for better formatting.
9362 # See 'mangle4.in' for a test case.
9363 else {
9364 2 $type = 'i';
9365 2 ▶ if ( $id_scan_state eq $scan_state_SIGIL && $tok eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state eq $scan_state_SIGIL and $tok eq "#") 0 2 2
Condition33%1/3
$id_scan_state eq $scan_state_SIGIL and $tok eq "#"
!ll&&!rl&&r
020
MC/DC0%0/2
$id_scan_state eq $scan_state_SIGIL and $tok eq "#"
$id_scan_state eq $scan_state_SIGIL $tok eq "#"
Truth table33%1/3
A and B
A= $id_scan_state eq $scan_state_SIGILB= $tok eq "#"
ABresult
0X0
100
111
9366 0 $type = 't';
9367 }
9368 2 $i = $i_save;
9369 }
9370 3 $id_scan_state = EMPTY_STRING;
9371 }
9372  
9373 # check for various punctuation variables
9374 elsif ( $identifier =~ /^[\$\*\@\%]$/ ) {
9375 35 $identifier .= $tok;
9376 }
9377  
9378 # POSTDEFREF: Postfix reference ->$* ->%* ->@* ->** ->&* ->$#*
9379 ▶ elsif ($tok eq '*'
Condition66%2/3
$tok eq "*" and $identifier =~ /\-\>([\@\%\$\*\&]|\$\#)$/
!ll&&!rl&&r
206
MC/DC50%1/2
$tok eq "*" and $identifier =~ /\-\>([\@\%\$\*\&]|\$\#)$/
$tok eq "*" $identifier =~ /\-\>([\@\%\$\*\&]|\$\#)$/
Truth table66%2/3
A and B
A= $tok eq "*"B= $identifier =~ /\-\>([\@\%\$\*\&]|\$\#)$/
ABresult
0X0
100
111
9380 && $identifier =~ /\-\>([\@\%\$\*\&]|\$\#)$/ )
9381 {
9382 6 $identifier .= $tok;
9383 }
9384  
9385 elsif ( $identifier eq '$#' ) {
9386  
9387 2 ▶ if ( $tok eq '{' ) { $type = 'i'; $i = $i_save }
Branch: 2 branches
BranchTrueFalseTotal
if ($tok eq '{') { } 0 2 2
elsif ($tok =~ /^[\:\-\+]$/) { } 0 2 2
9388  
9389 # perl seems to allow just these: $#: $#- $#+
9390 elsif ( $tok =~ /^[\:\-\+]$/ ) {
9391 0 $type = 'i';
9392 0 $identifier .= $tok;
9393 }
9394 else {
9395 2 $i = $i_save;
9396 2 $self->write_logfile_entry(
9397 'Use of $# is deprecated' . "\n" );
9398 }
9399 }
9400 elsif ( $identifier eq '$$' ) {
9401  
9402 # perl does not allow references to punctuation
9403 # variables without braces. For example, this
9404 # won't work:
9405 # $:=\4;
9406 # $a = $$:;
9407 # You would have to use
9408 # $a = ${$:};
9409  
9410 # '$$' alone is punctuation variable for PID
9411 0 $i = $i_save;
9412 0 ▶ if ( $tok eq '{' ) { $type = 't' }
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq '{') { } 0 0 0
9413 0 else { $type = 'i' }
9414 }
9415 elsif ( $identifier eq '->' ) {
9416 0 $i = $i_save;
9417 }
9418 else {
9419 0 $i = $i_save;
9420 0 ▶ if ( length($identifier) == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $identifier == 1) 0 0 0
9421 0 $identifier = EMPTY_STRING;
9422 }
9423 }
9424 46 $id_scan_state = EMPTY_STRING;
9425 }
9426 621 return;
9427 } ## end sub do_id_scan_state_dollar
9428  
9429 sub do_id_scan_state_alpha {
9430  
9431 119 ▶ my $self = shift;
Subroutine do_id_scan_state_alpha: called CC=8 SCAR=26.4
Pod undocumented
9432  
9433 # looking for alphanumeric after ::
9434 119 $tok_is_blank = $tok =~ /^\s*$/;
9435  
9436 119 ▶ if ( $tok =~ /^\w/ ) { # found it
Branch: 4 branches
BranchTrueFalseTotal
if ($tok =~ /^\w/) { } 106 13 119
elsif ($tok eq q['] and $allow_tick) { } 0 13 13
elsif ($tok_is_blank and $identifier =~ /^sub /) { } 0 13 13
elsif ($tok eq '(' and $identifier =~ /^sub /) { } 0 13 13
9437 106 $identifier .= $tok;
9438 106 $id_scan_state = $scan_state_COLON; # now need ::
9439 106 $saw_alpha = 1;
9440 }
9441 ▶ elsif ( $tok eq "'" && $allow_tick ) {
Condition33%1/3
$tok eq "'" and $allow_tick
!ll&&!rl&&r
1300
MC/DC0%0/2
$tok eq "'" and $allow_tick
$tok eq "'" $allow_tick
Truth table33%1/3
A and B
A= $tok eq "'"B= $allow_tick
ABresult
0X0
100
111
9442 0 $identifier .= $tok;
9443 0 $id_scan_state = $scan_state_COLON; # now need ::
9444 0 $saw_alpha = 1;
9445 }
9446 ▶ elsif ( $tok_is_blank && $identifier =~ /^sub / ) {
Condition66%2/3
$tok_is_blank and $identifier =~ /^sub /
!ll&&!rl&&r
760
MC/DC0%0/2
$tok_is_blank and $identifier =~ /^sub /
$tok_is_blank $identifier =~ /^sub /
Truth table66%2/3
A and B
A= $tok_is_blankB= $identifier =~ /^sub /
ABresult
0X0
100
111
9447 0 $id_scan_state = $scan_state_LPAREN;
9448 0 $identifier .= $tok;
9449 }
9450 ▶ elsif ( $tok eq '(' && $identifier =~ /^sub / ) {
Condition33%1/3
$tok eq "(" and $identifier =~ /^sub /
!ll&&!rl&&r
1300
MC/DC0%0/2
$tok eq "(" and $identifier =~ /^sub /
$tok eq "(" $identifier =~ /^sub /
Truth table33%1/3
A and B
A= $tok eq "("B= $identifier =~ /^sub /
ABresult
0X0
100
111
9451 0 $id_scan_state = $scan_state_RPAREN;
9452 0 $identifier .= $tok;
9453 }
9454 else {
9455 13 $id_scan_state = EMPTY_STRING;
9456 13 $i = $i_save;
9457 }
9458 119 return;
9459 } ## end sub do_id_scan_state_alpha
9460  
9461 sub do_id_scan_state_colon {
9462  
9463 476 ▶ my $self = shift;
Subroutine do_id_scan_state_colon: called CC=10 SCAR=25.4
Pod undocumented
9464  
9465 # looking for possible :: after alphanumeric
9466  
9467 476 $tok_is_blank = $tok =~ /^\s*$/;
9468  
9469 476 ▶ if ( $tok eq '::' ) { # got it
Branch: 5 branches
BranchTrueFalseTotal
if ($tok eq '::') { } 103 373 476
elsif ($tok =~ /^\w/) { } 20 353 373
elsif ($tok eq q['] and $allow_tick) { } 12 341 353
elsif ($tok_is_blank and $identifier =~ /^sub /) { } 0 341 341
elsif ($tok eq '(' and $identifier =~ /^sub /) { } 0 341 341
9470 103 $identifier .= $tok;
9471 103 $id_scan_state = $scan_state_ALPHA; # now require alpha
9472 }
9473 elsif ( $tok =~ /^\w/ ) { # more alphanumeric is ok here
9474 20 $identifier .= $tok;
9475 20 $id_scan_state = $scan_state_COLON; # now need ::
9476 20 $saw_alpha = 1;
9477 }
9478 ▶ elsif ( $tok eq "'" && $allow_tick ) { # tick
Condition66%2/3
$tok eq "'" and $allow_tick
!ll&&!rl&&r
341012
MC/DC50%1/2
$tok eq "'" and $allow_tick
$tok eq "'" $allow_tick
Truth table66%2/3
A and B
A= $tok eq "'"B= $allow_tick
ABresult
0X0
100
111
9479  
9480 12 ▶ if ( $is_keyword{$identifier} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_keyword{$identifier}) { } 0 12 12
9481 0 $id_scan_state = EMPTY_STRING; # that's all
9482 0 $i = $i_save;
9483 }
9484 else {
9485 12 $identifier .= $tok;
9486 }
9487 }
9488 ▶ elsif ( $tok_is_blank && $identifier =~ /^sub / ) {
Condition66%2/3
$tok_is_blank and $identifier =~ /^sub /
!ll&&!rl&&r
1871540
MC/DC0%0/2
$tok_is_blank and $identifier =~ /^sub /
$tok_is_blank $identifier =~ /^sub /
Truth table66%2/3
A and B
A= $tok_is_blankB= $identifier =~ /^sub /
ABresult
0X0
100
111
9489 0 $id_scan_state = $scan_state_LPAREN;
9490 0 $identifier .= $tok;
9491 }
9492 ▶ elsif ( $tok eq '(' && $identifier =~ /^sub / ) {
Condition66%2/3
$tok eq "(" and $identifier =~ /^sub /
!ll&&!rl&&r
312290
MC/DC0%0/2
$tok eq "(" and $identifier =~ /^sub /
$tok eq "(" $identifier =~ /^sub /
Truth table66%2/3
A and B
A= $tok eq "("B= $identifier =~ /^sub /
ABresult
0X0
100
111
9493 0 $id_scan_state = $scan_state_RPAREN;
9494 0 $identifier .= $tok;
9495 }
9496 else {
9497 341 $id_scan_state = EMPTY_STRING; # that's all
9498 341 $i = $i_save;
9499 }
9500 476 return;
9501 } ## end sub do_id_scan_state_colon
9502  
9503 sub do_id_scan_state_left_paren {
9504  
9505 0 ▶ my $self = shift;
Subroutine do_id_scan_state_left_paren: not called CC=3 SCAR=24.8
Pod undocumented
9506  
9507 # looking for possible '(' of a prototype
9508  
9509 0 ▶ if ( $tok eq '(' ) { # got it
Branch: 2 branches
BranchTrueFalseTotal
if ($tok eq '(') { } 0 0 0
elsif ($tok =~ /^\s*$/) { } 0 0 0
9510 0 $identifier .= $tok;
9511 0 $id_scan_state = $scan_state_RPAREN; # now find the end of it
9512 }
9513 elsif ( $tok =~ /^\s*$/ ) { # blank - keep going
9514 0 $identifier .= $tok;
9515 0 $tok_is_blank = 1;
9516 }
9517 else {
9518 0 $id_scan_state = EMPTY_STRING; # that's all - no prototype
9519 0 $i = $i_save;
9520 }
9521 0 return;
9522 } ## end sub do_id_scan_state_left_paren
9523  
9524 sub do_id_scan_state_right_paren {
9525  
9526 0 ▶ my $self = shift;
Subroutine do_id_scan_state_right_paren: not called CC=3 SCAR=24.8
Pod undocumented
9527  
9528 # looking for a ')' of prototype to close a '('
9529  
9530 0 $tok_is_blank = $tok =~ /^\s*$/;
9531  
9532 0 ▶ if ( $tok eq ')' ) { # got it
Branch: 2 branches
BranchTrueFalseTotal
if ($tok eq ')') { } 0 0 0
elsif ($tok =~ /^[\s\$\%\\\*\@\&\;]/) { } 0 0 0
9533 0 $identifier .= $tok;
9534 0 $id_scan_state = EMPTY_STRING; # all done
9535 }
9536 elsif ( $tok =~ /^[\s\$\%\\\*\@\&\;]/ ) {
9537 0 $identifier .= $tok;
9538 }
9539 else { # probable error in script, but keep going
9540 0 $self->warning(
9541 "Unexpected '$tok' while seeking end of prototype\n");
9542 0 $identifier .= $tok;
9543 }
9544 0 return;
9545 } ## end sub do_id_scan_state_right_paren
9546  
9547 sub do_id_scan_state_ampersand {
9548  
9549 104 ▶ my $self = shift;
Subroutine do_id_scan_state_ampersand: called CC=18 SCAR=47.0
Pod undocumented
9550  
9551 # Starting sub call after seeing an '&'
9552 104 ▶ if ( $tok =~ /^[\$\w]/ ) { # alphanumeric ..
Branch: 6 branches
BranchTrueFalseTotal
if ($tok =~ /^[\$\w]/) { } 87 17 104
elsif ($tok eq q['] and $allow_tick) { } 0 17 17
elsif ($tok =~ /^\s*$/) { } 2 15 17
elsif ($tok eq '::') { } 0 15 15
elsif ($tok eq '{') { } 15 0 15
elsif ($tok eq '^') { } 0 0 0
9553 87 $id_scan_state = $scan_state_COLON; # now need ::
9554 87 $saw_alpha = 1;
9555 87 $identifier .= $tok;
9556 }
9557 ▶ elsif ( $tok eq "'" && $allow_tick ) { # alphanumeric ..
Condition33%1/3
$tok eq "'" and $allow_tick
!ll&&!rl&&r
1700
MC/DC0%0/2
$tok eq "'" and $allow_tick
$tok eq "'" $allow_tick
Truth table33%1/3
A and B
A= $tok eq "'"B= $allow_tick
ABresult
0X0
100
111
9558 0 $id_scan_state = $scan_state_COLON; # now need ::
9559 0 $saw_alpha = 1;
9560 0 $identifier .= $tok;
9561 }
9562 elsif ( $tok =~ /^\s*$/ ) { # allow space
9563 2 $tok_is_blank = 1;
9564  
9565 # fix c139: trim line-ending type 't'
9566 2 ▶ if ( length($identifier) == 1 && $i == $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $identifier == 1 and $i == $max_token_index) 2 0 2
Condition33%1/3
length $identifier == 1 and $i == $max_token_index
!ll&&!rl&&r
002
MC/DC0%0/2
length $identifier == 1 and $i == $max_token_index
length $identifier == 1 $i == $max_token_index
Truth table33%1/3
A and B
A= length $identifier == 1B= $i == $max_token_index
ABresult
0X0
100
111
9567 2 $i = $i_save;
9568 2 $type = 't';
9569 }
9570 }
9571 elsif ( $tok eq '::' ) { # leading ::
9572 0 $id_scan_state = $scan_state_ALPHA; # accept alpha next
9573 0 $identifier .= $tok;
9574 }
9575 elsif ( $tok eq '{' ) {
9576 15 ▶ if ( $identifier eq '&' || $i == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($identifier eq "&" or $i == 0) 15 0 15
Condition33%1/3
$identifier eq "&" or $i == 0
l!l&&r!l&&!r
1500
MC/DC0%0/2
$identifier eq "&" or $i == 0
$identifier eq "&" $i == 0
Truth table33%1/3
A or B
A= $identifier eq "&"B= $i == 0
ABresult
1X1
011
000
9577 15 $identifier = EMPTY_STRING;
9578 }
9579 15 $i = $i_save;
9580 15 $id_scan_state = EMPTY_STRING;
9581 }
9582 elsif ( $tok eq '^' ) {
9583 0 ▶ if ( $identifier eq '&' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($identifier eq '&') { } 0 0 0
9584  
9585 # Special variable (c066)
9586 0 $identifier .= $tok;
9587 0 $type = 'i';
9588  
9589 # To be a special $^ variable, there may be one more character,
9590 # not a space, after the ^
9591 0 my $next1 = $rtokens->[ $i + 1 ];
9592 0 my $chr = substr( $next1, 0, 1 );
9593 0 ▶ if ( $is_special_variable_char{$chr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_special_variable_char{$chr}) { } 0 0 0
9594  
9595 # It is something like &^O
9596 0 $i++;
9597 0 $identifier .= $next1;
9598  
9599 # If pretoken $next1 is more than one character long,
9600 # set a flag indicating that it needs to be split.
9601 0 ▶ $id_scan_state =
Branch: 1 branch
BranchTrueFalseTotal
length $next1 > 1 ? : 0 0 0
9602 ( length($next1) > 1 ) ? $scan_state_SPLIT : EMPTY_STRING;
9603 }
9604 else {
9605  
9606 # It is &^. This is parsed by perl as a call to sub '^',
9607 # even though it would be difficult to create a sub '^'.
9608 # So we mark it as an identifier (c068).
9609 0 $id_scan_state = EMPTY_STRING;
9610 }
9611 }
9612 else {
9613 0 $identifier = EMPTY_STRING;
9614 0 $i = $i_save;
9615 }
9616 }
9617 else {
9618  
9619 # punctuation variable?
9620 # testfile: cunningham4.pl
9621 #
9622 # We have to be careful here. If we are in an unknown state,
9623 # we will reject the punctuation variable. In the following
9624 # example the '&' is a binary operator but we are in an unknown
9625 # state because there is no sigil on 'Prima', so we don't
9626 # know what it is. But it is a bad guess that
9627 # '&~' is a function variable.
9628 # $self->{text}->{colorMap}->[
9629 # Prima::PodView::COLOR_CODE_FOREGROUND
9630 # & ~tb::COLOR_INDEX ] =
9631 # $sec->{ColorCode}
9632  
9633 # Fix for case c033: a '#' here starts a side comment
9634 0 ▶ if ( $identifier eq '&' && $expecting && $tok ne '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($identifier eq '&' and $expecting and $tok ne '#') { } 0 0 0
Condition0%0/6
$identifier eq "&" and $expecting and $tok ne "#"
!ll&&!rl&&r
000
$identifier eq "&" and $expecting
!ll&&!rl&&r
000
MC/DC0%0/3
$identifier eq "&" and $expecting and $tok ne "#"
$identifier eq "&" $expecting $tok ne "#"
Truth table0%0/4
A and B and C
A= $identifier eq "&"B= $expectingC= $tok ne "#"
ABCresult
0XX0
10X0
1100
1111
9635 0 $identifier .= $tok;
9636 }
9637 else {
9638 0 $identifier = EMPTY_STRING;
9639 0 $i = $i_save;
9640 0 $type = '&';
9641 }
9642 0 $id_scan_state = EMPTY_STRING;
9643 }
9644 104 return;
9645 } ## end sub do_id_scan_state_ampersand
9646  
9647 #-------------------
9648 # hash of scanner subs
9649 #-------------------
9650 45 my $scan_identifier_code = {
9651 $scan_state_SIGIL => \&do_id_scan_state_dollar,
9652 $scan_state_ALPHA => \&do_id_scan_state_alpha,
9653 $scan_state_COLON => \&do_id_scan_state_colon,
9654 $scan_state_LPAREN => \&do_id_scan_state_left_paren,
9655 $scan_state_RPAREN => \&do_id_scan_state_right_paren,
9656 $scan_state_AMPERSAND => \&do_id_scan_state_ampersand,
9657 };
9658  
9659 sub scan_complex_identifier {
9660  
9661 (
9662 557 ▶ my $self,
Subroutine scan_complex_identifier: called CC=46 SCAR=45.5
Pod undocumented
9663  
9664 $i,
9665 $id_scan_state,
9666 $identifier,
9667 $rtokens,
9668 $max_token_index,
9669 $expecting,
9670 $container_type,
9671  
9672 ) = @_;
9673  
9674 # This routine assembles tokens into identifiers. It maintains a
9675 # scan state, id_scan_state. It updates id_scan_state based upon
9676 # current id_scan_state and token, and returns an updated
9677 # id_scan_state and the next index after the identifier.
9678  
9679 # This routine now serves a backup for sub scan_simple_identifier
9680 # which handles most identifiers.
9681  
9682 # Note that $self must be a 'my' variable and not be a closure
9683 # variables like the other args. Otherwise it will not get
9684 # deleted by a DESTROY call at the end of a file. Then an
9685 # attempt to create multiple tokenizers can occur when multiple
9686 # files are processed, causing an error.
9687  
9688 # return flag telling caller to split the pretoken
9689 557 my $split_pretoken_flag;
9690  
9691 #-------------------
9692 # Initialize my vars
9693 #-------------------
9694  
9695 557 initialize_my_scan_id_vars();
9696  
9697 #--------------------------------------------------------
9698 # get started by defining a type and a state if necessary
9699 #--------------------------------------------------------
9700  
9701 557 ▶ if ( !$id_scan_state ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $id_scan_state) { } 550 7 557
9702 550 $context = UNKNOWN_CONTEXT;
9703  
9704 # fixup for digraph
9705 550 ▶ if ( $tok eq '>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq ">") 0 550 550
9706 0 $tok = '->';
9707 0 $tok_begin = $tok;
9708 }
9709 550 $identifier = $tok;
9710  
9711 550 ▶ if ( $last_nonblank_token eq '->' ) {
Branch: 8 branches
BranchTrueFalseTotal
if ($last_nonblank_token eq '->') { } 8 542 550
elsif ($tok eq '$' or $tok eq '*') { } 355 187 542
elsif ($tok eq '%' or $tok eq '@') { } 85 102 187
elsif ($tok eq '&') { } 102 0 102
elsif ($tok eq 'sub' or $tok eq 'package') { } 0 0 0
elsif ($tok eq '::') { } 0 0 0
elsif ($tok =~ /^\w/) { } 0 0 0
elsif ($tok eq '->') { } 0 0 0
9712 8 $identifier = '->' . $identifier;
9713 8 $id_scan_state = $scan_state_SIGIL;
9714 }
9715 ▶ elsif ( $tok eq '$' || $tok eq '*' ) {
Condition100%3/3
$tok eq "\$" or $tok eq "*"
l!l&&r!l&&!r
3496187
MC/DC100%2/2
$tok eq "\$" or $tok eq "*"
$tok eq "\$" $tok eq "*"
Truth table100%3/3
A or B
A= $tok eq "\$"B= $tok eq "*"
ABresult
1X1
011
000
9716 355 $id_scan_state = $scan_state_SIGIL;
9717 355 $context = SCALAR_CONTEXT;
9718 }
9719 ▶ elsif ( $tok eq '%' || $tok eq '@' ) {
Condition100%3/3
$tok eq "%" or $tok eq "\@"
l!l&&r!l&&!r
2560102
MC/DC100%2/2
$tok eq "%" or $tok eq "\@"
$tok eq "%" $tok eq "\@"
Truth table100%3/3
A or B
A= $tok eq "%"B= $tok eq "\@"
ABresult
1X1
011
000
9720 85 $id_scan_state = $scan_state_SIGIL;
9721 85 $context = LIST_CONTEXT;
9722 }
9723 elsif ( $tok eq '&' ) {
9724 102 $id_scan_state = $scan_state_AMPERSAND;
9725 }
9726 ▶ elsif ( $tok eq 'sub' or $tok eq 'package' ) {
Condition0%0/3
$tok eq "sub" or $tok eq "package"
l!l&&r!l&&!r
000
MC/DC0%0/2
$tok eq "sub" or $tok eq "package"
$tok eq "sub" $tok eq "package"
Truth table0%0/3
A or B
A= $tok eq "sub"B= $tok eq "package"
ABresult
1X1
011
000
9727 0 $saw_alpha = 0; # 'sub' is considered type info here
9728 0 $id_scan_state = $scan_state_SIGIL;
9729 0 $identifier .=
9730 SPACE; # need a space to separate sub from sub name
9731 }
9732 elsif ( $tok eq '::' ) {
9733 0 $id_scan_state = $scan_state_ALPHA;
9734 }
9735 elsif ( $tok =~ /^\w/ ) {
9736 0 $id_scan_state = $scan_state_COLON;
9737 0 $saw_alpha = 1;
9738 }
9739 elsif ( $tok eq '->' ) {
9740 0 $id_scan_state = $scan_state_SIGIL;
9741 }
9742 else {
9743  
9744 # shouldn't happen: bad call parameter
9745 0 my $msg =
9746 "Program bug detected: scan_complex_identifier received bad starting token = '$tok'\n";
9747 0 if (DEVEL_MODE) { Fault($msg) }
9748 0 ▶ if ( !$self->[_in_error_] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[7]) 0 0 0
9749 0 $self->warning($msg);
9750 0 $self->[_in_error_] = 1;
9751 }
9752 0 $id_scan_state = EMPTY_STRING;
9753  
9754 # emergency return
9755 0 goto SCAN_ID_EMERGENCY_RETURN;
9756 }
9757 550 $saw_type = !$saw_alpha;
9758 }
9759 else {
9760 7 $i--;
9761 7 $saw_alpha = ( $tok =~ /^\w/ );
9762 7 $saw_type = ( $tok =~ /([\$\%\@\*\&])/ );
9763  
9764 # check for a valid starting state
9765 7 if ( DEVEL_MODE && !$is_returnable_scan_state{$id_scan_state} ) {
9766 Fault(<<EOM);
9767 Unexpected starting scan state in sub scan_complex_identifier: '$id_scan_state'
9768 EOM
9769 }
9770 }
9771  
9772 #------------------------------
9773 # loop to gather the identifier
9774 #------------------------------
9775  
9776 557 $i_save = $i;
9777  
9778 557 ▶ while ( $i < $max_token_index && $id_scan_state ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $max_token_index and $id_scan_state) 1323 120 1443
Condition100%3/3
$i < $max_token_index and $id_scan_state
!ll&&!rl&&r
21991323
MC/DC100%2/2
$i < $max_token_index and $id_scan_state
$i < $max_token_index $id_scan_state
Truth table100%3/3
A and B
A= $i < $max_token_indexB= $id_scan_state
ABresult
0X0
100
111
9779  
9780 # Be sure we have code to handle this state before we proceed
9781 1323 my $code = $scan_identifier_code->{$id_scan_state};
9782 1323 ▶ if ( !$code ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($code) 3 1320 1323
9783  
9784 3 ▶ if ( $id_scan_state eq $scan_state_SPLIT ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state eq $scan_state_SPLIT) { } 3 0 3
9785 ## OK: this is the signal to exit and split the pretoken
9786 }
9787  
9788 # unknown state - should not happen
9789 else {
9790 0 if (DEVEL_MODE) {
9791 Fault(<<EOM);
9792 Unknown scan state in sub scan_complex_identifier: '$id_scan_state'
9793 Scan state at sub entry was '$id_scan_state_begin'
9794 EOM
9795 }
9796 0 $id_scan_state = EMPTY_STRING;
9797 0 $i = $i_save;
9798 }
9799 3 last;
9800 }
9801  
9802 # Remember the starting index for progress check below
9803 1320 my $i_start_loop = $i;
9804  
9805 1320 $last_tok_is_blank = $tok_is_blank;
9806 1320 ▶ if ($tok_is_blank) { $tok_is_blank = undef }
Branch: 1 branch
BranchTrueFalseTotal
if ($tok_is_blank) { } 11 1309 1320
9807 1309 else { $i_save = $i }
9808  
9809 1320 $tok = $rtokens->[ ++$i ];
9810  
9811 # patch to make digraph :: if necessary
9812 1320 ▶ if ( ( $tok eq ':' ) && ( $rtokens->[ $i + 1 ] eq ':' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq ":" and $$rtokens[$i + 1] eq ":") 119 1201 1320
Condition100%3/3
$tok eq ":" and $$rtokens[$i + 1] eq ":"
!ll&&!rl&&r
11974119
MC/DC100%2/2
$tok eq ":" and $$rtokens[$i + 1] eq ":"
$tok eq ":" $$rtokens[$i + 1] eq ":"
Truth table100%3/3
A and B
A= $tok eq ":"B= $$rtokens[$i + 1] eq ":"
ABresult
0X0
100
111
9813 119 $tok = '::';
9814 119 $i++;
9815 }
9816  
9817 1320 $code->($self);
9818  
9819 # check for forward progress: a decrease in the index $i
9820 # implies that scanning has finished
9821 1320 ▶ last if ( $i <= $i_start_loop );
Branch: 1 branch
BranchTrueFalseTotal
if $i <= $i_start_loop 434 886 1320
9822  
9823 } ## end while ( $i < $max_token_index...)
9824  
9825 #-------------
9826 # Check result
9827 #-------------
9828  
9829 # Be sure a valid state is returned
9830 557 ▶ if ($id_scan_state) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state) 24 533 557
9831  
9832 24 ▶ if ( !$is_returnable_scan_state{$id_scan_state} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_returnable_scan_state{$id_scan_state}) 17 7 24
9833  
9834 17 ▶ if ( $id_scan_state eq $scan_state_SPLIT ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state eq $scan_state_SPLIT) 3 14 17
9835 3 $split_pretoken_flag = 1;
9836 }
9837  
9838 17 ▶ if ( $id_scan_state eq $scan_state_RPAREN ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state eq $scan_state_RPAREN) 0 17 17
9839 0 $self->warning(
9840 "Hit end of line while seeking ) to end prototype\n");
9841 }
9842  
9843 17 $id_scan_state = EMPTY_STRING;
9844 }
9845  
9846 # Patch: the deprecated variable $# does not combine with anything
9847 # on the next line.
9848 24 ▶ if ( $identifier eq '$#' ) { $id_scan_state = EMPTY_STRING }
Branch: 1 branch
BranchTrueFalseTotal
if ($identifier eq "\$#") 0 24 24
9849 }
9850  
9851 # Be sure the token index is valid
9852 557 ▶ if ( $i < 0 ) { $i = 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 0) 0 557 557
9853  
9854 # Be sure a token type is defined
9855 557 ▶ if ( !$type ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type) 529 28 557
9856  
9857 529 ▶ if ($saw_type) {
Branch: 2 branches
BranchTrueFalseTotal
if ($saw_type) { } 523 6 529
elsif ($saw_alpha) { } 5 1 6
9858  
9859 523 ▶ if ($saw_alpha) {
Branch: 3 branches
BranchTrueFalseTotal
if ($saw_alpha) { } 410 113 523
elsif ($identifier eq '->') { } 0 113 113
elsif (length $identifier > 1 and not $identifier =~ /\$$/ && $tok eq '{' and $identifier ne 'sub ' and $identifier ne 'package ') { } 53 60 113
9860  
9861 # The type without the -> should be the same as with the -> so
9862 # that if they get separated we get the same bond strengths,
9863 # etc. See b1234
9864 410 ▶ if ( $identifier =~ /^->/
Branch: 1 branch
BranchTrueFalseTotal
if ($identifier =~ /^->/ and $last_nonblank_type eq 'w' and substr($identifier, 2, 1) =~ /^\w/) { } 0 410 410
Condition50%3/6
$identifier =~ /^->/ and $last_nonblank_type eq "w" and substr($identifier, 2, 1) =~ /^\w/
!ll&&!rl&&r
41000
$identifier =~ /^->/ and $last_nonblank_type eq "w"
!ll&&!rl&&r
40820
MC/DC0%0/3
$identifier =~ /^->/ and $last_nonblank_type eq "w" and substr($identifier, 2, 1) =~ /^\w/
$identifier =~ /^->/ $last_nonblank_type eq "w" substr($identifier, 2, 1) =~ /^\w/
Truth table50%2/4
A and B and C
A= $identifier =~ /^->/B= $last_nonblank_type eq "w"C= substr($identifier, 2, 1) =~ /^\w/
ABCresult
0XX0
10X0
1100
1111
9865 && $last_nonblank_type eq 'w'
9866 && substr( $identifier, 2, 1 ) =~ /^\w/ )
9867 {
9868 0 $type = 'w';
9869 }
9870 410 else { $type = 'i' }
9871 }
9872 elsif ( $identifier eq '->' ) {
9873 0 $type = '->';
9874 }
9875 ▶ elsif (
Condition75%9/12
length $identifier > 1 and not $identifier =~ /\$$/ && $tok eq "{" and $identifier ne "sub " and $identifier ne "package "
!ll&&!rl&&r
60053
length $identifier > 1 and not $identifier =~ /\$$/ && $tok eq "{" and $identifier ne "sub "
!ll&&!rl&&r
60053
length $identifier > 1 and not $identifier =~ /\$$/ && $tok eq "{"
!ll&&!rl&&r
56453
$identifier =~ /\$$/ && $tok eq '{'
!ll&&!rl&&r
5304
MC/DC40%2/5
length $identifier > 1 and not $identifier =~ /\$$/ && $tok eq "{" and $identifier ne "sub " and $identifier ne "package "
length $identifier > 1 $identifier =~ /\$$/ $tok eq '{' $identifier ne "sub " $identifier ne "package "
Truth table37%3/8
A and not(B && C) and D and E
A= length $identifier > 1B= $identifier =~ /\$$/C= $tok eq '{'D= $identifier ne "sub "E= $identifier ne "package "
ABCDEresult
0XXXX0
111XX0
10X0X0
1100X0
10X100
110100
10X111
110111
9876 ( length($identifier) > 1 )
9877  
9878 # In something like '@$=' we have an identifier '@$'
9879 # In something like '$${' we have type '$$' (and only
9880 # part of an identifier)
9881 && !( $identifier =~ /\$$/ && $tok eq '{' )
9882 && $identifier ne 'sub '
9883 && $identifier ne 'package '
9884 )
9885 {
9886 53 $type = 'i';
9887 }
9888 60 else { $type = 't' }
9889 }
9890 elsif ($saw_alpha) {
9891  
9892 # type 'w' includes anything without leading type info
9893 # ($,%,@,*) including something like abc::def::ghi
9894 5 $type = 'w';
9895  
9896 # Fix for b1337, if restarting scan after line break between
9897 # '->' or sigil and identifier name, use type 'i'
9898 5 ▶ if ( $id_scan_state_begin
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state_begin and $identifier =~ /^([\$\%\@\*\&]|->)/) 5 0 5
Condition33%1/3
$id_scan_state_begin and $identifier =~ /^([\$\%\@\*\&]|->)/
!ll&&!rl&&r
005
MC/DC0%0/2
$id_scan_state_begin and $identifier =~ /^([\$\%\@\*\&]|->)/
$id_scan_state_begin $identifier =~ /^([\$\%\@\*\&]|->)/
Truth table33%1/3
A and B
A= $id_scan_state_beginB= $identifier =~ /^([\$\%\@\*\&]|->)/
ABresult
0X0
100
111
9899 && $identifier =~ /^([\$\%\@\*\&]|->)/ )
9900 {
9901 5 $type = 'i';
9902 }
9903 }
9904 else {
9905 1 $type = EMPTY_STRING;
9906 } # this can happen on a restart
9907 }
9908  
9909 # See if we formed an identifier...
9910 557 ▶ if ($identifier) {
Branch: 1 branch
BranchTrueFalseTotal
if ($identifier) { } 510 47 557
9911 510 $tok = $identifier;
9912 510 ▶ if ($message) { $self->write_logfile_entry($message) }
Branch: 1 branch
BranchTrueFalseTotal
if ($message) 1 509 510
9913 }
9914  
9915 # did not find an identifier, back up
9916 else {
9917 47 $tok = $tok_begin;
9918 47 $i = $i_begin;
9919 }
9920  
9921 SCAN_ID_EMERGENCY_RETURN:
9922  
9923 557 DEBUG_SCAN_ID && do {
9924 my ( $a, $b, $c ) = caller();
9925 print {*STDOUT}
9926 "SCANID: called from $a $b $c with tok, i, state, identifier =$tok_begin, $i_begin, $id_scan_state_begin, $identifier_begin\n";
9927 print {*STDOUT}
9928 "SCANID: returned with tok, i, state, identifier =$tok, $i, $id_scan_state, $identifier\n";
9929 };
9930  
9931 return (
9932  
9933 557 $i,
9934 $tok,
9935 $type,
9936 $id_scan_state,
9937 $identifier,
9938 $split_pretoken_flag,
9939 );
9940 } ## end sub scan_complex_identifier
9941 } ## end closure for sub scan_complex_identifier
9942  
9943 { ## closure for sub do_scan_sub
9944  
9945 # saved package and subnames in case prototype is on separate line
9946 45 my ( $package_saved, $subname_saved );
9947  
9948 # initialize subname each time a new 'sub' keyword is encountered
9949 sub initialize_subname {
9950 365 ▶ $package_saved = EMPTY_STRING;
Subroutine initialize_subname: called CC=1 SCAR=0.0
Pod undocumented
9951 365 $subname_saved = EMPTY_STRING;
9952 365 return;
9953 }
9954  
9955 use constant {
9956 45 SUB_CALL => 1,
9957 PAREN_CALL => 2,
9958 PROTOTYPE_CALL => 3,
9959 45 ▶ };
Subroutine BEGIN: called CC=1 SCAR=0.0
9960  
9961 sub do_scan_sub {
9962  
9963 371 ▶ my ( $self, $rcall_hash ) = @_;
Subroutine do_scan_sub: called CC=55 SCAR=46.8
Pod undocumented
9964  
9965 # Parse a sub name and prototype.
9966  
9967 371 my $input_line = $rcall_hash->{input_line};
9968 371 my $i = $rcall_hash->{i};
9969 371 my $i_beg = $rcall_hash->{i_beg};
9970 371 my $tok = $rcall_hash->{tok};
9971 371 my $type = $rcall_hash->{type};
9972 371 my $rtokens = $rcall_hash->{rtokens};
9973 371 my $rtoken_map = $rcall_hash->{rtoken_map};
9974 371 my $id_scan_state = $rcall_hash->{id_scan_state};
9975 371 my $max_token_index = $rcall_hash->{max_token_index};
9976  
9977 371 ▶ my $id_prefix = $rcall_hash->{is_lexical_method} ? '$' : EMPTY_STRING;
Branch: 1 branch
BranchTrueFalseTotal
$rcall_hash->{'is_lexical_method'} ? : 2 369 371
9978  
9979 # At present there are three basic CALL TYPES which are
9980 # distinguished by the starting value of '$tok':
9981 # 1. $tok='sub', id_scan_state='sub'
9982 # it is called with $i_beg equal to the index of the first nonblank
9983 # token following a 'sub' token.
9984 # 2. $tok='(', id_scan_state='sub',
9985 # it is called with $i_beg equal to the index of a '(' which may
9986 # start a prototype.
9987 # 3. $tok='prototype', id_scan_state='prototype'
9988 # it is called with $i_beg equal to the index of a '(' which is
9989 # preceded by ': prototype' and has $id_scan_state eq 'prototype'
9990  
9991 # Examples:
9992  
9993 # A single type 1 call will get both the sub and prototype
9994 # sub foo1 ( $$ ) { }
9995 # ^
9996  
9997 # The subname will be obtained with a 'sub' call
9998 # The prototype on line 2 will be obtained with a '(' call
9999 # sub foo1
10000 # ^ <---call type 1
10001 # ( $$ ) { }
10002 # ^ <---call type 2
10003  
10004 # The subname will be obtained with a 'sub' call
10005 # The prototype will be obtained with a 'prototype' call
10006 # sub foo1 ( $x, $y ) : prototype ( $$ ) { }
10007 # ^ <---type 1 ^ <---type 3
10008  
10009 # TODO: add future error checks to be sure we have a valid
10010 # sub name. For example, 'sub &doit' is wrong. Also, be sure
10011 # a name is given if and only if a non-anonymous sub is
10012 # appropriate.
10013 # USES GLOBAL VARS: $current_package, $last_nonblank_token,
10014 # $rsaw_function_definition,
10015 # $statement_type
10016  
10017 371 my $i_entry = $i;
10018  
10019 # Determine the CALL TYPE
10020 # 1=sub
10021 # 2=(
10022 # 3=prototype
10023 371 ▶ my $call_type =
Branch: 2 branches
BranchTrueFalseTotal
$tok eq 'prototype' ? : 2 369 371
$tok eq '(' ? : 5 364 369
10024 $tok eq 'prototype' ? PROTOTYPE_CALL
10025 : $tok eq '(' ? PAREN_CALL
10026 : SUB_CALL;
10027  
10028 371 $id_scan_state = EMPTY_STRING; # normally we get everything in one call
10029 371 my $subname = $subname_saved;
10030 371 my $package = $package_saved;
10031 371 my $proto = undef;
10032 371 my $attrs = undef;
10033 371 my $match;
10034  
10035 371 my $pos_beg = $rtoken_map->[$i_beg];
10036 371 pos($input_line) = $pos_beg;
10037  
10038 # Look for the sub NAME if this is a SUB call
10039 371 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($call_type == 1 and $input_line =~ /\G\s* ((?:\w*(?:'|::))*) # package - something that ends in :: or ' (\w+) # NAME - required /cgx) 176 195 371
Condition100%3/3
$call_type == 1 and $input_line =~ /\G\s*
!ll&&!rl&&r
7188176
MC/DC100%2/2
$call_type == 1 and $input_line =~ /\G\s* ((?:\w*(?:'|::))*) # package - something that ends in :: or ' (\w+) # NAME - required /cgx
$call_type == 1 $input_line =~ /\G\s* ((?:\w*(?:'|::))*) # package - something that ends in :: or ' (\w+) # NAME - required /cgx
Truth table100%3/3
A and B
A= $call_type == 1B= $input_line =~ /\G\s* ((?:\w*(?:'|::))*) # package - something that ends in :: or ' (\w+) # NAME - required /cgx
ABresult
0X0
100
111
10040 $call_type == SUB_CALL
10041 && $input_line =~ m{\G\s*
10042 ((?:\w*(?:'|::))*) # package - something that ends in :: or '
10043 (\w+) # NAME - required
10044 }gcx
10045 )
10046 {
10047 176 $match = 1;
10048 176 $subname = $2;
10049 my $is_lexical_sub = $last_nonblank_type eq 'k'
10050 176 ▶ && $is_my_our_state{$last_nonblank_token};
Condition33%1/3
$last_nonblank_type eq 'k' && $is_my_our_state{$last_nonblank_token}
!ll&&!rl&&r
17600
MC/DC0%0/2
$last_nonblank_type eq 'k' && $is_my_our_state{$last_nonblank_token}
$last_nonblank_type eq 'k' $is_my_our_state{$last_nonblank_token}
Truth table33%1/3
A && B
A= $last_nonblank_type eq 'k'B= $is_my_our_state{$last_nonblank_token}
ABresult
0X0
100
111
10051 176 ▶ if ( $is_lexical_sub && $1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_lexical_sub and $1) 0 176 176
Condition33%1/3
$is_lexical_sub and $1
!ll&&!rl&&r
17600
MC/DC0%0/2
$is_lexical_sub and $1
$is_lexical_sub $1
Truth table33%1/3
A and B
A= $is_lexical_subB= $1
ABresult
0X0
100
111
10052 0 $self->warning(
10053 "'$last_nonblank_token' sub $subname cannot be in package '$1'\n"
10054 );
10055 0 $is_lexical_sub = 0;
10056 }
10057  
10058 176 ▶ if ($is_lexical_sub) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_lexical_sub) { } 0 176 176
10059  
10060 # Lexical subs use the containing block sequence number as a
10061 # package name.
10062 0 my $seqno =
10063 $rcurrent_sequence_number->[BRACE]
10064 ->[ $rcurrent_depth->[BRACE] ];
10065 0 ▶ $seqno = SEQ_ROOT if ( !defined($seqno) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seqno 0 0 0
10066 0 $package = $seqno;
10067  
10068 # The value will eventually be the sequence number of the
10069 # opening curly brace of the definition (if any). We use -1
10070 # until we find it.
10071 0 $ris_lexical_sub->{$subname}->{$package} = -1;
10072  
10073 # Set a special signal to tell sub do_LEFT_CURLY_BRACKET to
10074 # update this value if the next opening sub block brace is for
10075 # this sub. The reason we need this value is to avoid applying
10076 # this new sub in its own definition block. Note that '911' is
10077 # not a possible sub name. Search for '911' for related code.
10078 0 $ris_lexical_sub->{911} = [ $subname, $package ];
10079  
10080 # Complain if lexical sub name hides a quote operator
10081 0 ▶ if ( $is_q_qq_qw_qx_qr_s_y_tr_m{$subname} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_q_qq_qw_qx_qr_s_y_tr_m{$subname}) 0 0 0
10082 0 $self->complain(
10083 "'my' sub '$subname' matches a builtin quote operator\n"
10084 );
10085 ## OLD CODING, before improved handling of lexical subs:
10086 ## This may end badly, it is safest to avoid formatting.
10087 ## For an example, see perl527/lexsub.t (issue c203)
10088 ## $self->[_do_not_format_] = 1;
10089 }
10090 }
10091 else {
10092 176 ▶ $package = ( defined($1) && $1 ) ? $1 : $current_package;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 && $1 ? : 6 170 176
Condition66%2/3
defined $1 and $1
!ll&&!rl&&r
01706
MC/DC50%1/2
defined $1 and $1
defined $1 $1
Truth table66%2/3
A and B
A= defined $1B= $1
ABresult
0X0
100
111
10093 176 $package =~ s/\'/::/g;
10094 176 ▶ if ( $package =~ /^\:/ ) { $package = 'main' . $package }
Branch: 1 branch
BranchTrueFalseTotal
if ($package =~ /^\:/) 0 176 176
10095 176 $package =~ s/::$//;
10096 }
10097  
10098 176 my $pos = pos($input_line);
10099 176 my $numc = $pos - $pos_beg;
10100 176 $tok = 'sub ' . $id_prefix . substr( $input_line, $pos_beg, $numc );
10101 176 $type = 'S'; ## Fix for c250, was 'i';
10102  
10103 # remember the sub name in case another call is needed to
10104 # get the prototype
10105 176 $package_saved = $package;
10106 176 $subname_saved = $subname;
10107 }
10108  
10109 # Now look for PROTO ATTRS for all call types
10110 # Look for prototype/attributes which are usually on the same
10111 # line as the sub name but which might be on a separate line.
10112 # For example, we might have an anonymous sub with attributes,
10113 # or a prototype on a separate line from its sub name
10114  
10115 # NOTE: We only want to parse PROTOTYPES here. If we see anything that
10116 # does not look like a prototype, we assume it is a SIGNATURE and we
10117 # will stop and let the standard tokenizer handle it. In
10118 # particular, we stop if we see any nested parens, braces, or commas.
10119 # Also note, a valid prototype cannot contain any alphabetic character
10120 # -- see https://perldoc.perl.org/perlsub
10121 # But it appears that an underscore is valid in a prototype, so the
10122 # regex below uses [A-Za-z] rather than \w
10123 # This is the old regex which has been replaced:
10124 # $input_line =~ m/\G(\s*\([^\)\(\}\{\,#]*\))? # PROTO
10125 # Added '=' for issue c362
10126 371 my $saw_opening_paren = $input_line =~ /\G\s*\(/;
10127 371 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /\G(\s*\([^\)\(\}\{\,#A-Za-z=]*\))? # PROTO (\s*:)? # ATTRS leading ':' /cgx and $1 || $2) 45 326 371
Condition83%5/6
$input_line =~ /\G(\s*\([^\)\(\}\{\,#A-Za-z=]*\))? # PROTO and $1 || $2
!ll&&!rl&&r
035912
$1 or $2
l!l&&r!l&&!r
3411326
MC/DC33%1/3
$input_line =~ /\G(\s*\([^\)\(\}\{\,#A-Za-z=]*\))? # PROTO (\s*:)? # ATTRS leading ':' /cgx and $1 || $2
$input_line =~ /\G(\s*\([^\)\(\}\{\,#A-Za-z=]*\))? # PROTO (\s*:)? # ATTRS leading ':' /cgx $1 $2
Truth table50%2/4
A and B or C
A= $input_line =~ /\G(\s*\([^\)\(\}\{\,#A-Za-z=]*\))? # PROTO (\s*:)? # ATTRS leading ':' /cgxB= $1C= $2
ABCresult
0XX0
1000
11X1
1011
10128 $input_line =~ m{\G(\s*\([^\)\(\}\{\,#A-Za-z=]*\))? # PROTO
10129 (\s*:)? # ATTRS leading ':'
10130 }gcx
10131 && ( $1 || $2 )
10132 )
10133 {
10134 45 $proto = $1;
10135 45 $attrs = $2;
10136  
10137 # Append the prototype to the starting token if it is 'sub' or
10138 # 'prototype'. This is not necessary but for compatibility with
10139 # previous versions when the -csc flag is used:
10140 45 ▶ if ( $proto && ( $match || $call_type == PROTOTYPE_CALL ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($proto and $match || $call_type == 3) { } 24 21 45
elsif ($call_type == 2) { } 2 19 21
Condition100%6/6
$proto and $match || $call_type == 3
!ll&&!rl&&r
111024
$match or $call_type == 3
l!l&&r!l&&!r
22210
MC/DC100%3/3
$proto and $match || $call_type == 3
$proto $match $call_type == 3
Truth table100%4/4
A and B or C
A= $protoB= $matchC= $call_type == 3
ABCresult
0XX0
1000
11X1
1011
10141 24 $tok .= $proto;
10142 }
10143  
10144 # If we just entered the sub at an opening paren on this call, not
10145 # a following :prototype, label it with the previous token. This is
10146 # necessary to propagate the sub name to its opening block.
10147 elsif ( $call_type == PAREN_CALL ) {
10148 2 $tok = $last_nonblank_token;
10149 }
10150 else {
10151 ##
10152 }
10153  
10154 45 ▶ $match ||= 1;
Condition100%2/2
$match ||= 1
l!l
3015
MC/DC100%1/1
$match ||= 1
$match
Truth table100%2/2
A
A= $match
Aresult
11
00
10155  
10156 # Patch part #1 to fixes cases b994 and b1053:
10157 # Mark an anonymous sub keyword without prototype as type 'k', i.e.
10158 # 'sub : lvalue { ...'
10159 45 $type = 'S'; ## C250, was 'i';
10160 45 ▶ if ( $tok eq 'sub' && !$proto ) { $type = 'k' }
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "sub" and not $proto) 2 43 45
Condition100%3/3
$tok eq "sub" and not $proto
!ll&&!rl&&r
3492
MC/DC100%2/2
$tok eq "sub" and not $proto
$tok eq "sub" not $proto
Truth table100%3/3
A and not(B)
A= $tok eq "sub"B= not $proto
ABresult
0X0
100
111
10161 }
10162  
10163 371 ▶ if ($match) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match) { } 191 180 371
10164  
10165 # ATTRS: if there are attributes, back up and let the ':' be
10166 # found later by the scanner.
10167 191 my $pos = pos($input_line);
10168 191 ▶ if ($attrs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrs) 15 176 191
10169 15 $pos -= length($attrs);
10170 }
10171  
10172 191 my $next_nonblank_token = $tok;
10173  
10174 # catch case of line with leading ATTR ':' after anonymous sub
10175 191 ▶ if ( $pos == $pos_beg && $tok eq ':' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos == $pos_beg and $tok eq ':') { } 1 190 191
Condition100%3/3
$pos == $pos_beg and $tok eq ":"
!ll&&!rl&&r
18821
MC/DC100%2/2
$pos == $pos_beg and $tok eq ":"
$pos == $pos_beg $tok eq ":"
Truth table100%3/3
A and B
A= $pos == $pos_begB= $tok eq ":"
ABresult
0X0
100
111
10176 1 $type = 'A';
10177 1 $self->[_in_attribute_list_] = 1;
10178 }
10179  
10180 # Otherwise, if we found a match we must convert back from
10181 # string position to the pre_token index for continued parsing.
10182 else {
10183  
10184 # I don't think an error flag can occur here ..but ?
10185 190 my $error;
10186 190 ( $i, $error ) = inverse_pretoken_map( $i, $pos, $rtoken_map,
10187 $max_token_index );
10188 190 ▶ if ($error) { $self->warning("Possibly invalid sub\n") }
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 190 190
10189  
10190 # Patch part #2 to fixes cases b994 and b1053:
10191 # Do not let spaces be part of the token of an anonymous sub
10192 # keyword which we marked as type 'k' above...i.e. for
10193 # something like:
10194 # 'sub : lvalue { ...'
10195 # Back up and let it be parsed as a blank
10196 190 ▶ if ( $type eq 'k'
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "k" and $attrs and $i > $i_entry and substr($rtokens->[$i], 0, 1) =~ /\s/) 2 188 190
Condition66%6/9
$type eq "k" and $attrs and $i > $i_entry and substr($rtokens->[$i], 0, 1) =~ /\s/
!ll&&!rl&&r
18802
$type eq "k" and $attrs and $i > $i_entry
!ll&&!rl&&r
18802
$type eq "k" and $attrs
!ll&&!rl&&r
18802
MC/DC25%1/4
$type eq "k" and $attrs and $i > $i_entry and substr($rtokens->[$i], 0, 1) =~ /\s/
$type eq "k" $attrs $i > $i_entry substr($rtokens->[$i], 0, 1) =~ /\s/
Truth table40%2/5
A and B and C and D
A= $type eq "k"B= $attrsC= $i > $i_entryD= substr($rtokens->[$i], 0, 1) =~ /\s/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
10197 && $attrs
10198 && $i > $i_entry
10199 && substr( $rtokens->[$i], 0, 1 ) =~ m/\s/ )
10200 {
10201 2 $i--;
10202 }
10203  
10204 # check for multiple definitions of a sub
10205 190 ( $next_nonblank_token, my $i_next_uu ) =
10206 find_next_nonblank_token_on_this_line( $i, $rtokens,
10207 $max_token_index );
10208 }
10209  
10210 191 ▶ if ( $next_nonblank_token =~ /^(\s*|#)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token =~ /^(\s*|#)$/) 7 184 191
10211 { # skip blank or side comment
10212 7 my ( $rpre_tokens, $rpre_types_uu ) =
10213 $self->peek_ahead_for_n_nonblank_pre_tokens(1);
10214 7 ▶ if ( defined($rpre_tokens) && @{$rpre_tokens} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rpre_tokens and @{$rpre_tokens;}) { } 7 0 7
Condition33%1/3
defined $rpre_tokens and @{$rpre_tokens;}
!ll&&!rl&&r
007
MC/DC0%0/2
defined $rpre_tokens and @{$rpre_tokens;}
defined $rpre_tokens @{$rpre_tokens;}
Truth table33%1/3
A and B
A= defined $rpre_tokensB= @{$rpre_tokens;}
ABresult
0X0
100
111
10215 7 $next_nonblank_token = $rpre_tokens->[0];
10216 }
10217 else {
10218 0 $next_nonblank_token = '}';
10219 }
10220 }
10221  
10222 # See what's next...
10223 191 ▶ if ( $next_nonblank_token eq '{' ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($next_nonblank_token eq '{') { } 153 38 191
elsif ($next_nonblank_token eq ';') { } 1 37 38
elsif ($next_nonblank_token eq '}') { } 0 37 37
elsif ($next_nonblank_token eq ':') { } 16 21 37
elsif ($next_nonblank_token eq '(') { } 21 0 21
elsif ($next_nonblank_token) { } 0 0 0
10224 153 ▶ if ($subname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subname) 143 10 153
10225  
10226 # Check for multiple definitions of a sub, but
10227 # it is ok to have multiple sub BEGIN, etc,
10228 # so we do not complain if name is all caps
10229 143 ▶ if ( $rsaw_function_definition->{$subname}->{$package}
Branch: 1 branch
BranchTrueFalseTotal
if ($rsaw_function_definition->{$subname}{$package} and not $subname =~ /^[A-Z]+$/) 0 143 143
Condition33%1/3
$rsaw_function_definition->{$subname}{$package} and not $subname =~ /^[A-Z]+$/
!ll&&!rl&&r
14300
MC/DC0%0/2
$rsaw_function_definition->{$subname}{$package} and not $subname =~ /^[A-Z]+$/
$rsaw_function_definition->{$subname}{$package} not $subname =~ /^[A-Z]+$/
Truth table33%1/3
A and not(B)
A= $rsaw_function_definition->{$subname}{$package}B= not $subname =~ /^[A-Z]+$/
ABresult
0X0
100
111
10230 && $subname !~ /^[A-Z]+$/ )
10231 {
10232 my $lno =
10233 0 $rsaw_function_definition->{$subname}->{$package};
10234 0 ▶ if ( $package =~ /^\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package =~ /^\d/) { } 0 0 0
10235 0 $self->warning(
10236 "already saw definition of lexical 'sub $subname' at line $lno\n"
10237 );
10238  
10239 }
10240 else {
10241 0 if ( !DEVEL_MODE ) {
10242 0 $self->warning(
10243 "already saw definition of 'sub $subname' in package '$package' at line $lno\n"
10244 );
10245 }
10246 }
10247 }
10248 143 $rsaw_function_definition->{$subname}->{$package} =
10249 $self->[_last_line_number_];
10250 }
10251 }
10252 elsif ( $next_nonblank_token eq ';' ) {
10253 }
10254 elsif ( $next_nonblank_token eq '}' ) {
10255 }
10256  
10257 # ATTRS - if an attribute list follows, remember the name
10258 # of the sub so the next opening brace can be labeled.
10259 # Setting 'statement_type' causes any ':'s to introduce
10260 # attributes.
10261 elsif ( $next_nonblank_token eq ':' ) {
10262 16 ▶ if ( $call_type == SUB_CALL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call_type == 1) 14 2 16
10263 14 ▶ $statement_type =
Branch: 1 branch
BranchTrueFalseTotal
substr($tok, 0, 3) eq 'sub' ? : 13 1 14
10264 substr( $tok, 0, 3 ) eq 'sub' ? $tok : 'sub';
10265 }
10266 }
10267  
10268 # if we stopped before an open paren ...
10269 elsif ( $next_nonblank_token eq '(' ) {
10270  
10271 # If we DID NOT see this paren above then it must be on the
10272 # next line so we will set a flag to come back here and see if
10273 # it is a PROTOTYPE
10274  
10275 # Otherwise, we assume it is a SIGNATURE rather than a
10276 # PROTOTYPE and let the normal tokenizer handle it as a list
10277 21 ▶ if ( !$saw_opening_paren ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($saw_opening_paren) 4 17 21
10278 4 $id_scan_state = 'sub'; # we must come back to get proto
10279 }
10280 21 ▶ if ( $call_type == SUB_CALL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call_type == 1) 21 0 21
10281 21 ▶ $statement_type =
Branch: 1 branch
BranchTrueFalseTotal
substr($tok, 0, 3) eq 'sub' ? : 21 0 21
10282 substr( $tok, 0, 3 ) eq 'sub' ? $tok : 'sub';
10283 }
10284 }
10285  
10286 # something else..
10287 elsif ($next_nonblank_token) {
10288  
10289 0 ▶ if ( $rcall_hash->{tok} eq 'method' && $call_type == SUB_CALL )
Branch: 1 branch
BranchTrueFalseTotal
if ($rcall_hash->{'tok'} eq 'method' and $call_type == 1) { } 0 0 0
Condition0%0/3
$rcall_hash->{"tok"} eq "method" and $call_type == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$rcall_hash->{"tok"} eq "method" and $call_type == 1
$rcall_hash->{"tok"} eq "method" $call_type == 1
Truth table0%0/3
A and B
A= $rcall_hash->{"tok"} eq "method"B= $call_type == 1
ABresult
0X0
100
111
10290 {
10291 # For a method call, silently ignore this error (rt145706)
10292 # to avoid needless warnings. Example which can produce it:
10293 # test(method Pack (), "method");
10294  
10295 # TODO: scan for use feature 'class' and:
10296 # - if we saw 'use feature 'class' then issue the warning.
10297 # - if we did not see use feature 'class' then issue the
10298 # warning and suggest turning off --use-feature=class
10299 }
10300 else {
10301 0 ▶ $subname = EMPTY_STRING unless ( defined($subname) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $subname 0 0 0
10302 0 $self->warning(
10303 "expecting ':' or ';' or '{' after definition or declaration of sub '$subname' but saw '$next_nonblank_token'\n"
10304 );
10305 }
10306 }
10307 else {
10308 ## EOF technically ok
10309 }
10310  
10311 191 check_prototype( $proto, $package, $subname );
10312 }
10313  
10314 # no match to either sub name or prototype, but line not blank
10315 else {
10316 ##
10317 }
10318 371 return ( $i, $tok, $type, $id_scan_state );
10319 } ## end sub do_scan_sub
10320 }
10321  
10322 #########################################################################
10323 # Tokenizer utility routines which may use CONSTANTS but no other GLOBALS
10324 #########################################################################
10325  
10326 45 sub find_next_nonblank_token {
10327 470 ▶ my ( $self, $i, $rtokens, $max_token_index ) = @_;
Subroutine find_next_nonblank_token: called CC=13 SCAR=27.5
Pod undocumented
10328  
10329 # Returns the next nonblank token after the token at index $i
10330 # To skip past a side comment, and any subsequent block comments
10331 # and blank lines, call with i=$max_token_index
10332  
10333 # Skip any ending blank (fix c258). It would be cleaner if caller passed
10334 # $rtoken_map, so we could check for type 'b', and avoid a regex test, but
10335 # benchmarking shows that this test does not take significant time. So
10336 # that would be a nice update but not essential. Also note that ending
10337 # blanks will not occur for text previously processed by perltidy.
10338 470 ▶ if ( $i == $max_token_index - 1
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $max_token_index - 1 and $rtokens->[$max_token_index] =~ /^\s+$/) 9 461 470
Condition100%3/3
$i == $max_token_index - 1 and $rtokens->[$max_token_index] =~ /^\s+$/
!ll&&!rl&&r
396659
MC/DC100%2/2
$i == $max_token_index - 1 and $rtokens->[$max_token_index] =~ /^\s+$/
$i == $max_token_index - 1 $rtokens->[$max_token_index] =~ /^\s+$/
Truth table100%3/3
A and B
A= $i == $max_token_index - 1B= $rtokens->[$max_token_index] =~ /^\s+$/
ABresult
0X0
100
111
10339 && $rtokens->[$max_token_index] =~ /^\s+$/ )
10340 {
10341 9 $i++;
10342 }
10343  
10344 470 ▶ if ( $i >= $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $max_token_index) 145 325 470
10345 145 ▶ if ( !peeked_ahead() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (peeked_ahead()) 143 2 145
10346 143 peeked_ahead(1);
10347 143 $self->peek_ahead_for_nonblank_token( $rtokens, $max_token_index );
10348 }
10349 }
10350  
10351 470 my $next_nonblank_token = $rtokens->[ ++$i ];
10352  
10353 # Any more tokens?
10354 470 ▶ return ( SPACE, $i )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next_nonblank_token and length $next_nonblank_token 0 470 470
Condition33%1/3
defined $next_nonblank_token and length $next_nonblank_token
!ll&&!rl&&r
00470
MC/DC0%0/2
defined $next_nonblank_token and length $next_nonblank_token
defined $next_nonblank_token length $next_nonblank_token
Truth table33%1/3
A and B
A= defined $next_nonblank_tokenB= length $next_nonblank_token
ABresult
0X0
100
111
10355 if ( !defined($next_nonblank_token) || !length($next_nonblank_token) );
10356  
10357 # Skip over whitespace
10358 470 my $ord = ord( substr( $next_nonblank_token, 0, 1 ) );
10359 470 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($ord <= 33 || $ord >= 126 and $ord == 32 || $ord == 9 || $next_nonblank_token =~ /^\s+$/) 0 161 161
Condition50%6/12
$ord <= 33 || $ord >= 126 and $ord == 32 || $ord == 9 || $next_nonblank_token =~ /^\s+$/
!ll&&!rl&&r
1613090
$ord <= 33 or $ord >= 126
l!l&&r!l&&!r
3090161
$ord == 32 or $ord == 9 or $next_nonblank_token =~ /^\s+$/
l!l&&r!l&&!r
30900
$ord == 32 or $ord == 9
l!l&&r!l&&!r
30900
MC/DC0%0/5
$ord <= 33 || $ord >= 126 and $ord == 32 || $ord == 9 || $next_nonblank_token =~ /^\s+$/
$ord <= 33 $ord >= 126 $ord == 32 $ord == 9 $next_nonblank_token =~ /^\s+$/
Truth table11%1/9
A or B and C or D or E
A= $ord <= 33B= $ord >= 126C= $ord == 32D= $ord == 9E= $next_nonblank_token =~ /^\s+$/
ABCDEresult
00XXX0
1X0000
010000
1X1XX1
1X01X1
1X0011
011XX1
0101X1
010011
10360  
10361 ( $ord <= ORD_PRINTABLE_MIN || $ord >= ORD_PRINTABLE_MAX )
10362  
10363 # Quick test for ascii space or tab
10364 && (
10365 ( $ord == ORD_SPACE || $ord == ORD_TAB )
10366  
10367 # Slow test to for something else identified as whitespace
10368 || $next_nonblank_token =~ /^\s+$/
10369 )
10370 )
10371 {
10372 309 $next_nonblank_token = $rtokens->[ ++$i ];
10373 309 ▶ return ( SPACE, $i ) unless ( defined($next_nonblank_token) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next_nonblank_token 0 309 309
10374 }
10375  
10376 # We should be at a nonblank now
10377 470 return ( $next_nonblank_token, $i );
10378  
10379 } ## end sub find_next_nonblank_token
10380  
10381 sub find_next_noncomment_token {
10382 110 ▶ my ( $self, $i, $rtokens, $max_token_index ) = @_;
Subroutine find_next_noncomment_token: called CC=8 SCAR=23.9
Pod undocumented
10383  
10384 # Given the current character position, look ahead past any comments
10385 # and blank lines and return the next token, including digraphs and
10386 # trigraphs.
10387  
10388 110 my ( $next_nonblank_token, $i_next ) =
10389 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
10390  
10391 # skip past any side comment
10392 110 ▶ if ( $next_nonblank_token eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "#") 0 110 110
10393 0 ( $next_nonblank_token, $i_next ) =
10394 $self->find_next_nonblank_token( $i_next, $rtokens,
10395 $max_token_index );
10396 }
10397  
10398 # check for a digraph
10399 110 ▶ if ( $next_nonblank_token
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token and $next_nonblank_token ne " " and defined $$rtokens[$i_next + 1]) 110 0 110
Condition33%2/6
$next_nonblank_token and $next_nonblank_token ne " " and defined $$rtokens[$i_next + 1]
!ll&&!rl&&r
00110
$next_nonblank_token and $next_nonblank_token ne " "
!ll&&!rl&&r
00110
MC/DC0%0/3
$next_nonblank_token and $next_nonblank_token ne " " and defined $$rtokens[$i_next + 1]
$next_nonblank_token $next_nonblank_token ne " " defined $$rtokens[$i_next + 1]
Truth table25%1/4
A and B and C
A= $next_nonblank_tokenB= $next_nonblank_token ne " "C= defined $$rtokens[$i_next + 1]
ABCresult
0XX0
10X0
1100
1111
10400 && $next_nonblank_token ne SPACE
10401 && defined( $rtokens->[ $i_next + 1 ] ) )
10402 {
10403 110 my $test2 = $next_nonblank_token . $rtokens->[ $i_next + 1 ];
10404 110 ▶ if ( $is_digraph{$test2} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_digraph{$test2}) 17 93 110
10405 17 $next_nonblank_token = $test2;
10406 17 $i_next = $i_next + 1;
10407  
10408 # check for a trigraph
10409 17 ▶ if ( defined( $rtokens->[ $i_next + 1 ] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$rtokens[$i_next + 1]) 17 0 17
10410 17 my $test3 = $next_nonblank_token . $rtokens->[ $i_next + 1 ];
10411 17 ▶ if ( $is_trigraph{$test3} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_trigraph{$test3}) 0 17 17
10412 0 $next_nonblank_token = $test3;
10413 0 $i_next = $i_next + 1;
10414 }
10415 }
10416 }
10417 }
10418  
10419 110 return ( $next_nonblank_token, $i_next );
10420 } ## end sub find_next_noncomment_token
10421  
10422 sub is_possible_numerator {
10423  
10424 0 ▶ my ( $self, $i, $rtokens, $max_token_index ) = @_;
Subroutine is_possible_numerator: not called CC=10 SCAR=47.0
Pod undocumented
10425  
10426 # Look at the next non-comment character and decide if it could be a
10427 # numerator. Returns the following code:
10428 # -1 - division not possible
10429 # 0 - can't tell if division possible
10430 # 1 - division possible
10431 # 2 - division probable: number follows
10432 # 3 - division very probable: number and one of ; ] } follow
10433 # 4 - is division, not pattern: number and ) follow
10434  
10435 0 my $divide_possible_code = 0;
10436  
10437 0 my $next_token = $rtokens->[ $i + 1 ];
10438 0 ▶ if ( $next_token eq '=' ) { $i++; } # handle /=
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token eq "=") 0 0 0
10439 0 my ( $next_nonblank_token, $i_next ) =
10440 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
10441  
10442 0 ▶ if ( $next_nonblank_token eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "#") 0 0 0
10443 0 ( $next_nonblank_token, $i_next ) =
10444 $self->find_next_nonblank_token( $max_token_index, $rtokens,
10445 $max_token_index );
10446 }
10447  
10448 0 ▶ if ( $next_nonblank_token =~ / [ \( \$ \w \. \@ ] /x ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($next_nonblank_token =~ / [ \( \$ \w \. \@ ] /x) { } 0 0 0
elsif ($next_nonblank_token =~ /^\s*$/) { } 0 0 0
10449 0 $divide_possible_code = 1;
10450  
10451 # look ahead one more token for some common patterns, such as
10452 # pi/2) pi/2; pi/2}
10453 0 ▶ if ( $next_nonblank_token =~ /^\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token =~ /^\d/) 0 0 0
10454 0 my ( $next_next_nonblank_token, $i_next_next_uu ) =
10455 $self->find_next_nonblank_token( $i_next, $rtokens,
10456 $max_token_index );
10457 0 ▶ if ( $next_next_nonblank_token eq ')' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($next_next_nonblank_token eq ')') { } 0 0 0
elsif ($next_next_nonblank_token eq ';' or $next_next_nonblank_token eq ']' or $next_next_nonblank_token eq '}') { } 0 0 0
10458 0 $divide_possible_code = 4;
10459 }
10460 ▶ elsif ($next_next_nonblank_token eq ';'
Condition0%0/6
$next_next_nonblank_token eq ";" or $next_next_nonblank_token eq "]" or $next_next_nonblank_token eq "}"
l!l&&r!l&&!r
000
$next_next_nonblank_token eq ";" or $next_next_nonblank_token eq "]"
l!l&&r!l&&!r
000
MC/DC0%0/3
$next_next_nonblank_token eq ";" or $next_next_nonblank_token eq "]" or $next_next_nonblank_token eq "}"
$next_next_nonblank_token eq ";" $next_next_nonblank_token eq "]" $next_next_nonblank_token eq "}"
Truth table0%0/4
A or B or C
A= $next_next_nonblank_token eq ";"B= $next_next_nonblank_token eq "]"C= $next_next_nonblank_token eq "}"
ABCresult
1XX1
01X1
0011
0000
10461 || $next_next_nonblank_token eq ']'
10462 || $next_next_nonblank_token eq '}' )
10463 {
10464 0 $divide_possible_code = 3;
10465 }
10466 else {
10467 0 $divide_possible_code = 2;
10468 }
10469 }
10470 }
10471 elsif ( $next_nonblank_token =~ /^\s*$/ ) {
10472 0 $divide_possible_code = 0;
10473 }
10474 else {
10475 0 $divide_possible_code = -1;
10476 }
10477  
10478 0 return $divide_possible_code;
10479 } ## end sub is_possible_numerator
10480  
10481 { ## closure for sub pattern_expected
10482 45 my %pattern_test;
10483  
10484 BEGIN {
10485  
10486 # List of tokens which may follow a pattern. Note that we will not
10487 # have formed digraphs at this point, so we will see '&' instead of
10488 # '&&' and '|' instead of '||'
10489  
10490 # /(\)|\}|\;|\&\&|\|\||and|or|while|if|unless)/
10491 45 ▶ my @q = qw( & && | || ? : + - * and or while if unless );
Subroutine BEGIN: called CC=2 SCAR=6.9
10492 45 push @q, ')', '}', ']', '>', COMMA, ';';
10493 45 $pattern_test{$_} = 1 for @q;
10494 } ## end BEGIN
10495  
10496 sub pattern_expected {
10497  
10498 0 ▶ my ( $self, $i, $rtokens, $max_token_index ) = @_;
Subroutine pattern_expected: not called CC=5 SCAR=34.0
Pod undocumented
10499  
10500 # This a filter for a possible pattern.
10501 # It looks at the token after a possible pattern and tries to
10502 # determine if that token could end a pattern.
10503 # returns -
10504 # 1 - yes
10505 # 0 - can't tell
10506 # -1 - no
10507 0 my $is_pattern = 0;
10508  
10509 0 my $next_token = $rtokens->[ $i + 1 ];
10510  
10511 # skip a possible quote modifier
10512 0 my $possible_modifiers = $quote_modifiers{'m'};
10513 0 ▶ if ( $next_token =~ /^$possible_modifiers/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token =~ /^$possible_modifiers/) 0 0 0
10514 0 $i++;
10515 }
10516  
10517 0 my ( $next_nonblank_token, $i_next_uu ) =
10518 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
10519  
10520 0 ▶ if ( $pattern_test{$next_nonblank_token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern_test{$next_nonblank_token}) { } 0 0 0
10521 0 $is_pattern = 1;
10522 }
10523 else {
10524  
10525 # Added '#' to fix issue c044
10526 0 ▶ if ( $next_nonblank_token =~ /^\s*$/
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token =~ /^\s*$/ or $next_nonblank_token eq '#') { } 0 0 0
Condition0%0/3
$next_nonblank_token =~ /^\s*$/ or $next_nonblank_token eq "#"
l!l&&r!l&&!r
000
MC/DC0%0/2
$next_nonblank_token =~ /^\s*$/ or $next_nonblank_token eq "#"
$next_nonblank_token =~ /^\s*$/ $next_nonblank_token eq "#"
Truth table0%0/3
A or B
A= $next_nonblank_token =~ /^\s*$/B= $next_nonblank_token eq "#"
ABresult
1X1
011
000
10527 || $next_nonblank_token eq '#' )
10528 {
10529 0 $is_pattern = 0;
10530 }
10531 else {
10532 0 $is_pattern = -1;
10533 }
10534 }
10535 0 return $is_pattern;
10536 } ## end sub pattern_expected
10537 }
10538  
10539 45 sub find_next_nonblank_token_on_this_line {
10540 647 ▶ my ( $i, $rtokens, $max_token_index ) = @_;
Subroutine find_next_nonblank_token_on_this_line: called CC=4 SCAR=13.9
Pod undocumented
10541 647 my $next_nonblank_token;
10542  
10543 647 ▶ if ( $i < $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $max_token_index) { } 639 8 647
10544 639 $next_nonblank_token = $rtokens->[ ++$i ];
10545  
10546 639 ▶ if ( $next_nonblank_token =~ /^\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token =~ /^\s*$/) 188 451 639
10547  
10548 188 ▶ if ( $i < $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $max_token_index) 186 2 188
10549 186 $next_nonblank_token = $rtokens->[ ++$i ];
10550 }
10551 }
10552 }
10553 else {
10554 8 $next_nonblank_token = EMPTY_STRING;
10555 }
10556 647 return ( $next_nonblank_token, $i );
10557 } ## end sub find_next_nonblank_token_on_this_line
10558  
10559 sub find_angle_operator_termination {
10560  
10561 8 ▶ my ( $self, $input_line, $i_beg, $rtoken_map, $expecting, $max_token_index )
Subroutine find_angle_operator_termination: called CC=29 SCAR=47.8
Pod undocumented
10562 = @_;
10563  
10564 # We are looking at a '<' and want to know if it is an angle operator.
10565 # Return:
10566 # $i = pretoken index of ending '>' if found, current $i otherwise
10567 # $type = 'Q' if found, '>' otherwise
10568  
10569 8 my $i = $i_beg;
10570 8 my $type = '<';
10571 8 pos($input_line) = 1 + $rtoken_map->[$i];
10572  
10573 # The token sequence '><' implies a markup language
10574 8 ▶ if ( $last_nonblank_token eq '>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_token eq ">") 0 8 8
10575 0 $self->[_html_tag_count_]++;
10576 }
10577  
10578 8 my $filter;
10579  
10580 8 my $expecting_TERM = $expecting == TERM;
10581  
10582 # we just have to find the next '>' if a term is expected
10583 8 ▶ if ($expecting_TERM) { $filter = '[\>]' }
Branch: 2 branches
BranchTrueFalseTotal
if ($expecting_TERM) { } 6 2 8
elsif ($expecting == 0) { } 2 0 2
10584  
10585 # we have to guess if we don't know what is expected
10586 2 elsif ( $expecting == UNKNOWN ) { $filter = '[\>\;\=\#\|\<]' }
10587  
10588 # shouldn't happen - we shouldn't be here if operator is expected
10589 else {
10590 0 if (DEVEL_MODE) {
10591 Fault(<<EOM);
10592 Bad call to find_angle_operator_termination
10593 EOM
10594 }
10595 0 return ( $i, $type );
10596 }
10597  
10598 # To illustrate what we might be looking at, in case we are
10599 # guessing, here are some examples of valid angle operators
10600 # (or file globs):
10601 # <tmp_imp/*>
10602 # <FH>
10603 # <$fh>
10604 # <*.c *.h>
10605 # <_>
10606 # <jskdfjskdfj* op/* jskdjfjkosvk*> ( glob.t)
10607 # <${PREFIX}*img*.$IMAGE_TYPE>
10608 # <img*.$IMAGE_TYPE>
10609 # <Timg*.$IMAGE_TYPE>
10610 # <$LATEX2HTMLVERSIONS${dd}html[1-9].[0-9].pl>
10611 #
10612 # Here are some examples of lines which do not have angle operators:
10613 # return unless $self->[2]++ < $#{$self->[1]};
10614 # < 2 || @$t >
10615 #
10616 # the following line from dlister.pl caused trouble:
10617 # print'~'x79,"\n",$D<1024?"0.$D":$D>>10,"K, $C files\n\n\n";
10618 #
10619 # If the '<' starts an angle operator, it must end on this line and
10620 # it must not have certain characters like ';' and '=' in it. I use
10621 # this to limit the testing. This filter should be improved if
10622 # possible.
10623  
10624 8 ▶ if ( $input_line =~ /($filter)/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /($filter)/g) 8 0 8
10625  
10626 8 ▶ if ( $1 eq '>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq '>') { } 8 0 8
10627  
10628 # We MAY have found an angle operator termination if we get
10629 # here, but we need to do more to be sure we haven't been
10630 # fooled.
10631 8 my $pos = pos($input_line);
10632  
10633 8 my $pos_beg = $rtoken_map->[$i];
10634 8 my $str = substr( $input_line, $pos_beg, ( $pos - $pos_beg ) );
10635  
10636 # Test for '<' after possible filehandle, issue c103
10637 # print $fh <>; # syntax error
10638 # print $fh <DATA>; # ok
10639 # print $fh < DATA>; # syntax error at '>'
10640 # print STDERR < DATA>; # ok, prints word 'DATA'
10641 # print BLABLA <DATA>; # ok; does nothing unless BLABLA is defined
10642 8 ▶ if ( $last_nonblank_type eq 'Z' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq "Z") 1 7 8
10643  
10644 # $str includes brackets; something like '<DATA>'
10645 1 ▶ if ( substr( $last_nonblank_token, 0, 1 ) !~ /[A-Za-z_]/
Branch: 1 branch
BranchTrueFalseTotal
unless (substr($last_nonblank_token, 0, 1) =~ /[A-Za-z_]/ or substr($str, 1, 1) =~ /[A-Za-z_]/) 0 1 1
Condition33%1/3
substr($last_nonblank_token, 0, 1) =~ /[A-Za-z_]/ or substr($str, 1, 1) =~ /[A-Za-z_]/
l!l&&r!l&&!r
100
MC/DC0%0/2
substr($last_nonblank_token, 0, 1) =~ /[A-Za-z_]/ or substr($str, 1, 1) =~ /[A-Za-z_]/
substr($last_nonblank_token, 0, 1) =~ /[A-Za-z_]/ substr($str, 1, 1) =~ /[A-Za-z_]/
Truth table33%1/3
A or B
A= substr($last_nonblank_token, 0, 1) =~ /[A-Za-z_]/B= substr($str, 1, 1) =~ /[A-Za-z_]/
ABresult
1X1
011
000
10646 && substr( $str, 1, 1 ) !~ /[A-Za-z_]/ )
10647 {
10648 0 return ( $i, $type );
10649 }
10650 }
10651  
10652 # Reject if the closing '>' follows a '-' as in:
10653 # if ( VERSION < 5.009 && $op-> name eq 'assign' ) { }
10654 8 ▶ if ( $expecting eq UNKNOWN ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting eq 0) 2 6 8
10655 2 my $check = substr( $input_line, $pos - 2, 1 );
10656 2 ▶ if ( $check eq '-' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check eq "-") 1 1 2
10657 1 return ( $i, $type );
10658 }
10659 }
10660  
10661 ######################################debug#####
10662 #$self->write_diagnostics( "ANGLE? :$str\n");
10663 #print "ANGLE: found $1 at pos=$pos str=$str check=$check\n";
10664 ######################################debug#####
10665 7 $type = 'Q';
10666 7 my $error;
10667 7 ( $i, $error ) =
10668 inverse_pretoken_map( $i, $pos, $rtoken_map, $max_token_index );
10669  
10670 # It may be possible that a quote ends midway in a pretoken.
10671 # If this happens, it may be necessary to split the pretoken.
10672 7 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 7 7
10673 0 if (DEVEL_MODE) {
10674 Fault(<<EOM);
10675 unexpected error condition returned by inverse_pretoken_map
10676 EOM
10677 }
10678 $self->warning(
10679 0 "Possible tokenization error..please check this line\n");
10680 }
10681  
10682 # Check for accidental formatting of a markup language doc...
10683 # Formatting will be skipped if we set _html_tag_count_ and
10684 # also set a warning of any kind.
10685 7 my $is_html_tag;
10686 7 ▶ my $is_first_string =
Condition33%1/3
$i_beg == 0 && $self->[21] == 1
!ll&&!rl&&r
700
MC/DC0%0/2
$i_beg == 0 && $self->[21] == 1
$i_beg == 0 $self->[21] == 1
Truth table33%1/3
A && B
A= $i_beg == 0B= $self->[21] == 1
ABresult
0X0
100
111
10687 $i_beg == 0 && $self->[_last_line_number_] == 1;
10688  
10689 # html comment '<!...' of any type
10690 7 ▶ if ( $str =~ /^<\s*!/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($str =~ /^<\s*!/) { } 0 7 7
elsif ($str =~ m[^<\s*/\w+\s*>$]) { } 0 7 7
elsif ($str =~ /^<\?xml\s.*\?>$/i and $is_first_string) { } 0 7 7
10691 0 $is_html_tag = 1;
10692 0 ▶ if ($is_first_string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_first_string) 0 0 0
10693 0 $self->warning(
10694 "looks like a markup language, continuing error checks\n"
10695 );
10696 }
10697 }
10698  
10699 # html end tag, something like </h1>
10700 elsif ( $str =~ /^<\s*\/\w+\s*>$/ ) {
10701 0 $is_html_tag = 1;
10702 }
10703  
10704 # xml prolog?
10705 ▶ elsif ( $str =~ /^<\?xml\s.*\?>$/i && $is_first_string ) {
Condition33%1/3
$str =~ /^<\?xml\s.*\?>$/i and $is_first_string
!ll&&!rl&&r
700
MC/DC0%0/2
$str =~ /^<\?xml\s.*\?>$/i and $is_first_string
$str =~ /^<\?xml\s.*\?>$/i $is_first_string
Truth table33%1/3
A and B
A= $str =~ /^<\?xml\s.*\?>$/iB= $is_first_string
ABresult
0X0
100
111
10706 0 $is_html_tag = 1;
10707 0 $self->warning(
10708 "looks like a markup language, continuing error checks\n");
10709 }
10710 else {
10711 ## doesn't look like a markup tag
10712 }
10713  
10714 7 ▶ if ($is_html_tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_html_tag) 0 7 7
10715 0 $self->[_html_tag_count_]++;
10716 }
10717  
10718 # count blanks on inside of brackets
10719 7 my $blank_count = 0;
10720 7 ▶ $blank_count++ if ( $str =~ /<\s+/ );
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /<\s+/ 1 6 7
10721 7 ▶ $blank_count++ if ( $str =~ /\s+>/ );
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /\s+>/ 1 6 7
10722  
10723 # Now let's see where we stand....
10724 # OK if math op not possible
10725 7 ▶ if ($expecting_TERM) {
Branch: 4 branches
BranchTrueFalseTotal
if ($expecting_TERM) { } 6 1 7
elsif ($is_html_tag) { } 0 1 1
elsif ($i <= $i_beg + 3 + $blank_count) { } 1 0 1
elsif ($str =~ /^<\s*\$?(\w|::|\s)+\s*>$/) { } 0 0 0
10726 }
10727  
10728 elsif ($is_html_tag) {
10729 }
10730  
10731 # OK if there are no more than 2 non-blank pre-tokens inside
10732 # (not possible to write 2 token math between < and >)
10733 # This catches most common cases
10734 elsif ( $i <= $i_beg + 3 + $blank_count ) {
10735  
10736 # No longer any need to document this common case
10737 ## $self->write_diagnostics("ANGLE(1 or 2 tokens): $str\n");
10738 }
10739  
10740 # OK if there is some kind of identifier inside
10741 # print $fh <tvg::INPUT>;
10742 elsif ( $str =~ /^<\s*\$?(\w|::|\s)+\s*>$/ ) {
10743 0 $self->write_diagnostics("ANGLE (contains identifier): $str\n");
10744 }
10745  
10746 # Not sure..
10747 else {
10748  
10749 # Let's try a Brace Test: any braces inside must balance
10750 0 my $br = $str =~ tr/\{/{/ - $str =~ tr/\}/}/;
10751 0 my $sb = $str =~ tr/\[/[/ - $str =~ tr/\]/]/;
10752 0 my $pr = $str =~ tr/\(/(/ - $str =~ tr/\)/)/;
10753  
10754 # if braces do not balance - not angle operator
10755 0 ▶ if ( $br || $sb || $pr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($br or $sb or $pr) { } 0 0 0
Condition0%0/6
$br or $sb or $pr
l!l&&r!l&&!r
000
$br or $sb
l!l&&r!l&&!r
000
MC/DC0%0/3
$br or $sb or $pr
$br $sb $pr
Truth table0%0/4
A or B or C
A= $brB= $sbC= $pr
ABCresult
1XX1
01X1
0011
0000
10756 0 $i = $i_beg;
10757 0 $type = '<';
10758 0 $self->write_diagnostics(
10759 "NOT ANGLE (BRACE={$br ($pr [$sb ):$str\n");
10760 }
10761  
10762 # we should keep doing more checks here...to be continued
10763 # Tentatively accepting this as a valid angle operator.
10764 # There are lots more things that can be checked.
10765 else {
10766 0 $self->write_diagnostics(
10767 "ANGLE-Guessing yes: $str expecting=$expecting\n");
10768 0 $self->write_logfile_entry(
10769 "Guessing angle operator here: $str\n");
10770 }
10771 }
10772 }
10773  
10774 # didn't find ending >
10775 else {
10776 0 ▶ if ($expecting_TERM) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting_TERM) 0 0 0
10777 0 $self->warning("No ending > for angle operator\n");
10778 }
10779 }
10780 }
10781 7 return ( $i, $type );
10782 } ## end sub find_angle_operator_termination
10783  
10784 sub scan_number_do {
10785  
10786 687 ▶ my ( $self, $input_line, $i, $rtoken_map, $input_type, $max_token_index ) =
Subroutine scan_number_do: called CC=13 SCAR=26.8
Pod undocumented
10787 @_;
10788  
10789 # Scan a number in any of the formats that Perl accepts
10790 # Underbars (_) are allowed in decimal numbers.
10791 # Given:
10792 # $input_line - the string to scan
10793 # $i - pre_token index to start scanning
10794 # $rtoken_map - reference to the pre_token map giving starting
10795 # character position in $input_line of token $i
10796 # Return:
10797 # $i - last pre_token index of the number just scanned
10798 # $type - the token type ('v' or 'n')
10799 # number - the number (characters); or undef if not a number
10800  
10801 687 my $pos_beg = $rtoken_map->[$i];
10802 687 my $pos;
10803 ##my $i_begin = $i;
10804 687 my $number = undef;
10805 687 my $type = $input_type;
10806  
10807 687 my $first_char = substr( $input_line, $pos_beg, 1 );
10808  
10809 # Look for bad starting characters; Shouldn't happen..
10810 687 ▶ if ( $first_char !~ /[\d\.\+\-Ee]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($first_char =~ /[\d\.\+\-Ee]/) 0 687 687
10811 0 if (DEVEL_MODE) {
10812 Fault(<<EOM);
10813 Program bug - scan_number given bad first character = '$first_char'
10814 EOM
10815 }
10816 0 return ( $i, $type, $number );
10817 }
10818  
10819 # handle v-string without leading 'v' character ('Two Dot' rule)
10820 # (vstring.t)
10821 # Here is the format prior to including underscores:
10822 ## if ( $input_line =~ /\G((\d+)?\.\d+(\.\d+)+)/g ) {
10823 687 pos($input_line) = $pos_beg;
10824 687 ▶ if ( $input_line =~ /\G((\d[_\d]*)?\.[\d_]+(\.[\d_]+)+)/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /\G((\d[_\d]*)?\.[\d_]+(\.[\d_]+)+)/g) 0 687 687
10825 0 $pos = pos($input_line);
10826 0 my $numc = $pos - $pos_beg;
10827 0 $number = substr( $input_line, $pos_beg, $numc );
10828 0 $type = 'v';
10829 }
10830  
10831 # handle octal, hex, binary
10832 687 ▶ if ( !defined($number) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $number) 687 0 687
10833 687 pos($input_line) = $pos_beg;
10834  
10835 # Perl 5.22 added floating point literals, like '0x0.b17217f7d1cf78p0'
10836 # For reference, the format prior to hex floating point is:
10837 # /\G[+-]?0(([xX][0-9a-fA-F_]+)|([0-7_]+)|([bB][01_]+))/g )
10838 # (hex) (octal) (binary)
10839 687 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ / \G[+-]?0( # leading [signed] 0 # a hex float, i.e. '0x0.b17217f7d1cf78p0' ([xX][0-9a-fA-F_]* # X and optional leading digits (\.([0-9a-fA-F][0-9a-fA-F_]*)?)? # optional decimal and fraction [Pp][+-]?[0-9a-fA-F] # REQUIRED exponent with digit [0-9a-fA-F_]*) # optional Additional exponent digits # or hex integer |([xX][0-9a-fA-F_]+) # or octal fraction |([oO]?[0-7_]+ # string of octal digits (\.([0-7][0-7_]*)?)? # optional decimal and fraction [Pp][+-]?[0-7] # REQUIRED exponent, no underscore [0-7_]*) # Additional exponent digits with underscores # or octal integer |([oO]?[0-7_]+) # string of octal digits # or a binary float |([bB][01_]* # 'b' with string of binary digits (\.([01][01_]*)?)? # optional decimal and fraction [Pp][+-]?[01] # Required exponent indicator, no underscore [01_]*) # additional exponent bits # or binary integer |([bB][01_]+) # 'b' with string of binary digits )/gx) 72 615 687
10840 $input_line =~ m{
10841  
10842 \G[+-]?0( # leading [signed] 0
10843  
10844 # a hex float, i.e. '0x0.b17217f7d1cf78p0'
10845 ([xX][0-9a-fA-F_]* # X and optional leading digits
10846 (\.([0-9a-fA-F][0-9a-fA-F_]*)?)? # optional decimal and fraction
10847 [Pp][+-]?[0-9a-fA-F] # REQUIRED exponent with digit
10848 [0-9a-fA-F_]*) # optional Additional exponent digits
10849  
10850 # or hex integer
10851 |([xX][0-9a-fA-F_]+)
10852  
10853 # or octal fraction
10854 |([oO]?[0-7_]+ # string of octal digits
10855 (\.([0-7][0-7_]*)?)? # optional decimal and fraction
10856 [Pp][+-]?[0-7] # REQUIRED exponent, no underscore
10857 [0-7_]*) # Additional exponent digits with underscores
10858  
10859 # or octal integer
10860 |([oO]?[0-7_]+) # string of octal digits
10861  
10862 # or a binary float
10863 |([bB][01_]* # 'b' with string of binary digits
10864 (\.([01][01_]*)?)? # optional decimal and fraction
10865 [Pp][+-]?[01] # Required exponent indicator, no underscore
10866 [01_]*) # additional exponent bits
10867  
10868 # or binary integer
10869 |([bB][01_]+) # 'b' with string of binary digits
10870  
10871 )}gx
10872 )
10873 {
10874 72 $pos = pos($input_line);
10875 72 my $numc = $pos - $pos_beg;
10876 72 $number = substr( $input_line, $pos_beg, $numc );
10877 72 $type = 'n';
10878 }
10879 }
10880  
10881 # handle decimal
10882 687 ▶ if ( !defined($number) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $number) 615 72 687
10883 615 pos($input_line) = $pos_beg;
10884  
10885 615 ▶ if ( $input_line =~ /\G([+-]?[\d_]*(\.[\d_]*)?([Ee][+-]?(\d+))?)/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /\G([+-]?[\d_]*(\.[\d_]*)?([Ee][+-]?(\d+))?)/g) 615 0 615
10886 615 $pos = pos($input_line);
10887  
10888 # watch out for things like 0..40 which would give 0. by this;
10889 615 ▶ if ( ( substr( $input_line, $pos - 1, 1 ) eq '.' )
Branch: 1 branch
BranchTrueFalseTotal
if (substr($input_line, $pos - 1, 1) eq "." and substr($input_line, $pos, 1) eq ".") 38 577 615
Condition100%3/3
substr($input_line, $pos - 1, 1) eq "." and substr($input_line, $pos, 1) eq "."
!ll&&!rl&&r
5611638
MC/DC100%2/2
substr($input_line, $pos - 1, 1) eq "." and substr($input_line, $pos, 1) eq "."
substr($input_line, $pos - 1, 1) eq "." substr($input_line, $pos, 1) eq "."
Truth table100%3/3
A and B
A= substr($input_line, $pos - 1, 1) eq "."B= substr($input_line, $pos, 1) eq "."
ABresult
0X0
100
111
10890 && ( substr( $input_line, $pos, 1 ) eq '.' ) )
10891 {
10892 38 $pos--;
10893 }
10894 615 my $numc = $pos - $pos_beg;
10895 615 $number = substr( $input_line, $pos_beg, $numc );
10896 615 $type = 'n';
10897 }
10898 }
10899  
10900 # filter out non-numbers like e + - . e2 .e3 +e6
10901 # the rule: at least one digit, and any 'e' must be preceded by a digit
10902 687 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $number =~ /\d/ or $number =~ /^(.*)[eE]/ and not $1 =~ /\d/) 304 383 687
Condition66%4/6
not $number =~ /\d/ or $number =~ /^(.*)[eE]/ and not $1 =~ /\d/
l!l&&r!l&&!r
3040383
$number =~ /^(.*)[eE]/ and not $1 =~ /\d/
!ll&&!rl&&r
367160
MC/DC33%1/3
not $number =~ /\d/ or $number =~ /^(.*)[eE]/ and not $1 =~ /\d/
not $number =~ /\d/ $number =~ /^(.*)[eE]/ not $1 =~ /\d/
Truth table50%2/4
not(A) or B and not(C)
A= not $number =~ /\d/B= $number =~ /^(.*)[eE]/C= not $1 =~ /\d/
ABCresult
1XX1
0111
00X0
0100
10903 $number !~ /\d/ # no digits
10904 || ( $number =~ /^(.*)[eE]/
10905 && $1 !~ /\d/ ) # or no digits before the 'e'
10906 )
10907 {
10908 304 $number = undef;
10909 304 $type = $input_type;
10910 304 return ( $i, $type, $number );
10911 }
10912  
10913 # Found a number; now we must convert back from character position
10914 # to pre_token index. An error here implies user syntax error.
10915 # An example would be an invalid octal number like '009'.
10916 383 my $error;
10917 383 ( $i, $error ) =
10918 inverse_pretoken_map( $i, $pos, $rtoken_map, $max_token_index );
10919 383 ▶ if ($error) { $self->warning("Possibly invalid number\n") }
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 383 383
10920  
10921 383 return ( $i, $type, $number );
10922 } ## end sub scan_number_do
10923  
10924 sub inverse_pretoken_map {
10925  
10926 # Starting with the current pre_token index $i, scan forward until
10927 # finding the index of the next pre_token whose position is $pos.
10928 2500 ▶ my ( $i, $pos, $rtoken_map, $max_token_index ) = @_;
Subroutine inverse_pretoken_map: called CC=4 SCAR=14.0
Pod undocumented
10929 2500 my $error = 0;
10930  
10931 2500 ▶ while ( ++$i <= $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$i <= $max_token_index) 4705 44 4749
10932  
10933 4705 ▶ if ( $pos <= $rtoken_map->[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos <= $rtoken_map->[$i]) 2456 2249 4705
10934  
10935 # Let the calling routine handle errors in which we do not
10936 # land on a pre-token boundary. It can happen by running
10937 # perltidy on some non-perl scripts, for example.
10938 2456 ▶ if ( $pos < $rtoken_map->[$i] ) { $error = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < $rtoken_map->[$i]) 0 2456 2456
10939 2456 $i--;
10940 2456 last;
10941 }
10942 } ## end while ( ++$i <= $max_token_index)
10943 2500 return ( $i, $error );
10944 } ## end sub inverse_pretoken_map
10945  
10946 sub find_here_doc {
10947  
10948 my (
10949  
10950 39 ▶ $self,
Subroutine find_here_doc: called CC=17 SCAR=32.7
Pod undocumented
10951  
10952 $expecting,
10953 $i,
10954 $rtokens,
10955 $rtoken_type,
10956 $rtoken_map_uu,
10957 $max_token_index,
10958  
10959 ) = @_;
10960  
10961 # Find the target of a here document, if any
10962 # Given:
10963 # $i - token index of the second < of <<
10964 # ($i must be less than the last token index if this is called)
10965 # Return:
10966 # $found_target = 0 didn't find target; =1 found target
10967 # HERE_TARGET - the target string (may be empty string)
10968 # $i - unchanged if not here doc,
10969 # or index of the last token of the here target
10970 # $saw_error - flag noting unbalanced quote on here target
10971 39 my $ibeg = $i;
10972 39 my $found_target = 0;
10973 39 my $here_doc_target = EMPTY_STRING;
10974 39 my $here_quote_character = EMPTY_STRING;
10975 39 my $saw_error = 0;
10976 39 my ( $next_nonblank_token, $i_next_nonblank, $next_token );
10977 39 $next_token = $rtokens->[ $i + 1 ];
10978  
10979 # perl allows a backslash before the target string (heredoc.t)
10980 39 my $backslash = 0;
10981 39 ▶ if ( $next_token eq BACKSLASH ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token eq "\\") 0 39 39
10982 0 $backslash = 1;
10983 0 $next_token = $rtokens->[ $i + 2 ];
10984 }
10985  
10986 39 ( $next_nonblank_token, $i_next_nonblank ) =
10987 find_next_nonblank_token_on_this_line( $i, $rtokens, $max_token_index );
10988  
10989 39 ▶ if ( $next_nonblank_token =~ /[\'\"\`]/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($next_nonblank_token =~ /[\'\"\`]/) { } 22 17 39
elsif ($next_token =~ /^\s*$/ and $expecting == -1) { } 0 17 17
elsif ($next_token =~ /^\w/) { } 15 2 17
10990  
10991 22 my $in_quote = 1;
10992 22 my $quote_depth = 0;
10993 22 my $quote_pos = 0;
10994 22 my $quoted_string;
10995  
10996 (
10997  
10998 22 $i,
10999 $in_quote,
11000 $here_quote_character,
11001 $quote_pos,
11002 $quote_depth,
11003 $quoted_string,
11004 )
11005 = $self->follow_quoted_string(
11006  
11007 $i_next_nonblank,
11008 $in_quote,
11009 $rtokens,
11010 $rtoken_type,
11011 $here_quote_character,
11012 $quote_pos,
11013 $quote_depth,
11014 $max_token_index,
11015 );
11016  
11017 22 ▶ if ($in_quote) { # didn't find end of quote, so no target found
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote) { } 0 22 22
11018 0 $i = $ibeg;
11019 0 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) 0 0 0
11020 0 $self->warning(
11021 "Did not find here-doc string terminator ($here_quote_character) before end of line \n"
11022 );
11023 0 $saw_error = 1;
11024 }
11025 }
11026 else { # found ending quote
11027 22 $found_target = 1;
11028  
11029 22 my $tokj;
11030 22 foreach my $j ( $i_next_nonblank + 1 .. $i - 1 ) {
11031 50 $tokj = $rtokens->[$j];
11032  
11033 # we have to remove any backslash before the quote character
11034 # so that the here-doc-target exactly matches this string
11035 next
11036 50 ▶ if ( $tokj eq BACKSLASH
Branch: 1 branch
BranchTrueFalseTotal
if $tokj eq "\\" and $j < $i - 1 and $$rtokens[$j + 1] eq $here_quote_character 4 46 50
Condition66%4/6
$tokj eq "\\" and $j < $i - 1 and $$rtokens[$j + 1] eq $here_quote_character
!ll&&!rl&&r
4604
$tokj eq "\\" and $j < $i - 1
!ll&&!rl&&r
4604
MC/DC33%1/3
$tokj eq "\\" and $j < $i - 1 and $$rtokens[$j + 1] eq $here_quote_character
$tokj eq "\\" $j < $i - 1 $$rtokens[$j + 1] eq $here_quote_character
Truth table50%2/4
A and B and C
A= $tokj eq "\\"B= $j < $i - 1C= $$rtokens[$j + 1] eq $here_quote_character
ABCresult
0XX0
10X0
1100
1111
11037 && $j < $i - 1
11038 && $rtokens->[ $j + 1 ] eq $here_quote_character );
11039 46 $here_doc_target .= $tokj;
11040 }
11041 }
11042 }
11043  
11044 ▶ elsif ( ( $next_token =~ /^\s*$/ ) and ( $expecting == TERM ) ) {
Condition66%2/3
$next_token =~ /^\s*$/ and $expecting == -1
!ll&&!rl&&r
1520
MC/DC0%0/2
$next_token =~ /^\s*$/ and $expecting == -1
$next_token =~ /^\s*$/ $expecting == -1
Truth table66%2/3
A and B
A= $next_token =~ /^\s*$/B= $expecting == -1
ABresult
0X0
100
111
11045 0 $found_target = 1;
11046 0 $self->write_logfile_entry(
11047 "found blank here-target after <<; suggest using \"\"\n");
11048 0 $i = $ibeg;
11049 }
11050 elsif ( $next_token =~ /^\w/ ) { # simple bareword or integer after <<
11051  
11052 15 my $here_doc_expected;
11053 15 ▶ if ( $expecting == UNKNOWN ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == 0) { } 0 15 15
11054 0 $here_doc_expected = $self->guess_if_here_doc($next_token);
11055 }
11056 else {
11057 15 $here_doc_expected = 1;
11058 }
11059  
11060 15 ▶ if ($here_doc_expected) {
Branch: 1 branch
BranchTrueFalseTotal
if ($here_doc_expected) 15 0 15
11061 15 $found_target = 1;
11062 15 $here_doc_target = $next_token;
11063 15 $i = $ibeg + 1;
11064 }
11065  
11066 }
11067 else {
11068  
11069 2 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) { } 0 2 2
11070 0 $found_target = 1;
11071 0 $self->write_logfile_entry("Note: bare here-doc operator <<\n");
11072 }
11073 else {
11074 2 $i = $ibeg;
11075 }
11076 }
11077  
11078 # patch to neglect any prepended backslash
11079 39 ▶ if ( $found_target && $backslash ) { $i++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($found_target and $backslash) 0 39 39
Condition66%2/3
$found_target and $backslash
!ll&&!rl&&r
2370
MC/DC0%0/2
$found_target and $backslash
$found_target $backslash
Truth table66%2/3
A and B
A= $found_targetB= $backslash
ABresult
0X0
100
111
11080  
11081 39 return ( $found_target, $here_doc_target, $here_quote_character, $i,
11082 $saw_error );
11083 } ## end sub find_here_doc
11084  
11085 sub do_quote {
11086  
11087 my (
11088  
11089 3233 ▶ $self,
Subroutine do_quote: called CC=6 SCAR=18.0
Pod undocumented
11090  
11091 $i,
11092 $in_quote,
11093 $quote_character,
11094 $quote_pos,
11095 $quote_depth,
11096 $quoted_string_1,
11097 $quoted_string_2,
11098 $rtokens,
11099 $rtoken_type,
11100 $rtoken_map_uu,
11101 $max_token_index,
11102  
11103 ) = @_;
11104  
11105 # Follow (or continue following) quoted string(s)
11106 # $in_quote = return code:
11107 # 0 - ok, found end
11108 # 1 - still must find end of quote whose target is $quote_character
11109 # 2 - still looking for end of first of two quotes
11110 #
11111 # Returns updated strings:
11112 # $quoted_string_1 = quoted string seen while in_quote=1
11113 # $quoted_string_2 = quoted string seen while in_quote=2
11114  
11115 3233 my $quoted_string;
11116 3233 ▶ if ( $in_quote == 2 ) { # two quotes/quoted_string_1s to follow
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote == 2) 31 3202 3233
11117 31 my $ibeg = $i;
11118 (
11119  
11120 31 $i,
11121 $in_quote,
11122 $quote_character,
11123 $quote_pos,
11124 $quote_depth,
11125 $quoted_string,
11126 )
11127 = $self->follow_quoted_string(
11128  
11129 $ibeg,
11130 $in_quote,
11131 $rtokens,
11132 $rtoken_type,
11133 $quote_character,
11134 $quote_pos,
11135 $quote_depth,
11136 $max_token_index,
11137 );
11138 31 $quoted_string_2 .= $quoted_string;
11139 31 ▶ if ( $in_quote == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote == 1) { } 31 0 31
11140 31 ▶ if ( $quote_character =~ /[\{\[\<\(]/ ) { $i++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($quote_character =~ /[\{\[\<\(]/) 1 30 31
11141 31 $quote_character = EMPTY_STRING;
11142 }
11143 else {
11144 0 $quoted_string_2 .= "\n";
11145 }
11146 }
11147  
11148 3233 ▶ if ( $in_quote == 1 ) { # one (more) quote to follow
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote == 1) 3233 0 3233
11149 3233 my $ibeg = $i;
11150 (
11151  
11152 3233 $i,
11153 $in_quote,
11154 $quote_character,
11155 $quote_pos,
11156 $quote_depth,
11157 $quoted_string,
11158 )
11159 = $self->follow_quoted_string(
11160  
11161 $ibeg,
11162 $in_quote,
11163 $rtokens,
11164 $rtoken_type,
11165 $quote_character,
11166 $quote_pos,
11167 $quote_depth,
11168 $max_token_index,
11169 );
11170 3233 $quoted_string_1 .= $quoted_string;
11171 3233 ▶ if ( $in_quote == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote == 1) 244 2989 3233
11172 244 $quoted_string_1 .= "\n";
11173 }
11174 }
11175 return (
11176  
11177 3233 $i,
11178 $in_quote,
11179 $quote_character,
11180 $quote_pos,
11181 $quote_depth,
11182 $quoted_string_1,
11183 $quoted_string_2,
11184  
11185 );
11186 } ## end sub do_quote
11187  
11188 45 ▶use constant DEBUG_FIND_INTERPOLATED_HERE_TARGETS => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
11189  
11190 sub find_interpolated_here_targets {
11191 2 ▶ my ( $self, $quoted_string, $len_starting_lines ) = @_;
Subroutine find_interpolated_here_targets: called CC=36 SCAR=41.1
Pod undocumented
11192  
11193 # Search for here targets in a quoted string
11194 # Given:
11195 # $quoted_string = the complete string of an interpolated quote
11196 # $len_starting_lines = number of characters of the first n-1 lines
11197 # (=0 if this is a single-line quote)
11198 # Task:
11199 # Find and return a list of all here targets on the last line;
11200 # i.e., if here target is index ii, we only return the
11201 # target if $rmap->[$ii]>=$len_starting_lines
11202  
11203 # The items returned are the format needed for @{$rhere_target_list};
11204 # [ $here_doc_target, $here_quote_character ]
11205 # there can be multiple here targets.
11206  
11207 2 my $rht;
11208  
11209 # Break the entire quote into pre-tokens, even if multi-line, because we
11210 # have to determine which parts are in single quotes
11211 2 my ( $rtokens, $rmap, $rtoken_type ) = pre_tokenize($quoted_string);
11212 2 my $max_ii = @{$rtokens} - 1;
11213  
11214 # Depth of braces controlled by a sigil
11215 2 my $code_depth = 0;
11216  
11217 # Loop over pre-tokens
11218 2 my $ii = -1;
11219 2 ▶ while ( ++$ii <= $max_ii ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$ii <= $max_ii) 21 2 23
11220 21 my $token = $rtokens->[$ii];
11221 21 if (DEBUG_FIND_INTERPOLATED_HERE_TARGETS) {
11222 print "i=$ii tok=$token block=$code_depth\n";
11223 }
11224  
11225 21 ▶ if ( $token eq BACKSLASH ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq "\\") 4 17 21
11226 4 ▶ if ( !$code_depth ) { $ii++ }
Branch: 1 branch
BranchTrueFalseTotal
unless ($code_depth) 0 4 4
11227 4 next;
11228 }
11229  
11230 # Look for start of interpolation code block, '${', '@{', '$var{', etc
11231 17 ▶ if ( !$code_depth ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($code_depth) 4 13 17
11232 4 ▶ if ( $token eq '$' || $token eq '@' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq "\$" or $token eq "\@") 4 0 4
Condition33%1/3
$token eq "\$" or $token eq "\@"
l!l&&r!l&&!r
400
MC/DC0%0/2
$token eq "\$" or $token eq "\@"
$token eq "\$" $token eq "\@"
Truth table33%1/3
A or B
A= $token eq "\$"B= $token eq "\@"
ABresult
1X1
011
000
11233  
11234 4 ▶ $ii++
Branch: 1 branch
BranchTrueFalseTotal
if $ii < $max_ii and $$rtoken_type[$ii + 1] eq "b" 2 2 4
Condition66%2/3
$ii < $max_ii and $$rtoken_type[$ii + 1] eq "b"
!ll&&!rl&&r
022
MC/DC50%1/2
$ii < $max_ii and $$rtoken_type[$ii + 1] eq "b"
$ii < $max_ii $$rtoken_type[$ii + 1] eq "b"
Truth table66%2/3
A and B
A= $ii < $max_iiB= $$rtoken_type[$ii + 1] eq "b"
ABresult
0X0
100
111
11235 if ( $ii < $max_ii && $rtoken_type->[ $ii + 1 ] eq 'b' );
11236  
11237 4 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if ($ii < $max_ii and $$rtoken_type[$ii + 1] eq "w" || $$rtoken_type[$ii + 1] eq "::") 0 4 4
Condition33%2/6
$ii < $max_ii and $$rtoken_type[$ii + 1] eq "w" || $$rtoken_type[$ii + 1] eq "::"
!ll&&!rl&&r
040
$$rtoken_type[$ii + 1] eq "w" or $$rtoken_type[$ii + 1] eq "::"
l!l&&r!l&&!r
004
MC/DC0%0/3
$ii < $max_ii and $$rtoken_type[$ii + 1] eq "w" || $$rtoken_type[$ii + 1] eq "::"
$ii < $max_ii $$rtoken_type[$ii + 1] eq "w" $$rtoken_type[$ii + 1] eq "::"
Truth table25%1/4
A and B or C
A= $ii < $max_iiB= $$rtoken_type[$ii + 1] eq "w"C= $$rtoken_type[$ii + 1] eq "::"
ABCresult
0XX0
1000
11X1
1011
11238 $ii < $max_ii
11239 && ( $rtoken_type->[ $ii + 1 ] eq 'w'
11240 || $rtoken_type->[ $ii + 1 ] eq '::' )
11241 )
11242 {
11243 0 $ii++;
11244 } ## end while ( $ii < $max_ii && ...)
11245  
11246 4 ▶ $ii++
Branch: 1 branch
BranchTrueFalseTotal
if $ii < $max_ii and $$rtoken_type[$ii + 1] eq "b" 0 4 4
Condition33%1/3
$ii < $max_ii and $$rtoken_type[$ii + 1] eq "b"
!ll&&!rl&&r
040
MC/DC0%0/2
$ii < $max_ii and $$rtoken_type[$ii + 1] eq "b"
$ii < $max_ii $$rtoken_type[$ii + 1] eq "b"
Truth table33%1/3
A and B
A= $ii < $max_iiB= $$rtoken_type[$ii + 1] eq "b"
ABresult
0X0
100
111
11247 if ( $ii < $max_ii && $rtoken_type->[ $ii + 1 ] eq 'b' );
11248  
11249 4 ▶ if ( $ii < $max_ii && $rtokens->[ $ii + 1 ] eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ii < $max_ii and $$rtokens[$ii + 1] eq "{") 4 0 4
Condition33%1/3
$ii < $max_ii and $$rtokens[$ii + 1] eq "{"
!ll&&!rl&&r
004
MC/DC0%0/2
$ii < $max_ii and $$rtokens[$ii + 1] eq "{"
$ii < $max_ii $$rtokens[$ii + 1] eq "{"
Truth table33%1/3
A and B
A= $ii < $max_iiB= $$rtokens[$ii + 1] eq "{"
ABresult
0X0
100
111
11250 4 $ii++;
11251 4 $code_depth++;
11252 }
11253 }
11254 4 next;
11255 }
11256  
11257 # Continue interpolating while $code_depth > 0..
11258 13 ▶ if ( $token eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq "{") 0 13 13
11259 0 $code_depth++;
11260 0 next;
11261 }
11262 13 ▶ if ( $token eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq "}") 4 9 13
11263 4 $code_depth--;
11264 4 next;
11265 }
11266  
11267 # Look for '<<'
11268 9 ▶ if ( $token ne '<'
Branch: 1 branch
BranchTrueFalseTotal
if ($token ne "<" or $ii >= $max_ii - 1 or $$rtokens[$ii + 1] ne "<") 0 4 4
Condition66%4/6
$token ne "<" or $ii >= $max_ii - 1 or $$rtokens[$ii + 1] ne "<"
l!l&&r!l&&!r
504
$token ne "<" or $ii >= $max_ii - 1
l!l&&r!l&&!r
504
MC/DC33%1/3
$token ne "<" or $ii >= $max_ii - 1 or $$rtokens[$ii + 1] ne "<"
$token ne "<" $ii >= $max_ii - 1 $$rtokens[$ii + 1] ne "<"
Truth table50%2/4
A or B or C
A= $token ne "<"B= $ii >= $max_ii - 1C= $$rtokens[$ii + 1] ne "<"
ABCresult
1XX1
01X1
0011
0000
11269 || $ii >= $max_ii - 1
11270 || $rtokens->[ $ii + 1 ] ne '<' )
11271 {
11272 5 next;
11273 }
11274  
11275 # Remember the location of the first '<' so it can be modified
11276 4 my $ii_left_shift = $ii;
11277  
11278 4 $ii++;
11279  
11280 # or '<<~'
11281 4 ▶ if ( $rtoken_type->[ $ii + 1 ] eq '~' && $ii < $max_ii - 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$rtoken_type[$ii + 1] eq "~" and $ii < $max_ii - 2) 0 4 4
Condition33%1/3
$$rtoken_type[$ii + 1] eq "~" and $ii < $max_ii - 2
!ll&&!rl&&r
400
MC/DC0%0/2
$$rtoken_type[$ii + 1] eq "~" and $ii < $max_ii - 2
$$rtoken_type[$ii + 1] eq "~" $ii < $max_ii - 2
Truth table33%1/3
A and B
A= $$rtoken_type[$ii + 1] eq "~"B= $ii < $max_ii - 2
ABresult
0X0
100
111
11282 0 $ii++;
11283 }
11284  
11285 # blanks ok before targets in quotes
11286 4 my $saw_blank;
11287 4 ▶ if ( $rtoken_type->[ $ii + 1 ] eq 'b' && $ii < $max_ii - 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$rtoken_type[$ii + 1] eq "b" and $ii < $max_ii - 2) 2 2 4
Condition66%2/3
$$rtoken_type[$ii + 1] eq "b" and $ii < $max_ii - 2
!ll&&!rl&&r
202
MC/DC50%1/2
$$rtoken_type[$ii + 1] eq "b" and $ii < $max_ii - 2
$$rtoken_type[$ii + 1] eq "b" $ii < $max_ii - 2
Truth table66%2/3
A and B
A= $$rtoken_type[$ii + 1] eq "b"B= $ii < $max_ii - 2
ABresult
0X0
100
111
11288 2 $saw_blank = 1;
11289 2 $ii++;
11290 }
11291  
11292 4 my $next_type = $rtoken_type->[ $ii + 1 ];
11293  
11294 # Look for unquoted targets like "${ \<<END1 }"
11295 4 ▶ if ( $next_type eq 'w' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($next_type eq 'w') { } 2 2 4
elsif ($next_type eq q['] or $next_type eq '"' or $next_type eq '`') { } 2 0 2
11296 2 ▶ if ($saw_blank) {
Branch: 1 branch
BranchTrueFalseTotal
if ($saw_blank) { } 0 2 2
11297 ## error: blank target is deprecated
11298 }
11299 else {
11300 2 $ii++;
11301 2 ▶ if ( $rmap->[$ii] >= $len_starting_lines ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rmap->[$ii] >= $len_starting_lines) 2 0 2
11302 2 push @{$rht}, [ $rtokens->[$ii], EMPTY_STRING ];
11303  
11304 # Modify the string so the target is not found again
11305 2 my $pos_left_shift = $rmap->[$ii_left_shift];
11306 2 substr( $quoted_string, $pos_left_shift, 1, SPACE );
11307 2 substr( $quoted_string, $pos_left_shift + 1, 1, SPACE );
11308 }
11309 }
11310 }
11311  
11312 # Look for quoted targets like "${ \<< 'END1' }${ \<<\"END2\" }";
11313 ▶ elsif ( $next_type eq "'" || $next_type eq '"' || $next_type eq '`' ) {
Condition50%3/6
$next_type eq "'" or $next_type eq "\"" or $next_type eq "`"
l!l&&r!l&&!r
200
$next_type eq "'" or $next_type eq "\""
l!l&&r!l&&!r
110
MC/DC0%0/3
$next_type eq "'" or $next_type eq "\"" or $next_type eq "`"
$next_type eq "'" $next_type eq "\"" $next_type eq "`"
Truth table50%2/4
A or B or C
A= $next_type eq "'"B= $next_type eq "\""C= $next_type eq "`"
ABCresult
1XX1
01X1
0011
0000
11314 2 my $quote_char = $next_type;
11315 2 $ii++;
11316 2 my $here_target = EMPTY_STRING;
11317 2 ▶ while ( ++$ii <= $max_ii && $rtokens->[$ii] ne $quote_char ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$ii <= $max_ii and $rtokens->[$ii] ne $quote_char) 2 2 4
Condition66%2/3
++$ii <= $max_ii and $rtokens->[$ii] ne $quote_char
!ll&&!rl&&r
022
MC/DC50%1/2
++$ii <= $max_ii and $rtokens->[$ii] ne $quote_char
++$ii <= $max_ii $rtokens->[$ii] ne $quote_char
Truth table66%2/3
A and B
A= ++$ii <= $max_iiB= $rtokens->[$ii] ne $quote_char
ABresult
0X0
100
111
11318 next
11319 2 ▶ if ( $quote_char ne "'" && $rtokens->[$ii] eq BACKSLASH );
Branch: 1 branch
BranchTrueFalseTotal
if $quote_char ne "'" and $rtokens->[$ii] eq "\\" 0 2 2
Condition66%2/3
$quote_char ne "'" and $rtokens->[$ii] eq "\\"
!ll&&!rl&&r
110
MC/DC0%0/2
$quote_char ne "'" and $rtokens->[$ii] eq "\\"
$quote_char ne "'" $rtokens->[$ii] eq "\\"
Truth table66%2/3
A and B
A= $quote_char ne "'"B= $rtokens->[$ii] eq "\\"
ABresult
0X0
100
111
11320 2 $here_target .= $rtokens->[$ii];
11321 }
11322 2 ▶ if ( $rmap->[$ii] >= $len_starting_lines ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rmap->[$ii] >= $len_starting_lines) 2 0 2
11323 2 push @{$rht}, [ $here_target, $quote_char ];
11324 }
11325 }
11326 else {
11327 ## no here target found
11328 }
11329 4 next;
11330 } ## end while ( ++$ii <= $max_ii )
11331 2 return ( $rht, $quoted_string );
11332 } ## end sub find_interpolated_here_targets
11333  
11334 # Some possible non-word quote delimiters, for preliminary checking
11335 45 my %is_punct_char;
11336  
11337 BEGIN {
11338  
11339 45 ▶ my @q = qw# / " ' { } ( ) [ ] < > ; + - * | % ! x ~ = ? : . ^ & #;
Subroutine BEGIN: called CC=2 SCAR=6.9
11340 45 push @q, '#';
11341 45 push @q, COMMA;
11342 45 $is_punct_char{$_} = 1 for @q;
11343 }
11344  
11345 sub follow_quoted_string {
11346  
11347 my (
11348  
11349 3286 ▶ $self,
Subroutine follow_quoted_string: called CC=33 SCAR=35.5
Pod undocumented
11350  
11351 $i_beg,
11352 $in_quote,
11353 $rtokens,
11354 $rtoken_type,
11355 $beginning_tok,
11356 $quote_pos,
11357 $quote_depth,
11358 $max_token_index,
11359  
11360 ) = @_;
11361  
11362 # Scan for a specific token, skipping escaped characters.
11363 # If the quote character is blank, use the first non-blank character.
11364 # Given:
11365 # $rtokens = reference to the array of tokens
11366 # $i = the token index of the first character to search
11367 # $in_quote = number of quoted strings being followed
11368 # $beginning_tok = the starting quote character
11369 # $quote_pos = index to check next for alphanumeric delimiter
11370 # Return:
11371 # $i = the token index of the ending quote character
11372 # $in_quote = decremented if found end, unchanged if not
11373 # $beginning_tok = the starting quote character
11374 # $quote_pos = index to check next for alphanumeric delimiter
11375 # $quote_depth = nesting depth, since delimiters '{ ( [ <' can be nested.
11376 # $quoted_string = the text of the quote (without quotation tokens)
11377 3286 my ( $tok, $end_tok );
11378 3286 my $i = $i_beg - 1;
11379 3286 my $quoted_string = EMPTY_STRING;
11380  
11381 3286 0 && do {
11382 print {*STDOUT}
11383 "QUOTE entering with quote_pos = $quote_pos i=$i beginning_tok =$beginning_tok\n";
11384 };
11385  
11386 # for a non-blank token, get the corresponding end token
11387 3286 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($is_punct_char{$beginning_tok} or length $beginning_tok and not $beginning_tok =~ /^\s+$/) { } 244 3042 3286
Condition50%3/6
$is_punct_char{$beginning_tok} or length $beginning_tok and not $beginning_tok =~ /^\s+$/
l!l&&r!l&&!r
24403042
length $beginning_tok and not $beginning_tok =~ /^\s+$/
!ll&&!rl&&r
304200
MC/DC33%1/3
$is_punct_char{$beginning_tok} or length $beginning_tok and not $beginning_tok =~ /^\s+$/
$is_punct_char{$beginning_tok} length $beginning_tok not $beginning_tok =~ /^\s+$/
Truth table50%2/4
A or B and not(C)
A= $is_punct_char{$beginning_tok}B= length $beginning_tokC= not $beginning_tok =~ /^\s+$/
ABCresult
1XX1
0111
00X0
0100
11388 $is_punct_char{$beginning_tok}
11389 || ( length($beginning_tok)
11390 && $beginning_tok !~ /^\s+$/ )
11391 )
11392 {
11393 $end_tok =
11394 $matching_end_token{$beginning_tok}
11395 244 ▶ ? $matching_end_token{$beginning_tok}
Branch: 1 branch
BranchTrueFalseTotal
$matching_end_token{$beginning_tok} ? : 187 57 244
11396 : $beginning_tok;
11397 }
11398  
11399 # for a blank token, find and use the first non-blank one
11400 else {
11401 3042 ▶ my $allow_quote_comments = ( $i < 0 ) ? 1 : 0; # i<0 means we saw a <cr>
Branch: 1 branch
BranchTrueFalseTotal
$i < 0 ? : 295 2747 3042
11402  
11403 3042 ▶ while ( $i < $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $max_token_index) 3044 0 3044
11404 3044 $tok = $rtokens->[ ++$i ];
11405  
11406 3044 ▶ if ( $rtoken_type->[$i] ne 'b' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rtoken_type->[$i] ne 'b') { } 3042 2 3044
11407  
11408 3042 ▶ if ( ( $tok eq '#' ) && ($allow_quote_comments) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq '#' and $allow_quote_comments) { } 0 3042 3042
Condition66%2/3
$tok eq "#" and $allow_quote_comments
!ll&&!rl&&r
303840
MC/DC0%0/2
$tok eq "#" and $allow_quote_comments
$tok eq "#" $allow_quote_comments
Truth table66%2/3
A and B
A= $tok eq "#"B= $allow_quote_comments
ABresult
0X0
100
111
11409 0 $i = $max_token_index;
11410 }
11411 else {
11412  
11413 3042 ▶ if ( length($tok) > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $tok > 1) { } 1 3041 3042
11414 1 ▶ if ( $quote_pos <= 0 ) { $quote_pos = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($quote_pos <= 0) 1 0 1
11415 1 $beginning_tok = substr( $tok, $quote_pos - 1, 1 );
11416 }
11417 else {
11418 3041 $beginning_tok = $tok;
11419 3041 $quote_pos = 0;
11420 }
11421 $end_tok =
11422 $matching_end_token{$beginning_tok}
11423 3042 ▶ ? $matching_end_token{$beginning_tok}
Branch: 1 branch
BranchTrueFalseTotal
$matching_end_token{$beginning_tok} ? : 140 2902 3042
11424 : $beginning_tok;
11425 3042 $quote_depth = 1;
11426 3042 last;
11427 }
11428 }
11429 else {
11430 2 $allow_quote_comments = 1;
11431 }
11432 } ## end while ( $i < $max_token_index)
11433 }
11434  
11435 # There are two different loops which search for the ending quote
11436 # character. In the rare case of an alphanumeric quote delimiter, we
11437 # have to look through alphanumeric tokens character-by-character, since
11438 # the pre-tokenization process combines multiple alphanumeric
11439 # characters, whereas for a non-alphanumeric delimiter, only tokens of
11440 # length 1 can match.
11441  
11442 #----------------------------------------------------------------
11443 # Case 1 (rare): loop for case of alphanumeric quote delimiter..
11444 # "quote_pos" is the position the current word to begin searching
11445 #----------------------------------------------------------------
11446 3286 ▶ if ( !$is_punct_char{$beginning_tok} && $beginning_tok =~ /\w/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_punct_char{$beginning_tok} and $beginning_tok =~ /\w/) { } 1 3285 3286
Condition100%3/3
not $is_punct_char{$beginning_tok} and $beginning_tok =~ /\w/
!ll&&!rl&&r
328321
MC/DC100%2/2
not $is_punct_char{$beginning_tok} and $beginning_tok =~ /\w/
not $is_punct_char{$beginning_tok} $beginning_tok =~ /\w/
Truth table100%3/3
not(A) and B
A= not $is_punct_char{$beginning_tok}B= $beginning_tok =~ /\w/
ABresult
0X0
100
111
11447  
11448 # Note this because it is not recommended practice except
11449 # for obfuscated perl contests
11450 1 ▶ if ( $in_quote == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote == 1) 1 0 1
11451 1 $self->write_logfile_entry(
11452 "Note: alphanumeric quote delimiter ($beginning_tok) \n");
11453 }
11454  
11455 # Note: changed < to <= here to fix c109. Relying on extra end blanks.
11456 1 ▶ while ( $i <= $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $max_token_index) 4 0 4
11457  
11458 4 ▶ if ( $quote_pos == 0 || ( $i < 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote_pos == 0 or $i < 0) 3 1 4
Condition66%2/3
$quote_pos == 0 or $i < 0
l!l&&r!l&&!r
301
MC/DC50%1/2
$quote_pos == 0 or $i < 0
$quote_pos == 0 $i < 0
Truth table66%2/3
A or B
A= $quote_pos == 0B= $i < 0
ABresult
1X1
011
000
11459 3 $tok = $rtokens->[ ++$i ];
11460  
11461 3 ▶ if ( $tok eq BACKSLASH ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "\\") 1 2 3
11462  
11463 # retain backslash unless it hides the end token
11464 1 ▶ $quoted_string .= $tok
Branch: 1 branch
BranchTrueFalseTotal
unless $$rtokens[$i + 1] eq $end_tok 1 0 1
11465 unless ( $rtokens->[ $i + 1 ] eq $end_tok );
11466 1 $quote_pos++;
11467 1 ▶ last if ( $i >= $max_token_index );
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $max_token_index 0 1 1
11468 1 $tok = $rtokens->[ ++$i ];
11469 }
11470 }
11471 4 my $old_pos = $quote_pos;
11472  
11473 4 $quote_pos = 1 + index( $tok, $end_tok, $quote_pos );
11474  
11475 4 ▶ if ( $quote_pos > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote_pos > 0) { } 1 3 4
11476  
11477 1 $quoted_string .=
11478 substr( $tok, $old_pos, $quote_pos - $old_pos - 1 );
11479  
11480 # NOTE: any quote modifiers will be at the end of '$tok'. If we
11481 # wanted to check them, this is the place to get them. But
11482 # this quote form is rarely used in practice, so it isn't
11483 # worthwhile.
11484  
11485 1 $quote_depth--;
11486  
11487 1 ▶ if ( $quote_depth == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote_depth == 0) 1 0 1
11488 1 $in_quote--;
11489 1 last;
11490 }
11491 }
11492 else {
11493 3 ▶ if ( $old_pos <= length($tok) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_pos <= length $tok) 3 0 3
11494 3 $quoted_string .= substr( $tok, $old_pos );
11495 }
11496 }
11497 } ## end while ( $i <= $max_token_index)
11498 }
11499  
11500 #-----------------------------------------------------------------------
11501 # Case 2 (normal): loop for case of a non-alphanumeric quote delimiter..
11502 #-----------------------------------------------------------------------
11503 else {
11504  
11505 3285 ▶ while ( $i < $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $max_token_index) 12595 244 12839
11506 12595 $tok = $rtokens->[ ++$i ];
11507  
11508 12595 ▶ if ( $tok eq $end_tok ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($tok eq $end_tok) { } 3042 9553 12595
elsif ($tok eq $beginning_tok) { } 1 9552 9553
elsif ($tok eq '\\') { } 467 9085 9552
11509 3042 $quote_depth--;
11510  
11511 3042 ▶ if ( $quote_depth == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote_depth == 0) 3041 1 3042
11512 3041 $in_quote--;
11513 3041 last;
11514 }
11515 }
11516 elsif ( $tok eq $beginning_tok ) {
11517 1 $quote_depth++;
11518 }
11519 elsif ( $tok eq BACKSLASH ) {
11520  
11521 # retain backslash unless it hides the beginning or end token
11522 467 $tok = $rtokens->[ ++$i ];
11523 467 ▶ $quoted_string .= BACKSLASH
Branch: 1 branch
BranchTrueFalseTotal
if $tok ne $end_tok and $tok ne $beginning_tok 443 24 467
Condition100%3/3
$tok ne $end_tok and $tok ne $beginning_tok
!ll&&!rl&&r
231443
MC/DC100%2/2
$tok ne $end_tok and $tok ne $beginning_tok
$tok ne $end_tok $tok ne $beginning_tok
Truth table100%3/3
A and B
A= $tok ne $end_tokB= $tok ne $beginning_tok
ABresult
0X0
100
111
11524 if ( $tok ne $end_tok && $tok ne $beginning_tok );
11525 }
11526 else {
11527 ## nothing special
11528 }
11529 9554 $quoted_string .= $tok;
11530 } ## end while ( $i < $max_token_index)
11531 }
11532 3286 ▶ if ( $i > $max_token_index ) { $i = $max_token_index }
Branch: 1 branch
BranchTrueFalseTotal
if ($i > $max_token_index) 10 3276 3286
11533 return (
11534  
11535 3286 $i,
11536 $in_quote,
11537 $beginning_tok,
11538 $quote_pos,
11539 $quote_depth,
11540 $quoted_string,
11541  
11542 );
11543 } ## end sub follow_quoted_string
11544  
11545 sub indicate_error {
11546 0 ▶ my ( $self, $msg, $line_number, $input_line, $pos, $caret ) = @_;
Subroutine indicate_error: not called CC=1 SCAR=6.9
Pod undocumented
11547  
11548 # write input line and line with carat's showing where error was detected
11549 0 $self->interrupt_logfile();
11550 0 $self->warning($msg);
11551 0 $self->write_error_indicator_pair( $line_number, $input_line, $pos,
11552 $caret );
11553 0 $self->resume_logfile();
11554 0 return;
11555 } ## end sub indicate_error
11556  
11557 sub write_error_indicator_pair {
11558 0 ▶ my ( $self, $line_number, $input_line, $pos, $caret ) = @_;
Subroutine write_error_indicator_pair: not called CC=1 SCAR=6.9
Pod undocumented
11559 0 my ( $offset, $numbered_line, $underline ) =
11560 make_numbered_line( $line_number, $input_line, $pos );
11561 0 $underline = write_on_underline( $underline, $pos - $offset, $caret );
11562 0 $self->warning( $numbered_line . "\n" );
11563 0 $underline =~ s/\s+$//;
11564 0 $self->warning( $underline . "\n" );
11565 0 return;
11566 } ## end sub write_error_indicator_pair
11567  
11568 sub make_numbered_line {
11569  
11570 0 ▶ my ( $lineno, $str, $pos ) = @_;
Subroutine make_numbered_line: not called CC=6 SCAR=37.4
Pod undocumented
11571  
11572 # Given:
11573 # $lineno=line number
11574 # $str = an input line
11575 # $pos = character position of interest
11576 # Create a string not longer than 80 characters of the form:
11577 # $lineno: sub_string
11578 # such that the sub_string of $str contains the position of interest
11579 #
11580 # Here is an example of what we want, in this case we add trailing
11581 # '...' because the line is long.
11582 #
11583 # 2: (One of QAML 2.0's authors is a member of the World Wide Web Con ...
11584 #
11585 # Here is another example, this time in which we used leading '...'
11586 # because of excessive length:
11587 #
11588 # 2: ... er of the World Wide Web Consortium's
11589 #
11590 # input parameters are:
11591 # $lineno = line number
11592 # $str = the text of the line
11593 # $pos = position of interest (the error) : 0 = first character
11594 #
11595 # We return :
11596 # - $offset = an offset which corrects the position in case we only
11597 # display part of a line, such that $pos-$offset is the effective
11598 # position from the start of the displayed line.
11599 # - $numbered_line = the numbered line as above,
11600 # - $underline = a blank 'underline' which is all spaces with the same
11601 # number of characters as the numbered line.
11602  
11603 0 ▶ my $offset = ( $pos < 60 ) ? 0 : $pos - 40;
Branch: 1 branch
BranchTrueFalseTotal
$pos < 60 ? : 0 0 0
11604 0 my $excess = length($str) - $offset - 68;
11605 0 ▶ my $numc = ( $excess > 0 ) ? 68 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$excess > 0 ? : 0 0 0
11606  
11607 0 ▶ if ( defined($numc) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $numc) { } 0 0 0
11608 0 ▶ if ( $offset == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset == 0) { } 0 0 0
11609 0 $str = substr( $str, $offset, $numc - 4 ) . " ...";
11610 }
11611 else {
11612 0 $str = "... " . substr( $str, $offset + 4, $numc - 4 ) . " ...";
11613 }
11614 }
11615 else {
11616  
11617 0 ▶ if ( $offset == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset == 0) { } 0 0 0
11618 }
11619 else {
11620 0 $str = "... " . substr( $str, $offset + 4 );
11621 }
11622 }
11623  
11624 0 my $numbered_line = sprintf( "%d: ", $lineno );
11625 0 $offset -= length($numbered_line);
11626 0 $numbered_line .= $str;
11627 0 my $underline = SPACE x length($numbered_line);
11628 0 return ( $offset, $numbered_line, $underline );
11629 } ## end sub make_numbered_line
11630  
11631 sub write_on_underline {
11632  
11633 0 ▶ my ( $underline, $pos, $pos_chr ) = @_;
Subroutine write_on_underline: not called CC=4 SCAR=30.0
Pod undocumented
11634  
11635 # The "underline" is a string that shows where an error is; it starts
11636 # out as a string of blanks with the same length as the numbered line of
11637 # code above it, and we have to add marking to show where an error is.
11638 # In the example below, we want to write the string '--^' just below
11639 # the line of bad code:
11640 #
11641 # 2: (One of QAML 2.0's authors is a member of the World Wide Web Con ...
11642 # ---^
11643 # We are given the current underline string, plus a position and a
11644 # string to write on it.
11645 #
11646 # In the above example, there will be 2 calls to do this:
11647 # First call: $pos=19, pos_chr=^
11648 # Second call: $pos=16, pos_chr=---
11649 #
11650 # This is a trivial thing to do with substr, but there is some
11651 # checking to do.
11652  
11653 # check for error..shouldn't happen
11654 0 ▶ if ( $pos < 0 || $pos > length($underline) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < 0 or $pos > length $underline) 0 0 0
Condition0%0/3
$pos < 0 or $pos > length $underline
l!l&&r!l&&!r
000
MC/DC0%0/2
$pos < 0 or $pos > length $underline
$pos < 0 $pos > length $underline
Truth table0%0/3
A or B
A= $pos < 0B= $pos > length $underline
ABresult
1X1
011
000
11655 0 return $underline;
11656 }
11657 0 my $excess = length($pos_chr) + $pos - length($underline);
11658 0 ▶ if ( $excess > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($excess > 0) 0 0 0
11659 0 $pos_chr = substr( $pos_chr, 0, length($pos_chr) - $excess );
11660 }
11661 0 substr( $underline, $pos, length($pos_chr), $pos_chr );
11662 0 return ($underline);
11663 } ## end sub write_on_underline
11664  
11665 sub pre_tokenize {
11666  
11667 7306 ▶ my ( $str, ($max_tokens_wanted) ) = @_;
Subroutine pre_tokenize: called CC=7 SCAR=19.5
Pod undocumented
11668  
11669 # Input parameters:
11670 # $str = string to be parsed
11671 # $max_tokens_wanted > 0 to stop on reaching this many tokens.
11672 # = undef or 0 means get all tokens
11673  
11674 # Break a string, $str, into a sequence of preliminary tokens (pre-tokens).
11675 # We look for these types of tokens:
11676 # words (type='w'), example: 'max_tokens_wanted'
11677 # digits (type = 'd'), example: '0755'
11678 # whitespace (type = 'b'), example: ' '
11679 # single character punct (type = char) example: '='
11680  
11681 # Later operations will combine one or more of these pre-tokens into final
11682 # tokens. We cannot do better than this yet because we might be in a
11683 # quoted string or pattern.
11684  
11685 # An advantage of doing this pre-tokenization step is that it keeps almost
11686 # all of the regex parsing very simple and localized right here. A
11687 # disadvantage is that in some extremely rare instances we will have to go
11688 # back and split a pre-token.
11689  
11690 # Return parameters:
11691 7306 my @tokens = (); # array of the tokens themselves
11692 7306 my @token_map = (0); # string position of start of each token
11693 7306 my @type = (); # 'b'=whitespace, 'd'=digits, 'w'=alpha, or punct
11694  
11695 7306 ▶ if ( !$max_tokens_wanted ) { $max_tokens_wanted = -1 }
Branch: 1 branch
BranchTrueFalseTotal
unless ($max_tokens_wanted) 6985 321 7306
11696  
11697 7306 ▶ while ( $max_tokens_wanted-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max_tokens_wanted--) 97725 162 97887
11698  
11699 97725 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ / \G( (\s+) # type 'b' = whitespace - this must come before \W | (\W) # or type=char = single-character, non-whitespace punct | (\d+) # or type 'd' = sequence of digits - must come before \w | (\w+) # or type 'w' = words not starting with a digit ) /cgx) { } 90581 7144 97725
11700 $str =~ m{
11701 \G(
11702 (\s+) # type 'b' = whitespace - this must come before \W
11703 | (\W) # or type=char = single-character, non-whitespace punct
11704 | (\d+) # or type 'd' = sequence of digits - must come before \w
11705 | (\w+) # or type 'w' = words not starting with a digit
11706 )
11707 }gcx
11708 )
11709 {
11710 90581 push @tokens, $1;
11711 90581 ▶ push @type,
Branch: 3 branches
BranchTrueFalseTotal
defined $2 ? : 22168 68413 90581
defined $3 ? : 45527 22886 68413
defined $4 ? : 3393 19493 22886
11712 defined($2) ? 'b' : defined($3) ? $1 : defined($4) ? 'd' : 'w';
11713 90581 push @token_map, pos($str);
11714 }
11715  
11716 # that's all..
11717 else {
11718 7144 return ( \@tokens, \@token_map, \@type );
11719 }
11720 } ## end while ( $max_tokens_wanted...)
11721  
11722 162 return ( \@tokens, \@token_map, \@type );
11723 } ## end sub pre_tokenize
11724  
11725 sub show_tokens {
11726  
11727 # This is an uncalled debug routine, saved for reference
11728 0 ▶ my ( $rtokens, $rtoken_map ) = @_;
Subroutine show_tokens: not called CC=2 SCAR=17.9
Pod undocumented
11729 0 my $num = scalar( @{$rtokens} );
11730  
11731 0 foreach my $i ( 0 .. $num - 1 ) {
11732 0 my $len = length( $rtokens->[$i] );
11733 0 print {*STDOUT} "$i:$len:$rtoken_map->[$i]:$rtokens->[$i]:\n";
11734 }
11735 0 return;
11736 } ## end sub show_tokens
11737  
11738 sub dump_token_types {
11739 0 ▶ my ( $class, $fh ) = @_;
Subroutine dump_token_types: not called CC=1 SCAR=6.9
Pod undocumented
11740  
11741 # This should be the latest list of token types in use
11742 # adding NEW_TOKENS: add a comment here
11743 0 $fh->print(<<'END_OF_LIST');
11744  
11745 Here is a list of the token types currently used for lines of type 'CODE'.
11746 For the following tokens, the "type" of a token is just the token itself.
11747  
11748 .. :: << >> ** && .. || // -> => += -= .= %= &= |= ^= *= <>
11749 ( ) <= >= == =~ !~ != ++ -- /= x=
11750 ... **= <<= >>= &&= ||= //= <=>
11751 , + - / * | % ! x ~ = \ ? : . < > ^ & ^^
11752  
11753 The following additional token types are defined:
11754  
11755 type meaning
11756 b blank (white space)
11757 { indent: opening structural curly brace or square bracket or paren
11758 (code block, anonymous hash reference, or anonymous array reference)
11759 } outdent: right structural curly brace or square bracket or paren
11760 [ left non-structural square bracket (enclosing an array index)
11761 ] right non-structural square bracket
11762 ( left non-structural paren (all but a list right of an =)
11763 ) right non-structural paren
11764 L left non-structural curly brace (enclosing a key)
11765 R right non-structural curly brace
11766 ; terminal semicolon
11767 f indicates a semicolon in a "for" statement
11768 h here_doc operator <<
11769 # a comment
11770 Q indicates a quote or pattern
11771 q indicates a qw quote block
11772 k a perl keyword
11773 C user-defined constant or constant function (with void prototype = ())
11774 U user-defined function taking parameters
11775 G user-defined function taking block parameter (like grep/map/eval)
11776 S sub definition (reported as type 'i' in older versions)
11777 P package definition (reported as type 'i' in older versions)
11778 t type indicator such as %,$,@,*,&,sub
11779 w bare word (perhaps a subroutine call)
11780 i identifier of some type (with leading %, $, @, *, &, sub, -> )
11781 n a number
11782 v a v-string
11783 F a file test operator (like -e)
11784 Y File handle
11785 Z identifier in indirect object slot: may be file handle, object
11786 J LABEL: code block label
11787 j LABEL after next, last, redo, goto
11788 p unary +
11789 m unary -
11790 pp pre-increment operator ++
11791 mm pre-decrement operator --
11792 A : used as attribute separator
11793  
11794 Here are the '_line_type' codes used internally:
11795 SYSTEM - system-specific code before hash-bang line
11796 CODE - line of perl code (including comments)
11797 POD_START - line starting pod, such as '=head'
11798 POD - pod documentation text
11799 POD_END - last line of pod section, '=cut'
11800 HERE - text of here-document
11801 HERE_END - last line of here-doc (target word)
11802 FORMAT - format section
11803 FORMAT_END - last line of format section, '.'
11804 SKIP - code skipping section
11805 SKIP_END - last line of code skipping section, '#>>V'
11806 DATA_START - __DATA__ line
11807 DATA - unidentified text following __DATA__
11808 END_START - __END__ line
11809 END - unidentified text following __END__
11810 ERROR - we are in big trouble, probably not a perl script
11811 END_OF_LIST
11812  
11813 0 return;
11814 } ## end sub dump_token_types
11815  
11816 #------------------
11817 # About Token Types
11818 #------------------
11819  
11820 # The array "valid_token_types" in the BEGIN section has an up-to-date list
11821 # of token types. Sub 'dump_token_types' should be kept up to date with
11822 # token types.
11823  
11824 # Ideally, tokens are the smallest pieces of text
11825 # such that a newline may be inserted between any pair of tokens without
11826 # changing or invalidating the program. This version comes close to this,
11827 # although there are necessarily a few exceptions which must be caught by
11828 # the formatter. Many of these involve the treatment of bare words.
11829 #
11830 # To simplify things, token types are either a single character, or they
11831 # are identical to the tokens themselves.
11832 #
11833 # As a debugging aid, the -D flag creates a file containing a side-by-side
11834 # comparison of the input string and its tokenization for each line of a file.
11835 # This is an invaluable debugging aid.
11836 #
11837 # In addition to tokens, and some associated quantities, the tokenizer
11838 # also returns flags indication any special line types. These include
11839 # quotes, here_docs, formats.
11840 #
11841 #------------------
11842 # Adding NEW_TOKENS
11843 #------------------
11844 #
11845 # Here are some notes on the minimal steps. I wrote these notes while
11846 # adding the 'v' token type for v-strings, which are things like version
11847 # numbers 5.6.0, and ip addresses, and will use that as an example. ( You
11848 # can use your editor to search for the string "NEW_TOKENS" to find the
11849 # appropriate sections to change):
11850  
11851 # *. For another example, search for the smartmatch operator '~~'
11852 # with your editor to see where updates were made for it.
11853  
11854 # *. For another example, search for the string 'c250', which shows
11855 # locations where changes for new types 'P' and 'S' were made.
11856  
11857 # *. Think of a new, unused character for the token type, and add to
11858 # the array @valid_token_types in the BEGIN section of this package.
11859 # For example, I used 'v' for v-strings.
11860 #
11861 # *. Implement coding to recognize the $type of the token in this routine.
11862 # This is the hardest part, and is best done by imitating or modifying
11863 # some of the existing coding. For example, to recognize v-strings, I
11864 # patched 'sub scan_bare_identifier' to recognize v-strings beginning with
11865 # 'v' and 'sub scan_number' to recognize v-strings without the leading 'v'.
11866 #
11867 # *. Update sub operator_expected. This update is critically important but
11868 # the coding is trivial. Look at the comments in that routine for help.
11869 # For v-strings, which should behave like numbers, I just added 'v' to the
11870 # regex used to handle numbers and strings (types 'n' and 'Q').
11871 #
11872 # *. Implement a 'bond strength' rule in sub set_bond_strengths in
11873 # Perl::Tidy::Formatter for breaking lines around this token type. You can
11874 # skip this step and take the default at first, then adjust later to get
11875 # desired results. For adding type 'v', I looked at sub bond_strength and
11876 # saw that number type 'n' was using default strengths, so I didn't do
11877 # anything. I may tune it up someday if I don't like the way line
11878 # breaks with v-strings look.
11879 #
11880 # *. Implement a 'whitespace' rule in sub set_whitespace_flags in
11881 # Perl::Tidy::Formatter. For adding type 'v', I looked at this routine
11882 # and saw that type 'n' used spaces on both sides, so I just added 'v'
11883 # to the array @spaces_both_sides.
11884 #
11885 # *. Update HtmlWriter package so that users can colorize the token as
11886 # desired. This is quite easy; see comments identified by 'NEW_TOKENS' in
11887 # that package. For v-strings, I initially chose to use a default color
11888 # equal to the default for numbers, but it might be nice to change that
11889 # eventually.
11890 #
11891 # *. Update comments in Perl::Tidy::Tokenizer::dump_token_types.
11892 #
11893 # *. Run lots and lots of debug tests. Start with special files designed
11894 # to test the new token type. Run with the -D flag to create a .DEBUG
11895 # file which shows the tokenization. When these work ok, test as many old
11896 # scripts as possible. Start with all of the '.t' files in the 'test'
11897 # directory of the distribution file. Compare .tdy output with previous
11898 # version and updated version to see the differences. Then include as
11899 # many more files as possible. My own technique has been to collect a huge
11900 # number of perl scripts (thousands!) into one directory and run perltidy
11901 # *, then run diff between the output of the previous version and the
11902 # current version.
11903  
11904 BEGIN {
11905  
11906 # These names are used in error messages
11907 45 ▶ @opening_brace_names = qw# '{' '[' '(' '?' #;
Subroutine BEGIN: called CC=38 SCAR=36.4
11908 45 @closing_brace_names = qw# '}' ']' ')' ':' #;
11909  
11910 45 my @q;
11911  
11912 45 my @digraphs = qw#
11913 .. :: << >> ** && || // -> => += -= .= %= &= |= ^= *= <>
11914 <= >= == =~ !~ != ++ -- /= x= ~~ ~. |. &. ^. ^^
11915 #;
11916 45 $is_digraph{$_} = 1 for @digraphs;
11917  
11918 45 @q = qw(
11919 . : < > * & | / - = + - % ^ ! x ~
11920 );
11921 45 $can_start_digraph{$_} = 1 for @q;
11922  
11923 45 my @trigraphs =
11924 qw( ... **= <<= >>= &&= ||= //= <=> !~~ &.= |.= ^.= <<~ ^^= );
11925 45 $is_trigraph{$_} = 1 for @trigraphs;
11926  
11927 45 my @tetragraphs = qw( <<>> );
11928 45 $is_tetragraph{$_} = 1 for @tetragraphs;
11929  
11930 # make a hash of all valid token types for self-checking the tokenizer
11931 # (adding NEW_TOKENS : select a new character and add to this list)
11932 # fix for c250: added new token type 'P' and 'S'
11933 45 my @valid_token_types = qw#
11934 A b C G L R f h Q k t w i q n p m F pp mm U j J Y Z v P S
11935 { } ( ) [ ] ; + - / * | % ! x ~ = ? : . < > ^ &
11936 #;
11937 45 push @valid_token_types, BACKSLASH;
11938 45 push @valid_token_types, @digraphs;
11939 45 push @valid_token_types, @trigraphs;
11940 45 push @valid_token_types, @tetragraphs;
11941 45 push @valid_token_types, ( '#', COMMA, 'CORE::' );
11942 45 $is_valid_token_type{$_} = 1 for @valid_token_types;
11943  
11944 # a list of file test letters, as in -e (Table 3-4 of 'camel 3')
11945 45 my @file_test_operators =
11946 qw( A B C M O R S T W X b c d e f g k l o p r s t u w x z );
11947 45 $is_file_test_operator{$_} = 1 for @file_test_operators;
11948  
11949 # these functions have prototypes of the form (&), so when they are
11950 # followed by a block, that block MAY BE followed by an operator.
11951 # Smartmatch operator ~~ may be followed by anonymous hash or array ref
11952 45 @q = qw( do eval );
11953 45 $is_block_operator{$_} = 1 for @q;
11954  
11955 # These functions allow an identifier in the indirect object slot:
11956 45 @q = qw( print printf sort exec system say );
11957 45 $is_indirect_object_taker{$_} = 1 for @q;
11958  
11959 # Keywords which definitely produce error if an OPERATOR is expected
11960 # The following small list was used until version 20260705:
11961 # @q = qw( my our state local use require );
11962 # This list was expanded to the list below to catch more errors (c613).
11963 45 @q = qw(
11964 AUTOLOAD BEGIN CHECK DESTROY
11965 END INIT UNITCHECK abs
11966 accept alarm atan2 bind
11967 binmode bless break caller
11968 catch chdir chmod chomp
11969 chop chown chr chroot
11970 close closedir connect continue
11971 cos crypt dbmclose dbmopen
11972 default defined delete die
11973 do dump each else
11974 elsif endgrent endhostent endnetent
11975 endprotoent endpwent endservent eof
11976 eval evalbytes exec exists
11977 exit exp fc fcntl
11978 fileno flock fork format
11979 formline getc getgrent getgrgid
11980 getgrnam gethostbyaddr gethostbyname gethostent
11981 getlogin getnetbyaddr getnetbyname getnetent
11982 getpeername getpgrp getppid getpriority
11983 getprotobyname getprotobynumber getprotoent getpwent
11984 getpwnam getpwuid getservbyname getservbyport
11985 getservent getsockname getsockopt given
11986 glob gmtime goto grep
11987 hex index int ioctl
11988 join keys kill last
11989 lc lcfirst length link
11990 listen local localtime lock
11991 log lstat m map
11992 mkdir msgctl msgget msgrcv
11993 msgsnd my next no
11994 not oct open opendir
11995 ord our pack package
11996 pipe pop pos print
11997 printf prototype push q
11998 qq qr quotemeta qw
11999 qx rand read readdir
12000 readline readlink readpipe recv
12001 redo ref rename require
12002 reset return reverse rewinddir
12003 rindex rmdir s say
12004 scalar seek seekdir select
12005 semctl semget semop send
12006 setgrent sethostent setnetent setpgrp
12007 setpriority setprotoent setpwent setservent
12008 setsockopt shift shmctl shmget
12009 shmread shmwrite shutdown sin
12010 sleep socket socketpair sort
12011 splice split sprintf sqrt
12012 srand stat state study
12013 sub substr switch symlink
12014 syscall sysopen sysread sysseek
12015 system syswrite tell telldir
12016 tie tied time times
12017 tr truncate uc ucfirst
12018 umask undef unlink unpack
12019 unshift untie use utime
12020 values vec wait waitpid
12021 wantarray warn write y
12022 );
12023 45 $is_TERM_keyword{$_} = 1 for @q;
12024  
12025 # Stable keyword infix operators which produce error if a TERM is expected
12026 45 @q = qw( and or xor eq ne ge gt le lt );
12027 45 $is_OPERATOR_keyword{$_} = 1 for @q;
12028  
12029 # Keywords which are omitted from the above TERM or OPERATOR lists.
12030 # Note that 'cmp' is here since it can be re-defined by File::Compare.
12031 # qw( isa err cmp if unless for foreach when while until case
12032 # EQ GE GT LE LT NE );
12033  
12034 # Note: 'field' will be added by sub check_options if --use-feature=class
12035 45 @q = qw( my our state );
12036 45 $is_my_our_state{$_} = 1 for @q;
12037  
12038 # These tokens may precede a code block
12039 # patched for SWITCH/CASE/CATCH. Actually these could be removed
12040 # now and we could let the extended-syntax coding handle them.
12041 # Added 'default' for Switch::Plain.
12042 # Note: 'ADJUST' will be added by sub check_options if --use-feature=class
12043 45 @q = qw(
12044 BEGIN END CHECK INIT AUTOLOAD DESTROY
12045 UNITCHECK continue if elsif else unless
12046 do while until eval for foreach
12047 map grep sort switch case given
12048 when default catch try finally
12049 );
12050 45 $is_code_block_token{$_} = 1 for @q;
12051  
12052 # These block types terminate statements and do not need a trailing
12053 # semicolon; patched for SWITCH/CASE/; This may be updated in sub
12054 # check_options.
12055 45 @q = qw( } { BEGIN END CHECK INIT AUTOLOAD DESTROY UNITCHECK continue ;
12056 if elsif else unless while until for foreach switch case given when );
12057 45 $is_zero_continuation_block_type{$_} = 1 for @q;
12058  
12059 # Note: this hash was formerly named '%is_not_zero_continuation_block_type'
12060 # to contrast it with the block types in '%is_zero_continuation_block_type'
12061 # Note: added 'sub' for anonymous sub blocks (c443)
12062 45 @q = qw( sort map grep eval do sub );
12063 45 $is_sort_map_grep_eval_do_sub{$_} = 1 for @q;
12064  
12065 45 @q = qw( sort map grep );
12066 45 $is_sort_map_grep{$_} = 1 for @q;
12067  
12068 45 %is_grep_alias = ();
12069  
12070 # I'll build the list of keywords incrementally
12071 45 my @Keywords = ();
12072  
12073 # keywords and tokens after which a value or pattern is expected,
12074 # but not an operator. In other words, these should consume terms
12075 # to their right, or at least they are not expected to be followed
12076 # immediately by operators.
12077 45 my @value_requestor = qw(
12078 AUTOLOAD BEGIN CHECK DESTROY
12079 END EQ GE GT
12080 INIT LE LT NE
12081 UNITCHECK abs accept alarm
12082 and atan2 bind binmode
12083 bless break caller chdir
12084 chmod chomp chop chown
12085 chr chroot close closedir
12086 cmp connect continue cos
12087 crypt dbmclose dbmopen defined
12088 delete die dump each
12089 else elsif eof eq
12090 evalbytes exec exists exit
12091 exp fc fcntl fileno
12092 flock for foreach formline
12093 ge getc getgrgid getgrnam
12094 gethostbyaddr gethostbyname getnetbyaddr getnetbyname
12095 getpeername getpgrp getpriority getprotobyname
12096 getprotobynumber getpwnam getpwuid getservbyname
12097 getservbyport getsockname getsockopt glob
12098 gmtime goto grep gt
12099 hex if index int
12100 ioctl join keys kill
12101 last lc lcfirst le
12102 length link listen local
12103 localtime lock log lstat
12104 lt map mkdir msgctl
12105 msgget msgrcv msgsnd my
12106 ne next no not
12107 oct open opendir or
12108 ord our pack pipe
12109 pop pos print printf
12110 prototype push quotemeta rand
12111 read readdir readlink readline
12112 readpipe recv redo ref
12113 rename require reset return
12114 reverse rewinddir rindex rmdir
12115 scalar seek seekdir select
12116 semctl semget semop send
12117 sethostent setnetent setpgrp setpriority
12118 setprotoent setservent setsockopt shift
12119 shmctl shmget shmread shmwrite
12120 shutdown sin sleep socket
12121 socketpair sort splice split
12122 sprintf sqrt srand stat
12123 state study substr symlink
12124 syscall sysopen sysread sysseek
12125 system syswrite tell telldir
12126 tie tied truncate uc
12127 ucfirst umask undef unless
12128 unlink unpack unshift untie
12129 until use utime values
12130 vec waitpid warn while
12131 write xor case catch
12132 default err given isa
12133 say switch when
12134 );
12135  
12136 # Note: 'ADJUST', 'field' are added by sub check_options
12137 # if --use-feature=class
12138  
12139 # patched above for SWITCH/CASE given/when err say
12140 # 'err' is a fairly safe addition.
12141 # Added 'default' for Switch::Plain. Note that we could also have
12142 # a separate set of keywords to include if we see 'use Switch::Plain'
12143 45 push @Keywords, @value_requestor;
12144  
12145 # These are treated the same but are not keywords:
12146 45 my @extra_vr = qw( constant vars );
12147 45 push @value_requestor, @extra_vr;
12148  
12149 45 $expecting_term_token{$_} = 1 for @value_requestor;
12150  
12151 # this list contains keywords which do not look for arguments,
12152 # so that they might be followed by an operator, or at least
12153 # not a term.
12154 45 my @operator_requestor = qw(
12155 endgrent endhostent endnetent endprotoent
12156 endpwent endservent fork getgrent
12157 gethostent getlogin getnetent getppid
12158 getprotoent getpwent getservent setgrent
12159 setpwent time times wait
12160 wantarray
12161 );
12162  
12163 45 push @Keywords, @operator_requestor;
12164  
12165 # These are treated the same but are not considered keywords:
12166 45 my @extra_or = qw( STDERR STDIN STDOUT );
12167  
12168 45 push @operator_requestor, @extra_or;
12169  
12170 45 $expecting_operator_token{$_} = 1 for @operator_requestor;
12171  
12172 # these token TYPES expect trailing operator but not a term
12173 # note: ++ and -- are post-increment and decrement, 'C' = constant
12174 45 my @operator_requestor_types = qw( ++ -- C <> q );
12175  
12176 # NOTE: This hash is available but not currently used
12177 45 $expecting_operator_types{$_} = 1 for @operator_requestor_types;
12178  
12179 # these token TYPES consume values (terms)
12180 # note: pp and mm are pre-increment and decrement
12181 # f=semicolon in for, F=file test operator
12182 45 my @value_requestor_type = qw#
12183 L { ( [ ~ !~ =~ ; . .. ... A : && ! || // = + - x
12184 **= += -= .= /= *= %= x= &= |= ^= <<= >>= &&= ||= //=
12185 <= >= == != => > < % * / ? & | ** <=> ~~ !~~ <<~
12186 f F pp mm Y p m U J G j >> << ^ t
12187 ~. ^. |. &. ^.= |.= &.= ^^
12188 #;
12189 45 push @value_requestor_type, BACKSLASH;
12190 45 push @value_requestor_type, COMMA;
12191  
12192 # NOTE: This hash is available but not currently used
12193 45 $expecting_term_types{$_} = 1 for @value_requestor_type;
12194  
12195 # Note: the following valid token types are not assigned here to
12196 # hashes requesting to be followed by values or terms, but are
12197 # instead currently hard-coded into sub operator_expected:
12198 # ) -> :: Q R Z ] b h i k n v w } #
12199  
12200 # A syntax error will occur if following operators are not followed by a
12201 # TERM (with an exception made for tokens in sub signatures).
12202 # NOTE: this list does not include unary operator '!'
12203  
12204 # Note the following omissions from the syntax checking operators below
12205 # 'U' = user sub, depends on prototype
12206 # 'F' = file test works on $_ if no following term
12207 # 'Y' = indirect object, too risky to check syntax
12208  
12209 45 my @binary_ops = qw#
12210 !~ =~ . .. : && || // = + - x
12211 **= += -= .= /= *= %= x= &= |= ^= <<= >>= &&= ||= //=
12212 <= >= == != > < % * / ? & | ** <=> ~~ !~~ <<~
12213 >> << ^
12214 ^. |. &. ^.= |.= &.= ^^
12215 #;
12216 45 $is_binary_operator_type{$_} = 1 for @binary_ops;
12217  
12218 # Note: omitting unary file test type 'F' here because it assumes $_
12219 45 my @unary_ops = qw# ! ~ ~. m p mm pp #;
12220 45 $is_binary_operator_type{$_} = 1 for @binary_ops;
12221 45 push @unary_ops, BACKSLASH;
12222 45 $is_binary_or_unary_operator_type{$_} = 1 for ( @binary_ops, @unary_ops );
12223  
12224 # added xor ge gt le lt ( git #206 )
12225 45 my @binary_keywords = qw( and or err eq ne cmp xor ge gt le lt );
12226 45 $is_binary_keyword{$_} = 1 for @binary_keywords;
12227  
12228 45 $is_binary_or_unary_keyword{$_} = 1 for ( @binary_keywords, 'not' );
12229  
12230 # A syntax error occurs if a binary operator follows any of these types:
12231 # NOTE: a ',' cannot be included because of parenless calls (c015).
12232 # For example this is valid: print "hello\n", && print "goodbye\n";
12233 # NOTE: the 'not' keyword could be added to a corresponding _keyword list
12234 # NOTE: label 'j' omitted, for example: -f $file ? redo BLOCK : last BLOCK;
12235 # NOTE: Removed 'A': fixes git162.t
12236 45 @q = qw< L { [ ( ; f J t >;
12237 45 $is_not_a_TERM_producer_type{$_} = 1 for ( @q, @unary_ops );
12238  
12239 45 @q = qw( q qq qx qr s y tr m );
12240 45 $is_q_qq_qx_qr_s_y_tr_m{$_} = 1 for @q;
12241  
12242 # Note added 'qw' here
12243 45 @q = qw( q qq qw qx qr s y tr m );
12244 45 $is_q_qq_qw_qx_qr_s_y_tr_m{$_} = 1 for @q;
12245  
12246 # Quote modifiers:
12247 # original ref: camel 3 p 147,
12248 # but perl may accept undocumented flags
12249 # perl 5.10 adds 'p' (preserve)
12250 # Perl version 5.22 added 'n'
12251 # From http://perldoc.perl.org/perlop.html we have
12252 # /PATTERN/msixpodualngc or m?PATTERN?msixpodualngc
12253 # s/PATTERN/REPLACEMENT/msixpodualngcer
12254 # y/SEARCHLIST/REPLACEMENTLIST/cdsr
12255 # tr/SEARCHLIST/REPLACEMENTLIST/cdsr
12256 # qr/STRING/msixpodualn
12257 45 %quote_modifiers = (
12258 's' => '[msixpodualngcer]',
12259 'y' => '[cdsr]',
12260 'tr' => '[cdsr]',
12261 'm' => '[msixpodualngc]',
12262 'qr' => '[msixpodualn]',
12263 'q' => EMPTY_STRING,
12264 'qq' => EMPTY_STRING,
12265 'qw' => EMPTY_STRING,
12266 'qx' => EMPTY_STRING,
12267 );
12268  
12269 # Note: 'class' will be added by sub check_options if -use-feature=class
12270 45 @q = qw( package );
12271 45 $is_package{$_} = 1 for @q;
12272  
12273 45 @q = qw( if elsif unless );
12274 45 $is_if_elsif_unless{$_} = 1 for @q;
12275  
12276 45 @q = qw( ; t );
12277 45 $is_semicolon_or_t{$_} = 1 for @q;
12278  
12279 45 @q = qw( if elsif unless case when );
12280 45 $is_if_elsif_unless_case_when{$_} = 1 for @q;
12281  
12282 # Hash of other possible line endings which may occur.
12283 # Keep these coordinated with the regex where this is used.
12284 # Note: chr(13) = chr(015)="\r".
12285 45 @q = ( chr(13), chr(29), chr(26) );
12286 45 $other_line_endings{$_} = 1 for @q;
12287  
12288 # These keywords are handled specially in the tokenizer code:
12289 45 my @special_keywords =
12290 qw( do eval format m package q qq qr qw qx s sub tr y );
12291 45 push @Keywords, @special_keywords;
12292  
12293 # Keywords after which list formatting may be used
12294 # WARNING: do not include |map|grep|eval or perl may die on
12295 # syntax errors (map1.t).
12296 45 my @keyword_taking_list = qw(
12297 and chmod chomp chop
12298 chown dbmopen die elsif
12299 exec fcntl for foreach
12300 formline getsockopt given if
12301 index ioctl join kill
12302 local msgctl msgrcv msgsnd
12303 my open or our
12304 pack print printf push
12305 read readpipe recv return
12306 reverse rindex seek select
12307 semctl semget send setpriority
12308 setsockopt shmctl shmget shmread
12309 shmwrite socket socketpair sort
12310 splice split sprintf state
12311 substr syscall sysopen sysread
12312 sysseek system syswrite tie
12313 unless unlink unpack unshift
12314 until vec warn when
12315 while
12316 );
12317  
12318 # NOTE: This hash is available but not currently used
12319 45 $is_keyword_taking_list{$_} = 1 for @keyword_taking_list;
12320  
12321 # perl functions which may be unary operators.
12322  
12323 # This list is used to decide if a pattern delimited by slashes, /pattern/,
12324 # can follow one of these keywords.
12325 45 @q = qw( chomp eof eval fc lc pop shift uc undef );
12326  
12327 45 $is_keyword_rejecting_slash_as_pattern_delimiter{$_} = 1 for @q;
12328  
12329 # These are keywords for which an arg may optionally be omitted. They are
12330 # currently only used to disambiguate a ? used as a ternary from one used
12331 # as a (deprecated) pattern delimiter. In the future, they might be used
12332 # to give a warning about ambiguous syntax before a /.
12333 # Note: split has been omitted (see note below).
12334 45 my @keywords_taking_optional_arg = qw(
12335 abs alarm caller chdir chomp chop
12336 chr chroot close cos defined die
12337 eof eval evalbytes exit exp fc
12338 getc glob gmtime hex int last
12339 lc lcfirst length localtime log lstat
12340 mkdir next oct ord pop pos
12341 print printf prototype quotemeta rand readline
12342 readlink readpipe redo ref require reset
12343 reverse rmdir say select shift sin
12344 sleep sqrt srand stat study tell
12345 uc ucfirst umask undef unlink warn
12346 write
12347 );
12348 45 $is_keyword_taking_optional_arg{$_} = 1 for @keywords_taking_optional_arg;
12349  
12350 # This list is used to decide if a pattern delimited by question marks,
12351 # ?pattern?, can follow one of these keywords. Note that from perl 5.22
12352 # on, a ?pattern? is not recognized, so we can be much more strict than
12353 # with a /pattern/. Note that 'split' is not in this list. In current
12354 # versions of perl a question following split must be a ternary, but
12355 # in older versions it could be a pattern. The guessing algorithm will
12356 # decide. We are combining two lists here to simplify the test.
12357 45 @q = ( @keywords_taking_optional_arg, @operator_requestor );
12358 45 $is_keyword_rejecting_question_as_pattern_delimiter{$_} = 1 for @q;
12359  
12360 # These are not used in any way yet
12361 # my @unused_keywords = qw(
12362 # __FILE__
12363 # __LINE__
12364 # __PACKAGE__
12365 # );
12366  
12367 # The list of keywords was originally extracted from function 'keyword' in
12368 # perl file toke.c version 5.005.03, using this utility, plus a
12369 # little editing: (file getkwd.pl):
12370 # while (<>) { while (/\"(.*)\"/g) { print "$1\n"; } }
12371 # Add 'get' prefix where necessary, then split into the above lists.
12372 # This list should be updated as necessary.
12373 # The list should not contain these special variables:
12374 # ARGV DATA ENV SIG STDERR STDIN STDOUT
12375 # __DATA__ __END__
12376  
12377 45 $is_keyword{$_} = 1 for @Keywords;
12378  
12379 45 %matching_end_token = (
12380 '{' => '}',
12381 '(' => ')',
12382 '[' => ']',
12383 '<' => '>',
12384 );
12385 } ## end BEGIN
12386  
12387 } ## end package Perl::Tidy::Tokenizer
12388 45 1;
« Tidy.pm ↑ Summary Tidy/Logger.pm »