Tidy/Tokenizer.pm

filter: Statementstmt 73.2% 2787 / 3806 Branchbran 66.6% 1314 / 1972 Conditioncond 64.8% 812 / 1253 MC/DCmcdc 42.7% 292 / 683 Subroutinesub 83.0% 167 / 201 Podpod 0.0% 0 / 146 totaltotal 66.6% 5372 / 8061 CC 1484 SCAR 43.2
CC
1484
Cov
70%
show_indentation_table
650.0
do_BAREWORD
225.8
guess_if_pattern_or_division
182.0
CRAP 74.8
« 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 = '20260826';
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 $rOpts_warn_unexpected_code_container,
189  
190 $tabsize,
191 %is_END_DATA_format_sub,
192 %is_grep_alias,
193 %is_sub,
194 $guess_if_method,
195 );
196  
197 # possible values of operator_expected()
198 45 ▶use constant TERM => -1;
Subroutine BEGIN: called CC=1 SCAR=0.0
199 45 ▶use constant UNKNOWN => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
200 45 ▶use constant OPERATOR => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
201  
202 # possible values of context
203 45 ▶use constant SCALAR_CONTEXT => -1;
Subroutine BEGIN: called CC=1 SCAR=0.0
204 45 ▶use constant UNKNOWN_CONTEXT => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
205 45 ▶use constant LIST_CONTEXT => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
206  
207 # Maximum number of little messages; probably need not be changed.
208 45 ▶use constant MAX_NAG_MESSAGES => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
209  
210 45 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
211  
212 # Array index names for $self.
213 # Do not combine with other BEGIN blocks (c101).
214 45 my $i = 0;
215 45 ▶ use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
216 45 _rhere_target_list_ => $i++,
217 _in_here_doc_ => $i++,
218 _here_doc_target_ => $i++,
219 _here_quote_character_ => $i++,
220 _in_data_ => $i++,
221 _in_end_ => $i++,
222 _in_format_ => $i++,
223 _in_error_ => $i++,
224 _do_not_format_ => $i++,
225 _warning_count_ => $i++,
226 _html_tag_count_ => $i++,
227 _in_pod_ => $i++,
228 _in_code_skipping_ => $i++,
229 _in_format_skipping_ => $i++,
230 _rformat_skipping_list_ => $i++,
231 _in_attribute_list_ => $i++,
232 _in_quote_ => $i++,
233 _quote_target_ => $i++,
234 _line_start_quote_ => $i++,
235 _starting_level_ => $i++,
236 _know_starting_level_ => $i++,
237 _last_line_number_ => $i++,
238 _saw_perl_dash_P_ => $i++,
239 _saw_perl_dash_w_ => $i++,
240 _saw_use_strict_ => $i++,
241 _saw_brace_error_ => $i++,
242 _hit_bug_ => $i++,
243 _look_for_autoloader_ => $i++,
244 _look_for_selfloader_ => $i++,
245 _saw_autoloader_ => $i++,
246 _saw_selfloader_ => $i++,
247 _saw_hash_bang_ => $i++,
248 _saw_end_ => $i++,
249 _saw_data_ => $i++,
250 _saw_negative_indentation_ => $i++,
251 _started_tokenizing_ => $i++,
252 _debugger_object_ => $i++,
253 _diagnostics_object_ => $i++,
254 _logger_object_ => $i++,
255 _save_logfile_ => $i++,
256 _unexpected_error_count_ => $i++,
257 _started_looking_for_here_target_at_ => $i++,
258 _nearly_matched_here_target_at_ => $i++,
259 _line_of_text_ => $i++,
260 _rlower_case_labels_at_ => $i++,
261 _maximum_level_ => $i++,
262 _true_brace_error_count_ => $i++,
263 _rOpts_ => $i++,
264 _rinput_lines_ => $i++,
265 _input_line_index_next_ => $i++,
266 _rtrimmed_input_lines_ => $i++,
267 _rclosing_brace_indentation_hash_ => $i++,
268 _show_indentation_table_ => $i++,
269 _rnon_indenting_brace_stack_ => $i++,
270 _rseqno_at_depth_ => $i++,
271 _rbareword_info_ => $i++,
272 _rsaw_unknown_syntax_in_seqno_ => $i++,
273 45 };
274 } ## end BEGIN
275  
276 { ## closure for subs to count instances
277  
278 # methods to count instances
279 45 my $_count = 0;
280 0 ▶ sub get_count { return $_count; }
Subroutine get_count: not called CC=1 SCAR=6.9
Pod undocumented
281 666 ▶ sub _increment_count { return ++$_count }
Subroutine _increment_count: called CC=1 SCAR=0.0
282 666 ▶ sub _decrement_count { return --$_count }
Subroutine _decrement_count: called CC=1 SCAR=0.0
283 }
284  
285 45 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
286 666 my $self = shift;
287 666 _decrement_count();
288 666 return;
289 }
290  
291 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
292  
293 # Catch any undefined sub calls so that we are sure to get
294 # some diagnostic information. This sub should never be called
295 # except for a programming error.
296 0 our $AUTOLOAD;
297 0 ▶ return if ( $AUTOLOAD =~ /\bDESTROY$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $Perl::Tidy::Tokenizer::AUTOLOAD =~ /\bDESTROY$/ 0 0 0
298 0 my ( $pkg, $fname, $lno ) = caller();
299 0 my $my_package = __PACKAGE__;
300 0 print {*STDERR} <<EOM;
301 ======================================================================
302 Error detected in package '$my_package', version $VERSION
303 Received unexpected AUTOLOAD call for sub '$AUTOLOAD'
304 Called from package: '$pkg'
305 Called from File '$fname' at line '$lno'
306 This error is probably due to a recent programming change
307 ======================================================================
308 EOM
309 0 exit 1;
310 } ## end sub AUTOLOAD
311  
312 0 ▶sub Die {
Subroutine Die: not called CC=1 SCAR=6.9
Pod undocumented
313 0 my ($msg) = @_;
314 0 Perl::Tidy::Die($msg);
315 0 croak "unexpected return from Perl::Tidy::Die";
316 }
317  
318 0 ▶sub Warn {
Subroutine Warn: not called CC=1 SCAR=6.9
Pod undocumented
319 0 my ($msg) = @_;
320 0 Perl::Tidy::Warn($msg);
321 0 return;
322 }
323  
324 0 ▶sub Fault {
Subroutine Fault: not called CC=1 SCAR=6.9
Pod undocumented
325 0 my ($msg) = @_;
326  
327 # This routine is called for errors that really should not occur
328 # except if there has been a bug introduced by a recent program change.
329 # Please add comments at calls to Fault to explain why the call
330 # should not occur, and where to look to fix it.
331 0 my ( $package0_uu, $filename0_uu, $line0, $subroutine0_uu ) = caller(0);
332 0 my ( $package1_uu, $filename1, $line1, $subroutine1 ) = caller(1);
333 0 my ( $package2_uu, $filename2_uu, $line2_uu, $subroutine2 ) = caller(2);
334 0 my $pkg = __PACKAGE__;
335 0 my $input_stream_name = Perl::Tidy::get_input_stream_name();
336  
337 0 Die(<<EOM);
338 ==============================================================================
339 While operating on input stream with name: '$input_stream_name'
340 A fault was detected at line $line0 of sub '$subroutine1'
341 in file '$filename1'
342 which was called from line $line1 of sub '$subroutine2'
343 Message: '$msg'
344 This is probably an error introduced by a recent programming change.
345 $pkg reports VERSION='$VERSION'.
346 ==============================================================================
347 EOM
348  
349 0 croak "unexpected return from sub Die";
350 } ## end sub Fault
351  
352 2656 ▶sub bad_pattern {
Subroutine bad_pattern: called CC=1 SCAR=0.0
Pod undocumented
353 2656 my ($pattern) = @_;
354  
355 # Return true if a regex pattern has an error
356 # Note: Formatter.pm also has a copy of this
357 2656 my $regex_uu = eval { qr/$pattern/ };
358 2656 return $EVAL_ERROR;
359 } ## end sub bad_pattern
360  
361 2656 ▶sub make_skipping_pattern {
Subroutine make_skipping_pattern: called CC=4 SCAR=14.4
Pod undocumented
362 2656 my ( $rOpts, $opt_name, $default ) = @_;
363  
364 # Make regex patterns for the format-skipping and code-skipping options
365 2656 my $param = $rOpts->{$opt_name};
366 2656 ▶ if ( !$param ) { $param = $default }
Branch: 1 branch
BranchTrueFalseTotal
unless ($param) 2652 4 2656
367 2656 $param =~ s/^\s+//;
368 2656 ▶ if ( $param !~ /^#/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($param =~ /^#/) 0 2656 2656
369 0 Die("ERROR: the $opt_name parameter '$param' must begin with '#'\n");
370 }
371  
372 # Note that the ending \s will match a newline
373 2656 my $pattern = '^\s*' . $param . '\s';
374 2656 ▶ if ( bad_pattern($pattern) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (bad_pattern($pattern)) 0 2656 2656
375 0 Die(
376 "ERROR: the $opt_name parameter '$param' causes the invalid regex '$pattern'\n"
377 );
378 }
379 2656 return $pattern;
380 } ## end sub make_skipping_pattern
381  
382 664 ▶sub check_options {
Subroutine check_options: called CC=16 SCAR=29.2
Pod undocumented
383  
384 # Check and pre-process tokenizer parameters
385 664 my $rOpts = shift;
386  
387 664 %is_sub = ();
388 664 $is_sub{'sub'} = 1;
389  
390 664 %is_END_DATA_format_sub = (
391 '__END__' => 1,
392 '__DATA__' => 1,
393 'format' => 1,
394 'sub' => 1,
395 );
396  
397 # Install any aliases to 'sub'
398 664 ▶ if ( $rOpts->{'sub-alias-list'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rOpts->{"sub-alias-list"}) 3 661 664
399  
400 # Note that any 'sub-alias-list' has been preprocessed to
401 # be a trimmed, space-separated list which includes 'sub'
402 # for example, it might be 'sub method fun'
403 3 my @sub_alias_list = split /\s+/, $rOpts->{'sub-alias-list'};
404 3 foreach my $word (@sub_alias_list) {
405 11 $is_sub{$word} = 1;
406 11 $is_END_DATA_format_sub{$word} = 1;
407 }
408 }
409  
410 # Set global flag to say if we have to guess if bareword 'method' is
411 # a sub when 'method' is in %is_sub. This will be true unless:
412 # (1) the user entered 'method' as sub alias, or
413 # (2) the user set --use-feature=class
414 # In these two cases we can assume that 'method' is a sub alias.
415 664 $guess_if_method = 1;
416 664 ▶ if ( $is_sub{'method'} ) { $guess_if_method = 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($is_sub{"method"}) 2 662 664
417  
418 #------------------------------------------------
419 # Update hash values for any -use-feature options
420 #------------------------------------------------
421  
422 664 my $use_feature_class = 1;
423  
424 664 my $str = $rOpts->{'use-feature'};
425 664 ▶ if ( defined($str) && length($str) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $str and length $str) 0 664 664
Condition33%1/3
defined $str and length $str
!ll&&!rl&&r
66400
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
426 0 $str =~ s/^\s+//;
427 0 $str =~ s/\s+$//;
428 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
429 ## all spaces
430 }
431 elsif ( $str =~ /\bnoclass\b/ ) {
432 0 $use_feature_class = 0;
433 }
434 elsif ( $str =~ /\bclass\b/ ) {
435 0 $guess_if_method = 0;
436 }
437 else {
438 # At present, only 'class' and 'noclass' are valid strings
439 # This is just a Warn, for testing, but will eventually be Die
440 0 Warn(
441 "Unexpected text in --use-feature: expecting 'class' or 'noclass'\n"
442 );
443 }
444 }
445  
446 # These are the main updates for this option. There are additional
447 # changes elsewhere, usually indicated with a comment 'rt145706'
448  
449 # Update hash values for use_feature=class, added for rt145706
450 # see 'perlclass.pod'
451  
452 # IMPORTANT: We are changing global hash values initially set in a BEGIN
453 # block. Values must be defined (true or false) for each of these new
454 # words whether true or false. Otherwise, programs using the module which
455 # change options between runs (such as test code) will have
456 # incorrect settings and fail.
457  
458 # There are 4 new keywords:
459  
460 # 'class' - treated specially as generalization of 'package'
461 # Note: we must not set 'class' to be a keyword to avoid problems
462 # with older uses.
463 664 $is_package{'class'} = $use_feature_class;
464  
465 # 'method' - treated like sub using the sub-alias-list option
466 # Note: we must not set 'method' to be a keyword to avoid problems
467 # with older uses.
468 664 ▶ if ($use_feature_class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_feature_class) 664 0 664
469 664 $is_sub{'method'} = 1;
470 664 $is_END_DATA_format_sub{'method'} = 1;
471 }
472  
473 # 'field' - added as a keyword, and works like 'my'
474 # Setting zero_continuation_block_type allows inclusion in table of level
475 # differences in case of a missing or extra brace (see sub wrapup).
476 664 $is_keyword{'field'} = $use_feature_class;
477 664 $is_my_our_state{'field'} = $use_feature_class;
478 664 $is_zero_continuation_block_type{'field'} = $use_feature_class;
479  
480 # 'ADJUST' - added as a keyword and works like 'BEGIN'
481 # See update git #182 for 'ADJUST :params'
482 # Setting zero_continuation_block_type allows inclusion in table of level
483 # differences in case of a missing or extra brace (see sub wrapup).
484 664 $is_keyword{'ADJUST'} = $use_feature_class;
485 664 $is_code_block_token{'ADJUST'} = $use_feature_class;
486 664 $is_zero_continuation_block_type{'ADJUST'} = $use_feature_class;
487  
488 664 %is_grep_alias = ();
489 664 ▶ if ( $rOpts->{'grep-alias-list'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rOpts->{"grep-alias-list"}) 664 0 664
490  
491 # Note that 'grep-alias-list' has been preprocessed to be a trimmed,
492 # space-separated list
493 664 my @q = split /\s+/, $rOpts->{'grep-alias-list'};
494 664 $is_grep_alias{$_} = 1 for @q;
495 }
496  
497 664 $rOpts_starting_indentation_level = $rOpts->{'starting-indentation-level'};
498 664 $rOpts_indent_columns = $rOpts->{'indent-columns'};
499 664 $rOpts_look_for_hash_bang = $rOpts->{'look-for-hash-bang'};
500 664 $rOpts_look_for_autoloader = $rOpts->{'look-for-autoloader'};
501 664 $rOpts_look_for_selfloader = $rOpts->{'look-for-selfloader'};
502 664 $rOpts_trim_qw = $rOpts->{'trim-qw'};
503 664 $rOpts_extended_syntax = $rOpts->{'extended-syntax'};
504 664 $rOpts_continuation_indentation = $rOpts->{'continuation-indentation'};
505 664 $rOpts_outdent_labels = $rOpts->{'outdent-labels'};
506 664 $rOpts_maximum_level_errors = $rOpts->{'maximum-level-errors'};
507 664 $rOpts_maximum_unexpected_errors = $rOpts->{'maximum-unexpected-errors'};
508 664 $rOpts_code_skipping = $rOpts->{'code-skipping'};
509 664 $rOpts_code_skipping_begin = $rOpts->{'code-skipping-begin'};
510 664 $rOpts_format_skipping = $rOpts->{'format-skipping'};
511 664 $rOpts_format_skipping_begin = $rOpts->{'format-skipping-begin'};
512 664 $rOpts_format_skipping_end = $rOpts->{'format-skipping-end'};
513 664 $rOpts_indent_closing_brace = $rOpts->{'indent-closing-brace'};
514 664 $rOpts_non_indenting_braces = $rOpts->{'non-indenting-braces'};
515 664 $rOpts_non_indenting_brace_prefix = $rOpts->{'non-indenting-brace-prefix'};
516 664 $rOpts_whitespace_cycle = $rOpts->{'whitespace-cycle'};
517  
518 $rOpts_warn_unexpected_code_container =
519 664 $rOpts->{'warn-unexpected-code-container'};
520  
521 # In the Tokenizer, --indent-columns is just used for guessing old
522 # indentation, and must be positive. If -i=0 is used for this run (which
523 # is possible) we'll just guess that the old run used 4 spaces per level.
524 664 ▶ if ( !$rOpts_indent_columns ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rOpts_indent_columns) 12 652 664
525 12 $rOpts_indent_columns = INDENT_COLUMNS_DEFAULT;
526 }
527  
528 # Define $tabsize, the number of spaces per tab for use in
529 # guessing the indentation of source lines with leading tabs.
530 # Assume same as for this run if tabs are used, otherwise assume
531 # a default value, typically 8
532 $tabsize =
533 $rOpts->{'entab-leading-whitespace'}
534 ? $rOpts->{'entab-leading-whitespace'}
535 : $rOpts->{'tabs'} ? $rOpts->{'indent-columns'}
536 664 ▶ : $rOpts->{'default-tabsize'};
Branch: 2 branches
BranchTrueFalseTotal
$rOpts->{'entab-leading-whitespace'} ? : 2 662 664
$rOpts->{'tabs'} ? : 0 662 662
537 0 ▶ if ( !$tabsize ) { $tabsize = TAB_SIZE_DEFAULT }
Branch: 1 branch
BranchTrueFalseTotal
unless ($tabsize) 0 664 664
538  
539 $code_skipping_pattern_begin =
540 664 make_skipping_pattern( $rOpts, 'code-skipping-begin', '#<<V' );
541 664 $code_skipping_pattern_end =
542 make_skipping_pattern( $rOpts, 'code-skipping-end', '#>>V' );
543  
544 664 $format_skipping_pattern_begin =
545 make_skipping_pattern( $rOpts, 'format-skipping-begin', '#<<<' );
546 664 $format_skipping_pattern_end =
547 make_skipping_pattern( $rOpts, 'format-skipping-end', '#>>>' );
548  
549 664 return;
550 } ## end sub check_options
551  
552 666 ▶sub new {
Subroutine new: called CC=7 SCAR=19.6
Pod undocumented
553  
554 666 my ( $class, @arglist ) = @_;
555 0 ▶ if ( @arglist % 2 ) { croak "Odd number of items in arg hash list\n" }
Branch: 1 branch
BranchTrueFalseTotal
if (@arglist % 2) 0 666 666
556  
557 666 my %defaults = (
558 source_object => undef,
559 debugger_object => undef,
560 diagnostics_object => undef,
561 logger_object => undef,
562 starting_level => undef,
563 starting_line_number => 1,
564 rOpts => {},
565 );
566 666 my %args = ( %defaults, @arglist );
567  
568 # we are given an object with a get_line() method to supply source lines
569 666 my $source_object = $args{source_object};
570 666 my $rOpts = $args{rOpts};
571  
572 # Check call args
573 666 ▶ if ( !defined($source_object) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $source_object) 0 666 666
574 0 Die(
575 "Perl::Tidy::Tokenizer::new called without a 'source_object' parameter\n"
576 );
577 }
578 666 ▶ if ( !ref($source_object) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $source_object) 0 666 666
579 0 Die(<<EOM);
580 sub Perl::Tidy::Tokenizer::new received a 'source_object' parameter which is not a reference;
581 'source_object' must be a reference to a STRING, ARRAY, or object with a 'getline' method
582 EOM
583 }
584  
585 666 my $logger_object = $args{logger_object};
586  
587 # Tokenizer state data is as follows:
588 # _rhere_target_list_ reference to list of here-doc targets
589 # _here_doc_target_ the target string for a here document
590 # _here_quote_character_ the type of here-doc quoting (" ' ` or none)
591 # to determine if interpolation is done
592 # _quote_target_ character we seek if chasing a quote
593 # _line_start_quote_ line where we started looking for a long quote
594 # _in_here_doc_ flag indicating if we are in a here-doc
595 # _in_pod_ flag set if we are in pod documentation
596 # _in_code_skipping_ flag set if we are in a code skipping section
597 # _in_format_skipping_ flag set if we are in a format skipping section
598 # _in_error_ flag set if we saw severe error (binary in script)
599 # _do_not_format_ flag set if formatting should be skipped
600 # _warning_count_ number of calls to logger sub warning
601 # _html_tag_count_ number of apparent html tags seen (indicates html)
602 # _in_data_ flag set if we are in __DATA__ section
603 # _in_end_ flag set if we are in __END__ section
604 # _in_format_ flag set if we are in a format description
605 # _in_attribute_list_ flag telling if we are looking for attributes
606 # _in_quote_ flag telling if we are chasing a quote
607 # _starting_level_ indentation level of first line
608 # _diagnostics_object_ place to write debugging information
609 # _unexpected_error_count_ error count used to limit output
610 # _lower_case_labels_at_ line numbers where lower case labels seen
611 # _hit_bug_ program bug detected
612  
613 666 my $self = [];
614 666 $self->[_rhere_target_list_] = [];
615 666 $self->[_in_here_doc_] = 0;
616 666 $self->[_here_doc_target_] = EMPTY_STRING;
617 666 $self->[_here_quote_character_] = EMPTY_STRING;
618 666 $self->[_in_data_] = 0;
619 666 $self->[_in_end_] = 0;
620 666 $self->[_in_format_] = 0;
621 666 $self->[_in_error_] = 0;
622 666 $self->[_do_not_format_] = 0;
623 666 $self->[_warning_count_] = 0;
624 666 $self->[_html_tag_count_] = 0;
625 666 $self->[_in_pod_] = 0;
626 $self->[_in_code_skipping_] =
627 666 ▶ $rOpts->{'code-skipping-from-start'} && $rOpts_code_skipping;
Condition33%1/3
$rOpts->{'code-skipping-from-start'} && $rOpts_code_skipping
!ll&&!rl&&r
66600
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
628 666 $self->[_in_format_skipping_] = 0;
629 666 $self->[_rformat_skipping_list_] = [];
630 666 $self->[_in_attribute_list_] = 0;
631 666 $self->[_in_quote_] = 0;
632 666 $self->[_quote_target_] = EMPTY_STRING;
633 666 $self->[_line_start_quote_] = -1;
634 666 $self->[_starting_level_] = $args{starting_level};
635 666 $self->[_know_starting_level_] = defined( $args{starting_level} );
636 666 $self->[_last_line_number_] = $args{starting_line_number} - 1;
637 666 $self->[_saw_perl_dash_P_] = 0;
638 666 $self->[_saw_perl_dash_w_] = 0;
639 666 $self->[_saw_use_strict_] = 0;
640 666 $self->[_saw_brace_error_] = 0;
641 666 $self->[_hit_bug_] = 0;
642 666 $self->[_look_for_autoloader_] = $rOpts_look_for_autoloader;
643 666 $self->[_look_for_selfloader_] = $rOpts_look_for_selfloader;
644 666 $self->[_saw_autoloader_] = 0;
645 666 $self->[_saw_selfloader_] = 0;
646 666 $self->[_saw_hash_bang_] = 0;
647 666 $self->[_saw_end_] = 0;
648 666 $self->[_saw_data_] = 0;
649 666 $self->[_saw_negative_indentation_] = 0;
650 666 $self->[_started_tokenizing_] = 0;
651 666 $self->[_debugger_object_] = $args{debugger_object};
652 666 $self->[_diagnostics_object_] = $args{diagnostics_object};
653 666 $self->[_logger_object_] = $logger_object;
654 666 $self->[_unexpected_error_count_] = 0;
655 666 $self->[_started_looking_for_here_target_at_] = 0;
656 666 $self->[_nearly_matched_here_target_at_] = undef;
657 666 $self->[_line_of_text_] = EMPTY_STRING;
658 666 $self->[_rlower_case_labels_at_] = undef;
659 666 $self->[_maximum_level_] = 0;
660 666 $self->[_true_brace_error_count_] = 0;
661 666 $self->[_rnon_indenting_brace_stack_] = [];
662 666 $self->[_rseqno_at_depth_] = [SEQ_ROOT];
663 666 $self->[_show_indentation_table_] = 0;
664 666 $self->[_rbareword_info_] = {};
665 666 $self->[_rsaw_unknown_syntax_in_seqno_] = {};
666  
667 666 $self->[_rclosing_brace_indentation_hash_] = {
668 valid => undef,
669 rhistory_line_number => [0],
670 rhistory_level_diff => [0],
671 rhistory_anchor_point => [1],
672 };
673  
674 666 $self->[_rOpts_] = $rOpts;
675 666 ▶ $self->[_save_logfile_] =
Condition100%3/3
defined $logger_object && $logger_object->get_save_logfile
!ll&&!rl&&r
26631
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
676 defined($logger_object) && $logger_object->get_save_logfile();
677  
678 666 bless $self, $class;
679  
680 666 $self->prepare_for_a_new_file($source_object);
681 666 $self->find_starting_indentation_level();
682  
683 # This is not a full class yet, so die if an attempt is made to
684 # create more than one object.
685  
686 666 ▶ if ( _increment_count() > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_increment_count() > 1) 0 666 666
687 0 confess
688 "Attempt to create more than 1 object in $class, which is not a true class yet\n";
689 }
690  
691 666 return $self;
692  
693 } ## end sub new
694  
695 # Called externally
696 4 ▶sub get_unexpected_error_count {
Subroutine get_unexpected_error_count: called CC=1 SCAR=0.0
Pod undocumented
697 4 my ($self) = @_;
698 4 return $self->[_unexpected_error_count_];
699 }
700  
701 # Called externally
702 4 ▶sub is_keyword {
Subroutine is_keyword: called CC=1 SCAR=0.0
Pod undocumented
703 4 my ($str) = @_;
704 4 return $is_keyword{$str};
705 }
706  
707 #----------------------------------------------------------------
708 # Line input routines, previously handled by the LineBuffer class
709 #----------------------------------------------------------------
710 666 ▶sub make_source_array {
Subroutine make_source_array: called CC=8 SCAR=25.4
Pod undocumented
711  
712 666 my ( $self, $line_source_object ) = @_;
713  
714 # Convert the source into an array of lines
715 # Given:
716 # $line_source_object = the input source stream
717 # Task:
718 # Convert the source to an array ref and store in $self
719  
720 666 my $rinput_lines = [];
721  
722 666 my $rsource = ref($line_source_object);
723 666 my $source_string;
724  
725 666 ▶ if ( !$rsource ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $rsource) { } 0 666 666
elsif ($rsource eq 'ARRAY') { } 0 666 666
elsif ($rsource eq 'SCALAR') { } 666 0 666
726  
727 # shouldn't happen: this should have been checked in sub new
728 0 Fault(<<EOM);
729 sub Perl::Tidy::Tokenizer::new received a 'source_object' parameter which is not a reference;
730 'source_object' must be a reference to a STRING, ARRAY, or object with a 'getline' method
731 EOM
732 }
733  
734 # handle an ARRAY ref
735 elsif ( $rsource eq 'ARRAY' ) {
736 0 $rinput_lines = $line_source_object;
737 0 $source_string = join( EMPTY_STRING, @{$line_source_object} );
738 }
739  
740 # handle a SCALAR ref
741 elsif ( $rsource eq 'SCALAR' ) {
742 666 $source_string = ${$line_source_object};
743 666 my @lines = split /^/, $source_string;
744 666 $rinput_lines = \@lines;
745 }
746  
747 # handle an object - must have a get_line method
748 else {
749  
750 # This will die if user's object does have a 'get_line' method
751 0 my $line;
752 0 ▶ while ( defined( $line = $line_source_object->get_line() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $line_source_object->get_line)) 0 0 0
753 0 push @{$rinput_lines}, $line;
754 }
755 0 $source_string = join( EMPTY_STRING, @{$rinput_lines} );
756 }
757  
758 # Get trimmed lines. It is much faster to strip leading whitespace from
759 # the whole input file at once than line-by-line.
760  
761 # Add a terminal newline if needed to keep line count unchanged:
762 # - avoids problem of losing a last line which is just \r and no \n (c283)
763 # - but check input line count to avoid adding line to an empty file (c286)
764 666 ▶ if ( @{$rinput_lines} && $source_string !~ /\n$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rinput_lines;} and not $source_string =~ /\n$/) 1 665 666
Condition100%3/3
@{$rinput_lines;} and not $source_string =~ /\n$/
!ll&&!rl&&r
26631
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
765 1 $source_string .= "\n";
766 }
767  
768 # Remove leading whitespace except newlines
769 666 $source_string =~ s/^ [^\S\n]+ //gxm;
770  
771 # Then break the string into lines
772 666 my @trimmed_lines = split /^/, $source_string;
773  
774 # Safety check - a change in number of lines would be a disaster
775 666 ▶ if ( @trimmed_lines != @{$rinput_lines} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@trimmed_lines != @{$rinput_lines;}) 0 666 666
776  
777 # Shouldn't happen - die in DEVEL_MODE and fix
778 0 my $ntr = @trimmed_lines;
779 0 my $utr = @{$rinput_lines};
780 0 DEVEL_MODE
781 && Fault("trimmed / untrimmed line counts differ: $ntr / $utr\n");
782  
783 # Otherwise we can safely continue with undefined trimmed lines. They
784 # will be detected and fixed later.
785 0 @trimmed_lines = ();
786 }
787  
788 666 $self->[_rinput_lines_] = $rinput_lines;
789 666 $self->[_rtrimmed_input_lines_] = \@trimmed_lines;
790 666 $self->[_input_line_index_next_] = 0;
791 666 return;
792 } ## end sub make_source_array
793  
794 1406 ▶sub peek_ahead {
Subroutine peek_ahead: called CC=2 SCAR=6.9
Pod undocumented
795 1406 my ( $self, $buffer_index ) = @_;
796  
797 # look $buffer_index lines ahead of the current location in the input
798 # stream without disturbing the input
799 1406 my $line;
800 1406 my $rinput_lines = $self->[_rinput_lines_];
801 1406 my $line_index = $buffer_index + $self->[_input_line_index_next_];
802 1406 ▶ if ( $line_index < @{$rinput_lines} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line_index < @{$rinput_lines;}) 1394 12 1406
803 1394 $line = $rinput_lines->[$line_index];
804 }
805 1406 return $line;
806 } ## end sub peek_ahead
807  
808 #-----------------------------------------
809 # interface to Perl::Tidy::Logger routines
810 #-----------------------------------------
811 0 ▶sub warning {
Subroutine warning: not called CC=2 SCAR=17.9
Pod undocumented
812  
813 0 my ( $self, $msg ) = @_;
814  
815 0 my $logger_object = $self->[_logger_object_];
816 0 $self->[_warning_count_]++;
817 0 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 0 0 0
818 0 my $msg_line_number = $self->[_last_line_number_];
819 0 $logger_object->warning( $msg, $msg_line_number );
820 }
821 0 return;
822 } ## end sub warning
823  
824 0 ▶sub warning_do_not_format {
Subroutine warning_do_not_format: not called CC=1 SCAR=6.9
Pod undocumented
825 0 my ( $self, $msg ) = @_;
826  
827 # Issue a warning message and set a flag to skip formatting this file.
828 0 $self->warning($msg);
829 0 $self->[_do_not_format_] = 1;
830 0 return;
831 } ## end sub warning_do_not_format
832  
833 41 ▶sub complain {
Subroutine complain: called CC=2 SCAR=7.0
Pod undocumented
834  
835 41 my ( $self, $msg ) = @_;
836  
837 41 my $logger_object = $self->[_logger_object_];
838 41 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 41 0 41
839 41 my $input_line_number = $self->[_last_line_number_];
840 41 $logger_object->complain( $msg, $input_line_number );
841 }
842 41 return;
843 } ## end sub complain
844  
845 2281 ▶sub write_logfile_entry {
Subroutine write_logfile_entry: called CC=2 SCAR=6.9
Pod undocumented
846  
847 2281 my ( $self, $msg ) = @_;
848  
849 2281 my $logger_object = $self->[_logger_object_];
850 2281 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 2275 6 2281
851 2275 $logger_object->write_logfile_entry($msg);
852 }
853 2281 return;
854 } ## end sub write_logfile_entry
855  
856 0 ▶sub interrupt_logfile {
Subroutine interrupt_logfile: not called CC=2 SCAR=17.9
Pod undocumented
857  
858 0 my $self = shift;
859  
860 0 my $logger_object = $self->[_logger_object_];
861 0 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 0 0 0
862 0 $logger_object->interrupt_logfile();
863 }
864 0 return;
865 } ## end sub interrupt_logfile
866  
867 0 ▶sub resume_logfile {
Subroutine resume_logfile: not called CC=2 SCAR=17.9
Pod undocumented
868  
869 0 my $self = shift;
870  
871 0 my $logger_object = $self->[_logger_object_];
872 0 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 0 0 0
873 0 $logger_object->resume_logfile();
874 }
875 0 return;
876 } ## end sub resume_logfile
877  
878 0 ▶sub brace_warning {
Subroutine brace_warning: not called CC=2 SCAR=17.9
Pod undocumented
879 0 my ( $self, $msg ) = @_;
880 0 $self->[_saw_brace_error_]++;
881  
882 0 my $logger_object = $self->[_logger_object_];
883 0 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 0 0 0
884 0 my $msg_line_number = $self->[_last_line_number_];
885 0 $logger_object->brace_warning( $msg, $msg_line_number );
886 }
887 0 return;
888 } ## end sub brace_warning
889  
890 0 ▶sub increment_brace_error {
Subroutine increment_brace_error: not called CC=2 SCAR=17.9
Pod undocumented
891  
892 # This is same as sub brace_warning but without a message
893 0 my $self = shift;
894 0 $self->[_saw_brace_error_]++;
895  
896 0 my $logger_object = $self->[_logger_object_];
897 0 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 0 0 0
898 0 $logger_object->increment_brace_error();
899 }
900 0 return;
901 } ## end sub increment_brace_error
902  
903 0 ▶sub get_saw_brace_error {
Subroutine get_saw_brace_error: not called CC=1 SCAR=6.9
Pod undocumented
904 0 my $self = shift;
905 0 return $self->[_saw_brace_error_];
906 }
907  
908 0 ▶sub report_definite_bug {
Subroutine report_definite_bug: not called CC=2 SCAR=17.9
Pod undocumented
909 0 my $self = shift;
910 0 $self->[_hit_bug_] = 1;
911 0 my $logger_object = $self->[_logger_object_];
912 0 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 0 0 0
913 0 $logger_object->report_definite_bug();
914 }
915 0 return;
916 } ## end sub report_definite_bug
917  
918 #-------------------------------------
919 # Interface to Perl::Tidy::Diagnostics
920 #-------------------------------------
921 0 ▶sub write_diagnostics {
Subroutine write_diagnostics: not called CC=2 SCAR=17.9
Pod undocumented
922 0 my ( $self, $msg ) = @_;
923 0 my $input_line_number = $self->[_last_line_number_];
924 0 my $diagnostics_object = $self->[_diagnostics_object_];
925 0 ▶ if ($diagnostics_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diagnostics_object) 0 0 0
926 0 $diagnostics_object->write_diagnostics( $msg, $input_line_number );
927 }
928 0 return;
929 } ## end sub write_diagnostics
930  
931 666 ▶sub report_tokenization_errors {
Subroutine report_tokenization_errors: called CC=34 SCAR=51.8
Pod undocumented
932  
933 666 my ($self) = @_;
934  
935 # Report any tokenization errors and return a flag '$severe_error'.
936 # Set $severe_error = 1 if the tokenization errors are so severe that
937 # the formatter should not attempt to format the file. Instead, it will
938 # just output the file verbatim.
939  
940 # set severe error flag if tokenizer has encountered file reading problems
941 # (i.e. unexpected binary characters)
942 # or code which may not be formatted correctly (such as 'my sub q')
943 # The difference between _in_error_ and _do_not_format_ is that
944 # _in_error_ stops the tokenizer immediately whereas
945 # _do_not_format_ lets the tokenizer finish so that all errors are seen
946 # Both block formatting and cause the input stream to be output verbatim.
947 666 ▶ my $severe_error = $self->[_in_error_] || $self->[_do_not_format_];
Condition33%1/3
$self->[7] || $self->[8]
l!l&&r!l&&!r
00666
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
948  
949 # And do not format if it looks like an html file (c209)
950 666 ▶ $severe_error ||= $self->[_html_tag_count_] && $self->[_warning_count_];
Condition33%2/6
$severe_error ||= $self->[10] && $self->[9]
l!l&&r!l&&!r
00666
$self->[10] && $self->[9]
!ll&&!rl&&r
66600
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
951  
952 # Inform the logger object on length of input stream
953 666 my $logger_object = $self->[_logger_object_];
954 666 ▶ if ($logger_object) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger_object) 664 2 666
955 664 my $last_line_number = $self->[_last_line_number_];
956 664 $logger_object->set_last_input_line_number($last_line_number);
957 }
958  
959 666 my $maxle = $rOpts_maximum_level_errors;
960 666 my $maxue = $rOpts_maximum_unexpected_errors;
961 666 ▶ $maxle = 1 unless ( defined($maxle) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $maxle 0 666 666
962 666 ▶ $maxue = 0 unless ( defined($maxue) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $maxue 0 666 666
963  
964 666 my $level = get_indentation_level();
965 666 ▶ if ( $level != $self->[_starting_level_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level != $self->[19]) 0 666 666
966 0 $self->warning("final indentation level: $level\n");
967  
968 0 $self->[_show_indentation_table_] = 1;
969  
970 0 my $level_diff = $self->[_starting_level_] - $level;
971 0 ▶ if ( $level_diff < 0 ) { $level_diff = -$level_diff }
Branch: 1 branch
BranchTrueFalseTotal
if ($level_diff < 0) 0 0 0
972  
973 # Set severe error flag if the level error is greater than 1.
974 # The formatter can function for any level error but it is probably
975 # best not to attempt formatting for a high level error.
976 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
977 0 $severe_error = 1;
978 0 $self->warning(<<EOM);
979 Formatting will be skipped because level error '$level_diff' exceeds -maxle=$maxle; use -maxle=-1 to force formatting
980 EOM
981 }
982 }
983  
984 666 $self->check_final_nesting_depths();
985  
986 666 ▶ if ( $self->[_show_indentation_table_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[52]) 0 666 666
987 0 $self->show_indentation_table();
988 }
989  
990 # Likewise, large numbers of brace errors usually indicate non-perl
991 # scripts, so set the severe error flag at a low number. This is similar
992 # to the level check, but different because braces may balance but be
993 # incorrectly interlaced.
994 666 ▶ if ( $self->[_true_brace_error_count_] > 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[46] > 2) 0 666 666
995 0 $severe_error = 1;
996 }
997  
998 666 ▶ if ( $rOpts_look_for_hash_bang
Branch: 1 branch
BranchTrueFalseTotal
if ($rOpts_look_for_hash_bang and not $self->[31]) 0 666 666
Condition66%2/3
$rOpts_look_for_hash_bang and not $self->[31]
!ll&&!rl&&r
66510
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
999 && !$self->[_saw_hash_bang_] )
1000 {
1001 0 $self->warning(
1002 "hit EOF without seeing hash-bang line; maybe don't need -x?\n");
1003 }
1004  
1005 666 ▶ if ( $self->[_in_format_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[6]) 0 666 666
1006 0 $self->warning("hit EOF while in format description\n");
1007 }
1008  
1009 666 ▶ if ( $self->[_in_code_skipping_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[12]) 0 666 666
1010 0 $self->write_logfile_entry(
1011 "hit EOF while in lines skipped with --code-skipping\n");
1012 }
1013  
1014 666 ▶ if ( $self->[_in_pod_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[11]) 0 666 666
1015  
1016 # Just write log entry if this is after __END__ or __DATA__
1017 # because this happens to often, and it is not likely to be
1018 # a parsing error.
1019 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
1020 0 $self->write_logfile_entry(
1021 "hit eof while in pod documentation (no =cut seen)\n\tthis can cause trouble with some pod utilities\n"
1022 );
1023 }
1024  
1025 else {
1026 0 $self->complain(
1027 "hit eof while in pod documentation (no =cut seen)\n\tthis can cause trouble with some pod utilities\n"
1028 );
1029 }
1030  
1031 }
1032  
1033 666 ▶ if ( $self->[_in_here_doc_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[1]) 0 666 666
1034 0 $severe_error = 1;
1035 0 my $here_doc_target = $self->[_here_doc_target_];
1036 0 my $started_looking_for_here_target_at =
1037 $self->[_started_looking_for_here_target_at_];
1038 0 ▶ if ($here_doc_target) {
Branch: 1 branch
BranchTrueFalseTotal
if ($here_doc_target) { } 0 0 0
1039 0 $self->warning(
1040 "hit EOF in here document starting at line $started_looking_for_here_target_at with target: $here_doc_target\n"
1041 );
1042 }
1043 else {
1044 0 $self->warning(<<EOM);
1045 Hit EOF in here document starting at line $started_looking_for_here_target_at with empty target string.
1046 (Perl will match to the end of file but this may not be intended).
1047 EOM
1048 }
1049 0 my $nearly_matched_here_target_at =
1050 $self->[_nearly_matched_here_target_at_];
1051 0 ▶ if ($nearly_matched_here_target_at) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nearly_matched_here_target_at) 0 0 0
1052 0 $self->warning(
1053 "NOTE: almost matched at input line $nearly_matched_here_target_at except for whitespace\n"
1054 );
1055 }
1056 }
1057  
1058 # Something is seriously wrong if we ended inside a quote
1059 666 ▶ if ( $self->[_in_quote_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[16]) 0 666 666
1060 0 $severe_error = 1;
1061 0 my $line_start_quote = $self->[_line_start_quote_];
1062 0 my $quote_target = $self->[_quote_target_];
1063 0 ▶ my $what =
Branch: 1 branch
BranchTrueFalseTotal
$self->[15] ? : 0 0 0
1064 ( $self->[_in_attribute_list_] )
1065 ? "attribute list"
1066 : "quote/pattern";
1067 0 $self->warning(
1068 "hit EOF seeking end of $what starting at line $line_start_quote ending in $quote_target\n"
1069 );
1070 }
1071  
1072 666 ▶ if ( $self->[_hit_bug_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[26]) 0 666 666
1073 0 $severe_error = 1;
1074 }
1075  
1076 # Multiple "unexpected" type tokenization errors usually indicate parsing
1077 # non-perl scripts, or that something is seriously wrong, so we should
1078 # avoid formatting them. This can happen for example if we run perltidy on
1079 # a shell script or an html file. But unfortunately this check can
1080 # interfere with some extended syntaxes, such as RPerl, so it has to be off
1081 # by default.
1082 666 my $ue_count = $self->[_unexpected_error_count_];
1083 666 ▶ if ( $maxue > 0 && $ue_count > $maxue ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($maxue > 0 and $ue_count > $maxue) 0 666 666
Condition33%1/3
$maxue > 0 and $ue_count > $maxue
!ll&&!rl&&r
66600
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
1084 0 $self->warning(<<EOM);
1085 Formatting will be skipped since unexpected token count = $ue_count > -maxue=$maxue; use -maxue=0 to force formatting
1086 EOM
1087 0 $severe_error = 1;
1088 }
1089  
1090 666 ▶ if ( !$self->[_saw_perl_dash_w_] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[23]) 649 17 666
1091 649 $self->write_logfile_entry("Suggest including 'use warnings;'\n");
1092 }
1093  
1094 666 ▶ if ( $self->[_saw_perl_dash_P_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[22]) 0 666 666
1095 0 $self->write_logfile_entry(
1096 "Use of -P parameter for defines is discouraged\n");
1097 }
1098  
1099 666 ▶ if ( !$self->[_saw_use_strict_] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[24]) 652 14 666
1100 652 $self->write_logfile_entry("Suggest including 'use strict;'\n");
1101 }
1102  
1103 # it is suggested that labels have at least one upper case character
1104 # for legibility and to avoid code breakage as new keywords are introduced
1105 666 ▶ if ( $self->[_rlower_case_labels_at_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[44]) 12 654 666
1106 12 my @lower_case_labels_at = @{ $self->[_rlower_case_labels_at_] };
1107 12 $self->write_logfile_entry(
1108 "Suggest using upper case characters in label(s)\n");
1109 12 local $LIST_SEPARATOR = ')(';
1110 12 $self->write_logfile_entry(
1111 " defined at line(s): (@lower_case_labels_at)\n");
1112 }
1113  
1114 # Get the text of any leading format skipping tag
1115 666 my $early_FS_end_marker;
1116 666 my $rformat_skipping_list = $self->[_rformat_skipping_list_];
1117 666 ▶ 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 663 666
Condition100%3/3
@{$rformat_skipping_list;} and $rformat_skipping_list->[0][0] == -1
!ll&&!rl&&r
653103
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
1118 3 $early_FS_end_marker = $rformat_skipping_list->[0]->[2];
1119 }
1120  
1121 return {
1122 666 severe_error => $severe_error,
1123 early_FS_end_marker => $early_FS_end_marker,
1124 };
1125  
1126 } ## end sub report_tokenization_errors
1127  
1128 0 ▶sub show_indentation_table {
Subroutine show_indentation_table: not called CC=25 SCAR=64.8
Pod undocumented
1129 0 my ($self) = @_;
1130  
1131 # Output indentation table made at closing braces. This can be helpful for
1132 # the case of a missing brace in a previously formatted file.
1133  
1134 # skip if problem reading file
1135 0 ▶ return if ( $self->[_in_error_] );
Branch: 1 branch
BranchTrueFalseTotal
if $self->[7] 0 0 0
1136  
1137 # skip if -wc is used (rare); it is too complex to use
1138 0 ▶ return if ($rOpts_whitespace_cycle);
Branch: 1 branch
BranchTrueFalseTotal
if $rOpts_whitespace_cycle 0 0 0
1139  
1140 # skip if non-indenting-brace-prefix (very rare, but could be fixed)
1141 0 ▶ return if ($rOpts_non_indenting_brace_prefix);
Branch: 1 branch
BranchTrueFalseTotal
if $rOpts_non_indenting_brace_prefix 0 0 0
1142  
1143 # skip if starting level is not zero (probably in editor)
1144 0 ▶ return if ($rOpts_starting_indentation_level);
Branch: 1 branch
BranchTrueFalseTotal
if $rOpts_starting_indentation_level 0 0 0
1145  
1146 # skip if indentation analysis is not valid
1147 0 my $rhash = $self->[_rclosing_brace_indentation_hash_];
1148 0 ▶ return if ( !$rhash->{valid} );
Branch: 1 branch
BranchTrueFalseTotal
unless $rhash->{"valid"} 0 0 0
1149  
1150 0 my $rhistory_line_number = $rhash->{rhistory_line_number};
1151 0 my $rhistory_level_diff = $rhash->{rhistory_level_diff};
1152 0 my $rhistory_anchor_point = $rhash->{rhistory_anchor_point};
1153  
1154 # Remove the first artificial point from the table
1155 0 shift @{$rhistory_line_number};
1156 0 shift @{$rhistory_level_diff};
1157 0 shift @{$rhistory_anchor_point};
1158  
1159 # Remove dubious points at an anchor point = 2 and beyond
1160 # These can occur when non-indenting braces are used
1161 0 my $num_his = @{$rhistory_level_diff};
1162 0 foreach my $i ( 0 .. $num_his - 1 ) {
1163 0 ▶ if ( $rhistory_anchor_point->[$i] == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rhistory_anchor_point->[$i] == 2) 0 0 0
1164 0 $num_his = $i;
1165 0 last;
1166 }
1167 }
1168 0 ▶ return if ( $num_his <= 1 );
Branch: 1 branch
BranchTrueFalseTotal
if $num_his <= 1 0 0 0
1169  
1170 # Ignore an ending non-anchor point
1171 0 ▶ if ( !$rhistory_anchor_point->[-1] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rhistory_anchor_point->[-1]) 0 0 0
1172 0 $num_his -= 1;
1173 }
1174  
1175 # Ignore an ending point which is the same as the previous point
1176 0 ▶ if ( $num_his > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num_his > 1) 0 0 0
1177 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
1178 $rhistory_level_diff->[ $num_his - 2 ] )
1179 {
1180 0 $num_his -= 1;
1181 }
1182 }
1183  
1184 # Skip if the table does not have at least 2 points to pinpoint an error
1185 0 ▶ return if ( $num_his <= 1 );
Branch: 1 branch
BranchTrueFalseTotal
if $num_his <= 1 0 0 0
1186  
1187 # Skip if first point shows a level error - the analysis may not be valid
1188 0 ▶ return if ( $rhistory_level_diff->[0] );
Branch: 1 branch
BranchTrueFalseTotal
if $rhistory_level_diff->[0] 0 0 0
1189  
1190 # Remove table points which return from negative to zero; they follow
1191 # an error and may not be correct. c448.
1192 0 my $min_lev = $rhistory_level_diff->[0];
1193 0 foreach my $ii ( 1 .. $num_his - 1 ) {
1194 0 my $lev = $rhistory_level_diff->[$ii];
1195 0 ▶ if ( $lev < $min_lev ) { $min_lev = $lev; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($lev < $min_lev) 0 0 0
1196 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
1197 0 $num_his = $ii;
1198 0 last;
1199 }
1200 }
1201  
1202 # Since the table could be arbitrarily large, we will limit the table to N
1203 # lines. If there are more lines than that, we will show N-3 lines, then
1204 # ..., then the last 2 lines. Allow about 3 lines per error, so a table
1205 # limit of 10 can localize up to about 3 errors in a file.
1206 0 my $nlines_max = 10;
1207 0 my @pre_indexes = ( 0 .. $num_his - 1 );
1208 0 my @post_indexes = ();
1209 0 ▶ if ( @pre_indexes > $nlines_max ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pre_indexes > $nlines_max) 0 0 0
1210 0 ▶ if ( $nlines_max >= 5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nlines_max >= 5) { } 0 0 0
1211 0 @pre_indexes = ( 0 .. $nlines_max - 4 );
1212 0 @post_indexes = ( $num_his - 2, $num_his - 1 );
1213 }
1214 else {
1215 0 @pre_indexes = ( 0 .. $nlines_max - 1 );
1216 }
1217 }
1218  
1219 0 my @output_lines;
1220 0 push @output_lines, <<EOM;
1221 Table of initial nesting level differences at closing braces.
1222 This might help localize brace errors IF perltidy previously formatted the file.
1223 line: error=[new brace level]-[old indentation level]
1224 EOM
1225 0 foreach my $i (@pre_indexes) {
1226 0 my $lno = $rhistory_line_number->[$i];
1227 0 my $diff = $rhistory_level_diff->[$i];
1228 0 push @output_lines, <<EOM;
1229 $lno: $diff
1230 EOM
1231 }
1232 0 ▶ if (@post_indexes) {
Branch: 1 branch
BranchTrueFalseTotal
if (@post_indexes) 0 0 0
1233 0 push @output_lines, "...\n";
1234 0 foreach my $i (@post_indexes) {
1235 0 my $lno = $rhistory_line_number->[$i];
1236 0 my $diff = $rhistory_level_diff->[$i];
1237 0 push @output_lines, <<EOM;
1238 $lno: $diff
1239 EOM
1240 }
1241 }
1242  
1243 # Try to give a hint
1244 0 my $level_diff_1 = $rhistory_level_diff->[1];
1245 0 my $ln_0 = $rhistory_line_number->[0];
1246 0 my $ln_1 = $rhistory_line_number->[1];
1247 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
1248 0 push @output_lines,
1249 "There may be an extra '}' or missing '{' between lines $ln_0 and $ln_1\n";
1250 }
1251 elsif ( $level_diff_1 > 0 ) {
1252 0 push @output_lines,
1253 "There may be a missing '}' or extra '{' between lines $ln_0 and $ln_1\n";
1254 }
1255 else {
1256 ## two leading zeros in the table - probably can't happen - no hint
1257 }
1258  
1259 0 push @output_lines, "\n";
1260 0 my $output_str = join( EMPTY_STRING, @output_lines );
1261  
1262 0 $self->interrupt_logfile();
1263 0 $self->warning($output_str);
1264 0 $self->resume_logfile();
1265  
1266 0 return;
1267 } ## end sub show_indentation_table
1268  
1269 448 ▶sub is_valid_token_type {
Subroutine is_valid_token_type: called CC=1 SCAR=0.0
Pod undocumented
1270 448 my ($type) = @_;
1271 448 return $is_valid_token_type{$type};
1272 }
1273  
1274 276 ▶sub log_numbered_msg {
Subroutine log_numbered_msg: called CC=1 SCAR=0.0
Pod undocumented
1275 276 my ( $self, $msg ) = @_;
1276  
1277 # write input line number + message to logfile
1278 276 my $input_line_number = $self->[_last_line_number_];
1279 276 $self->write_logfile_entry("Line $input_line_number: $msg");
1280 276 return;
1281 } ## end sub log_numbered_msg
1282  
1283 9900 ▶sub get_line {
Subroutine get_line: called CC=70 SCAR=48.7
Pod undocumented
1284  
1285 9900 my $self = shift;
1286  
1287 # Read the next input line and tokenize it
1288 # Returns:
1289 # $line_of_tokens = ref to hash of info for the tokenized line
1290  
1291 # USES GLOBAL VARIABLES:
1292 # $brace_depth, $square_bracket_depth, $paren_depth
1293  
1294 # get the next line from the input array
1295 9900 my $input_line;
1296 my $trimmed_input_line;
1297 9900 my $line_index = $self->[_input_line_index_next_];
1298 9900 my $rinput_lines = $self->[_rinput_lines_];
1299 9900 ▶ if ( $line_index < @{$rinput_lines} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line_index < @{$rinput_lines;}) { } 9234 666 9900
1300 9234 $trimmed_input_line = $self->[_rtrimmed_input_lines_]->[$line_index];
1301 9234 $input_line = $rinput_lines->[ $line_index++ ];
1302 9234 $self->[_input_line_index_next_] = $line_index;
1303 }
1304  
1305 # End of file .. check if file ends in a binary operator (c565)
1306 else {
1307 666 ▶ 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 666 666
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
00666
$last_nonblank_type eq "k" and $is_binary_or_unary_keyword{$last_nonblank_token}
!ll&&!rl&&r
66600
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 table25%1/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
1308 $is_binary_or_unary_operator_type{$last_nonblank_type}
1309 || ( $last_nonblank_type eq 'k'
1310 && $is_binary_or_unary_keyword{$last_nonblank_token} )
1311 )
1312 {
1313 0 $self->warning(
1314 "Unexpected EOF at operator '$last_nonblank_token'\n");
1315  
1316 # avoid repeating this message
1317 0 $last_nonblank_token = ';';
1318 0 $last_nonblank_type = ';';
1319 }
1320 }
1321  
1322 9900 $self->[_line_of_text_] = $input_line;
1323  
1324 9900 ▶ return if ( !defined($input_line) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $input_line 666 9234 9900
1325  
1326 9234 my $input_line_number = ++$self->[_last_line_number_];
1327  
1328 # Find and remove what characters terminate this line, including any
1329 # control r
1330 9234 my $input_line_separator = EMPTY_STRING;
1331 9234 ▶ if ( chomp $input_line ) {
Branch: 1 branch
BranchTrueFalseTotal
if (chomp $input_line) 9233 1 9234
1332 9233 $input_line_separator = $INPUT_RECORD_SEPARATOR;
1333 }
1334  
1335 # The first test here very significantly speeds things up, but be sure to
1336 # keep the regex and hash %other_line_endings the same.
1337 9234 ▶ if ( $other_line_endings{ substr( $input_line, -1 ) } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other_line_endings{substr $input_line, -1}) 0 9234 9234
1338 0 ▶ if ( $input_line =~ s/([\r\035\032])+$// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ s/([\r\035\032])+$//) 0 0 0
1339 0 $input_line_separator = $1 . $input_line_separator;
1340  
1341 # This could make the trimmed input line incorrect, so the
1342 # safe thing to do is to make it undef to force it to be
1343 # recomputed later.
1344 0 $trimmed_input_line = undef;
1345 }
1346 }
1347  
1348 # For backwards compatibility we keep the line text terminated with
1349 # a newline character
1350 9234 $input_line .= "\n";
1351 9234 $self->[_line_of_text_] = $input_line;
1352  
1353 # create a data structure describing this line which will be
1354 # returned to the caller.
1355  
1356 # _line_type codes are:
1357 # SYSTEM - system-specific code before hash-bang line
1358 # CODE - line of perl code (including comments)
1359 # POD_START - line starting pod, such as '=head'
1360 # POD - pod documentation text
1361 # POD_END - last line of pod section, '=cut'
1362 # HERE - text of here-document
1363 # HERE_END - last line of here-doc (target word)
1364 # FORMAT - format section
1365 # FORMAT_END - last line of format section, '.'
1366 # SKIP - code skipping section
1367 # SKIP_END - last line of code skipping section, '#>>V'
1368 # DATA_START - __DATA__ line
1369 # DATA - unidentified text following __DATA__
1370 # END_START - __END__ line
1371 # END - unidentified text following __END__
1372 # ERROR - we are in big trouble, probably not a perl script
1373  
1374 # Other variables:
1375 # _curly_brace_depth - depth of curly braces at start of line
1376 # _square_bracket_depth - depth of square brackets at start of line
1377 # _paren_depth - depth of parens at start of line
1378 # _starting_in_quote - this line continues a multi-line quote
1379 # (so don't trim leading blanks!)
1380 # _ending_in_quote - this line ends in a multi-line quote
1381 # (so don't trim trailing blanks!)
1382 9234 my $line_of_tokens = {
1383 _line_type => 'EOF',
1384 _line_text => $input_line,
1385 _line_number => $input_line_number,
1386 _guessed_indentation_level => 0,
1387 _curly_brace_depth => $brace_depth,
1388 _square_bracket_depth => $square_bracket_depth,
1389 _paren_depth => $paren_depth,
1390 ## Skip these needless initializations for efficiency:
1391 ## _rtoken_type => undef,
1392 ## _rtokens => undef,
1393 ## _rlevels => undef,
1394 ## _rblock_type => undef,
1395 ## _rtype_sequence => undef,
1396 ## _starting_in_quote => 0,
1397 ## _ending_in_quote => 0,
1398 };
1399  
1400 # Must print line unchanged if we are in a here document
1401 9234 ▶ if ( $self->[_in_here_doc_] ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($self->[1]) { } 126 9108 9234
elsif ($self->[6]) { } 3 9105 9108
elsif ($self->[11]) { } 51 9054 9105
elsif ($self->[12]) { } 8 9046 9054
elsif ($self->[7]) { } 0 9046 9046
elsif ($self->[4]) { } 1 9045 9046
elsif ($self->[5]) { } 56 8989 9045
1402  
1403 126 $line_of_tokens->{_line_type} = 'HERE';
1404 126 my $here_doc_target = $self->[_here_doc_target_];
1405 126 my $here_quote_character = $self->[_here_quote_character_];
1406 126 my $candidate_target = $input_line;
1407 126 my $leading_whitespace = EMPTY_STRING;
1408 126 chomp $candidate_target;
1409  
1410 # Handle <<~ targets, which are indicated here by a leading space on
1411 # the here quote character. c603 has test cases.
1412 # the leading whitespace of all here text lines match it.
1413 126 my $ix = rindex( $candidate_target, $here_doc_target );
1414 126 ▶ if ( $ix > 0 && $here_quote_character =~ /^\s/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ix > 0 and $here_quote_character =~ /^\s/) 18 108 126
Condition66%2/3
$ix > 0 and $here_quote_character =~ /^\s/
!ll&&!rl&&r
108018
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
1415 18 $leading_whitespace = substr( $candidate_target, 0, $ix );
1416 18 ▶ if ( $leading_whitespace !~ /^\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($leading_whitespace =~ /^\s*$/) 0 18 18
1417 0 $leading_whitespace = EMPTY_STRING;
1418 }
1419 }
1420  
1421 126 ▶ if ( $candidate_target eq $leading_whitespace . $here_doc_target ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($candidate_target eq $leading_whitespace . $here_doc_target) { } 47 79 126
1422 47 $self->[_nearly_matched_here_target_at_] = undef;
1423 47 $line_of_tokens->{_line_type} = 'HERE_END';
1424 47 $self->log_numbered_msg("Exiting HERE document $here_doc_target\n");
1425  
1426 47 my $rhere_target_list = $self->[_rhere_target_list_];
1427 47 ▶ if ( @{$rhere_target_list} ) { # there can be multiple here targets
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rhere_target_list;}) { } 10 37 47
1428 ( $here_doc_target, $here_quote_character ) =
1429 10 @{ shift @{$rhere_target_list} };
1430 10 $self->[_here_doc_target_] = $here_doc_target;
1431 10 $self->[_here_quote_character_] = $here_quote_character;
1432 10 $self->log_numbered_msg(
1433 "Entering HERE document $here_doc_target\n");
1434 10 $self->[_nearly_matched_here_target_at_] = undef;
1435 10 $self->[_started_looking_for_here_target_at_] =
1436 $input_line_number;
1437 }
1438 else {
1439 37 $self->[_in_here_doc_] = 0;
1440 37 $self->[_here_doc_target_] = EMPTY_STRING;
1441 37 $self->[_here_quote_character_] = EMPTY_STRING;
1442 }
1443 }
1444  
1445 # check for error of extra whitespace
1446 # note for PERL6: leading whitespace is allowed
1447 else {
1448 79 $candidate_target =~ s/^ \s+ | \s+ $//gx; # trim both ends
1449 79 ▶ if ( $candidate_target eq $here_doc_target ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($candidate_target eq $here_doc_target) 0 79 79
1450 0 $self->[_nearly_matched_here_target_at_] = $input_line_number;
1451 }
1452 }
1453 126 return $line_of_tokens;
1454 }
1455  
1456 # Print line unchanged if we are in a format section
1457 elsif ( $self->[_in_format_] ) {
1458  
1459 3 ▶ if ( $input_line =~ /^\.[\s#]*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^\.[\s#]*$/) { } 1 2 3
1460  
1461 # Decrement format depth count at a '.' after a 'format'
1462 1 $self->[_in_format_]--;
1463  
1464 # This is the end when count reaches 0
1465 1 ▶ if ( !$self->[_in_format_] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[6]) 1 0 1
1466 1 $self->log_numbered_msg("Exiting format section\n");
1467 1 $line_of_tokens->{_line_type} = 'FORMAT_END';
1468  
1469 # Make the tokenizer mark an opening brace which follows
1470 # as a code block. Fixes issue c202/t032.
1471 1 $last_nonblank_token = ';';
1472 1 $last_nonblank_type = ';';
1473 }
1474 }
1475 else {
1476 2 $line_of_tokens->{_line_type} = 'FORMAT';
1477 2 ▶ if ( $input_line =~ /^\s*format\s+\w+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^\s*format\s+\w+/) 0 2 2
1478  
1479 # Increment format depth count at a 'format' within a 'format'
1480 # This is a simple way to handle nested formats (issue c019).
1481 0 $self->[_in_format_]++;
1482 }
1483 }
1484 3 return $line_of_tokens;
1485 }
1486  
1487 # must print line unchanged if we are in pod documentation
1488 elsif ( $self->[_in_pod_] ) {
1489  
1490 51 $line_of_tokens->{_line_type} = 'POD';
1491 51 ▶ if ( $input_line =~ /^=cut/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^=cut/) 22 29 51
1492 22 $line_of_tokens->{_line_type} = 'POD_END';
1493 22 $self->log_numbered_msg("Exiting POD section\n");
1494 22 $self->[_in_pod_] = 0;
1495 }
1496 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
1497 0 $self->warning(
1498 "Hash-bang in pod can cause older versions of perl to fail! \n"
1499 );
1500 }
1501  
1502 51 return $line_of_tokens;
1503 }
1504  
1505 # print line unchanged if in skipped section
1506 elsif ( $self->[_in_code_skipping_] ) {
1507  
1508 8 $line_of_tokens->{_line_type} = 'SKIP';
1509 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
1510 2 $line_of_tokens->{_line_type} = 'SKIP_END';
1511 2 $self->log_numbered_msg("Exiting code-skipping section\n");
1512 2 $self->[_in_code_skipping_] = 0;
1513 }
1514 elsif ( $input_line =~ /$code_skipping_pattern_begin/ ) {
1515  
1516 # warn of duplicate starting comment lines, git #118
1517 0 my $lno = $self->[_in_code_skipping_];
1518 0 $self->warning(
1519 "Already in code-skipping section which started at line $lno\n"
1520 );
1521 }
1522 else {
1523 ## not a code-skipping control line
1524 }
1525 8 return $line_of_tokens;
1526 }
1527  
1528 # must print line unchanged if we have seen a severe error (i.e., we
1529 # are seeing illegal tokens and cannot continue. Syntax errors do
1530 # not pass this route). Calling routine can decide what to do, but
1531 # the default can be to just pass all lines as if they were after __END__
1532 elsif ( $self->[_in_error_] ) {
1533 0 $line_of_tokens->{_line_type} = 'ERROR';
1534 0 return $line_of_tokens;
1535 }
1536  
1537 # print line unchanged if we are __DATA__ section
1538 elsif ( $self->[_in_data_] ) {
1539  
1540 # ...but look for POD
1541 # Note that the _in_data and _in_end flags remain set
1542 # so that we return to that state after seeing the
1543 # end of a pod section
1544 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
1545 0 $line_of_tokens->{_line_type} = 'POD_START';
1546 0 $self->log_numbered_msg("Entering POD section\n");
1547 0 $self->[_in_pod_] = 1;
1548 0 return $line_of_tokens;
1549 }
1550 else {
1551 1 $line_of_tokens->{_line_type} = 'DATA';
1552 1 return $line_of_tokens;
1553 }
1554 }
1555  
1556 # print line unchanged if we are in __END__ section
1557 elsif ( $self->[_in_end_] ) {
1558  
1559 # ...but look for POD
1560 # Note that the _in_data and _in_end flags remain set
1561 # so that we return to that state after seeing the
1562 # end of a pod section
1563 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
1564 7 $line_of_tokens->{_line_type} = 'POD_START';
1565 7 $self->log_numbered_msg("Entering POD section\n");
1566 7 $self->[_in_pod_] = 1;
1567 7 return $line_of_tokens;
1568 }
1569 else {
1570 49 $line_of_tokens->{_line_type} = 'END';
1571 49 return $line_of_tokens;
1572 }
1573 }
1574 else {
1575 ## not a special control line
1576 }
1577  
1578 # check for a hash-bang line if we haven't seen one
1579 8989 ▶ 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 8973 8989
Condition83%5/6
not $self->[31] and substr($input_line, 0, 2) eq "#!" and $input_line =~ /^\#\!.*perl\b/
!ll&&!rl&&r
8973016
not $self->[31] and substr($input_line, 0, 2) eq "#!"
!ll&&!rl&&r
628834516
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
1580 && substr( $input_line, 0, 2 ) eq '#!'
1581 && $input_line =~ /^\#\!.*perl\b/ )
1582 {
1583 16 $self->[_saw_hash_bang_] = $input_line_number;
1584  
1585 # check for -w and -P flags
1586 16 ▶ if ( $input_line =~ /^\#\!.*perl\s.*-.*P/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^\#\!.*perl\s.*-.*P/) 0 16 16
1587 0 $self->[_saw_perl_dash_P_] = 1;
1588 }
1589  
1590 16 ▶ if ( $input_line =~ /^\#\!.*perl\s.*-.*w/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^\#\!.*perl\s.*-.*w/) 9 7 16
1591 9 $self->[_saw_perl_dash_w_] = 1;
1592 }
1593  
1594 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
1595 $input_line_number > 1
1596  
1597 # leave any hash bang in a BEGIN block alone
1598 # i.e. see 'debugger-duck_type.t'
1599 && !(
1600 $last_nonblank_block_type
1601 && $last_nonblank_block_type eq 'BEGIN'
1602 )
1603 && !$rOpts_look_for_hash_bang
1604  
1605 # Try to avoid giving a false alarm at a simple comment.
1606 # These look like valid hash-bang lines:
1607  
1608 #!/usr/bin/perl -w
1609 #! /usr/bin/perl -w
1610 #!c:\perl\bin\perl.exe
1611  
1612 # These are comments:
1613 #! I love perl
1614 #! sunos does not yet provide a /usr/bin/perl
1615  
1616 # Comments typically have multiple spaces, which suggests
1617 # the filter
1618 && $input_line =~ /^\#\!(\s+)?(\S+)?perl/
1619 )
1620 {
1621  
1622 # this is helpful for VMS systems; we may have accidentally
1623 # tokenized some DCL commands
1624 1 ▶ if ( $self->[_started_tokenizing_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[35]) { } 0 1 1
1625 0 $self->warning(
1626 "There seems to be a hash-bang after line 1; do you need to run with -x ?\n"
1627 );
1628 }
1629 else {
1630 1 $self->complain("Useless hash-bang after line 1\n");
1631 }
1632 }
1633  
1634 # Report the leading hash-bang as a system line
1635 # This will prevent -dac from deleting it
1636 else {
1637 15 $line_of_tokens->{_line_type} = 'SYSTEM';
1638 15 return $line_of_tokens;
1639 }
1640 }
1641  
1642 # wait for a hash-bang before parsing if the user invoked us with -x
1643 8974 ▶ if ( $rOpts_look_for_hash_bang
Branch: 1 branch
BranchTrueFalseTotal
if ($rOpts_look_for_hash_bang and not $self->[31]) 5 8969 8974
Condition100%3/3
$rOpts_look_for_hash_bang and not $self->[31]
!ll&&!rl&&r
896815
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
1644 && !$self->[_saw_hash_bang_] )
1645 {
1646 5 $line_of_tokens->{_line_type} = 'SYSTEM';
1647 5 return $line_of_tokens;
1648 }
1649  
1650 # a first line of the form ': #' will be marked as SYSTEM
1651 # since lines of this form may be used by tcsh
1652 8969 ▶ if ( $input_line_number == 1 && $input_line =~ /^\s*\:\s*\#/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line_number == 1 and $input_line =~ /^\s*\:\s*\#/) 0 8969 8969
Condition66%2/3
$input_line_number == 1 and $input_line =~ /^\s*\:\s*\#/
!ll&&!rl&&r
83206490
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
1653 0 $line_of_tokens->{_line_type} = 'SYSTEM';
1654 0 return $line_of_tokens;
1655 }
1656  
1657 # now we know that it is ok to tokenize the line...
1658 # the line tokenizer will modify any of these private variables:
1659 # _rhere_target_list_
1660 # _in_data_
1661 # _in_end_
1662 # _in_format_
1663 # _in_error_
1664 # _in_code_skipping_
1665 # _in_format_skipping_
1666 # _in_pod_
1667 # _in_quote_
1668  
1669 8969 $self->tokenize_this_line( $line_of_tokens, $trimmed_input_line );
1670  
1671 # Now finish defining the return structure and return it
1672 8969 $line_of_tokens->{_ending_in_quote} = $self->[_in_quote_];
1673  
1674 # handle severe error (binary data in script)
1675 8969 ▶ if ( $self->[_in_error_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[7]) 0 8969 8969
1676 0 $self->[_in_quote_] = 0; # to avoid any more messages
1677 0 $self->warning("Giving up after error\n");
1678 0 $line_of_tokens->{_line_type} = 'ERROR';
1679 0 reset_indentation_level(0); # avoid error messages
1680 0 return $line_of_tokens;
1681 }
1682  
1683 # handle start of pod documentation
1684 8969 ▶ if ( $self->[_in_pod_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[11]) 15 8954 8969
1685  
1686 # This gets tricky..above a __DATA__ or __END__ section, perl
1687 # accepts '=cut' as the start of pod section. But afterwards,
1688 # only pod utilities see it and they may ignore an =cut without
1689 # leading =head. In any case, this isn't good.
1690 15 ▶ if ( $input_line =~ /^=cut\b/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^=cut\b/) { } 0 15 15
1691 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
1692 0 $self->complain("=cut while not in pod ignored\n");
1693 0 $self->[_in_pod_] = 0;
1694 0 $line_of_tokens->{_line_type} = 'POD_END';
1695 }
1696 else {
1697 0 $line_of_tokens->{_line_type} = 'POD_START';
1698 0 if ( !DEVEL_MODE ) {
1699 0 $self->warning(
1700 "=cut starts a pod section .. this can fool pod utilities.\n"
1701 );
1702 }
1703 0 $self->log_numbered_msg("Entering POD section\n");
1704 }
1705 }
1706  
1707 else {
1708 15 $line_of_tokens->{_line_type} = 'POD_START';
1709 15 $self->log_numbered_msg("Entering POD section\n");
1710 }
1711  
1712 15 return $line_of_tokens;
1713 }
1714  
1715 # handle start of skipped section
1716 8954 ▶ if ( $self->[_in_code_skipping_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[12]) 2 8952 8954
1717  
1718 2 $line_of_tokens->{_line_type} = 'SKIP';
1719 2 $self->log_numbered_msg("Entering code-skipping section\n");
1720 2 return $line_of_tokens;
1721 }
1722  
1723 # see if this line contains here doc targets
1724 8952 my $rhere_target_list = $self->[_rhere_target_list_];
1725 8952 ▶ if ( @{$rhere_target_list} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rhere_target_list;}) 37 8915 8952
1726  
1727 my ( $here_doc_target, $here_quote_character ) =
1728 37 @{ shift @{$rhere_target_list} };
1729 37 $self->[_in_here_doc_] = 1;
1730 37 $self->[_here_doc_target_] = $here_doc_target;
1731 37 $self->[_here_quote_character_] = $here_quote_character;
1732 37 $self->log_numbered_msg("Entering HERE document $here_doc_target\n");
1733 37 $self->[_started_looking_for_here_target_at_] = $input_line_number;
1734 }
1735  
1736 # NOTE: __END__ and __DATA__ statements are written unformatted
1737 # because they can theoretically contain additional characters
1738 # which are not tokenized (and cannot be read with <DATA> either!).
1739 8952 ▶ if ( $self->[_in_data_] ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->[4]) { } 1 8951 8952
elsif ($self->[5]) { } 7 8944 8951
1740 1 $line_of_tokens->{_line_type} = 'DATA_START';
1741 1 $self->log_numbered_msg("Starting __DATA__ section\n");
1742 1 $self->[_saw_data_] = 1;
1743  
1744 # keep parsing after __DATA__ if use SelfLoader was seen
1745 1 ▶ if ( $self->[_saw_selfloader_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[30]) 0 1 1
1746 0 $self->[_in_data_] = 0;
1747 0 $self->log_numbered_msg(
1748 "SelfLoader seen, continuing; -nlsl deactivates\n");
1749 }
1750  
1751 1 return $line_of_tokens;
1752 }
1753  
1754 elsif ( $self->[_in_end_] ) {
1755 7 $line_of_tokens->{_line_type} = 'END_START';
1756 7 $self->log_numbered_msg("Starting __END__ section\n");
1757 7 $self->[_saw_end_] = 1;
1758  
1759 # keep parsing after __END__ if use AutoLoader was seen
1760 7 ▶ if ( $self->[_saw_autoloader_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[29]) 0 7 7
1761 0 $self->[_in_end_] = 0;
1762 0 $self->log_numbered_msg(
1763 "AutoLoader seen, continuing; -nlal deactivates\n");
1764 }
1765 7 return $line_of_tokens;
1766 }
1767 else {
1768 ## not in __END__ or __DATA__
1769 }
1770  
1771 # now, finally, we know that this line is type 'CODE'
1772 8944 $line_of_tokens->{_line_type} = 'CODE';
1773  
1774 # remember if we have seen any real code
1775 8944 ▶ if ( !$self->[_started_tokenizing_]
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[35] or $input_line =~ /^\s*$/ or $input_line =~ /^\s*#/) 662 8282 8944
Condition100%6/6
$self->[35] or $input_line =~ /^\s*$/ or $input_line =~ /^\s*#/
l!l&&r!l&&!r
7952330662
$self->[35] or $input_line =~ /^\s*$/
l!l&&r!l&&!r
793220992
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
1776 && $input_line !~ /^\s*$/
1777 && $input_line !~ /^\s*#/ )
1778 {
1779 662 $self->[_started_tokenizing_] = 1;
1780 }
1781  
1782 8944 ▶ if ( $self->[_debugger_object_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[36]) 7 8937 8944
1783 7 $self->[_debugger_object_]->write_debug_entry($line_of_tokens);
1784 }
1785  
1786 # Note: if keyword 'format' occurs in this line code, it is still CODE
1787 # (keyword 'format' need not start a line)
1788 8944 ▶ if ( $self->[_in_format_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[6]) 1 8943 8944
1789 1 $self->log_numbered_msg("Entering format section\n");
1790 }
1791  
1792 8944 ▶ if ( $self->[_in_quote_]
Branch: 2 branches
BranchTrueFalseTotal
if ($self->[16] and $self->[18] < 0) { } 63 8881 8944
elsif ($self->[18] >= 0 and not $self->[16]) { } 62 8819 8881
Condition100%3/3
$self->[16] and $self->[18] < 0
!ll&&!rl&&r
869718463
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
1793 and ( $self->[_line_start_quote_] < 0 ) )
1794 {
1795 63 ▶ if ( ( my $quote_target = $self->[_quote_target_] ) !~ /^\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ((my $quote_target = $self->[17]) =~ /^\s*$/) 62 1 63
1796 62 $self->[_line_start_quote_] = $input_line_number;
1797 62 $self->log_numbered_msg(
1798 "Start multi-line quote or pattern ending in $quote_target\n");
1799 }
1800 }
1801 ▶ elsif ( ( $self->[_line_start_quote_] >= 0 )
Condition100%3/3
$self->[18] >= 0 and not $self->[16]
!ll&&!rl&&r
863518462
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
1802 && !$self->[_in_quote_] )
1803 {
1804 62 $self->[_line_start_quote_] = -1;
1805 62 $self->log_numbered_msg("End of multi-line quote or pattern\n");
1806 }
1807 else {
1808 ## not at the edge of a quote
1809 }
1810  
1811 # we are returning a line of CODE
1812 8944 return $line_of_tokens;
1813 } ## end sub get_line
1814  
1815 666 ▶sub find_starting_indentation_level {
Subroutine find_starting_indentation_level: called CC=15 SCAR=28.0
Pod undocumented
1816  
1817 # We need to find the indentation level of the first line of the
1818 # script being formatted. Often it will be zero for an entire file,
1819 # but if we are formatting a local block of code (within an editor for
1820 # example) it may not be zero. The user may specify this with the
1821 # -sil=n parameter but normally doesn't so we have to guess.
1822 #
1823 666 my ($self) = @_;
1824 666 my $starting_level = 0;
1825  
1826 # use value if given as parameter
1827 666 ▶ if ( $self->[_know_starting_level_] ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->[20]) { } 1 665 666
elsif ($rOpts_look_for_hash_bang) { } 1 664 665
1828 1 $starting_level = $self->[_starting_level_];
1829 }
1830  
1831 # if we know there is a hash_bang line, the level must be zero
1832 elsif ($rOpts_look_for_hash_bang) {
1833 1 $self->[_know_starting_level_] = 1;
1834 }
1835  
1836 # otherwise figure it out from the input file
1837 else {
1838 664 my $line;
1839 664 my $i = 0;
1840  
1841 # keep looking at lines until we find a hash bang or piece of code
1842 # ( or, for now, an =pod line)
1843 664 my $msg = EMPTY_STRING;
1844 664 my $in_code_skipping;
1845 my $line_for_guess;
1846 664 ▶ while ( defined( $line = $self->peek_ahead( $i++ ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->peek_ahead($i++))) 994 2 996
1847  
1848 # if first line is #! then assume starting level is zero
1849 994 ▶ if ( $i == 1 && $line =~ /^\#\!/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 1 and $line =~ /^\#\!/) 14 980 994
Condition100%3/3
$i == 1 and $line =~ /^\#\!/
!ll&&!rl&&r
33264814
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
1850 14 $starting_level = 0;
1851 14 last;
1852 }
1853  
1854 # ignore lines fenced off with code-skipping comments
1855 980 ▶ if ( $line =~ /^\s*#/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*#/) 314 666 980
1856  
1857 # use first comment for indentation guess in case of no code
1858 314 ▶ if ( !defined($line_for_guess) ) { $line_for_guess = $line }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $line_for_guess) 258 56 314
1859  
1860 314 ▶ if ( !$in_code_skipping ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $in_code_skipping) { } 314 0 314
1861 314 ▶ if ( $rOpts_code_skipping
Branch: 1 branch
BranchTrueFalseTotal
if ($rOpts_code_skipping and $line =~ /$code_skipping_pattern_begin/) 0 314 314
Condition33%1/3
$rOpts_code_skipping and $line =~ /$code_skipping_pattern_begin/
!ll&&!rl&&r
03140
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
1862 && $line =~ /$code_skipping_pattern_begin/ )
1863 {
1864 0 $in_code_skipping = 1;
1865 0 next;
1866 }
1867 }
1868 else {
1869 0 ▶ if ( $line =~ /$code_skipping_pattern_end/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /$code_skipping_pattern_end/) 0 0 0
1870 0 $in_code_skipping = 0;
1871 }
1872 0 next;
1873 }
1874  
1875 # Note that we could also ignore format-skipping lines here
1876 # but it isn't clear if that would be best.
1877 # See c326 for example code.
1878  
1879 314 next;
1880 }
1881 666 ▶ next if ($in_code_skipping);
Branch: 1 branch
BranchTrueFalseTotal
if $in_code_skipping 0 666 666
1882  
1883 666 ▶ next if ( $line =~ /^\s*$/ ); # skip past blank lines
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 18 648 666
1884  
1885 # use first line of code for indentation guess
1886 648 $line_for_guess = $line;
1887 648 last;
1888 } ## end while ( defined( $line = ...))
1889  
1890 664 ▶ if ( defined($line_for_guess) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line_for_guess) 648 16 664
1891 648 $starting_level =
1892 $self->guess_old_indentation_level($line_for_guess);
1893 }
1894 664 $msg = "Line $i implies starting-indentation-level = $starting_level\n";
1895 664 $self->write_logfile_entry("$msg");
1896 }
1897 666 $self->[_starting_level_] = $starting_level;
1898 666 reset_indentation_level($starting_level);
1899 666 return;
1900 } ## end sub find_starting_indentation_level
1901  
1902 651 ▶sub guess_old_indentation_level {
Subroutine guess_old_indentation_level: called CC=7 SCAR=19.6
Pod undocumented
1903 651 my ( $self, $line ) = @_;
1904  
1905 # Guess the indentation level of an input line.
1906 #
1907 # For the first line of code this result will define the starting
1908 # indentation level. It will mainly be non-zero when perltidy is applied
1909 # within an editor to a local block of code.
1910 #
1911 # This is an impossible task in general because we can't know what tabs
1912 # meant for the old script and how many spaces were used for one
1913 # indentation level in the given input script. For example it may have
1914 # been previously formatted with -i=7 -et=3. But we can at least try to
1915 # make sure that perltidy guesses correctly if it is applied repeatedly to
1916 # a block of code within an editor, so that the block stays at the same
1917 # level when perltidy is applied repeatedly.
1918 #
1919 # USES GLOBAL VARIABLES: (none)
1920 651 my $level = 0;
1921  
1922 # find leading tabs, spaces, and any statement label
1923 651 my $spaces = 0;
1924 651 ▶ if ( $line =~ /^(\t+)?(\s+)?(\w+:[^:])?/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(\t+)?(\s+)?(\w+:[^:])?/) 651 0 651
1925  
1926 # If there are leading tabs, we use the tab scheme for this run, if
1927 # any, so that the code will remain stable when editing.
1928 651 ▶ if ($1) { $spaces += length($1) * $tabsize }
Branch: 1 branch
BranchTrueFalseTotal
if ($1) 2 649 651
1929  
1930 651 ▶ if ($2) { $spaces += length($2) }
Branch: 1 branch
BranchTrueFalseTotal
if ($2) 90 561 651
1931  
1932 # correct for outdented labels
1933 651 ▶ if ( $3
Branch: 1 branch
BranchTrueFalseTotal
if ($3 and $rOpts_outdent_labels and $rOpts_continuation_indentation > 0) 1 650 651
Condition66%4/6
$3 and $rOpts_outdent_labels and $rOpts_continuation_indentation > 0
!ll&&!rl&&r
65001
$3 and $rOpts_outdent_labels
!ll&&!rl&&r
65001
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
1934 && $rOpts_outdent_labels
1935 && $rOpts_continuation_indentation > 0 )
1936 {
1937 1 $spaces += $rOpts_continuation_indentation;
1938 }
1939 }
1940  
1941 651 $level = int( $spaces / $rOpts_indent_columns );
1942 651 return ($level);
1943 } ## end sub guess_old_indentation_level
1944  
1945 0 ▶sub dump_functions {
Subroutine dump_functions: not called CC=7 SCAR=40.3
Pod undocumented
1946  
1947 # This is an unused debug routine, save for future use
1948  
1949 0 my $fh = *STDOUT;
1950 0 foreach my $pkg ( keys %{$ris_user_function} ) {
1951 0 $fh->print("\nnon-constant subs in package $pkg\n");
1952  
1953 0 foreach my $sub ( keys %{ $ris_user_function->{$pkg} } ) {
1954 0 my $msg = EMPTY_STRING;
1955 0 ▶ if ( $ris_block_list_function->{$pkg}->{$sub} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ris_block_list_function->{$pkg}{$sub}) 0 0 0
1956 0 $msg = 'block_list';
1957 }
1958  
1959 0 ▶ if ( $ris_block_function->{$pkg}->{$sub} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ris_block_function->{$pkg}{$sub}) 0 0 0
1960 0 $msg = 'block';
1961 }
1962 0 $fh->print("$sub $msg\n");
1963 }
1964 }
1965  
1966 0 foreach my $pkg ( keys %{$ris_constant} ) {
1967 0 $fh->print("\nconstants and constant subs in package $pkg\n");
1968  
1969 0 foreach my $sub ( keys %{ $ris_constant->{$pkg} } ) {
1970 0 $fh->print("$sub\n");
1971 }
1972 }
1973 0 return;
1974 } ## end sub dump_functions
1975  
1976 666 ▶sub prepare_for_a_new_file {
Subroutine prepare_for_a_new_file: called CC=1 SCAR=0.0
Pod undocumented
1977  
1978 666 my ( $self, $source_object ) = @_;
1979  
1980 # copy the source object lines to an array of lines
1981 666 $self->make_source_array($source_object);
1982  
1983 # previous tokens needed to determine what to expect next
1984 666 $last_nonblank_token = ';'; # the only possible starting state which
1985 666 $last_nonblank_type = ';'; # will make a leading brace a code block
1986 666 $last_nonblank_block_type = EMPTY_STRING;
1987  
1988 # scalars for remembering statement types across multiple lines
1989 666 $statement_type = EMPTY_STRING; # '' or 'use' or 'sub..' or 'case..'
1990  
1991 # scalars for remembering where we are in the file
1992 666 $current_package = "main";
1993 666 $context = UNKNOWN_CONTEXT;
1994  
1995 # hashes used to remember function information
1996 666 $ris_constant = {}; # user-defined constants
1997 666 $ris_user_function = {}; # user-defined functions
1998 666 $ruser_function_prototype = {}; # their prototypes
1999 666 $ris_block_function = {};
2000 666 $ris_block_list_function = {};
2001 666 $rsaw_function_definition = {};
2002 666 $rsaw_use_module = {};
2003  
2004 # variables used to track depths of various containers
2005 # and report nesting errors
2006 666 $paren_depth = 0;
2007 666 $brace_depth = 0;
2008 666 $square_bracket_depth = 0;
2009 666 $rcurrent_depth = [ (0) x scalar(@closing_brace_names) ];
2010 666 $total_depth = 0;
2011 666 $rtotal_depth = [];
2012 666 $rcurrent_sequence_number = [];
2013 666 $ris_lexical_sub = {};
2014 666 $next_sequence_number = SEQ_ROOT + 1;
2015  
2016 666 $rparen_type = [];
2017 666 $rparen_semicolon_count = [];
2018 666 $rparen_vars = [];
2019 666 $rbrace_type = [];
2020 666 $rbrace_structural_type = [];
2021 666 $rbrace_context = [];
2022 666 $rbrace_package = [];
2023 666 $rsquare_bracket_type = [];
2024 666 $rsquare_bracket_structural_type = [];
2025 666 $rdepth_array = [];
2026 666 $rnested_ternary_flag = [];
2027 666 $rnested_statement_type = [];
2028 666 $rstarting_line_of_current_depth = [];
2029  
2030 666 $rparen_type->[$paren_depth] = EMPTY_STRING;
2031 666 $rparen_semicolon_count->[$paren_depth] = 0;
2032 666 $rparen_vars->[$paren_depth] = [];
2033 666 $rbrace_type->[$brace_depth] = ';'; # identify opening brace as code block
2034 666 $rbrace_structural_type->[$brace_depth] = EMPTY_STRING;
2035 666 $rbrace_context->[$brace_depth] = UNKNOWN_CONTEXT;
2036 666 $rbrace_package->[$paren_depth] = $current_package;
2037 666 $rsquare_bracket_type->[$square_bracket_depth] = EMPTY_STRING;
2038 666 $rsquare_bracket_structural_type->[$square_bracket_depth] = EMPTY_STRING;
2039  
2040 666 initialize_tokenizer_state();
2041 666 return;
2042 } ## end sub prepare_for_a_new_file
2043  
2044 { ## closure for sub tokenize_this_line
2045  
2046 45 ▶ use constant BRACE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2047 45 ▶ use constant SQUARE_BRACKET => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
2048 45 ▶ use constant PAREN => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
2049 45 ▶ use constant QUESTION_COLON => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
2050  
2051 # TV1: scalars for processing one LINE.
2052 # Re-initialized on each entry to sub tokenize_this_line.
2053 my (
2054 45 $block_type, $container_type, $expecting,
2055 $i, $i_tok, $input_line,
2056 $input_line_number, $last_nonblank_i, $max_token_index,
2057 $next_tok, $next_type, $peeked_ahead,
2058 $prototype, $rhere_target_list, $rtoken_map,
2059 $rtoken_type, $rtokens, $tok,
2060 $type, $type_sequence, $indent_flag,
2061 );
2062  
2063 # TV2: refs to ARRAYS for processing one LINE
2064 # Re-initialized on each call.
2065 45 my $routput_token_list = []; # stack of output token indexes
2066 45 my $routput_token_type = []; # token types
2067 45 my $routput_block_type = []; # types of code block
2068 45 my $routput_type_sequence = []; # nesting sequential number
2069 45 my $routput_indent_flag = []; #
2070  
2071 # TV3: SCALARS for quote variables. These are initialized with a
2072 # subroutine call and continually updated as lines are processed.
2073 my (
2074 45 $in_quote, $quote_type,
2075 $quote_character, $quote_pos,
2076 $quote_depth, $quoted_string_1,
2077 $quoted_string_2, $allowed_quote_modifiers,
2078 $quote_starting_tok, $quote_here_target_2,
2079 );
2080  
2081 # TV4: SCALARS for multi-line identifiers and
2082 # statements. These are initialized with a subroutine call
2083 # and continually updated as lines are processed.
2084 45 my ( $id_scan_state, $identifier, $want_paren );
2085  
2086 # TV5: SCALARS for tracking indentation level.
2087 # Initialized once and continually updated as lines are
2088 # processed.
2089 my (
2090 45 $nesting_token_string, $nesting_block_string,
2091 $nesting_block_flag, $level_in_tokenizer,
2092 );
2093  
2094 # TV6: SCALARS for remembering several previous
2095 # tokens. Initialized once and continually updated as
2096 # lines are processed.
2097 my (
2098 45 $last_nonblank_container_type, $last_nonblank_type_sequence,
2099 $last_last_nonblank_token, $last_last_nonblank_type,
2100 $last_nonblank_prototype,
2101 );
2102  
2103 # ----------------------------------------------------------------
2104 # beginning of tokenizer variable access and manipulation routines
2105 # ----------------------------------------------------------------
2106  
2107 666 ▶ sub initialize_tokenizer_state {
Subroutine initialize_tokenizer_state: called CC=1 SCAR=0.0
Pod undocumented
2108  
2109 # GV1: initialized once
2110 # TV1: initialized on each call
2111 # TV2: initialized on each call
2112 # TV3:
2113 666 $in_quote = 0;
2114 666 $quote_type = 'Q';
2115 666 $quote_character = EMPTY_STRING;
2116 666 $quote_pos = 0;
2117 666 $quote_depth = 0;
2118 666 $quoted_string_1 = EMPTY_STRING;
2119 666 $quoted_string_2 = EMPTY_STRING;
2120 666 $allowed_quote_modifiers = EMPTY_STRING;
2121 666 $quote_starting_tok = EMPTY_STRING;
2122 666 $quote_here_target_2 = undef;
2123  
2124 # TV4:
2125 666 $id_scan_state = EMPTY_STRING;
2126 666 $identifier = EMPTY_STRING;
2127 666 $want_paren = EMPTY_STRING;
2128  
2129 # TV5:
2130 666 $nesting_token_string = EMPTY_STRING;
2131 666 $nesting_block_string = '1'; # initially in a block
2132 666 $nesting_block_flag = 1;
2133 666 $level_in_tokenizer = 0;
2134  
2135 # TV6:
2136 666 $last_nonblank_container_type = EMPTY_STRING;
2137 666 $last_nonblank_type_sequence = EMPTY_STRING;
2138 666 $last_last_nonblank_token = ';';
2139 666 $last_last_nonblank_type = ';';
2140 666 $last_nonblank_prototype = EMPTY_STRING;
2141 666 return;
2142 } ## end sub initialize_tokenizer_state
2143  
2144 0 ▶ sub save_tokenizer_state {
Subroutine save_tokenizer_state: not called CC=1 SCAR=6.9
Pod undocumented
2145  
2146 # Global variables:
2147 0 my $rGV1 = [
2148 $brace_depth,
2149 $context,
2150 $current_package,
2151 $last_nonblank_block_type,
2152 $last_nonblank_token,
2153 $last_nonblank_type,
2154 $next_sequence_number,
2155 $paren_depth,
2156 $rbrace_context,
2157 $rbrace_package,
2158 $rbrace_structural_type,
2159 $rbrace_type,
2160 $rcurrent_depth,
2161 $rcurrent_sequence_number,
2162 $ris_lexical_sub,
2163 $rdepth_array,
2164 $ris_block_function,
2165 $ris_block_list_function,
2166 $ris_constant,
2167 $ris_user_function,
2168 $rnested_statement_type,
2169 $rnested_ternary_flag,
2170 $rparen_semicolon_count,
2171 $rparen_vars,
2172 $rparen_type,
2173 $rsaw_function_definition,
2174 $rsaw_use_module,
2175 $rsquare_bracket_structural_type,
2176 $rsquare_bracket_type,
2177 $rstarting_line_of_current_depth,
2178 $rtotal_depth,
2179 $ruser_function_prototype,
2180 $square_bracket_depth,
2181 $statement_type,
2182 $total_depth,
2183  
2184 ];
2185  
2186 # Tokenizer closure variables:
2187 0 my $rTV1 = [
2188 $block_type, $container_type, $expecting,
2189 $i, $i_tok, $input_line,
2190 $input_line_number, $last_nonblank_i, $max_token_index,
2191 $next_tok, $next_type, $peeked_ahead,
2192 $prototype, $rhere_target_list, $rtoken_map,
2193 $rtoken_type, $rtokens, $tok,
2194 $type, $type_sequence, $indent_flag,
2195 ];
2196  
2197 0 my $rTV2 = [
2198 $routput_token_list, $routput_token_type,
2199 $routput_block_type, $routput_type_sequence,
2200 $routput_indent_flag,
2201 ];
2202  
2203 0 my $rTV3 = [
2204 $in_quote, $quote_type,
2205 $quote_character, $quote_pos,
2206 $quote_depth, $quoted_string_1,
2207 $quoted_string_2, $allowed_quote_modifiers,
2208 $quote_starting_tok, $quote_here_target_2,
2209 ];
2210  
2211 0 my $rTV4 = [ $id_scan_state, $identifier, $want_paren ];
2212  
2213 0 my $rTV5 = [
2214 $nesting_token_string, $nesting_block_string,
2215 $nesting_block_flag, $level_in_tokenizer,
2216 ];
2217  
2218 0 my $rTV6 = [
2219 $last_nonblank_container_type, $last_nonblank_type_sequence,
2220 $last_last_nonblank_token, $last_last_nonblank_type,
2221 $last_nonblank_prototype,
2222 ];
2223 0 return [ $rGV1, $rTV1, $rTV2, $rTV3, $rTV4, $rTV5, $rTV6 ];
2224 } ## end sub save_tokenizer_state
2225  
2226 0 ▶ sub restore_tokenizer_state {
Subroutine restore_tokenizer_state: not called CC=1 SCAR=6.9
Pod undocumented
2227 0 my ($rstate) = @_;
2228 0 my ( $rGV1, $rTV1, $rTV2, $rTV3, $rTV4, $rTV5, $rTV6 ) = @{$rstate};
2229  
2230 (
2231 $brace_depth,
2232 $context,
2233 $current_package,
2234 $last_nonblank_block_type,
2235 $last_nonblank_token,
2236 $last_nonblank_type,
2237 $next_sequence_number,
2238 $paren_depth,
2239 $rbrace_context,
2240 $rbrace_package,
2241 $rbrace_structural_type,
2242 $rbrace_type,
2243 $rcurrent_depth,
2244 $rcurrent_sequence_number,
2245 $ris_lexical_sub,
2246 $rdepth_array,
2247 $ris_block_function,
2248 $ris_block_list_function,
2249 $ris_constant,
2250 $ris_user_function,
2251 $rnested_statement_type,
2252 $rnested_ternary_flag,
2253 $rparen_semicolon_count,
2254 $rparen_vars,
2255 $rparen_type,
2256 $rsaw_function_definition,
2257 $rsaw_use_module,
2258 $rsquare_bracket_structural_type,
2259 $rsquare_bracket_type,
2260 $rstarting_line_of_current_depth,
2261 $rtotal_depth,
2262 $ruser_function_prototype,
2263 $square_bracket_depth,
2264 $statement_type,
2265 $total_depth,
2266  
2267 0 ) = @{$rGV1};
2268  
2269 (
2270 $block_type, $container_type, $expecting,
2271 $i, $i_tok, $input_line,
2272 $input_line_number, $last_nonblank_i, $max_token_index,
2273 $next_tok, $next_type, $peeked_ahead,
2274 $prototype, $rhere_target_list, $rtoken_map,
2275 $rtoken_type, $rtokens, $tok,
2276 $type, $type_sequence, $indent_flag,
2277 0 ) = @{$rTV1};
2278  
2279 (
2280 $routput_token_list, $routput_token_type,
2281 $routput_block_type, $routput_type_sequence,
2282 $routput_indent_flag,
2283 0 ) = @{$rTV2};
2284  
2285 (
2286 $in_quote, $quote_type,
2287 $quote_character, $quote_pos,
2288 $quote_depth, $quoted_string_1,
2289 $quoted_string_2, $allowed_quote_modifiers,
2290 $quote_starting_tok, $quote_here_target_2,
2291 0 ) = @{$rTV3};
2292  
2293 0 ( $id_scan_state, $identifier, $want_paren ) = @{$rTV4};
2294  
2295 (
2296 $nesting_token_string, $nesting_block_string,
2297 $nesting_block_flag, $level_in_tokenizer,
2298 0 ) = @{$rTV5};
2299  
2300 (
2301 $last_nonblank_container_type, $last_nonblank_type_sequence,
2302 $last_last_nonblank_token, $last_last_nonblank_type,
2303 $last_nonblank_prototype,
2304 0 ) = @{$rTV6};
2305 0 return;
2306 } ## end sub restore_tokenizer_state
2307  
2308 8 ▶ sub split_pretoken {
Subroutine split_pretoken: called CC=8 SCAR=21.2
Pod undocumented
2309  
2310 8 my ( $self, $numc ) = @_;
2311  
2312 # This provides a way to work around the limitations of the
2313 # pre-tokenization scheme upon which perltidy is based. It is rarely
2314 # needed.
2315  
2316 # Split the leading $numc characters from the current token (at
2317 # index=$i) which is pre-type 'w' and insert the remainder back into
2318 # the pretoken stream with appropriate settings. Since we are
2319 # splitting a pre-type 'w', there are three cases, depending on if the
2320 # remainder starts with a digit:
2321 # Case 1: remainder is type 'd', all digits
2322 # Case 2: remainder is type 'd' and type 'w': digits & other characters
2323 # Case 3: remainder is type 'w'
2324  
2325 # Examples, for $numc=1:
2326 # $tok => $tok_0 $tok_1 $tok_2
2327 # 'x10' => 'x' '10' # case 1
2328 # 'x10if' => 'x' '10' 'if' # case 2
2329 # '0ne => 'O' 'ne' # case 3
2330  
2331 # where:
2332 # $tok_1 is a possible string of digits (pre-type 'd')
2333 # $tok_2 is a possible word (pre-type 'w')
2334  
2335 # return 1 if successful
2336 # return undef if error (shouldn't happen)
2337  
2338 # Calling routine should update '$type' and '$tok' if successful.
2339  
2340 8 my $pretoken = $rtokens->[$i];
2341 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
2342 && length($pretoken) > $numc
2343 && substr( $pretoken, $numc ) =~ /^(\d*)(.*)$/ )
2344 {
2345  
2346 # Split $tok into up to 3 tokens:
2347 8 my $tok_0 = substr( $pretoken, 0, $numc );
2348 8 ▶ my $tok_1 = defined($1) ? $1 : EMPTY_STRING;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 ? : 8 0 8
2349 8 ▶ my $tok_2 = defined($2) ? $2 : EMPTY_STRING;
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 8 0 8
2350  
2351 8 my $len_0 = length($tok_0);
2352 8 my $len_1 = length($tok_1);
2353 8 my $len_2 = length($tok_2);
2354  
2355 ##my $pre_type_0 = 'w';
2356 8 my $pre_type_1 = 'd';
2357 8 my $pre_type_2 = 'w';
2358  
2359 8 my $pos_0 = $rtoken_map->[$i];
2360 8 my $pos_1 = $pos_0 + $len_0;
2361 8 my $pos_2 = $pos_1 + $len_1;
2362  
2363 8 my $isplice = $i + 1;
2364  
2365 # Splice in any digits
2366 8 ▶ if ($len_1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len_1) 5 3 8
2367 5 splice( @{$rtoken_map}, $isplice, 0, $pos_1 );
2368 5 splice( @{$rtokens}, $isplice, 0, $tok_1 );
2369 5 splice( @{$rtoken_type}, $isplice, 0, $pre_type_1 );
2370 5 $max_token_index++;
2371 5 $isplice++;
2372 }
2373  
2374 # Splice in any trailing word
2375 8 ▶ if ($len_2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len_2) 4 4 8
2376 4 splice( @{$rtoken_map}, $isplice, 0, $pos_2 );
2377 4 splice( @{$rtokens}, $isplice, 0, $tok_2 );
2378 4 splice( @{$rtoken_type}, $isplice, 0, $pre_type_2 );
2379 4 $max_token_index++;
2380 }
2381  
2382 8 $rtokens->[$i] = $tok_0;
2383 8 return 1;
2384 }
2385  
2386 # Shouldn't get here - bad call parameters
2387 0 if (DEVEL_MODE) {
2388 Fault(<<EOM);
2389 While working near line number $input_line_number, bad arg '$tok' passed to sub split_pretoken()
2390 EOM
2391 }
2392 0 return;
2393 } ## end sub split_pretoken
2394  
2395 666 ▶ sub get_indentation_level {
Subroutine get_indentation_level: called CC=1 SCAR=0.0
Pod undocumented
2396 666 return $level_in_tokenizer;
2397 }
2398  
2399 666 ▶ sub reset_indentation_level {
Subroutine reset_indentation_level: called CC=1 SCAR=0.0
Pod undocumented
2400 666 $level_in_tokenizer = shift;
2401 666 return;
2402 }
2403  
2404 288 ▶ sub peeked_ahead {
Subroutine peeked_ahead: called CC=2 SCAR=6.9
Pod undocumented
2405 288 ( ( my $flag ) ) = @_;
2406  
2407 # get or set the closure flag '$peeked_ahead':
2408 # - set $peeked_ahead to $flag if given, then
2409 # - return current value
2410 288 ▶ $peeked_ahead = defined($flag) ? $flag : $peeked_ahead;
Branch: 1 branch
BranchTrueFalseTotal
defined $flag ? : 143 145 288
2411 288 return $peeked_ahead;
2412 } ## end sub peeked_ahead
2413  
2414 # ------------------------------------------------------------
2415 # end of tokenizer variable access and manipulation routines
2416 # ------------------------------------------------------------
2417  
2418 #------------------------------
2419 # beginning of tokenizer hashes
2420 #------------------------------
2421  
2422 45 my %matching_start_token = ( '}' => '{', ']' => '[', ')' => '(' );
2423  
2424 45 my @q;
2425  
2426 # 'L' is token for opening { at hash key
2427 my %is_opening_type;
2428 45 @q = qw< L { ( [ >;
2429 45 $is_opening_type{$_} = 1 for @q;
2430  
2431 45 my %is_opening_or_ternary_type;
2432 45 push @q, '?';
2433 45 $is_opening_or_ternary_type{$_} = 1 for @q;
2434  
2435 # 'R' is token for closing } at hash key
2436 45 my %is_closing_type;
2437 45 @q = qw< R } ) ] >;
2438 45 $is_closing_type{$_} = 1 for @q;
2439  
2440 45 my %is_closing_or_ternary_type;
2441 45 push @q, ':';
2442 45 $is_closing_or_ternary_type{$_} = 1 for @q;
2443  
2444 45 my %is_redo_last_next_goto;
2445 45 @q = qw( redo last next goto );
2446 45 $is_redo_last_next_goto{$_} = 1 for @q;
2447  
2448 45 my %is_use_require;
2449 45 @q = qw( use require );
2450 45 $is_use_require{$_} = 1 for @q;
2451  
2452 # This hash holds the array index in $self for these keywords:
2453 # Fix for issue c035: removed 'format' from this hash
2454 45 my %is_END_DATA = (
2455 '__END__' => _in_end_,
2456 '__DATA__' => _in_data_,
2457 );
2458  
2459 # table showing how many quoted things to look for after quote operator..
2460 # s, y, tr have 2 (pattern and replacement)
2461 # others have 1 (pattern only)
2462 45 my %quote_items = (
2463 's' => 2,
2464 'y' => 2,
2465 'tr' => 2,
2466 'm' => 1,
2467 'qr' => 1,
2468 'q' => 1,
2469 'qq' => 1,
2470 'qw' => 1,
2471 'qx' => 1,
2472 );
2473  
2474 45 my %is_for_foreach;
2475 45 @q = qw( for foreach );
2476 45 $is_for_foreach{$_} = 1 for @q;
2477  
2478 # These keywords may introduce blocks after parenthesized expressions,
2479 # in the form:
2480 # keyword ( .... ) { BLOCK }
2481 # patch for SWITCH/CASE: added 'switch' 'case' 'given' 'when'
2482 45 my %is_blocktype_with_paren;
2483 45 @q =
2484 qw(if elsif unless while until for foreach switch case given when catch);
2485 45 $is_blocktype_with_paren{$_} = 1 for @q;
2486  
2487 45 my %is_case_default;
2488 45 @q = qw( case default );
2489 45 $is_case_default{$_} = 1 for @q;
2490  
2491 #------------------------
2492 # end of tokenizer hashes
2493 #------------------------
2494  
2495 # ------------------------------------------------------------
2496 # beginning of various scanner interface routines
2497 # ------------------------------------------------------------
2498 0 ▶ sub scan_replacement_text {
Subroutine scan_replacement_text: not called CC=5 SCAR=34.0
Pod undocumented
2499  
2500 # check for here-docs in replacement text invoked by
2501 # a substitution operator with executable modifier 'e'.
2502 #
2503 # given:
2504 # $replacement_text
2505 # return:
2506 # $rht = reference to any here-doc targets
2507 0 my ( $self, $replacement_text ) = @_;
2508  
2509 # quick check
2510 0 ▶ return if ( $replacement_text !~ /<</ );
Branch: 1 branch
BranchTrueFalseTotal
unless $replacement_text =~ /<</ 0 0 0
2511  
2512 0 $self->write_logfile_entry(
2513 "scanning replacement text for here-doc targets\n");
2514  
2515 # save the logger object for error messages
2516 0 my $logger_object = $self->[_logger_object_];
2517  
2518 # save all lexical variables
2519 0 my $rstate = save_tokenizer_state();
2520 0 _decrement_count(); # avoid error check for multiple tokenizers
2521  
2522 # make a new tokenizer
2523 0 my $tokenizer = Perl::Tidy::Tokenizer->new(
2524 source_object => \$replacement_text,
2525 logger_object => $logger_object,
2526 starting_line_number => $input_line_number,
2527 );
2528  
2529 # scan the replacement text
2530 0 ▶ while ( $tokenizer->get_line() ) { }
Branch: 1 branch
BranchTrueFalseTotal
if ($tokenizer->get_line) 0 0 0
2531  
2532 # remove any here doc targets
2533 0 my $rht = undef;
2534 0 ▶ if ( $tokenizer->[_in_here_doc_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokenizer->[1]) 0 0 0
2535 0 $rht = [];
2536 0 push @{$rht},
2537 [
2538 $tokenizer->[_here_doc_target_],
2539 $tokenizer->[_here_quote_character_],
2540 ];
2541 0 ▶ if ( $tokenizer->[_rhere_target_list_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokenizer->[0]) 0 0 0
2542 0 push @{$rht}, @{ $tokenizer->[_rhere_target_list_] };
2543 0 $tokenizer->[_rhere_target_list_] = undef;
2544 }
2545 0 $tokenizer->[_in_here_doc_] = undef;
2546 }
2547  
2548 # now its safe to report errors
2549 0 my $rtokenization_info_uu = $tokenizer->report_tokenization_errors();
2550  
2551 # TODO: Could propagate a severe error up
2552  
2553 # restore all tokenizer lexical variables
2554 0 restore_tokenizer_state($rstate);
2555  
2556 # return the here doc targets
2557 0 return $rht;
2558 } ## end sub scan_replacement_text
2559  
2560 1870 ▶ sub scan_bare_identifier {
Subroutine scan_bare_identifier: called CC=1 SCAR=0.0
Pod undocumented
2561 1870 my $self = shift;
2562  
2563 # Scan a token starting with an alphanumeric variable or package
2564 # separator, :: or '.
2565  
2566 1870 ( $i, $tok, $type, $prototype ) = $self->scan_bare_identifier_do(
2567  
2568 $input_line,
2569 $i,
2570 $tok,
2571 $type,
2572 $prototype,
2573 $rtoken_map,
2574 $max_token_index,
2575 );
2576 1870 return;
2577 } ## end sub scan_bare_identifier
2578  
2579 557 ▶ sub scan_identifier {
Subroutine scan_identifier: called CC=5 SCAR=19.9
Pod undocumented
2580  
2581 # Scan for an identifier following a sigil or -> or other
2582 # identifier prefix, such as '::'
2583  
2584 557 my $self = shift;
2585  
2586 (
2587  
2588 557 $i,
2589 $tok,
2590 $type,
2591 $id_scan_state,
2592 $identifier,
2593 my $split_pretoken_flag,
2594  
2595 ) = $self->scan_complex_identifier(
2596  
2597 $i,
2598 $id_scan_state,
2599 $identifier,
2600 $rtokens,
2601 $max_token_index,
2602 $expecting,
2603 $rparen_type->[$paren_depth],
2604 );
2605  
2606 # Check for signal to fix a special variable adjacent to a keyword,
2607 # such as '$^One$0'.
2608 557 ▶ if ($split_pretoken_flag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($split_pretoken_flag) 3 554 557
2609  
2610 # Try to fix it by splitting the pretoken
2611 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
2612 && $rtokens->[ $i - 1 ] eq '^'
2613 && $self->split_pretoken(1) )
2614 {
2615 3 $identifier = substr( $identifier, 0, 3 );
2616 3 $tok = $identifier;
2617 }
2618 else {
2619  
2620 # This shouldn't happen ...
2621 0 my $var = substr( $tok, 0, 3 );
2622 0 my $excess = substr( $tok, 3 );
2623 0 $self->interrupt_logfile();
2624 0 $self->warning(<<EOM);
2625 $input_line_number: Trouble parsing at characters '$excess' after special variable '$var'.
2626 A space may be needed after '$var'.
2627 EOM
2628 0 $self->resume_logfile();
2629 }
2630 }
2631 557 return;
2632 } ## end sub scan_identifier
2633  
2634 45 ▶ use constant VERIFY_FASTSCAN => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2635 45 my %fast_scan_context;
2636  
2637 45 ▶ BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
2638 45 %fast_scan_context = (
2639 '$' => SCALAR_CONTEXT,
2640 '*' => SCALAR_CONTEXT,
2641 '@' => LIST_CONTEXT,
2642 '%' => LIST_CONTEXT,
2643 '&' => UNKNOWN_CONTEXT,
2644 );
2645 } ## end BEGIN
2646  
2647 5756 ▶ sub scan_simple_identifier {
Subroutine scan_simple_identifier: called CC=19 SCAR=30.4
Pod undocumented
2648  
2649 5756 my $self = shift;
2650  
2651 # This is a wrapper for sub scan_identifier. It does a fast preliminary
2652 # scan for certain common identifiers:
2653 # '$var', '@var', %var, *var, &var, '@{...}', '%{...}'
2654 # If it does not find one of these, or this is a restart, it calls the
2655 # original scanner directly.
2656  
2657 # This gives the same results as the full scanner in about 1/4 the
2658 # total runtime for a typical input stream.
2659  
2660 # Notation:
2661 # $var * 2
2662 # ^^ ^
2663 # || |
2664 # || ---- $i_next [= next nonblank pretoken ]
2665 # |----$i_plus_1 [= a bareword ]
2666 # ---$i_begin [= a sigil]
2667  
2668 5756 my $i_begin = $i;
2669 5756 my $tok_begin = $tok;
2670 5756 my $i_plus_1 = $i + 1;
2671 5756 my $fast_scan_type;
2672  
2673 #-------------------------------------------------------
2674 # Do full scan for anything following a pointer, such as
2675 # $cref->&*; # a postderef
2676 #-------------------------------------------------------
2677 5756 ▶ if ( $last_nonblank_token eq '->' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($last_nonblank_token eq '->') { } 8 5748 5756
elsif (not $id_scan_state and $i_plus_1 <= $max_token_index and $fast_scan_context{$tok}) { } 5642 106 5748
elsif ($tok eq '->' and $i < $max_token_index and $rtokens->[$i_plus_1] eq '{' || $rtokens->[$i_plus_1] eq '[') { } 0 106 106
2678  
2679 }
2680  
2681 #------------------------------
2682 # quick scan with leading sigil
2683 #------------------------------
2684 ▶ 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
41025642
not $id_scan_state and $i_plus_1 <= $max_token_index
!ll&&!rl&&r
045744
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
2685 && $i_plus_1 <= $max_token_index
2686 && $fast_scan_context{$tok} )
2687 {
2688 5642 $context = $fast_scan_context{$tok};
2689  
2690 # look for $var, @var, ...
2691 5642 ▶ if ( $rtoken_type->[$i_plus_1] eq 'w' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rtoken_type->[$i_plus_1] eq 'w') { } 5279 363 5642
elsif ($rtoken_type->[$i_plus_1] eq '{' and $tok_begin eq '@' || $tok_begin eq '%') { } 43 320 363
2692 5279 my $pretype_next = EMPTY_STRING;
2693 5279 ▶ if ( $i_plus_1 < $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_plus_1 < $max_token_index) 5157 122 5279
2694 5157 my $i_next = $i_plus_1 + 1;
2695 5157 ▶ if ( $rtoken_type->[$i_next] eq 'b'
Branch: 1 branch
BranchTrueFalseTotal
if ($rtoken_type->[$i_next] eq "b" and $i_next < $max_token_index) 2075 3082 5157
Condition100%3/3
$rtoken_type->[$i_next] eq "b" and $i_next < $max_token_index
!ll&&!rl&&r
307932075
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
2696 && $i_next < $max_token_index )
2697 {
2698 2075 $i_next += 1;
2699 }
2700 5157 $pretype_next = $rtoken_type->[$i_next];
2701 }
2702 5279 ▶ if ( $pretype_next ne ':' && $pretype_next ne "'" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pretype_next ne ":" and $pretype_next ne "'") 5163 116 5279
Condition100%3/3
$pretype_next ne ":" and $pretype_next ne "'"
!ll&&!rl&&r
10885163
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
2703  
2704 # Found type 'i' like '$var', '@var', or '%var'
2705 5163 $identifier = $tok . $rtokens->[$i_plus_1];
2706 5163 $tok = $identifier;
2707 5163 $type = 'i';
2708 5163 $i = $i_plus_1;
2709 5163 $fast_scan_type = $type;
2710 }
2711 }
2712  
2713 # Look for @{ or %{ .
2714 # But we must let the full scanner handle things ${ because it may
2715 # keep going to get a complete identifier like '${#}' .
2716 ▶ 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
2717 $rtoken_type->[$i_plus_1] eq '{'
2718 && ( $tok_begin eq '@'
2719 || $tok_begin eq '%' )
2720 )
2721 {
2722  
2723 43 $identifier = $tok;
2724 43 $type = 't';
2725 43 $fast_scan_type = $type;
2726 }
2727 else {
2728 ## out of tricks
2729 }
2730 }
2731  
2732 #---------------------------
2733 # Quick scan with leading ->
2734 # Look for ->[ and ->{
2735 #---------------------------
2736 ▶ 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
2737 $tok eq '->'
2738 && $i < $max_token_index
2739 && ( $rtokens->[$i_plus_1] eq '{'
2740 || $rtokens->[$i_plus_1] eq '[' )
2741 )
2742 {
2743 0 $type = $tok;
2744 0 $fast_scan_type = $type;
2745 0 $identifier = $tok;
2746 0 $context = UNKNOWN_CONTEXT;
2747 }
2748 else {
2749 ## out of tricks
2750 }
2751  
2752 #--------------------------------------
2753 # Verify correctness during development
2754 #--------------------------------------
2755 5756 if ( VERIFY_FASTSCAN && $fast_scan_type ) {
2756  
2757 # We will call the full method
2758 my $identifier_simple = $identifier;
2759 my $tok_simple = $tok;
2760 my $i_simple = $i;
2761 my $context_simple = $context;
2762  
2763 $tok = $tok_begin;
2764 $i = $i_begin;
2765 $self->scan_identifier();
2766  
2767 if ( $tok ne $tok_simple
2768 || $type ne $fast_scan_type
2769 || $i != $i_simple
2770 || $identifier ne $identifier_simple
2771 || $id_scan_state
2772 || $context ne $context_simple )
2773 {
2774 print {*STDERR} <<EOM;
2775 scan_simple_identifier differs from scan_identifier:
2776 simple: i=$i_simple, tok=$tok_simple, type=$fast_scan_type, ident=$identifier_simple, context='$context_simple
2777 full: i=$i, tok=$tok, type=$type, ident=$identifier, context='$context state=$id_scan_state
2778 EOM
2779 }
2780 }
2781  
2782 #-------------------------------------------------
2783 # call full scanner if fast method did not succeed
2784 #-------------------------------------------------
2785 5756 ▶ if ( !$fast_scan_type ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fast_scan_type) 550 5206 5756
2786 550 $self->scan_identifier();
2787 }
2788 5756 return;
2789 } ## end sub scan_simple_identifier
2790  
2791 14 ▶ sub method_ok_here {
Subroutine method_ok_here: called CC=12 SCAR=25.5
Pod undocumented
2792  
2793 14 my ( $self, $next_nonblank_token ) = @_;
2794  
2795 # Return:
2796 # false if this is definitely an invalid method declaration
2797 # true otherwise (even if not sure)
2798  
2799 # We are trying to avoid problems with old uses of 'method'
2800 # when --use-feature=class is set (rt145706).
2801 # For example, this should cause a return of 'false':
2802  
2803 # method paint => sub {
2804 # return;
2805 # };
2806  
2807 # Assume non-method if an error would occur
2808 14 ▶ return if ( $expecting == OPERATOR );
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 14 14
2809  
2810 # Currently marking a line-ending 'method' as a bareword (fix c532)
2811 14 ▶ return if ( $i_tok >= $max_token_index );
Branch: 1 branch
BranchTrueFalseTotal
if $i_tok >= $max_token_index 0 14 14
2812  
2813 # If a '$' follows 'method'...
2814 # Check for possible Object::Pad lexical method like
2815 # 'method $var {'
2816 # TODO: maybe merge this with the code below by increasing pos by 1
2817 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
2818 2 return 1;
2819 }
2820  
2821 # Otherwise, not a method if non-word follows ..
2822 12 ▶ if ( $next_nonblank_token !~ /^[\w\:]/ ) { return }
Branch: 1 branch
BranchTrueFalseTotal
unless ($next_nonblank_token =~ /^[\w\:]/) 4 8 12
2823  
2824 # from do_scan_sub:
2825 8 my $i_beg = $i + 1;
2826 8 my $pos_beg = $rtoken_map->[$i_beg];
2827 8 pos($input_line) = $pos_beg;
2828  
2829 # TEST 1: look a valid sub NAME
2830 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
2831 $input_line =~ m{\G\s*
2832 ((?:\w*(?:'|::))*) # package - something that ends in :: or '
2833 (\w+) # NAME - required
2834 }gcx
2835 )
2836 {
2837 # For possible future use..
2838 ##my $subname = $2;
2839 ##my $package = $1 ? $1 : EMPTY_STRING;
2840 }
2841 else {
2842 0 return;
2843 }
2844  
2845 # TEST 2: look for invalid characters after name, such as here:
2846 # method paint => sub {
2847 # ...
2848 # }
2849 8 my $next_char = EMPTY_STRING;
2850 8 ▶ if ( $input_line =~ m/\s*(\S)/gcx ) { $next_char = $1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /\s*(\S)/cgx) 7 1 8
2851 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
2852 1 ( $next_char, my $i_next_uu ) =
2853 $self->find_next_nonblank_token( $max_token_index,
2854 $rtokens, $max_token_index );
2855 }
2856  
2857 8 ▶ if ( !$next_char ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($next_char) 0 8 8
2858  
2859 # out of characters - give up
2860 0 return;
2861 }
2862  
2863 # Possibly valid next token types:
2864 # '(' could start prototype or signature
2865 # ':' could start ATTRIBUTE
2866 # '{' cold start BLOCK
2867 # ';' or '}' could end a statement
2868 8 ▶ if ( $next_char !~ /^[\(\:\{\;\}]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($next_char =~ /^[\(\:\{\;\}]/) 3 5 8
2869  
2870 # This does not match use feature 'class' syntax
2871 3 return;
2872 }
2873  
2874 # We will stop here and assume that this is valid syntax for
2875 # use feature 'class'.
2876 5 return 1;
2877 } ## end sub method_ok_here
2878  
2879 12 ▶ sub class_ok_here {
Subroutine class_ok_here: called CC=8 SCAR=21.5
Pod undocumented
2880  
2881 12 my $self = shift;
2882  
2883 # Return:
2884 # false if this is definitely an invalid class declaration
2885 # true otherwise (even if not sure)
2886  
2887 # We are trying to avoid problems with old uses of 'class'
2888 # when --use-feature=class is set (rt145706). We look ahead
2889 # see if this use of 'class' is obviously inconsistent with
2890 # the syntax of use feature 'class'. This allows the default
2891 # setting --use-feature=class to work for old syntax too.
2892  
2893 # Valid class declarations look like
2894 # class NAME ?ATTRS ?VERSION ?BLOCK
2895 # where ATTRS VERSION and BLOCK are optional
2896  
2897 # For example, this should produce a return of 'false':
2898 #
2899 # class ExtendsBasicAttributes is BasicAttributes{
2900  
2901 # TEST 1: class stmt can only go where a new statement can start
2902 0 ▶ if ( !new_statement_ok() ) { return }
Branch: 1 branch
BranchTrueFalseTotal
unless (new_statement_ok()) 0 12 12
2903  
2904 12 my $i_beg = $i + 1;
2905 12 my $pos_beg = $rtoken_map->[$i_beg];
2906 12 pos($input_line) = $pos_beg;
2907  
2908 # TEST 2: look for a valid NAME
2909 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
2910 $input_line =~ m{\G\s*
2911 ((?:\w*(?:'|::))*) # package - something that ends in :: or '
2912 (\w+) # NAME - required
2913 }gcx
2914 )
2915 {
2916 # For possible future use..
2917 ##my $subname = $2;
2918 ##my $package = $1 ? $1 : EMPTY_STRING;
2919 }
2920 else {
2921 0 return;
2922 }
2923  
2924 # TEST 3: look for valid characters after NAME
2925 12 my $next_char = EMPTY_STRING;
2926 12 ▶ if ( $input_line =~ m/\s*(\S)/gcx ) { $next_char = $1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /\s*(\S)/cgx) 11 1 12
2927 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
2928 1 ( $next_char, my $i_next_uu ) =
2929 $self->find_next_nonblank_token( $max_token_index,
2930 $rtokens, $max_token_index );
2931 }
2932 12 ▶ if ( !$next_char ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($next_char) 0 12 12
2933  
2934 # out of characters - give up
2935 0 return;
2936 }
2937  
2938 # Must see one of: ATTRIBUTE, VERSION, BLOCK, or end stmt
2939  
2940 # Possibly valid next token types:
2941 # ':' could start ATTRIBUTE
2942 # '\d' could start VERSION
2943 # '{' cold start BLOCK
2944 # ';' could end a statement
2945 # '}' could end statement but would be strange
2946  
2947 12 ▶ if ( $next_char !~ /^[\:\d\{\;\}]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($next_char =~ /^[\:\d\{\;\}]/) 2 10 12
2948  
2949 # This does not match use feature 'class' syntax
2950 2 return;
2951 }
2952  
2953 # We will stop here and assume that this is valid syntax for
2954 # use feature 'class'.
2955 10 return 1;
2956 } ## end sub class_ok_here
2957  
2958 427 ▶ sub scan_id {
Subroutine scan_id: called CC=1 SCAR=0.0
Pod undocumented
2959 427 my $self = shift;
2960  
2961 # Scan for a sub or package name
2962  
2963 427 ( $i, $tok, $type, $id_scan_state ) = $self->scan_id_do(
2964  
2965 $input_line,
2966 $i, $tok,
2967 $rtokens,
2968 $rtoken_map,
2969 $id_scan_state,
2970 $max_token_index,
2971 );
2972 427 return;
2973 } ## end sub scan_id
2974  
2975 687 ▶ sub scan_number {
Subroutine scan_number: called CC=1 SCAR=0.0
Pod undocumented
2976 687 my $self = shift;
2977 687 my $number;
2978 687 ( $i, $type, $number ) =
2979 $self->scan_number_do( $input_line, $i, $rtoken_map, $type,
2980 $max_token_index );
2981 687 return $number;
2982 } ## end sub scan_number
2983  
2984 45 ▶ use constant VERIFY_FASTNUM => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2985  
2986 2913 ▶ sub scan_number_fast {
Subroutine scan_number_fast: called CC=13 SCAR=25.7
Pod undocumented
2987  
2988 2913 my $self = shift;
2989  
2990 # This is a wrapper for sub scan_number. It does a fast preliminary
2991 # scan for a simple integer. It calls the original scan_number if it
2992 # does not find one.
2993  
2994 2913 my $i_begin = $i;
2995 2913 my $tok_begin = $tok;
2996 2913 my $number;
2997  
2998 #---------------------------------
2999 # Quick check for (signed) integer
3000 #---------------------------------
3001  
3002 # This will be the string of digits:
3003 2913 my $i_d = $i;
3004 2913 my $tok_d = $tok;
3005 2913 my $typ_d = $rtoken_type->[$i_d];
3006  
3007 # check for signed integer
3008 2913 my $sign = EMPTY_STRING;
3009 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
3010 && ( $typ_d eq '+' || $typ_d eq '-' )
3011 && $i_d < $max_token_index )
3012 {
3013 392 $sign = $tok_d;
3014 392 $i_d++;
3015 392 $tok_d = $rtokens->[$i_d];
3016 392 $typ_d = $rtoken_type->[$i_d];
3017 }
3018  
3019 # Handle integers
3020 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
3023182293
$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
272266318
$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/DC80%4/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 table83%5/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
3021 $typ_d eq 'd'
3022 && (
3023 $i_d == $max_token_index
3024 || ( $i_d < $max_token_index
3025 && $rtoken_type->[ $i_d + 1 ] ne '.'
3026 && $rtoken_type->[ $i_d + 1 ] ne 'w' )
3027 )
3028 )
3029 {
3030 # Let the full scanner handle multi-digit integers beginning with
3031 # '0' because there could be error messages. For example, '009' is
3032 # not a valid number.
3033  
3034 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
3035 2236 $number = $sign . $tok_d;
3036 2236 $type = 'n';
3037 2236 $i = $i_d;
3038 }
3039 }
3040  
3041 #--------------------------------------
3042 # Verify correctness during development
3043 #--------------------------------------
3044 2913 if ( VERIFY_FASTNUM && defined($number) ) {
3045  
3046 # We will call the full method
3047 my $type_simple = $type;
3048 my $i_simple = $i;
3049 my $number_simple = $number;
3050  
3051 $tok = $tok_begin;
3052 $i = $i_begin;
3053 $number = $self->scan_number();
3054  
3055 if ( $type ne $type_simple
3056 || ( $i != $i_simple && $i <= $max_token_index )
3057 || $number ne $number_simple )
3058 {
3059 print {*STDERR} <<EOM;
3060 scan_number_fast differs from scan_number:
3061 simple: i=$i_simple, type=$type_simple, number=$number_simple
3062 full: i=$i, type=$type, number=$number
3063 EOM
3064 }
3065 }
3066  
3067 #----------------------------------------
3068 # call full scanner if may not be integer
3069 #----------------------------------------
3070 2913 ▶ if ( !defined($number) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $number) 677 2236 2913
3071 677 $number = $self->scan_number();
3072 }
3073 2913 return $number;
3074 } ## end sub scan_number_fast
3075  
3076 1689 ▶ sub error_if_expecting_TERM {
Subroutine error_if_expecting_TERM: called CC=9 SCAR=25.4
Pod undocumented
3077 1689 my ($self) = @_;
3078  
3079 # Issue a warning if a binary operator is missing a term to operate on
3080  
3081 # This should only be called if a term is expected here
3082 0 ▶ if ( $expecting != TERM ) { return }
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting != -1) 0 1689 1689
3083  
3084 # Be sure a TERM is definitely required ..
3085 1689 ▶ 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}) 1 1688 1689
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
101688
$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
101688
$last_nonblank_type eq "k" and $is_binary_or_unary_keyword{$last_nonblank_token}
!ll&&!rl&&r
15321560
$is_not_a_TERM_producer_type{$last_nonblank_type} and $is_binary_operator_type{$tok}
!ll&&!rl&&r
8528360
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 table50%4/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
3086  
3087 # .. following a binary operator token type, like '='
3088 $is_binary_or_unary_operator_type{$last_nonblank_type}
3089  
3090 # .. or following a binary keyword operator, like 'and'
3091 || ( $last_nonblank_type eq 'k'
3092 && $is_binary_or_unary_keyword{$last_nonblank_token} )
3093  
3094 # .. or for a binary operator following something like a ';'
3095 || ( $is_not_a_TERM_producer_type{$last_nonblank_type}
3096 && $is_binary_operator_type{$tok} )
3097 )
3098 {
3099  
3100 # We must exclude error checking in sub signatures which have some
3101 # unusual syntax. For example the following syntax is okay within
3102 # a signature:
3103 # sub mysub ($=,) {...}
3104 # $ = undef
3105 1 my $ct = $rparen_type->[$paren_depth];
3106 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
3107  
3108 $self->report_unexpected(
3109 {
3110 0 found => $tok,
3111 expecting => "term",
3112 i_tok => $i_tok,
3113 last_nonblank_i => $last_nonblank_i,
3114 rpretoken_map => $rtoken_map,
3115 rpretoken_type => $rtoken_type,
3116 input_line => $input_line,
3117 }
3118 );
3119 0 return 1;
3120 }
3121 1688 return;
3122 } ## end sub error_if_expecting_TERM
3123  
3124 # a sub to warn if token found where operator expected
3125 823 ▶ sub error_if_expecting_OPERATOR {
Subroutine error_if_expecting_OPERATOR: called CC=4 SCAR=24.1
Pod undocumented
3126  
3127 823 my ( $self, ($thing) ) = @_;
3128  
3129 # Issue warning on error if expecting operator
3130 # Given:
3131 # $thing = the unexpected token or issue
3132 # = undef to use current pre-token
3133  
3134 823 ▶ if ( $expecting == OPERATOR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == 1) 0 823 823
3135 0 ▶ if ( !defined($thing) ) { $thing = $tok }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $thing) 0 0 0
3136 $self->report_unexpected(
3137 {
3138 0 found => $thing,
3139 expecting => "operator",
3140 i_tok => $i_tok,
3141 last_nonblank_i => $last_nonblank_i,
3142 rpretoken_map => $rtoken_map,
3143 rpretoken_type => $rtoken_type,
3144 input_line => $input_line,
3145 }
3146 );
3147 0 ▶ if ( $i_tok == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_tok == 0) 0 0 0
3148 0 $self->interrupt_logfile();
3149 0 $self->warning("Missing ';' or ',' above?\n");
3150 0 $self->resume_logfile();
3151 }
3152 0 return 1;
3153 }
3154 823 return;
3155 } ## end sub error_if_expecting_OPERATOR
3156  
3157 # ------------------------------------------------------------
3158 # end scanner interfaces
3159 # ------------------------------------------------------------
3160  
3161 #------------------
3162 # Tokenization subs
3163 #------------------
3164 # An identifier in possible indirect object location followed by any of
3165 # these tokens: -> , ; } (plus others) is not an indirect object. Fix c257.
3166 my %Z_test_hash;
3167  
3168 45 ▶ BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
3169 45 my @qZ = qw#
3170 -> ; } ) ]
3171 => =~ = == !~ || >= != *= .. && |= .= -= += <= %=
3172 ^= &&= ||= //= <=>
3173 #;
3174 45 push @qZ, COMMA;
3175 45 $Z_test_hash{$_} = 1 for @qZ;
3176 }
3177  
3178 4892 ▶ sub do_DOLLAR_SIGN {
Subroutine do_DOLLAR_SIGN: called CC=10 SCAR=23.1
Pod undocumented
3179  
3180 4892 my $self = shift;
3181  
3182 # '$'
3183 # start looking for a scalar
3184 4892 ▶ $self->error_if_expecting_OPERATOR("Scalar")
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 4892 4892
3185 if ( $expecting == OPERATOR );
3186 4892 $self->scan_simple_identifier();
3187  
3188 4892 ▶ if ( $identifier eq '$^W' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($identifier eq "\$^W") 1 4891 4892
3189 1 $self->[_saw_perl_dash_w_] = 1;
3190 }
3191  
3192 # Check for identifier in indirect object slot
3193 # (vorboard.pl, sort.t). Something like:
3194 # /^(print|printf|sort|exec|system)$/
3195 4892 ▶ 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")) 110 4782 4892
Condition86%13/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
65454782
$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
43224827
$is_indirect_object_taker{$last_nonblank_token} and $last_nonblank_type eq "k"
!ll&&!rl&&r
4849043
$last_nonblank_token eq "(" and $is_indirect_object_taker{$rparen_type->[$paren_depth]}
!ll&&!rl&&r
395687122
$last_nonblank_type eq "w" or $last_nonblank_type eq "U"
l!l&&r!l&&!r
4504782
MC/DC66%4/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 table33%5/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
3196 $is_indirect_object_taker{$last_nonblank_token}
3197 && $last_nonblank_type eq 'k'
3198 || ( ( $last_nonblank_token eq '(' )
3199 && $is_indirect_object_taker{ $rparen_type->[$paren_depth] } )
3200 || ( $last_nonblank_type eq 'w'
3201 || $last_nonblank_type eq 'U' ) # possible object
3202 )
3203 {
3204  
3205 # An identifier followed by '->' is not indirect object;
3206 # fixes b1175, b1176. Fix c257: Likewise for other tokens like
3207 # comma, semicolon, closing brace, and single space.
3208 110 my ( $next_nonblank_token, $i_next_uu ) =
3209 $self->find_next_noncomment_token( $i, $rtokens,
3210 $max_token_index );
3211 110 ▶ $type = 'Z' if ( !$Z_test_hash{$next_nonblank_token} );
Branch: 1 branch
BranchTrueFalseTotal
unless $Z_test_hash{$next_nonblank_token} 45 65 110
3212 }
3213 4892 return;
3214 } ## end sub do_DOLLAR_SIGN
3215  
3216 2447 ▶ sub do_LEFT_PARENTHESIS {
Subroutine do_LEFT_PARENTHESIS: called CC=19 SCAR=38.3
Pod undocumented
3217  
3218 2447 my $self = shift;
3219  
3220 # '('
3221 2447 ++$paren_depth;
3222  
3223 # variable to enable check for brace after closing paren (c230)
3224 2447 my $want_brace = EMPTY_STRING;
3225  
3226 2447 ▶ if ($want_paren) {
Branch: 2 branches
BranchTrueFalseTotal
if ($want_paren) { } 313 2134 2447
elsif (substr($statement_type, 0, 3) eq 'sub' and $statement_type =~ /^sub\b/) { } 20 2114 2134
3227 313 $container_type = $want_paren;
3228 313 $want_brace = $want_paren;
3229 313 $want_paren = EMPTY_STRING;
3230 }
3231 ▶ 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
2114020
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
3232 && $statement_type =~ /^sub\b/ )
3233 {
3234 20 $container_type = $statement_type;
3235 }
3236 else {
3237 2114 $container_type = $last_nonblank_token;
3238  
3239 # We can check for a syntax error here of unexpected '(',
3240 # but this is going to get messy...
3241 2114 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == 1 and not $last_nonblank_token =~ /^(?:[\]\}\)\&]|\-\>)/) 3 2111 2114
Condition100%3/3
$expecting == 1 and not $last_nonblank_token =~ /^(?:[\]\}\)\&]|\-\>)/
!ll&&!rl&&r
14646473
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
3242 $expecting == OPERATOR
3243  
3244 # Be sure this is not a method call of the form
3245 # &method(...), $method->(..), &{method}(...),
3246 # $ref[2](list) is ok & short for $ref[2]->(list)
3247 # NOTE: at present, braces in something like &{ xxx }
3248 # are not marked as a block, we might have a method call.
3249 # Added ')' to fix case c017, something like ()()()
3250 && $last_nonblank_token !~ /^(?:[\]\}\)\&]|\-\>)/
3251 )
3252 {
3253  
3254 # ref: camel 3 p 703.
3255 3 ▶ if ( $last_last_nonblank_token eq 'do' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_last_nonblank_token eq 'do') { } 0 3 3
3256 0 $self->complain(
3257 "do SUBROUTINE is deprecated; consider & or -> notation\n"
3258 );
3259 }
3260 else {
3261  
3262 # if this is an empty list, (), then it is not an
3263 # error; for example, we might have a constant pi and
3264 # invoke it with pi() or just pi;
3265 3 my ( $next_nonblank_token, $i_next_uu ) =
3266 $self->find_next_nonblank_token( $i, $rtokens,
3267 $max_token_index );
3268  
3269 # Patch for c029: give up error check if
3270 # a side comment follows
3271 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
3272 && $next_nonblank_token ne '#' )
3273 {
3274 0 my $hint;
3275  
3276 0 $self->error_if_expecting_OPERATOR('(');
3277  
3278 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
3279 0 $hint =
3280 "$last_nonblank_token has a void prototype\n";
3281 }
3282 elsif ( $last_nonblank_type eq 'i' ) {
3283 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
3284 && $last_nonblank_token =~ /^\$/ )
3285 {
3286 0 $hint =
3287 "Do you mean '$last_nonblank_token->(' ?";
3288 0 ▶ if ( $is_for_foreach{ $rtokens->[0] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_for_foreach{$rtokens->[0]}) 0 0 0
3289 0 $hint .= " ... or is a ';' missing above?";
3290 }
3291 0 $hint .= "\n";
3292 }
3293 }
3294 else {
3295 ## no hint
3296 }
3297 0 ▶ if ($hint) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hint) 0 0 0
3298 0 $self->interrupt_logfile();
3299 0 $self->warning($hint);
3300 0 $self->resume_logfile();
3301 }
3302 } ## end if ( $next_nonblank_token...
3303 } ## end else [ if ( $last_last_nonblank_token...
3304 } ## end if ( $expecting == OPERATOR...
3305 }
3306  
3307 2447 ( $type_sequence, $indent_flag ) =
3308 $self->increase_nesting_depth( PAREN, $rtoken_map->[$i_tok] );
3309  
3310 # propagate types down through nested parens
3311 # for example: the second paren in 'if ((' would be structural
3312 # since the first is.
3313  
3314 2447 ▶ if ( $last_nonblank_token eq '(' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_token eq '(') { } 61 2386 2447
3315 61 $type = $last_nonblank_type;
3316 }
3317  
3318 # We exclude parens as structural after a ',' because it
3319 # causes subtle problems with continuation indentation for
3320 # something like this, where the first 'or' will not get
3321 # indented.
3322 #
3323 # assert(
3324 # __LINE__,
3325 # ( not defined $check )
3326 # or ref $check
3327 # or $check eq "new"
3328 # or $check eq "old",
3329 # );
3330 #
3331 # Likewise, we exclude parens where a statement can start
3332 # because of problems with continuation indentation, like
3333 # these:
3334 #
3335 # ($firstline =~ /^#\!.*perl/)
3336 # and (print $File::Find::name, "\n")
3337 # and (return 1);
3338 #
3339 # (ref($usage_fref) =~ /CODE/)
3340 # ? &$usage_fref
3341 # : (&blast_usage, &blast_params, &blast_general_params);
3342  
3343 else {
3344 2386 $type = '{';
3345 }
3346  
3347 2447 ▶ if ( $last_nonblank_type eq ')' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq ")") 0 2447 2447
3348 0 $self->warning(
3349 "Syntax error? found token '$last_nonblank_type' then '('\n");
3350 }
3351  
3352 # git #105: Copy container type and want-brace flag at ') (';
3353 # propagate the container type onward so that any subsequent brace gets
3354 # correctly marked. I have implemented this as a general rule, which
3355 # should be safe, but if necessary it could be restricted to certain
3356 # container statement types such as 'for'.
3357 2447 ▶ if ( $last_nonblank_token eq ')' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_token eq ")") 1 2446 2447
3358 1 my $rvars = $rparen_vars->[$paren_depth];
3359 1 ▶ if ( defined($rvars) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rvars) 1 0 1
3360 1 $container_type = $rparen_type->[$paren_depth];
3361 1 ( my $type_lp_uu, $want_brace ) = @{$rvars};
3362 }
3363 }
3364  
3365 2447 $rparen_type->[$paren_depth] = $container_type;
3366 2447 $rparen_vars->[$paren_depth] = [ $type, $want_brace ];
3367 2447 $rparen_semicolon_count->[$paren_depth] = 0;
3368  
3369 2447 return;
3370  
3371 } ## end sub do_LEFT_PARENTHESIS
3372  
3373 2447 ▶ sub do_RIGHT_PARENTHESIS {
Subroutine do_RIGHT_PARENTHESIS: called CC=12 SCAR=25.5
Pod undocumented
3374  
3375 2447 my $self = shift;
3376  
3377 2447 ( $type_sequence, $indent_flag ) =
3378 $self->decrease_nesting_depth( PAREN, $rtoken_map->[$i_tok] );
3379  
3380 # ')'
3381 2447 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) 363 2084 2447
3382 $self->error_if_expecting_TERM()
3383 363 ▶ if ( !$self->[_rsaw_unknown_syntax_in_seqno_]->{$type_sequence} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->[56]{$type_sequence} 361 2 363
3384 }
3385  
3386 2447 my $rvars = $rparen_vars->[$paren_depth];
3387 2447 ▶ if ( defined($rvars) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rvars) 2447 0 2447
3388 2447 my ( $type_lp, $want_brace_uu ) = @{$rvars};
3389 2447 ▶ if ( $type_lp && $type_lp eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_lp and $type_lp eq "{") 2447 0 2447
Condition33%1/3
$type_lp and $type_lp eq "{"
!ll&&!rl&&r
002447
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
3390 2447 $type = '}';
3391 }
3392 }
3393  
3394 2447 $container_type = $rparen_type->[$paren_depth];
3395  
3396 # restore statement type as 'sub' at closing paren of a signature
3397 # so that a subsequent ':' is identified as an attribute
3398 2447 ▶ 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 2417 2447
Condition100%3/3
substr($container_type, 0, 3) eq "sub" and $container_type =~ /^sub\b/
!ll&&!rl&&r
2416130
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
3399 && $container_type =~ /^sub\b/ )
3400 {
3401 30 $statement_type = $container_type;
3402 }
3403  
3404 2447 ▶ if ( $is_for_foreach{ $rparen_type->[$paren_depth] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_for_foreach{$rparen_type->[$paren_depth]}) 79 2368 2447
3405 79 my $num_sc = $rparen_semicolon_count->[$paren_depth];
3406 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
3407 0 $self->warning("Expected 2 ';' in 'for(;;)' but saw $num_sc\n");
3408 }
3409 }
3410  
3411 2447 ▶ if ( $paren_depth > 0 ) { $paren_depth-- }
Branch: 1 branch
BranchTrueFalseTotal
if ($paren_depth > 0) 2447 0 2447
3412 2447 return;
3413 } ## end sub do_RIGHT_PARENTHESIS
3414  
3415 3722 ▶ sub do_COMMA {
Subroutine do_COMMA: called CC=5 SCAR=16.8
Pod undocumented
3416  
3417 3722 my $self = shift;
3418  
3419 # ','
3420 3722 ▶ if ( $last_nonblank_type eq COMMA ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($last_nonblank_type eq ',') { } 10 3712 3722
elsif ($last_nonblank_token eq '(' and $last_nonblank_type eq '{') { } 0 3712 3712
3421 10 $self->complain("Repeated ','s \n");
3422 }
3423  
3424 # Note that we have to check both token and type here because a
3425 # comma following a qw list can have last token='(' but type = 'q'
3426 ▶ elsif ( $last_nonblank_token eq '(' && $last_nonblank_type eq '{' ) {
Condition33%1/3
$last_nonblank_token eq "(" and $last_nonblank_type eq "{"
!ll&&!rl&&r
371200
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
3427 0 $self->warning("Unexpected leading ',' after a '('\n");
3428 }
3429 else {
3430 ## Error check added in update c565, moved to end of $code loop.
3431 }
3432  
3433 # patch for operator_expected: note if we are in the list (use.t)
3434 3722 ▶ if ( $statement_type eq 'use' ) { $statement_type = '_use' }
Branch: 1 branch
BranchTrueFalseTotal
if ($statement_type eq "use") 6 3716 3722
3435 3722 return;
3436  
3437 } ## end sub do_COMMA
3438  
3439 2967 ▶ sub do_SEMICOLON {
Subroutine do_SEMICOLON: called CC=4 SCAR=13.9
Pod undocumented
3440  
3441 2967 my $self = shift;
3442  
3443 # ';'
3444 2967 $context = UNKNOWN_CONTEXT;
3445 2967 $statement_type = EMPTY_STRING;
3446 2967 $want_paren = EMPTY_STRING;
3447  
3448 2967 ▶ if ( $is_for_foreach{ $rparen_type->[$paren_depth] } )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_for_foreach{$rparen_type->[$paren_depth]}) { } 35 2932 2967
3449 { # mark ; in for loop
3450  
3451 # Be careful: we do not want a semicolon such as the
3452 # following to be included:
3453 #
3454 # for (sort {strcoll($a,$b);} keys %investments) {
3455  
3456 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
3457 && $square_bracket_depth ==
3458 $rdepth_array->[PAREN]->[SQUARE_BRACKET]->[$paren_depth] )
3459 {
3460  
3461 34 $type = 'f';
3462 34 $rparen_semicolon_count->[$paren_depth]++;
3463 }
3464 }
3465 else {
3466 ## Error check added in update c565, moved to end of $code loop.
3467 }
3468 2967 return;
3469 } ## end sub do_SEMICOLON
3470  
3471 1297 ▶ sub do_QUOTATION_MARK {
Subroutine do_QUOTATION_MARK: called CC=2 SCAR=7.0
Pod undocumented
3472  
3473 1297 my $self = shift;
3474  
3475 # '"'
3476 1297 ▶ $self->error_if_expecting_OPERATOR("String")
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 1297 1297
3477 if ( $expecting == OPERATOR );
3478 1297 $in_quote = 1;
3479 1297 $type = 'Q';
3480 1297 $allowed_quote_modifiers = EMPTY_STRING;
3481 1297 $quote_starting_tok = $tok;
3482 1297 $quote_here_target_2 = undef;
3483 1297 return;
3484 } ## end sub do_QUOTATION_MARK
3485  
3486 1349 ▶ sub do_APOSTROPHE {
Subroutine do_APOSTROPHE: called CC=2 SCAR=7.0
Pod undocumented
3487  
3488 1349 my $self = shift;
3489  
3490 # "'"
3491 1349 ▶ $self->error_if_expecting_OPERATOR("String")
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 1349 1349
3492 if ( $expecting == OPERATOR );
3493 1349 $in_quote = 1;
3494 1349 $type = 'Q';
3495 1349 $allowed_quote_modifiers = EMPTY_STRING;
3496 1349 $quote_starting_tok = $tok;
3497 1349 $quote_here_target_2 = undef;
3498 1349 return;
3499 } ## end sub do_APOSTROPHE
3500  
3501 0 ▶ sub do_BACKTICK {
Subroutine do_BACKTICK: not called CC=2 SCAR=17.9
Pod undocumented
3502  
3503 0 my $self = shift;
3504  
3505 # '`'
3506 0 ▶ $self->error_if_expecting_OPERATOR("String")
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 0 0
3507 if ( $expecting == OPERATOR );
3508 0 $in_quote = 1;
3509 0 $type = 'Q';
3510 0 $allowed_quote_modifiers = EMPTY_STRING;
3511 0 $quote_starting_tok = $tok;
3512 0 $quote_here_target_2 = undef;
3513 0 return;
3514 } ## end sub do_BACKTICK
3515  
3516 225 ▶ sub do_SLASH {
Subroutine do_SLASH: called CC=7 SCAR=21.6
Pod undocumented
3517  
3518 225 my $self = shift;
3519  
3520 # '/'
3521 225 my $is_pattern;
3522  
3523 # a pattern cannot follow certain keywords which take optional
3524 # arguments, like 'shift' and 'pop'. See also '?'.
3525 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
3526 $last_nonblank_type eq 'k'
3527 && $is_keyword_rejecting_slash_as_pattern_delimiter{
3528 $last_nonblank_token}
3529 )
3530 {
3531 0 $is_pattern = 0;
3532 }
3533 elsif ( $expecting == UNKNOWN ) { # indeterminate, must guess..
3534 (
3535 0 $is_pattern,
3536 my $msg,
3537  
3538 ) = $self->guess_if_pattern_or_division(
3539  
3540 $i,
3541 $rtokens,
3542 $rtoken_type,
3543 $rtoken_map,
3544 $max_token_index,
3545 );
3546  
3547 0 ▶ if ($msg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg) 0 0 0
3548 0 if ( 0 && DEBUG_GUESS_MODE ) {
3549 $self->warning("DEBUG_GUESS_MODE message:\n$msg\n");
3550 }
3551 0 $self->write_diagnostics("DIVIDE:$msg\n");
3552 0 $self->write_logfile_entry($msg);
3553 }
3554 }
3555 else {
3556 225 $is_pattern = ( $expecting == TERM );
3557 }
3558  
3559 225 ▶ if ($is_pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_pattern) { } 88 137 225
3560 88 $in_quote = 1;
3561 88 $type = 'Q';
3562 88 $allowed_quote_modifiers = $quote_modifiers{'m'};
3563 88 $quote_starting_tok = 'm';
3564 88 $quote_here_target_2 = undef;
3565 }
3566 else { # not a pattern; check for a /= token
3567  
3568 137 ▶ if ( $rtokens->[ $i + 1 ] eq '=' ) { # form token /=
Branch: 1 branch
BranchTrueFalseTotal
if ($$rtokens[$i + 1] eq "=") 4 133 137
3569 4 $i++;
3570 4 $tok = '/=';
3571 4 $type = $tok;
3572 }
3573  
3574 #DEBUG - collecting info on what tokens follow a divide
3575 # for development of guessing algorithm
3576 ## if (
3577 ## $self->is_possible_numerator( $i, $rtokens,
3578 ## $max_token_index ) < 0
3579 ## )
3580 ## {
3581 ## $self->write_diagnostics("DIVIDE? $input_line\n");
3582 ## }
3583 }
3584 225 return;
3585 } ## end sub do_SLASH
3586  
3587 2084 ▶ sub do_LEFT_CURLY_BRACKET {
Subroutine do_LEFT_CURLY_BRACKET: called CC=43 SCAR=48.9
Pod undocumented
3588  
3589 2084 my $self = shift;
3590  
3591 # '{'
3592 2084 if ( 0 && $next_tok eq '%' ) {
3593 ## c583: Spot for possible future check for a '{% ' which starts
3594 ## a simple macro. If there is a matching closing '%}' on this
3595 ## line then mark the whole structure as a quote.
3596 }
3597  
3598 # if we just saw a ')', we will label this block with
3599 # its type. We need to do this to allow sub
3600 # code_block_type to determine if this brace starts a
3601 # code block or anonymous hash. (The type of a paren
3602 # pair is the preceding token, such as 'if', 'else',
3603 # etc).
3604 2084 $container_type = EMPTY_STRING;
3605  
3606 # ATTRS: for a '{' following an attribute list, reset
3607 # things to look like we just saw a sub name
3608 # Added 'package' (can be 'class') for --use-feature=class (rt145706)
3609 2084 ▶ if ( substr( $statement_type, 0, 3 ) eq 'sub' ) {
Branch: 5 branches
BranchTrueFalseTotal
if (substr($statement_type, 0, 3) eq 'sub') { } 36 2048 2084
elsif (substr($statement_type, 0, 7) eq 'package') { } 10 2038 2048
elsif ($statement_type eq 'case' || $statement_type eq 'when' and $statement_type eq $last_nonblank_token) { } 0 2038 2038
elsif ($last_nonblank_token eq ')') { } 301 1737 2038
elsif ($last_nonblank_token eq 'qw' and $is_for_foreach{$want_paren}) { } 0 1737 1737
3610 36 $last_nonblank_token = $statement_type;
3611 36 $last_nonblank_type = 'S'; # c250 change
3612 36 $statement_type = EMPTY_STRING;
3613 }
3614 elsif ( substr( $statement_type, 0, 7 ) eq 'package' ) {
3615 10 $last_nonblank_token = $statement_type;
3616 10 $last_nonblank_type = 'P'; # c250 change
3617 10 $statement_type = EMPTY_STRING;
3618 }
3619  
3620 # patch for SWITCH/CASE: hide these keywords from an immediately
3621 # following opening brace
3622 ▶ 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
1990480
$statement_type eq "case" or $statement_type eq "when"
l!l&&r!l&&!r
4351990
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
3623 && $statement_type eq $last_nonblank_token )
3624 {
3625 0 $last_nonblank_token = ";";
3626 }
3627  
3628 elsif ( $last_nonblank_token eq ')' ) {
3629 301 $last_nonblank_token = $rparen_type->[ $paren_depth + 1 ];
3630  
3631 # defensive move in case of a nesting error (pbug.t)
3632 # in which this ')' had no previous '('
3633 # this nesting error will have been caught
3634 301 ▶ if ( !defined($last_nonblank_token) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $last_nonblank_token) 0 301 301
3635 0 $last_nonblank_token = 'if';
3636 }
3637  
3638 # Syntax check at '){'
3639 301 ▶ if ( $is_blocktype_with_paren{$last_nonblank_token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_blocktype_with_paren{$last_nonblank_token}) { } 285 16 301
3640  
3641 285 my $rvars = $rparen_vars->[ $paren_depth + 1 ];
3642 285 ▶ if ( defined($rvars) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rvars) 285 0 285
3643 285 my ( $type_lp_uu, $want_brace ) = @{$rvars};
3644  
3645 # Issue an error if we are definitely not expecting a block
3646 # brace. Since this type of error can be triggered by a
3647 # previous error, to avoid confusion we will only issue a
3648 # warning if no other warnings have gone out yet.
3649 # See git #124 and c635.
3650 285 ▶ if ( !$want_brace
Branch: 1 branch
BranchTrueFalseTotal
if (not $want_brace and $rOpts_warn_unexpected_code_container and not $self->[9]) 0 285 285
Condition33%2/6
not $want_brace and $rOpts_warn_unexpected_code_container and not $self->[9]
!ll&&!rl&&r
28500
not $want_brace and $rOpts_warn_unexpected_code_container
!ll&&!rl&&r
28500
MC/DC0%0/3
not $want_brace and $rOpts_warn_unexpected_code_container and not $self->[9]
not $want_brace $rOpts_warn_unexpected_code_container not $self->[9]
Truth table25%1/4
not(A) and B and not(C)
A= not $want_braceB= $rOpts_warn_unexpected_code_containerC= not $self->[9]
ABCresult
0XX0
10X0
1100
1111
3651 && $rOpts_warn_unexpected_code_container
3652 && !$self->[_warning_count_] )
3653 {
3654 0 $self->warning(<<EOM);
3655 unexpected '{' after closing ')' of a trailing '$last_nonblank_token'" ... missing ';' above?
3656 to skip this warning, use -nwucc
3657 EOM
3658 }
3659 }
3660 }
3661 else {
3662 16 ▶ if ($rOpts_extended_syntax) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rOpts_extended_syntax) { } 16 0 16
3663  
3664 # we append a trailing () to mark this as an unknown
3665 # block type. This allows perltidy to format some
3666 # common extensions of perl syntax.
3667 # This is used by sub code_block_type
3668 16 $last_nonblank_token .= '()';
3669 }
3670 else {
3671 0 my $list =
3672 join( SPACE, sort keys %is_blocktype_with_paren );
3673 0 $self->warning(
3674 "syntax error at ') {', didn't see one of: <<$list>>; If this code is okay try using the -xs flag\n"
3675 );
3676 }
3677 }
3678 }
3679  
3680 # patch for paren-less for/foreach glitch, part 2.
3681 # see note below under 'qw'
3682 ▶ elsif ($last_nonblank_token eq 'qw'
Condition33%1/3
$last_nonblank_token eq "qw" and $is_for_foreach{$want_paren}
!ll&&!rl&&r
173700
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
3683 && $is_for_foreach{$want_paren} )
3684 {
3685 0 $last_nonblank_token = $want_paren;
3686 0 ▶ if ( $last_last_nonblank_token eq $want_paren ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_last_nonblank_token eq $want_paren) 0 0 0
3687 0 $self->warning(
3688 "syntax error at '$want_paren .. {' -- missing \$ loop variable\n"
3689 );
3690  
3691 }
3692 0 $want_paren = EMPTY_STRING;
3693 }
3694 else {
3695 ## not special
3696 }
3697  
3698 # now identify which of the three possible types of
3699 # curly braces we have: hash index container, anonymous
3700 # hash reference, or code block.
3701  
3702 # Patch for Object::Pad "field $var BLOCK"
3703 2084 ▶ 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 2076 2084
elsif (is_non_structural_brace()) { } 588 1488 2076
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
207608
$statement_type eq "field" and $last_last_nonblank_token eq "field" and $last_nonblank_type eq "i"
!ll&&!rl&&r
207608
$statement_type eq "field" and $last_last_nonblank_token eq "field"
!ll&&!rl&&r
207608
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
3704 && $last_last_nonblank_token eq 'field'
3705 && $last_nonblank_type eq 'i'
3706 && $last_last_nonblank_type eq 'k' )
3707 {
3708 8 $type = '{';
3709 8 $block_type = $statement_type;
3710 }
3711  
3712 # non-structural (hash index) curly brace pair
3713 # get marked 'L' and 'R'
3714 elsif ( is_non_structural_brace() ) {
3715 588 $type = 'L';
3716  
3717 # patch for SWITCH/CASE:
3718 # allow paren-less identifier after 'when'
3719 # if the brace is preceded by a space
3720 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
3721 && $last_nonblank_type eq 'i'
3722 && $last_last_nonblank_type eq 'k'
3723 && ( $i_tok == 0 || $rtoken_type->[ $i_tok - 1 ] eq 'b' ) )
3724 {
3725 0 $type = '{';
3726 0 $block_type = $statement_type;
3727 }
3728 }
3729  
3730 # code and anonymous hash have the same type, '{', but are
3731 # distinguished by 'block_type',
3732 # which will be blank for an anonymous hash
3733 else {
3734 1488 $block_type =
3735 $self->code_block_type( $i_tok, $rtokens, $rtoken_type,
3736 $max_token_index );
3737  
3738 # Is a new lexical sub looking for its block sequence number?
3739 # This is indicated with a special '911' signal.
3740 1488 ▶ 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 1488 1488
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
148800
$block_type and $ris_lexical_sub->{911} and $last_nonblank_type eq "S"
!ll&&!rl&&r
148800
$block_type and $ris_lexical_sub->{911}
!ll&&!rl&&r
34111470
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
3741 && $ris_lexical_sub->{911}
3742 && $last_nonblank_type eq 'S'
3743 && substr( $block_type, 0, 3 ) eq 'sub' )
3744 {
3745 0 my ( $subname, $package ) = @{ $ris_lexical_sub->{911} };
3746 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
3747 && $is_my_our_state{$last_last_nonblank_token} )
3748 {
3749 0 $ris_lexical_sub->{$subname}->{$package} =
3750 $next_sequence_number;
3751 }
3752  
3753 # Turn the signal off, even if we did not find the block being
3754 # sought - it may not exist if the sub statement was a simple
3755 # declaration without a block definition.
3756 0 $ris_lexical_sub->{911} = undef;
3757 }
3758  
3759 # patch to promote bareword type to function taking block
3760 1488 ▶ if ( $block_type
Branch: 1 branch
BranchTrueFalseTotal
if ($block_type and $last_nonblank_type eq "w" and $last_nonblank_i >= 0) 36 1452 1488
Condition83%5/6
$block_type and $last_nonblank_type eq "w" and $last_nonblank_i >= 0
!ll&&!rl&&r
1452036
$block_type and $last_nonblank_type eq "w"
!ll&&!rl&&r
341111136
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
3761 && $last_nonblank_type eq 'w'
3762 && $last_nonblank_i >= 0 )
3763 {
3764 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
3765 $routput_token_type->[$last_nonblank_i] =
3766 36 ▶ $is_grep_alias{$block_type} ? 'k' : 'G';
Branch: 1 branch
BranchTrueFalseTotal
$is_grep_alias{$block_type} ? : 5 31 36
3767 }
3768 }
3769  
3770 # patch for SWITCH/CASE: if we find a stray opening block brace
3771 # where we might accept a 'case' or 'when' block, then take it
3772 1488 ▶ if ( $statement_type eq 'case'
Branch: 1 branch
BranchTrueFalseTotal
if ($statement_type eq "case" or $statement_type eq "when") 48 1440 1488
Condition100%3/3
$statement_type eq "case" or $statement_type eq "when"
l!l&&r!l&&!r
4351440
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
3773 || $statement_type eq 'when' )
3774 {
3775 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
3776 4 $block_type = $statement_type;
3777 }
3778 }
3779 }
3780  
3781 2084 $rbrace_type->[ ++$brace_depth ] = $block_type;
3782  
3783 # Patch for CLASS BLOCK definitions: do not update the package for the
3784 # current depth if this is a BLOCK type definition.
3785 # TODO: should make 'class' separate from 'package' and only do
3786 # this for 'class'
3787 2084 ▶ $rbrace_package->[$brace_depth] = $current_package
Branch: 1 branch
BranchTrueFalseTotal
if substr($block_type, 0, 8) ne "package " 2074 10 2084
3788 if ( substr( $block_type, 0, 8 ) ne 'package ' );
3789  
3790 2084 $rbrace_structural_type->[$brace_depth] = $type;
3791 2084 $rbrace_context->[$brace_depth] = $context;
3792 2084 ( $type_sequence, $indent_flag ) =
3793 $self->increase_nesting_depth( BRACE, $rtoken_map->[$i_tok] );
3794  
3795 2084 return;
3796 } ## end sub do_LEFT_CURLY_BRACKET
3797  
3798 2084 ▶ sub do_RIGHT_CURLY_BRACKET {
Subroutine do_RIGHT_CURLY_BRACKET: called CC=11 SCAR=24.0
Pod undocumented
3799  
3800 2084 my $self = shift;
3801  
3802 # '}'
3803 2084 $block_type = $rbrace_type->[$brace_depth];
3804 2084 ▶ if ($block_type) { $statement_type = EMPTY_STRING }
Branch: 1 branch
BranchTrueFalseTotal
if ($block_type) 1159 925 2084
3805 2084 ▶ if ( defined( $rbrace_package->[$brace_depth] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rbrace_package->[$brace_depth]) { } 2074 10 2084
3806 2074 $current_package = $rbrace_package->[$brace_depth];
3807 }
3808 else {
3809 ## can happen on brace error (caught elsewhere)
3810 }
3811 2084 ( $type_sequence, $indent_flag ) =
3812 $self->decrease_nesting_depth( BRACE, $rtoken_map->[$i_tok] );
3813  
3814 2084 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) 954 1130 2084
3815 $self->error_if_expecting_TERM()
3816 if (
3817 954 ▶ !$self->[_rsaw_unknown_syntax_in_seqno_]->{$type_sequence}
Branch: 1 branch
BranchTrueFalseTotal
if not $self->[56]{$type_sequence} and $last_nonblank_type ne "%" 952 2 954
Condition66%2/3
not $self->[56]{$type_sequence} and $last_nonblank_type ne "%"
!ll&&!rl&&r
20952
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
3818  
3819 # c583: no error check at a possible end-of-macro combo '%}'
3820 && $last_nonblank_type ne '%'
3821 );
3822 }
3823  
3824 2084 ▶ if ( $rbrace_structural_type->[$brace_depth] eq 'L' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rbrace_structural_type->[$brace_depth] eq "L") 588 1496 2084
3825 588 $type = 'R';
3826 }
3827  
3828 # propagate type information for 'do' and 'eval' blocks, and also
3829 # for smartmatch operator. This is necessary to enable us to know
3830 # if an operator or term is expected next.
3831 2084 ▶ if ( $is_block_operator{$block_type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_block_operator{$block_type}) 88 1996 2084
3832 88 $tok = $block_type;
3833 }
3834  
3835 # pop non-indenting brace stack if sequence number matches
3836 2084 ▶ if ( @{ $self->[_rnon_indenting_brace_stack_] }
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->[53];} and $self->[53][-1] eq $type_sequence) 6 2078 2084
Condition100%3/3
@{$self->[53];} and $self->[53][-1] eq $type_sequence
!ll&&!rl&&r
207626
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
3837 && $self->[_rnon_indenting_brace_stack_]->[-1] eq $type_sequence )
3838 {
3839 6 pop @{ $self->[_rnon_indenting_brace_stack_] };
3840 }
3841  
3842 2084 $context = $rbrace_context->[$brace_depth];
3843 2084 ▶ if ( $brace_depth > 0 ) { $brace_depth--; }
Branch: 1 branch
BranchTrueFalseTotal
if ($brace_depth > 0) 2084 0 2084
3844 2084 return;
3845 } ## end sub do_RIGHT_CURLY_BRACKET
3846  
3847 126 ▶ sub do_AMPERSAND {
Subroutine do_AMPERSAND: called CC=4 SCAR=13.9
Pod undocumented
3848  
3849 126 my $self = shift;
3850  
3851 # '&' = maybe sub call? start looking
3852 # We have to check for sub call unless we are sure we
3853 # are expecting an operator. This example from s2p
3854 # got mistaken as a q operator in an early version:
3855 # print BODY &q(<<'EOT');
3856 126 ▶ if ( $expecting != OPERATOR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting != 1) { } 106 20 126
3857  
3858 # But only look for a sub call if we are expecting a term or
3859 # if there is no existing space after the &.
3860 # For example we probably don't want & as sub call here:
3861 # Fcntl::S_IRUSR & $mode;
3862 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
3863 103 $self->scan_simple_identifier();
3864 }
3865 }
3866 else {
3867 ## '&' is an operator
3868 }
3869 126 return;
3870 } ## end sub do_AMPERSAND
3871  
3872 33 ▶ sub do_LESS_THAN_SIGN {
Subroutine do_LESS_THAN_SIGN: called CC=2 SCAR=6.9
Pod undocumented
3873  
3874 33 my $self = shift;
3875  
3876 # '<' - angle operator or less than?
3877 33 ▶ if ( $expecting != OPERATOR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting != 1) { } 8 25 33
3878 8 ( $i, $type ) = $self->find_angle_operator_termination(
3879  
3880 $input_line,
3881 $i,
3882 $rtoken_map,
3883 $expecting,
3884 $max_token_index,
3885 );
3886 8 if ( DEBUG_GUESS_MODE && $expecting == UNKNOWN ) {
3887 my $msg = "guessing that '<' is ";
3888 $msg .=
3889 $type eq 'Q' ? "an angle operator" : "a less than symbol";
3890 if ( $type eq 'Q' ) {
3891 $self->warning("DEBUG_GUESS_MODE message:\n$msg\n");
3892 }
3893 }
3894 }
3895 else {
3896 ## ok: '<' is less than
3897 }
3898 33 return;
3899 } ## end sub do_LESS_THAN_SIGN
3900  
3901 193 ▶ sub do_QUESTION_MARK {
Subroutine do_QUESTION_MARK: called CC=7 SCAR=20.6
Pod undocumented
3902  
3903 193 my $self = shift;
3904  
3905 # '?' = conditional or starting pattern?
3906 193 my $is_pattern;
3907  
3908 # Patch for rt #126965
3909 # a pattern cannot follow certain keywords which take optional
3910 # arguments, like 'shift' and 'pop'. See also '/'.
3911 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
3912 $last_nonblank_type eq 'k'
3913 && $is_keyword_rejecting_question_as_pattern_delimiter{
3914 $last_nonblank_token}
3915 )
3916 {
3917 1 $is_pattern = 0;
3918 }
3919  
3920 # patch for RT#131288, user constant function without prototype
3921 # last type is 'U' followed by ?.
3922 elsif ( $last_nonblank_type =~ /^[FUY]$/ ) {
3923 1 $is_pattern = 0;
3924 }
3925 elsif ( $expecting == UNKNOWN ) {
3926  
3927 # In older versions of Perl, a bare ? can be a pattern
3928 # delimiter. In perl version 5.22 this was
3929 # dropped, but we have to support it in order to format
3930 # older programs. See:
3931 ## https://perl.developpez.com/documentations/en/5.22.0/perl5211delta.html
3932 # For example, the following line worked
3933 # at one time:
3934 # ?(.*)? && (print $1,"\n");
3935 # In current versions it would have to be written with slashes:
3936 # /(.*)/ && (print $1,"\n");
3937 (
3938 12 $is_pattern,
3939 my $msg,
3940  
3941 ) = $self->guess_if_pattern_or_conditional(
3942  
3943 $i,
3944 $rtokens,
3945 $rtoken_type,
3946 $rtoken_map,
3947 $max_token_index,
3948 );
3949  
3950 12 ▶ if ($msg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg) 12 0 12
3951 12 $self->write_logfile_entry($msg);
3952 12 if ( DEBUG_GUESS_MODE && $is_pattern ) {
3953 $self->warning("DEBUG_GUESS_MODE message:\n$msg\n");
3954 }
3955 }
3956 }
3957 else {
3958 179 $is_pattern = ( $expecting == TERM );
3959 }
3960  
3961 193 ▶ if ($is_pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_pattern) { } 0 193 193
3962 0 $in_quote = 1;
3963 0 $type = 'Q';
3964 0 $allowed_quote_modifiers = $quote_modifiers{'m'};
3965 0 $quote_starting_tok = 'm';
3966 0 $quote_here_target_2 = undef;
3967 }
3968 else {
3969 193 ( $type_sequence, $indent_flag ) =
3970 $self->increase_nesting_depth( QUESTION_COLON,
3971 $rtoken_map->[$i_tok] );
3972 }
3973 193 return;
3974 } ## end sub do_QUESTION_MARK
3975  
3976 254 ▶ sub do_STAR {
Subroutine do_STAR: called CC=8 SCAR=20.8
Pod undocumented
3977  
3978 254 my $self = shift;
3979  
3980 # '*' = typeglob, or multiply?
3981  
3982 # Guess based on next token. See also c036, and versions before 2026-
3983 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
3984  
3985 # Check for a normal glob, like *OUT:
3986 6 ▶ if ( $next_tok =~ /^[_A-Za-z]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_tok =~ /^[_A-Za-z]/) { } 0 6 6
3987 0 $expecting = TERM;
3988 }
3989 else {
3990 ## Could check for glob of a simple punctuation variable here
3991 ## by looking ahead one more character
3992 }
3993 }
3994  
3995 254 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) { } 21 233 254
3996 21 $self->scan_simple_identifier();
3997 }
3998 else {
3999  
4000 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
4001 2 $tok = '*=';
4002 2 $type = $tok;
4003 2 $i++;
4004 }
4005 elsif ( $rtokens->[ $i + 1 ] eq '*' ) {
4006 42 $tok = '**';
4007 42 $type = $tok;
4008 42 $i++;
4009 42 ▶ if ( $rtokens->[ $i + 1 ] eq '=' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$rtokens[$i + 1] eq "=") 2 40 42
4010 2 $tok = '**=';
4011 2 $type = $tok;
4012 2 $i++;
4013 }
4014 }
4015 else {
4016 ## not multiple characters
4017 }
4018 }
4019 254 return;
4020 } ## end sub do_STAR
4021  
4022 176 ▶ sub do_DOT {
Subroutine do_DOT: called CC=2 SCAR=6.9
Pod undocumented
4023  
4024 176 my $self = shift;
4025  
4026 # '.' = what kind of . ?
4027 176 ▶ if ( $expecting != OPERATOR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting != 1) 10 166 176
4028 10 $self->scan_number();
4029 }
4030 176 return;
4031 } ## end sub do_DOT
4032  
4033 285 ▶ sub do_COLON {
Subroutine do_COLON: called CC=13 SCAR=26.6
Pod undocumented
4034  
4035 285 my $self = shift;
4036  
4037 # ':' = label, ternary, attribute, ?
4038  
4039 # if this is the first nonblank character, call it a label
4040 # since perl seems to just swallow it
4041 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
4042 0 $type = 'J';
4043 }
4044  
4045 # ATTRS: check for a ':' which introduces an attribute list
4046 # either after a 'sub' keyword or within a paren list
4047 # Added 'package' (can be 'class') for --use-feature=class (rt145706)
4048 elsif ( $statement_type =~ /^(sub|package)\b/ ) {
4049 22 $type = 'A';
4050 22 $self->[_in_attribute_list_] = 1;
4051 }
4052  
4053 # Within a signature, unless we are in a ternary. For example,
4054 # from 't/filter_example.t':
4055 # method foo4 ( $class: $bar ) { $class->bar($bar) }
4056 ▶ 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
4057 && !is_balanced_closing_container(QUESTION_COLON) )
4058 {
4059 1 $type = 'A';
4060 1 $self->[_in_attribute_list_] = 1;
4061 }
4062  
4063 # check for scalar attribute, such as
4064 # my $foo : shared = 1;
4065 ▶ 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
4066 && $rcurrent_depth->[QUESTION_COLON] == 0 )
4067 {
4068 17 $type = 'A';
4069 17 $self->[_in_attribute_list_] = 1;
4070 }
4071  
4072 # Look for Switch::Plain syntax if an error would otherwise occur
4073 # here. Note that we do not need to check if the extended syntax
4074 # flag is set because otherwise an error would occur, and we would
4075 # then have to output a message telling the user to set the
4076 # extended syntax flag to avoid the error.
4077 # case 1: {
4078 # default: {
4079 # default:
4080 # Note that the line 'default:' will be parsed as a label elsewhere.
4081 ▶ 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
4082 && !is_balanced_closing_container(QUESTION_COLON) )
4083 {
4084 # mark it as a perltidy label type
4085 46 $type = 'J';
4086 }
4087  
4088 # mark colon as attribute if an error would occur otherwise; git #162
4089 elsif ( !$rcurrent_depth->[QUESTION_COLON] ) {
4090 6 $type = 'A';
4091 6 $self->[_in_attribute_list_] = 1;
4092  
4093 # and set a flag to skip error messages
4094 6 my $seqno = $self->[_rseqno_at_depth_]->[$total_depth];
4095 6 ▶ $self->[_rsaw_unknown_syntax_in_seqno_]->{$seqno} = 1 if ($seqno);
Branch: 1 branch
BranchTrueFalseTotal
if $seqno 6 0 6
4096 }
4097  
4098 # otherwise, it should be part of a ?/: operator
4099 else {
4100 193 ( $type_sequence, $indent_flag ) =
4101 $self->decrease_nesting_depth( QUESTION_COLON,
4102 $rtoken_map->[$i_tok] );
4103 193 ▶ if ( $last_nonblank_token eq '?' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_token eq "?") 0 193 193
4104 0 $self->warning("Syntax error near ? :\n");
4105 }
4106 }
4107 285 return;
4108 } ## end sub do_COLON
4109  
4110 240 ▶ sub do_PLUS_SIGN {
Subroutine do_PLUS_SIGN: called CC=6 SCAR=18.5
Pod undocumented
4111  
4112 240 my $self = shift;
4113  
4114 # '+' = what kind of plus?
4115 240 ▶ if ( $expecting == TERM ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($expecting == -1) { } 14 226 240
elsif ($expecting == 1) { } 224 2 226
4116 14 my $number = $self->scan_number_fast();
4117  
4118 # unary plus is safest assumption if not a number
4119 14 ▶ if ( !defined($number) ) { $type = 'p'; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $number) 14 0 14
4120 }
4121 elsif ( $expecting == OPERATOR ) {
4122 }
4123 else {
4124 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
4125 }
4126 240 return;
4127 } ## end sub do_PLUS_SIGN
4128  
4129 532 ▶ sub do_AT_SIGN {
Subroutine do_AT_SIGN: called CC=2 SCAR=7.0
Pod undocumented
4130  
4131 532 my $self = shift;
4132  
4133 # '@' = sigil for array?
4134 532 ▶ $self->error_if_expecting_OPERATOR("Array")
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 532 532
4135 if ( $expecting == OPERATOR );
4136 532 $self->scan_simple_identifier();
4137 532 return;
4138 } ## end sub do_AT_SIGN
4139  
4140 218 ▶ sub do_PERCENT_SIGN {
Subroutine do_PERCENT_SIGN: called CC=5 SCAR=20.9
Pod undocumented
4141  
4142 218 my $self = shift;
4143  
4144 # '%' = hash or modulo?
4145 # first guess is hash if no following blank or paren
4146 218 ▶ if ( $expecting == UNKNOWN ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == 0) 0 218 218
4147 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
4148 0 $expecting = TERM;
4149 }
4150 }
4151 218 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) 208 10 218
4152 208 $self->scan_simple_identifier();
4153 }
4154 218 return;
4155 } ## end sub do_PERCENT_SIGN
4156  
4157 817 ▶ sub do_LEFT_SQUARE_BRACKET {
Subroutine do_LEFT_SQUARE_BRACKET: called CC=2 SCAR=6.9
Pod undocumented
4158  
4159 817 my $self = shift;
4160  
4161 # '['
4162 817 $rsquare_bracket_type->[ ++$square_bracket_depth ] =
4163 $last_nonblank_token;
4164 817 ( $type_sequence, $indent_flag ) =
4165 $self->increase_nesting_depth( SQUARE_BRACKET,
4166 $rtoken_map->[$i_tok] );
4167  
4168 # It may seem odd, but structural square brackets have
4169 # type '{' and '}'. This simplifies the indentation logic.
4170 817 ▶ if ( !is_non_structural_brace() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_non_structural_brace()) 377 440 817
4171 377 $type = '{';
4172 }
4173 817 $rsquare_bracket_structural_type->[$square_bracket_depth] = $type;
4174 817 return;
4175 } ## end sub do_LEFT_SQUARE_BRACKET
4176  
4177 817 ▶ sub do_RIGHT_SQUARE_BRACKET {
Subroutine do_RIGHT_SQUARE_BRACKET: called CC=6 SCAR=18.0
Pod undocumented
4178  
4179 817 my $self = shift;
4180  
4181 # ']'
4182 817 ( $type_sequence, $indent_flag ) =
4183 $self->decrease_nesting_depth( SQUARE_BRACKET,
4184 $rtoken_map->[$i_tok] );
4185  
4186 817 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) 91 726 817
4187 $self->error_if_expecting_TERM()
4188 91 ▶ if ( !$self->[_rsaw_unknown_syntax_in_seqno_]->{$type_sequence} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->[56]{$type_sequence} 91 0 91
4189 }
4190  
4191 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
4192 {
4193 377 $type = '}';
4194 }
4195  
4196 # propagate type information for smartmatch operator. This is
4197 # necessary to enable us to know if an operator or term is expected
4198 # next.
4199 817 ▶ if ( $rsquare_bracket_type->[$square_bracket_depth] eq '~~' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rsquare_bracket_type->[$square_bracket_depth] eq "~~") 20 797 817
4200 20 $tok = $rsquare_bracket_type->[$square_bracket_depth];
4201 }
4202  
4203 817 ▶ if ( $square_bracket_depth > 0 ) { $square_bracket_depth--; }
Branch: 1 branch
BranchTrueFalseTotal
if ($square_bracket_depth > 0) 817 0 817
4204 817 return;
4205 } ## end sub do_RIGHT_SQUARE_BRACKET
4206  
4207 491 ▶ sub do_MINUS_SIGN {
Subroutine do_MINUS_SIGN: called CC=8 SCAR=20.9
Pod undocumented
4208  
4209 491 my $self = shift;
4210  
4211 # '-' = what kind of minus?
4212 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
4213 && $is_file_test_operator{$next_tok} )
4214 {
4215 12 my ( $next_nonblank_token, $i_next_uu ) =
4216 $self->find_next_nonblank_token( $i + 1, $rtokens,
4217 $max_token_index );
4218  
4219 # check for a quoted word like "-w=>xx";
4220 # it is sufficient to just check for a following '='
4221 12 ▶ if ( $next_nonblank_token eq '=' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq '=') { } 0 12 12
4222 0 $type = 'm';
4223 }
4224 else {
4225 12 $i++;
4226 12 $tok .= $next_tok;
4227 12 $type = 'F';
4228 }
4229 }
4230 elsif ( $expecting == TERM ) {
4231 378 my $number = $self->scan_number_fast();
4232  
4233 # maybe part of bareword token? unary is safest
4234 378 ▶ if ( !defined($number) ) { $type = 'm'; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $number) 288 90 378
4235  
4236 }
4237 elsif ( $expecting == OPERATOR ) {
4238 }
4239 else {
4240 4 ▶ if ( $next_type eq 'w' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_type eq "w") 4 0 4
4241 4 $type = 'm';
4242 }
4243 }
4244 491 return;
4245 } ## end sub do_MINUS_SIGN
4246  
4247 12 ▶ sub do_CARAT_SIGN {
Subroutine do_CARAT_SIGN: called CC=9 SCAR=25.4
Pod undocumented
4248  
4249 12 my $self = shift;
4250  
4251 # '^'
4252 # check for special variables like ${^WARNING_BITS}
4253 12 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) 5 7 12
4254  
4255 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
4256 && ( $next_tok !~ /^\d/ )
4257 && ( $next_tok =~ /^\w/ ) )
4258 {
4259  
4260 5 ▶ if ( $next_tok eq 'W' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_tok eq "W") 1 4 5
4261 1 $self->[_saw_perl_dash_w_] = 1;
4262 }
4263 5 $tok = $tok . $next_tok;
4264 5 $i = $i + 1;
4265 5 $type = 'w';
4266  
4267 # Optional coding to try to catch syntax errors. This can
4268 # be removed if it ever causes incorrect warning messages.
4269 # The '{^' should be preceded by either by a type or '$#'
4270 # Examples:
4271 # $#{^CAPTURE} ok
4272 # *${^LAST_FH}{NAME} ok
4273 # @{^HOWDY} ok
4274 # $hash{^HOWDY} error
4275  
4276 # Note that a type sigil '$' may be tokenized as 'Z'
4277 # after something like 'print', so allow type 'Z'
4278 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
4279 && $last_last_nonblank_type ne 'Z'
4280 && $last_last_nonblank_token ne '$#' )
4281 {
4282 0 $self->warning("Possible syntax error near '{^'\n");
4283 }
4284 }
4285 }
4286 12 return;
4287 } ## end sub do_CARAT_SIGN
4288  
4289 9 ▶ sub do_DOUBLE_COLON {
Subroutine do_DOUBLE_COLON: called CC=1 SCAR=0.0
Pod undocumented
4290  
4291 9 my $self = shift;
4292  
4293 # '::' = probably a sub call
4294 9 $self->scan_bare_identifier();
4295 9 return;
4296 } ## end sub do_DOUBLE_COLON
4297  
4298 31 ▶ sub do_LEFT_SHIFT {
Subroutine do_LEFT_SHIFT: called CC=9 SCAR=27.7
Pod undocumented
4299  
4300 31 my $self = shift;
4301  
4302 # '<<' = maybe a here-doc?
4303 31 ▶ if ( $expecting != OPERATOR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting != 1) { } 31 0 31
4304 my (
4305 31 $found_target,
4306 $here_doc_target,
4307 $here_quote_character,
4308 $i_return,
4309 $saw_error,
4310  
4311 ) = $self->find_here_doc(
4312  
4313 $expecting,
4314 $i,
4315 $rtokens,
4316 $rtoken_type,
4317 $rtoken_map,
4318 $max_token_index,
4319 );
4320 31 $i = $i_return;
4321  
4322 31 ▶ if ($found_target) {
Branch: 2 branches
BranchTrueFalseTotal
if ($found_target) { } 29 2 31
elsif ($expecting == -1) { } 0 2 2
4323 29 push @{$rhere_target_list},
4324 [ $here_doc_target, $here_quote_character ];
4325 29 $type = 'h';
4326 29 ▶ if ( length($here_doc_target) > 80 ) {
Branch: 3 branches
BranchTrueFalseTotal
if (length $here_doc_target > 80) { } 0 29 29
elsif (not $here_doc_target) { } 0 29 29
elsif (not $here_doc_target =~ /^[A-Z_]\w+$/) { } 8 21 29
4327 0 my $truncated = substr( $here_doc_target, 0, 80 );
4328 0 $self->complain("Long here-target: '$truncated' ...\n");
4329 }
4330 elsif ( !$here_doc_target ) {
4331 0 ▶ $self->warning(
Branch: 1 branch
BranchTrueFalseTotal
unless $here_quote_character 0 0 0
4332 'Use of bare << to mean <<"" is deprecated' . "\n" )
4333 if ( !$here_quote_character );
4334 }
4335 elsif ( $here_doc_target !~ /^[A-Z_]\w+$/ ) {
4336 8 $self->complain(
4337 "Unconventional here-target: '$here_doc_target'\n");
4338 }
4339 else {
4340 ## nothing to complain about
4341 }
4342 }
4343 elsif ( $expecting == TERM ) {
4344 0 ▶ if ( !$saw_error ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($saw_error) 0 0 0
4345  
4346 # shouldn't happen..arriving here implies an error in
4347 # the logic in sub 'find_here_doc'
4348 0 if (DEVEL_MODE) {
4349 Fault(<<EOM);
4350 Program bug; didn't find here doc target
4351 EOM
4352 }
4353 $self->warning(
4354 0 "Possible program error: didn't find here doc target\n"
4355 );
4356 0 $self->report_definite_bug();
4357 }
4358 }
4359  
4360 # target not found, expecting == UNKNOWN
4361 else {
4362 ## assume it is a shift
4363 }
4364 }
4365 else {
4366 ## '<<' is shift
4367 }
4368 31 return;
4369 } ## end sub do_LEFT_SHIFT
4370  
4371 14 ▶ sub do_NEW_HERE_DOC {
Subroutine do_NEW_HERE_DOC: called CC=8 SCAR=28.2
Pod undocumented
4372  
4373 # '<<~' = a here-doc, new type added in v26
4374  
4375 14 my $self = shift;
4376  
4377 return
4378 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
4379 14 ▶ if ( $expecting != OPERATOR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting != 1) { } 14 0 14
4380 my (
4381 14 $found_target,
4382 $here_doc_target,
4383 $here_quote_character,
4384 $i_return,
4385 $saw_error,
4386  
4387 ) = $self->find_here_doc(
4388  
4389 $expecting,
4390 $i,
4391 $rtokens,
4392 $rtoken_type,
4393 $rtoken_map,
4394 $max_token_index,
4395 );
4396 14 $i = $i_return;
4397  
4398 14 ▶ if ($found_target) {
Branch: 2 branches
BranchTrueFalseTotal
if ($found_target) { } 14 0 14
elsif ($expecting == -1) { } 0 0 0
4399  
4400 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
4401 0 my $truncated = substr( $here_doc_target, 0, 80 );
4402 0 $self->complain("Long here-target: '$truncated' ...\n");
4403 }
4404 elsif ( $here_doc_target !~ /^[A-Z_]\w+$/ ) {
4405 0 $self->complain(
4406 "Unconventional here-target: '$here_doc_target'\n");
4407 }
4408 else {
4409 ## nothing to complain about
4410 }
4411  
4412 # Note that we put a leading space on the here quote
4413 # character indicate that it may be preceded by spaces
4414 14 $here_quote_character = SPACE . $here_quote_character;
4415 14 push @{$rhere_target_list},
4416 [ $here_doc_target, $here_quote_character ];
4417 14 $type = 'h';
4418 }
4419  
4420 # target not found ..
4421 elsif ( $expecting == TERM ) {
4422 0 ▶ if ( !$saw_error ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($saw_error) 0 0 0
4423  
4424 # shouldn't happen..arriving here implies an error in
4425 # the logic in sub 'find_here_doc'
4426 0 if (DEVEL_MODE) {
4427 Fault(<<EOM);
4428 Program bug; didn't find here doc target
4429 EOM
4430 }
4431 $self->warning(
4432 0 "Possible program error: didn't find here doc target\n"
4433 );
4434 0 $self->report_definite_bug();
4435 }
4436 }
4437  
4438 # Target not found, expecting==UNKNOWN
4439 else {
4440 0 $self->warning("didn't find here doc target after '<<~'\n");
4441 }
4442 }
4443 else {
4444 0 $self->error_if_expecting_OPERATOR();
4445 }
4446 14 return;
4447 } ## end sub do_NEW_HERE_DOC
4448  
4449 1197 ▶ sub do_POINTER {
Subroutine do_POINTER: called CC=1 SCAR=0.0
Pod undocumented
4450  
4451 # '->'
4452 1197 return;
4453 }
4454  
4455 50 ▶ sub do_PLUS_PLUS {
Subroutine do_PLUS_PLUS: called CC=5 SCAR=16.6
Pod undocumented
4456  
4457 50 my $self = shift;
4458  
4459 # '++'
4460 # type = 'pp' for pre-increment, '++' for post-increment
4461 50 ▶ if ( $expecting == OPERATOR ) { $type = '++' }
Branch: 2 branches
BranchTrueFalseTotal
if ($expecting == 1) { } 41 9 50
elsif ($expecting == -1) { } 7 2 9
4462 7 elsif ( $expecting == TERM ) { $type = 'pp' }
4463  
4464 # handle ( $expecting == UNKNOWN )
4465 else {
4466  
4467 # look ahead ..
4468 2 my ( $next_nonblank_token, $i_next ) =
4469 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
4470  
4471 # Fix for c042: look past a side comment
4472 2 ▶ if ( $next_nonblank_token eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "#") 0 2 2
4473 0 ( $next_nonblank_token, $i_next ) =
4474 $self->find_next_nonblank_token( $max_token_index,
4475 $rtokens, $max_token_index );
4476 }
4477  
4478 0 ▶ if ( $next_nonblank_token eq '$' ) { $type = 'pp' }
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "\$") 0 2 2
4479 }
4480 50 return;
4481 } ## end sub do_PLUS_PLUS
4482  
4483 1117 ▶ sub do_FAT_COMMA {
Subroutine do_FAT_COMMA: called CC=3 SCAR=11.2
Pod undocumented
4484  
4485 1117 my $self = shift;
4486  
4487 # '=>'
4488 1117 ▶ if ( $last_nonblank_type eq $tok ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq $tok) 0 1117 1117
4489 0 $self->complain("Repeated '=>'s \n");
4490 }
4491  
4492 # patch for operator_expected: note if we are in the list (use.t)
4493 # TODO: make version numbers a new token type
4494 1117 ▶ if ( $statement_type eq 'use' ) { $statement_type = '_use' }
Branch: 1 branch
BranchTrueFalseTotal
if ($statement_type eq "use") 20 1097 1117
4495 1117 return;
4496 } ## end sub do_FAT_COMMA
4497  
4498 2 ▶ sub do_MINUS_MINUS {
Subroutine do_MINUS_MINUS: called CC=5 SCAR=25.2
Pod undocumented
4499  
4500 2 my $self = shift;
4501  
4502 # '--'
4503 # type = 'mm' for pre-decrement, '--' for post-decrement
4504  
4505 0 ▶ if ( $expecting == OPERATOR ) { $type = '--' }
Branch: 2 branches
BranchTrueFalseTotal
if ($expecting == 1) { } 0 2 2
elsif ($expecting == -1) { } 2 0 2
4506 2 elsif ( $expecting == TERM ) { $type = 'mm' }
4507  
4508 # handle ( $expecting == UNKNOWN )
4509 else {
4510  
4511 # look ahead ..
4512 0 my ( $next_nonblank_token, $i_next ) =
4513 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
4514  
4515 # Fix for c042: look past a side comment
4516 0 ▶ if ( $next_nonblank_token eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "#") 0 0 0
4517 0 ( $next_nonblank_token, $i_next ) =
4518 $self->find_next_nonblank_token( $max_token_index,
4519 $rtokens, $max_token_index );
4520 }
4521  
4522 0 ▶ if ( $next_nonblank_token eq '$' ) { $type = 'mm' }
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "\$") 0 0 0
4523 }
4524  
4525 2 return;
4526 } ## end sub do_MINUS_MINUS
4527  
4528 2521 ▶ sub do_DIGITS {
Subroutine do_DIGITS: called CC=3 SCAR=13.0
Pod undocumented
4529  
4530 2521 my $self = shift;
4531  
4532 # 'd' = string of digits
4533 2521 ▶ $self->error_if_expecting_OPERATOR("Number")
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 2521 2521
4534 if ( $expecting == OPERATOR );
4535  
4536 2521 my $number = $self->scan_number_fast();
4537 2521 ▶ if ( !defined($number) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $number) 0 2521 2521
4538  
4539 # shouldn't happen - we should always get a number
4540 0 if (DEVEL_MODE) {
4541 Fault(<<EOM);
4542 non-number beginning with digit--program bug
4543 EOM
4544 }
4545 $self->warning(
4546 0 "Unexpected error condition: non-number beginning with digit\n"
4547 );
4548 0 $self->report_definite_bug();
4549 }
4550 2521 return;
4551 } ## end sub do_DIGITS
4552  
4553 45 ▶ sub do_ATTRIBUTE_LIST {
Subroutine do_ATTRIBUTE_LIST: called CC=4 SCAR=13.9
Pod undocumented
4554  
4555 45 my ( $self, $next_nonblank_token ) = @_;
4556  
4557 # Called at a bareword encountered while in an attribute list
4558 # returns 'is_attribute':
4559 # true if attribute found
4560 # false if an attribute (continue parsing bareword)
4561  
4562 # treat bare word followed by open paren like qw(
4563 45 ▶ if ( $next_nonblank_token eq '(' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq '(') { } 20 25 45
4564  
4565 # For something like:
4566 # : prototype($$)
4567 # we should let do_scan_sub see it so that it can see
4568 # the prototype. All other attributes get parsed as a
4569 # quoted string.
4570 20 ▶ if ( $tok eq 'prototype' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "prototype") 2 18 20
4571 2 $id_scan_state = 'prototype';
4572  
4573 # start just after the word 'prototype'
4574 2 my $i_beg = $i + 1;
4575 2 ( $i, $tok, $type, $id_scan_state ) = $self->do_scan_sub(
4576 {
4577 input_line => $input_line,
4578 i => $i,
4579 i_beg => $i_beg,
4580 tok => $tok,
4581 type => $type,
4582 rtokens => $rtokens,
4583 rtoken_map => $rtoken_map,
4584 id_scan_state => $id_scan_state,
4585 max_token_index => $max_token_index,
4586 }
4587 );
4588  
4589 # If successful, mark as type 'q' to be consistent
4590 # with other attributes. Type 'w' would also work.
4591 2 ▶ if ( $i > $i_beg ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > $i_beg) 2 0 2
4592 2 $type = 'q';
4593 2 return 1;
4594 }
4595  
4596 # If not successful, continue and parse as a quote.
4597 }
4598  
4599 # All other attribute lists must be parsed as quotes
4600 # (see 'signatures.t' for good examples)
4601 18 $in_quote = $quote_items{'q'};
4602 18 $allowed_quote_modifiers = $quote_modifiers{'q'};
4603 18 $quote_starting_tok = 'q';
4604 18 $type = 'q';
4605 18 $quote_type = 'q';
4606 18 $quote_here_target_2 = undef;
4607 18 return 1;
4608 }
4609  
4610 # handle bareword not followed by open paren
4611 else {
4612 25 $type = 'w';
4613 25 return 1;
4614 }
4615  
4616 # attribute not found
4617 0 return;
4618 } ## end sub do_ATTRIBUTE_LIST
4619  
4620 17 ▶ sub do_X_OPERATOR {
Subroutine do_X_OPERATOR: called CC=4 SCAR=14.7
Pod undocumented
4621  
4622 17 my $self = shift;
4623  
4624 # We are at a pretoken starting with 'x' where an operator is expected
4625  
4626 17 ▶ if ( $tok eq 'x' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq 'x') { } 15 2 17
4627 15 ▶ if ( $rtokens->[ $i + 1 ] eq '=' ) { # x=
Branch: 1 branch
BranchTrueFalseTotal
if ($$rtokens[$i + 1] eq '=') { } 0 15 15
4628 0 $tok = 'x=';
4629 0 $type = $tok;
4630 0 $i++;
4631 }
4632 else {
4633 15 $type = 'x';
4634 }
4635 }
4636 else {
4637  
4638 # Split a pretoken like 'x10' into 'x' and '10'.
4639 # Note: In previous versions of perltidy it was marked
4640 # as a number, $type = 'n', and fixed downstream by the
4641 # Formatter.
4642 2 $type = 'n';
4643 2 ▶ if ( $self->split_pretoken(1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->split_pretoken(1)) 2 0 2
4644 2 $type = 'x';
4645 2 $tok = 'x';
4646 }
4647 }
4648 17 return;
4649 } ## end sub do_X_OPERATOR
4650  
4651 18 ▶ sub do_USE_CONSTANT {
Subroutine do_USE_CONSTANT: called CC=3 SCAR=11.0
Pod undocumented
4652  
4653 18 my $self = shift;
4654  
4655 # We just saw 'use constant' and must look ahead
4656  
4657 18 $self->scan_bare_identifier();
4658 18 my ( $next_nonblank_tok2, $i_next2_uu ) =
4659 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
4660  
4661 18 ▶ if ($next_nonblank_tok2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_tok2) 18 0 18
4662  
4663 18 ▶ if ( $is_keyword{$next_nonblank_tok2} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_keyword{$next_nonblank_tok2}) { } 1 17 18
4664  
4665 # One example of where a keyword could follow is 'qw' here:
4666 # use constant qw{ DEBUG 0 };
4667 # But otherwise, using a keyword here is probably not a good
4668 # idea. But perl does not complain, so we will not.
4669 }
4670  
4671 else {
4672 17 $ris_constant->{$current_package}->{$next_nonblank_tok2} = 1;
4673 }
4674 }
4675 18 return;
4676 } ## end sub do_USE_CONSTANT
4677  
4678 3142 ▶ sub do_KEYWORD {
Subroutine do_KEYWORD: called CC=23 SCAR=34.8
Pod undocumented
4679  
4680 3142 my $self = shift;
4681  
4682 # found a keyword - set any associated flags
4683 3142 $type = 'k';
4684  
4685 # Since for and foreach may not be followed immediately
4686 # by an opening paren, we have to remember which keyword
4687 # is associated with the next '('
4688 # Previously, before update c230 : if ( $is_for_foreach{$tok} ) {
4689 ##(if elsif unless while until for foreach switch case given when catch)
4690 3142 ▶ if ( $is_blocktype_with_paren{$tok} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_blocktype_with_paren{$tok}) 501 2641 3142
4691  
4692 # Set $want_paren to help catch missing semicolon errors.
4693 # Bias the result in favor of the block form of the keyword.
4694 # That is, if (!$want_paren) then we really do not expect a block,
4695 # and we can be confident that a warning should be given.
4696 # See issue git124, and update c635.
4697 501 ▶ $want_paren =
Branch: 1 branch
BranchTrueFalseTotal
$expecting == 1 ? : 103 398 501
4698 ( $expecting == OPERATOR )
4699 ? EMPTY_STRING
4700 : $tok;
4701 }
4702  
4703 # Catch unexpected keywords (c517, c613).
4704 3142 ▶ if ( $expecting == TERM ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($expecting == -1) { } 2771 371 3142
elsif ($expecting == 1) { } 337 34 371
4705 $self->error_if_expecting_TERM()
4706 2771 ▶ if ( $is_OPERATOR_keyword{$tok} );
Branch: 1 branch
BranchTrueFalseTotal
if $is_OPERATOR_keyword{$tok} 0 2771 2771
4707 }
4708 elsif ( $expecting == OPERATOR ) {
4709 $self->error_if_expecting_OPERATOR()
4710 337 ▶ if ( $is_TERM_keyword{$tok} );
Branch: 1 branch
BranchTrueFalseTotal
if $is_TERM_keyword{$tok} 0 337 337
4711 }
4712 else {
4713 ## expecting == UNKNOWN
4714 }
4715  
4716 # recognize 'use' statements, which are special
4717 3142 ▶ if ( $is_use_require{$tok} ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($is_use_require{$tok}) { } 180 2962 3142
elsif ($is_my_our_state{$tok}) { } 773 2189 2962
elsif ($tok eq 'elsif') { } 35 2154 2189
elsif ($tok eq 'else') { } 53 2101 2154
elsif ($tok eq 'when' or $tok eq 'case' or $tok eq 'default') { } 70 2031 2101
elsif ($tok eq 'err') { } 1 2030 2031
4718 180 $statement_type = $tok;
4719 }
4720  
4721 # remember my and our to check for trailing ": shared"
4722 elsif ( $is_my_our_state{$tok} ) {
4723 773 $statement_type = $tok;
4724 }
4725  
4726 # Check for unexpected 'elsif'
4727 elsif ( $tok eq 'elsif' ) {
4728 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
4729  
4730 !$is_if_elsif_unless{$last_nonblank_block_type}
4731  
4732 # Allow isolated blocks of any kind during editing
4733 # by checking for a last noblank token of ';' and no
4734 # sequence numbers having been issued (c272). The check
4735 # on sequence number is not perfect but good enough.
4736 && !(
4737 $last_nonblank_token eq ';'
4738 && $next_sequence_number == SEQ_ROOT + 1
4739 )
4740  
4741 )
4742 {
4743 ## prevent formatting and avoid instability (b1553)
4744 0 $self->warning_do_not_format(
4745 "expecting '$tok' to follow one of 'if|elsif|unless'\n");
4746 }
4747 }
4748  
4749 # Check for unexpected 'else'
4750 elsif ( $tok eq 'else' ) {
4751  
4752 # patched for SWITCH/CASE
4753 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
4754  
4755 !$is_if_elsif_unless_case_when{$last_nonblank_block_type}
4756  
4757 # patch to avoid an unwanted error message for
4758 # the case of a parenless 'case' (RT 105484):
4759 # switch ( 1 ) { case x { 2 } else { } }
4760 && !$is_if_elsif_unless_case_when{$statement_type}
4761  
4762 # Allow isolated blocks of any kind during editing (c272)
4763 && !(
4764 $last_nonblank_token eq ';'
4765 && $next_sequence_number == SEQ_ROOT + 1
4766 )
4767  
4768 )
4769 {
4770 ## prevent formatting and avoid instability (b1553)
4771 0 $self->warning_do_not_format(
4772 "expecting '$tok' to follow one of 'if|elsif|unless|case|when'\n"
4773 );
4774 }
4775 }
4776  
4777 # patch for SWITCH/CASE if 'case' and 'when are
4778 # treated as keywords. Also 'default' for Switch::Plain
4779 ▶ elsif ($tok eq 'when'
Condition100%6/6
$tok eq "when" or $tok eq "case" or $tok eq "default"
l!l&&r!l&&!r
6822031
$tok eq "when" or $tok eq "case"
l!l&&r!l&&!r
4642033
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
4780 || $tok eq 'case'
4781 || $tok eq 'default' )
4782 {
4783 70 $statement_type = $tok; # next '{' is block
4784 }
4785  
4786 # feature 'err' was removed in Perl 5.10. So mark this as
4787 # a bareword unless an operator is expected (see c158).
4788 elsif ( $tok eq 'err' ) {
4789 1 ▶ if ( $expecting != OPERATOR ) { $type = 'w' }
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting != 1) 1 0 1
4790 }
4791 else {
4792 ## no special treatment needed
4793 }
4794  
4795 3142 return;
4796 } ## end sub do_KEYWORD
4797  
4798 237 ▶ sub do_QUOTE_OPERATOR {
Subroutine do_QUOTE_OPERATOR: called CC=7 SCAR=25.2
Pod undocumented
4799  
4800 237 my $self = shift;
4801  
4802 # We have arrived at a quote operator: q, qq, qw, qx, qr, s, y, tr, m
4803  
4804 237 ▶ if ( $expecting == OPERATOR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == 1) 0 237 237
4805  
4806 # Be careful not to call an error for a qw quote
4807 # where a parenthesized list is allowed. For example,
4808 # it could also be a for/foreach construct such as
4809 #
4810 # foreach my $key qw\Uno Due Tres Quadro\ {
4811 # print "Set $key\n";
4812 # }
4813 #
4814  
4815 # Or it could be a function call.
4816 # NOTE: Braces in something like &{ xxx } are not
4817 # marked as a block, we might have a method call.
4818 # &method(...), $method->(..), &{method}(...),
4819 # $ref[2](list) is ok & short for $ref[2]->(list)
4820 #
4821 # See notes in 'sub code_block_type' and
4822 # 'sub is_non_structural_brace'
4823  
4824 my $paren_list_possible = $tok eq 'qw'
4825 && ( $last_nonblank_token =~ /^([\]\}\&]|\-\>)/
4826 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
4827  
4828 0 ▶ if ( !$paren_list_possible ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($paren_list_possible) 0 0 0
4829 0 $self->error_if_expecting_OPERATOR();
4830 }
4831 }
4832 237 $in_quote = $quote_items{$tok};
4833 237 $allowed_quote_modifiers = $quote_modifiers{$tok};
4834 237 $quote_starting_tok = $tok;
4835 237 $quote_here_target_2 = undef;
4836  
4837 # All quote types are 'Q' except possibly qw quotes.
4838 # qw quotes are special in that they may generally be trimmed
4839 # of leading and trailing whitespace. So they are given a
4840 # separate type, 'q', unless requested otherwise.
4841 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
4842 ( $tok eq 'qw' && $rOpts_trim_qw )
4843 ? 'q'
4844 : 'Q';
4845 237 $quote_type = $type;
4846 237 return;
4847 } ## end sub do_QUOTE_OPERATOR
4848  
4849 1036 ▶ sub do_UNKNOWN_BAREWORD {
Subroutine do_UNKNOWN_BAREWORD: called CC=27 SCAR=45.8
Pod undocumented
4850  
4851 1036 my ( $self, $next_nonblank_token ) = @_;
4852  
4853 # We have encountered a bareword which needs more work to classify
4854  
4855 1036 $self->scan_bare_identifier();
4856  
4857 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
4858 && $last_nonblank_token eq 'use' )
4859 {
4860 111 $rsaw_use_module->{$current_package}->{$tok} = 1;
4861 }
4862  
4863 1036 ▶ if ( $type eq 'w' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "w") 1009 27 1036
4864  
4865 1009 ▶ if ( $expecting == OPERATOR ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == 1) 2 1007 1009
4866  
4867 # Patch to avoid error message for RPerl overloaded
4868 # operator functions: use overload
4869 # '+' => \&sse_add,
4870 # '-' => \&sse_sub,
4871 # '*' => \&sse_mul,
4872 # '/' => \&sse_div;
4873 # TODO: this could eventually be generalized
4874 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
4875 && $tok =~ /^sse_(mul|div|add|sub)$/ )
4876 {
4877  
4878 }
4879  
4880 # patch for Syntax::Operator::In, git #162
4881 ▶ 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
4882  
4883 }
4884  
4885 # Fix part 1 for git #63 in which a comment falls
4886 # between an -> and the following word. An
4887 # alternate fix would be to change operator_expected
4888 # to return an UNKNOWN for this type.
4889 elsif ( $last_nonblank_type eq '->' ) {
4890  
4891 }
4892  
4893 # don't complain about possible indirect object
4894 # notation.
4895 # For example:
4896 # package main;
4897 # sub new($) { ... }
4898 # $b = new A::; # calls A::new
4899 # $c = new A; # same thing but suspicious
4900 # This will call A::new but we have a 'new' in
4901 # main:: which looks like a constant.
4902 #
4903 elsif ( $last_nonblank_type eq 'C' ) {
4904 0 ▶ if ( $tok !~ /::$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tok =~ /::$/) 0 0 0
4905 0 $self->complain(<<EOM);
4906 Expecting operator after '$last_nonblank_token' but found bare word '$tok'
4907 Maybe indirect object notation?
4908 EOM
4909 }
4910 }
4911 else {
4912 0 $self->error_if_expecting_OPERATOR("bareword");
4913 }
4914 }
4915  
4916 # mark bare words immediately followed by a paren as
4917 # functions
4918 1009 $next_tok = $rtokens->[ $i + 1 ];
4919 1009 ▶ if ( $next_tok eq '(' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_tok eq "(") 298 711 1009
4920  
4921 # Patch for issue c151, where we are processing a snippet and
4922 # have not seen that SPACE is a constant. In this case 'x' is
4923 # probably an operator. The only disadvantage with an incorrect
4924 # guess is that the space after it may be incorrect. For example
4925 # $str .= SPACE x ( 16 - length($str) ); See also b1410.
4926 0 ▶ 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
4927  
4928 # Fix part 2 for git #63. Leave type as 'w' to keep
4929 # the type the same as if the -> were not separated
4930 298 elsif ( $last_nonblank_type ne '->' ) { $type = 'U' }
4931  
4932 # not a special case
4933 else { }
4934  
4935 }
4936  
4937 # underscore after file test operator is file handle
4938 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
4939 0 $type = 'Z';
4940 }
4941  
4942 # patch for SWITCH/CASE if 'case' and 'when are
4943 # not treated as keywords:
4944 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 table14%1/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
4945 ( $tok eq 'case' && $rbrace_type->[$brace_depth] eq 'switch' )
4946 || ( $tok eq 'when'
4947 && $rbrace_type->[$brace_depth] eq 'given' )
4948 )
4949 {
4950 0 $statement_type = $tok; # next '{' is block
4951 0 $type = 'k'; # for keyword syntax coloring
4952 }
4953 1009 ▶ if ( $next_nonblank_token eq '(' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "(") 263 746 1009
4954  
4955 # patch for SWITCH/CASE if switch and given not keywords
4956 # Switch is not a perl 5 keyword, but we will gamble
4957 # and mark switch followed by paren as a keyword. This
4958 # is only necessary to get html syntax coloring nice,
4959 # and does not commit this as being a switch/case.
4960 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
4961 0 $type = 'k'; # for keyword syntax coloring
4962 }
4963  
4964 # mark 'x' as operator for something like this (see b1410)
4965 # my $line = join( LD_X, map { LD_H x ( $_ + 2 ) } @$widths );
4966 ▶ 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
4967 0 $type = 'x';
4968 }
4969 else {
4970 ## not a special case
4971 }
4972 }
4973 }
4974 1036 return;
4975 } ## end sub do_UNKNOWN_BAREWORD
4976  
4977 37 ▶ sub sub_attribute_ok_here {
Subroutine sub_attribute_ok_here: called CC=6 SCAR=18.4
Pod undocumented
4978  
4979 37 my ( $self, $tok_kw, $next_nonblank_token, $i_next ) = @_;
4980  
4981 # Decide if a ':' can introduce an attribute. For example,
4982 # something like 'sub :'
4983  
4984 # Given:
4985 # $tok_kw = a bareword token
4986 # $next_nonblank_token = a following ':' being examined
4987 # $i_next = the index of the following ':'
4988  
4989 # We will decide based on if the colon is followed by a bareword
4990 # which is not a keyword. Changed inext+1 to inext to fixed case
4991 # b1190.
4992 37 my $sub_attribute_ok_here;
4993 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
4994 && $expecting != OPERATOR
4995 && $next_nonblank_token eq ':' )
4996 {
4997 3 my ( $nn_nonblank_token, $i_nn_uu ) =
4998 $self->find_next_nonblank_token( $i_next, $rtokens,
4999 $max_token_index );
5000 $sub_attribute_ok_here =
5001 $nn_nonblank_token =~ /^\w/
5002 && $nn_nonblank_token !~ /^\d/
5003 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
5004 }
5005 37 return $sub_attribute_ok_here;
5006 } ## end sub sub_attribute_ok_here
5007  
5008 45 ▶ use constant DEBUG_BAREWORD => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5009  
5010 961 ▶ sub saw_bareword_function {
Subroutine saw_bareword_function: called CC=1 SCAR=0.0
Pod undocumented
5011 961 my ( $self, $bareword ) = @_;
5012 $self->[_rbareword_info_]->{$current_package}->{$bareword}
5013 961 ->{function_count}++;
5014 961 return;
5015 } ## end sub saw_bareword_function
5016  
5017 182 ▶ sub saw_bareword_constant {
Subroutine saw_bareword_constant: called CC=1 SCAR=0.0
Pod undocumented
5018 182 my ( $self, $bareword ) = @_;
5019 $self->[_rbareword_info_]->{$current_package}->{$bareword}
5020 182 ->{constant_count}++;
5021 182 return;
5022 } ## end sub saw_bareword_constant
5023  
5024 0 ▶ sub get_bareword_counts {
Subroutine get_bareword_counts: not called CC=6 SCAR=37.4
Pod undocumented
5025 0 my ( $self, $bareword ) = @_;
5026  
5027 # Given:
5028 # $bareword = a bareword
5029 # Return:
5030 # $function_count = number of times seen as function taking >0 args
5031 # $constant_count = number of times seen as function taking 0 args
5032 # Note:
5033 # $function_count > 0 implies that a TERM should come next
5034 # $constant_count > 0 implies that an OPERATOR **may** come next,
5035 # but this can be incorrect if $bareword can take 0 or more args.
5036 # This is used to help guess tokenization around unknown barewords.
5037 0 my $function_count;
5038 my $constant_count;
5039 0 my $rbareword_info_tok = $self->[_rbareword_info_]->{$current_package};
5040 0 ▶ if ($rbareword_info_tok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rbareword_info_tok) 0 0 0
5041 0 $rbareword_info_tok = $rbareword_info_tok->{$bareword};
5042 0 ▶ if ($rbareword_info_tok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rbareword_info_tok) 0 0 0
5043 0 $function_count = $rbareword_info_tok->{function_count};
5044 0 $constant_count = $rbareword_info_tok->{constant_count};
5045  
5046 # a positive function count overrides a constant count
5047 0 ▶ if ($function_count) { $constant_count = 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($function_count) 0 0 0
5048 }
5049 }
5050 0 ▶ if ( !defined($function_count) ) { $function_count = 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $function_count) 0 0 0
5051 0 ▶ if ( !defined($constant_count) ) { $constant_count = 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $constant_count) 0 0 0
5052 0 return ( $function_count, $constant_count );
5053 } ## end sub get_bareword_counts
5054  
5055 # hashes used to help determine a bareword type
5056 45 my %is_wiUC;
5057 45 my %is_function_follower;
5058 45 my %is_constant_follower;
5059 45 my %is_use_require_no;
5060  
5061 45 ▶ BEGIN {
Subroutine BEGIN: called CC=5 SCAR=16.1
5062 45 my @qz = qw( w i U C );
5063 45 $is_wiUC{$_} = 1 for @qz;
5064  
5065 45 @qz = qw( use require no );
5066 45 $is_use_require_no{$_} = 1 for @qz;
5067  
5068 # These pre-token types after a bareword imply that it
5069 # is not a constant, except when '(' is followed by ')'.
5070 45 @qz = qw# ( [ { $ @ " ' m #;
5071 45 $is_function_follower{$_} = 1 for @qz;
5072  
5073 # These pre-token types after a bareword imply that it
5074 # MIGHT be a constant, but it also might be a function taking
5075 # 0 or more call args.
5076 45 @qz = qw# ; ) ] } if unless #;
5077 45 push @qz, COMMA;
5078 45 $is_constant_follower{$_} = 1 for @qz;
5079 }
5080  
5081 6747 ▶ sub do_BAREWORD {
Subroutine do_BAREWORD: called CC=106 SCAR=54.2
Pod undocumented
5082  
5083 6747 my ($self) = @_;
5084  
5085 # handle a bareword token:
5086 # returns
5087 # true if this token ends the current line
5088 # false otherwise
5089  
5090 6747 my $next_nonblank_token;
5091 6747 my $i_next = $i + 1;
5092 6747 ▶ 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") 4113 2634 6747
Condition100%3/3
$i_next <= $max_token_index and $rtoken_type->[$i_next] eq "b"
!ll&&!rl&&r
7825564113
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
5093 4113 $i_next++;
5094 }
5095 6747 ▶ if ( $i_next <= $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_next <= $max_token_index) { } 6663 84 6747
5096 6663 $next_nonblank_token = $rtokens->[$i_next];
5097 }
5098 else {
5099 84 ( $next_nonblank_token, $i_next ) =
5100 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
5101 }
5102  
5103 # Fix for git #182: If --use-feature=class is set, then
5104 # a colon between words 'ADJUST' and 'params', and on the same line,
5105 # does not form the label 'ADJUST:'. It will get marked as type 'A'.
5106 6747 my $is_not_label;
5107 6747 ▶ 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 6745 6747
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
674502
$tok eq "ADJUST" and $is_code_block_token{$tok} and $rtokens->[$i_next] eq ":"
!ll&&!rl&&r
674412
$tok eq "ADJUST" and $is_code_block_token{$tok}
!ll&&!rl&&r
674403
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
5108 && $is_code_block_token{$tok}
5109 && $rtokens->[$i_next] eq ':'
5110 && $i_next < $max_token_index )
5111 {
5112 2 ▶ my $i_next2 =
Branch: 1 branch
BranchTrueFalseTotal
$$rtoken_type[$i_next + 1] eq 'b' ? : 0 2 2
5113 $rtoken_type->[ $i_next + 1 ] eq 'b' ? $i_next + 2 : $i_next + 1;
5114 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
5115 ( $i_next2 <= $max_token_index
5116 && $rtoken_type->[$i_next2] eq 'w'
5117 && $rtokens->[$i_next2] eq 'params' );
5118 }
5119  
5120 # a bare word immediately followed by :: is not a keyword;
5121 # use $tok_kw when testing for keywords to avoid a mistake
5122 6747 my $tok_kw = $tok;
5123 6747 ▶ if ( $rtokens->[ $i + 1 ] eq ':'
Branch: 1 branch
BranchTrueFalseTotal
if ($$rtokens[$i + 1] eq ":" and $$rtokens[$i + 2] eq ":") 272 6475 6747
Condition100%3/3
$$rtokens[$i + 1] eq ":" and $$rtokens[$i + 2] eq ":"
!ll&&!rl&&r
644233272
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
5124 && $rtokens->[ $i + 2 ] eq ':' )
5125 {
5126 272 $tok_kw .= '::';
5127 }
5128  
5129 6747 ▶ if ( $self->[_in_attribute_list_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[15]) 45 6702 6747
5130 45 my $is_attribute = $self->do_ATTRIBUTE_LIST($next_nonblank_token);
5131 45 ▶ return if ($is_attribute);
Branch: 1 branch
BranchTrueFalseTotal
if $is_attribute 45 0 45
5132 }
5133  
5134 #-----------------------------------------
5135 # Preliminary check for a lexical sub name
5136 #-----------------------------------------
5137 6702 my $is_lexical_sub_type;
5138  
5139 # Has this name been seen as a lexical sub?
5140 6702 ▶ if ( my $rseqno_hash = $ris_lexical_sub->{$tok_kw} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rseqno_hash = $ris_lexical_sub->{$tok_kw}) 0 6702 6702
5141  
5142 # Look back up the stack to see if it is still in scope.
5143 # Use the deepest we find if there are multiple versions.
5144 0 my @seqno_tested;
5145 0 my $cd_aa = $rcurrent_depth->[BRACE];
5146 0 foreach my $cd ( reverse( 0 .. $cd_aa ) ) {
5147 0 ▶ my $p_seqno =
Branch: 1 branch
BranchTrueFalseTotal
$cd ? : 0 0 0
5148 $cd
5149 ? $rcurrent_sequence_number->[BRACE]->[$cd]
5150 : SEQ_ROOT;
5151  
5152 0 push @seqno_tested, $p_seqno;
5153  
5154 # Lexical subs use their containing sequence number as package
5155 0 ▶ if ( my $seqno_brace = $rseqno_hash->{$p_seqno} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $seqno_brace = $rseqno_hash->{$p_seqno}) 0 0 0
5156  
5157 # This sub is in scope .. lookup its type
5158 $is_lexical_sub_type =
5159 $ris_constant->{$p_seqno}->{$tok_kw} ? 'C'
5160 : $ris_block_function->{$p_seqno}->{$tok_kw} ? 'G'
5161 : $ris_block_list_function->{$p_seqno}->{$tok_kw} ? 'G'
5162 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
5163 : 'U';
5164  
5165 # But lexical subs do not apply within their defining code
5166 0 foreach (@seqno_tested) {
5167 0 ▶ next if ( $_ != $seqno_brace );
Branch: 1 branch
BranchTrueFalseTotal
if $_ != $seqno_brace 0 0 0
5168 0 $is_lexical_sub_type = undef;
5169 0 last;
5170 }
5171  
5172 0 last;
5173 }
5174 }
5175 }
5176  
5177 #----------------------------------------
5178 # Starting final if-elsif- chain of tests
5179 #----------------------------------------
5180  
5181 # This is the return flag:
5182 # true => this is the last token on the line
5183 # false => keep tokenizing the line
5184 6702 my $is_last;
5185  
5186 # The following blocks of code must update these vars:
5187 # $type - the final token type, must always be set
5188  
5189 # In addition, if additional pretokens are added:
5190 # $tok - the final token
5191 # $i - the index of the last pretoken
5192  
5193 # They may also need to check and set various flags
5194  
5195 # Scan a bare word following a -> as an identifier; it could
5196 # have a long package name. Fixes c037, c041.
5197 6702 ▶ if ( $last_nonblank_token eq '->' ) {
Branch: 19 branches
BranchTrueFalseTotal
if ($last_nonblank_token eq '->') { } 786 5916 6702
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 5090 5916
elsif ($next_nonblank_token eq '}' and $last_nonblank_type eq 'L' || $last_nonblank_type eq 'm' && $last_last_nonblank_type eq 'L') { } 138 4952 5090
elsif ($expecting == 1 and substr($tok, 0, 1) eq 'x' and length $tok == 1 || substr($tok, 1, 1) =~ /^\d/) { } 17 4935 4952
elsif ($tok_kw eq 'CORE::') { } 3 4932 4935
elsif ($tok eq 'strict' and $last_nonblank_token eq 'use') { } 14 4918 4932
elsif ($tok eq 'warnings' and $last_nonblank_token eq 'use') { } 7 4911 4918
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 4911 4911
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 4911 4911
elsif ($tok eq 'constant' and $last_nonblank_token eq 'use') { } 18 4893 4911
elsif ($is_lexical_sub_type) { } 0 4893 4893
elsif ($is_q_qq_qw_qx_qr_s_y_tr_m{$tok}) { } 237 4656 4893
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 4623 4656
elsif ($is_sub{$tok_kw}) { } 374 4249 4623
elsif ($is_package{$tok_kw}) { } 54 4195 4249
elsif ($tok_kw eq 'format' and new_statement_ok()) { } 1 4194 4195
elsif (defined $is_END_DATA{$tok_kw}) { } 8 4186 4194
elsif ($is_keyword{$tok_kw}) { } 3142 1044 4186
elsif ($last_nonblank_type eq 'k' and $is_redo_last_next_goto{$last_nonblank_token}) { } 19 1025 1044
5198 786 $self->scan_bare_identifier();
5199  
5200 # a bareward after '->' gets type 'i'
5201 786 $type = 'i';
5202 }
5203  
5204 # Quote a word followed by => operator
5205 ▶ 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
50891826
$next_nonblank_token eq "=" and $$rtokens[$i_next + 1] eq ">"
!ll&&!rl&&r
507811827
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
5206 ( $next_nonblank_token eq '=' && $rtokens->[ $i_next + 1 ] eq '>' )
5207  
5208 # unless the word is __END__ or __DATA__ and is the only word on
5209 # the line.
5210 && ( !defined( $is_END_DATA{$tok_kw} )
5211 || $input_line !~ /^\s*__(?:END|DATA)__\s*$/ )
5212 )
5213 {
5214 # Bareword followed by a fat comma - see 'git18.in'
5215 # This code was previously sub do_QUOTED_BAREWORD: see c316, c317
5216  
5217 # Note: in some older perl versions these would produce an error:
5218 # 'v25=>1' # is a v-string key!
5219 # '-v25=>1' # is also a v-string key!
5220 # This is no longer true; see git #165
5221  
5222 # If tok is something like 'x17' then it could
5223 # actually be operator x followed by number 17.
5224 # For example, here:
5225 # 123x17 => [ 792, 1224 ],
5226 # (a key of 123 repeated 17 times, perhaps not
5227 # what was intended). We will mark x17 as type
5228 # 'n' and it will be split. If the previous token
5229 # was also a bareword then it is not very clear is
5230 # going on. In this case we will not be sure that
5231 # an operator is expected, so we just mark it as a
5232 # bareword. Perl is a little murky in what it does
5233 # with stuff like this, and its behavior can change
5234 # over time. Something like
5235 # a x18 => [792, 1224], will compile as
5236 # a key with 18 a's. But something like
5237 # push @array, a x18;
5238 # is a syntax error.
5239 826 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == 1 and substr($tok, 0, 1) eq 'x' and length $tok == 1 || substr($tok, 1, 1) =~ /^\d/) { } 3 823 826
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
5240 $expecting == OPERATOR
5241 && substr( $tok, 0, 1 ) eq 'x'
5242 && ( length($tok) == 1
5243 || substr( $tok, 1, 1 ) =~ /^\d/ )
5244 )
5245 {
5246 3 $type = 'n';
5247 3 ▶ if ( $self->split_pretoken(1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->split_pretoken(1)) 3 0 3
5248 3 $type = 'x';
5249 3 $tok = 'x';
5250 }
5251 3 $self->complain("x operator in hash key\n");
5252 }
5253 else {
5254  
5255 # git #18
5256 823 $type = 'w';
5257 823 $self->error_if_expecting_OPERATOR();
5258 }
5259 }
5260  
5261 # quote a bare word within braces..like xxx->{s}; note that we
5262 # must be sure this is not a structural brace, to avoid
5263 # mistaking {s} in the following for a quoted bare word:
5264 # for(@[){s}bla}BLA}
5265 # Also treat q in something like var{-q} as a bare word, not
5266 # a quote operator
5267 ▶ 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
492329138
$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
5268 $next_nonblank_token eq '}'
5269 && (
5270 $last_nonblank_type eq 'L'
5271 || ( $last_nonblank_type eq 'm'
5272 && $last_last_nonblank_type eq 'L' )
5273 )
5274 )
5275 {
5276 138 $type = 'w';
5277 }
5278  
5279 # handle operator x (now we know it isn't $x=)
5280 ▶ 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
4935017
$expecting == 1 and substr($tok, 0, 1) eq "x"
!ll&&!rl&&r
459633917
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
5281 $expecting == OPERATOR
5282 && substr( $tok, 0, 1 ) eq 'x'
5283 && ( length($tok) == 1
5284 || substr( $tok, 1, 1 ) =~ /^\d/ )
5285 )
5286 {
5287 17 $self->do_X_OPERATOR();
5288 }
5289 elsif ( $tok_kw eq 'CORE::' ) {
5290 3 $type = $tok = $tok_kw;
5291 3 $i += 2;
5292 }
5293 ▶ elsif ( ( $tok eq 'strict' )
Condition100%3/3
$tok eq "strict" and $last_nonblank_token eq "use"
!ll&&!rl&&r
4916214
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
5294 and ( $last_nonblank_token eq 'use' ) )
5295 {
5296 14 $self->[_saw_use_strict_] = 1;
5297 14 $self->scan_bare_identifier();
5298 }
5299  
5300 ▶ elsif ( ( $tok eq 'warnings' )
Condition100%3/3
$tok eq "warnings" and $last_nonblank_token eq "use"
!ll&&!rl&&r
490927
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
5301 and ( $last_nonblank_token eq 'use' ) )
5302 {
5303 7 $self->[_saw_perl_dash_w_] = 1;
5304  
5305 # scan as identifier, so that we pick up something like:
5306 # use warnings::register
5307 7 $self->scan_bare_identifier();
5308 }
5309  
5310 ▶ 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
491100
$tok eq "AutoLoader" and $self->[27]
!ll&&!rl&&r
491100
$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
5311 $tok eq 'AutoLoader'
5312 && $self->[_look_for_autoloader_]
5313 && (
5314 $last_nonblank_token eq 'use'
5315  
5316 # these regexes are from AutoSplit.pm, which we want
5317 # to mimic
5318 || $input_line =~ /^\s*(use|require)\s+AutoLoader\b/
5319 || $input_line =~ /\bISA\s*=.*\bAutoLoader\b/
5320 )
5321 )
5322 {
5323 0 $self->write_logfile_entry("AutoLoader seen, -nlal deactivates\n");
5324 0 $self->[_saw_autoloader_] = 1;
5325 0 $self->[_look_for_autoloader_] = 0;
5326 0 $self->scan_bare_identifier();
5327 }
5328  
5329 ▶ 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
491100
$tok eq "SelfLoader" and $self->[28]
!ll&&!rl&&r
491100
$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
5330 $tok eq 'SelfLoader'
5331 && $self->[_look_for_selfloader_]
5332 && ( $last_nonblank_token eq 'use'
5333 || $input_line =~ /^\s*(use|require)\s+SelfLoader\b/
5334 || $input_line =~ /\bISA\s*=.*\bSelfLoader\b/ )
5335 )
5336 {
5337 0 $self->write_logfile_entry("SelfLoader seen, -nlsl deactivates\n");
5338 0 $self->[_saw_selfloader_] = 1;
5339 0 $self->[_look_for_selfloader_] = 0;
5340 0 $self->scan_bare_identifier();
5341 }
5342  
5343 ▶ elsif ( ( $tok eq 'constant' )
Condition66%2/3
$tok eq "constant" and $last_nonblank_token eq "use"
!ll&&!rl&&r
4893018
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
5344 and ( $last_nonblank_token eq 'use' ) )
5345 {
5346 18 $self->do_USE_CONSTANT();
5347 }
5348  
5349 # Lexical sub names override keywords, labels. Based on testing,
5350 # this seems to be the correct location for this check.
5351 elsif ($is_lexical_sub_type) {
5352 0 $type = $is_lexical_sub_type;
5353 }
5354  
5355 # various quote operators
5356 elsif ( $is_q_qq_qw_qx_qr_s_y_tr_m{$tok} ) {
5357 237 $self->do_QUOTE_OPERATOR();
5358 }
5359  
5360 # check for a statement label
5361 ▶ 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
4621233
$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
4619235
$next_nonblank_token eq ":" and not $is_not_label and $$rtokens[$i_next + 1] ne ":" and $i_next <= $max_token_index
!ll&&!rl&&r
4616337
$next_nonblank_token eq ":" and not $is_not_label and $$rtokens[$i_next + 1] ne ":"
!ll&&!rl&&r
434327340
$next_nonblank_token eq ":" and not $is_not_label
!ll&&!rl&&r
43412313
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
5362 ( $next_nonblank_token eq ':' )
5363 && !$is_not_label
5364 && ( $rtokens->[ $i_next + 1 ] ne ':' )
5365 && ( $i_next <= $max_token_index ) # colon on same line
5366  
5367 # like 'sub : lvalue' ?
5368 && !$self->sub_attribute_ok_here( $tok_kw, $next_nonblank_token,
5369 $i_next )
5370 && new_statement_ok()
5371 )
5372 {
5373 33 ▶ if ( $tok !~ /[A-Z]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tok =~ /[A-Z]/) 15 18 33
5374 15 push @{ $self->[_rlower_case_labels_at_] }, $input_line_number;
5375 }
5376 33 $type = 'J';
5377 33 $tok .= ':';
5378 33 $i = $i_next;
5379 }
5380  
5381 # 'sub' or other sub alias
5382 elsif ( $is_sub{$tok_kw} ) {
5383  
5384 # Guess what to do for unknown word 'method':
5385 # Updated for --use-feature=class (rt145706):
5386 374 ▶ 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 367 374
Condition100%6/6
$tok_kw eq "method" and $guess_if_method and not $self->method_ok_here($next_nonblank_token)
!ll&&!rl&&r
36077
$tok_kw eq "method" and $guess_if_method
!ll&&!rl&&r
358214
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
5387 && $guess_if_method
5388 && !$self->method_ok_here($next_nonblank_token) )
5389 {
5390 7 $self->do_UNKNOWN_BAREWORD($next_nonblank_token);
5391 }
5392 else {
5393 367 ▶ $self->error_if_expecting_OPERATOR()
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 367 367
5394 if ( $expecting == OPERATOR );
5395 367 initialize_subname();
5396 367 $self->scan_id();
5397 }
5398 }
5399  
5400 # 'package'
5401 elsif ( $is_package{$tok_kw} ) {
5402  
5403 # Update for --use-feature=class (rt145706):
5404 # We have to be extra careful because 'class' may be used for other
5405 # purposes on older code; i.e.
5406 # class($x) - valid sub call
5407 # package($x) - error
5408 54 ▶ if ( $tok_kw eq 'class' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok_kw eq 'class') { } 14 40 54
5409 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
5410 || $next_nonblank_token !~ /^[\w\:]/
5411 || !$self->class_ok_here() )
5412 {
5413 4 $self->do_UNKNOWN_BAREWORD($next_nonblank_token);
5414 }
5415 10 else { $self->scan_id() }
5416 }
5417 else {
5418 40 ▶ $self->error_if_expecting_OPERATOR()
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == 1 0 40 40
5419 if ( $expecting == OPERATOR );
5420 40 $self->scan_id();
5421 }
5422 }
5423  
5424 # Fix for c035: split 'format' from 'is_format_END_DATA' to be
5425 # more restrictive. Require a new statement to be ok here.
5426 ▶ elsif ( $tok_kw eq 'format' && new_statement_ok() ) {
Condition66%2/3
$tok_kw eq "format" and new_statement_ok()
!ll&&!rl&&r
419401
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
5427 1 $type = ';'; # make tokenizer look for TERM next
5428 1 $self->[_in_format_] = 1;
5429 1 $is_last = 1; ## is last token on this line
5430 }
5431  
5432 # Note on token types for format, __DATA__, __END__:
5433 # It simplifies things to give these type ';', so that when we
5434 # start rescanning we will be expecting a token of type TERM.
5435 # We will switch to type 'k' before outputting the tokens.
5436 elsif ( defined( $is_END_DATA{$tok_kw} ) ) {
5437  
5438 # Warn if this follows an operator expecting a term (c565)
5439 8 ▶ $self->error_if_expecting_TERM()
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == -1 8 0 8
5440 if ( $expecting == TERM );
5441  
5442 8 $type = ';'; # make tokenizer look for TERM next
5443  
5444 # Remember that we are in one of these three sections
5445 8 $self->[ $is_END_DATA{$tok_kw} ] = 1;
5446 8 $is_last = 1; ## is last token on this line
5447 }
5448 elsif ( $is_keyword{$tok_kw} ) {
5449 3142 $self->do_KEYWORD();
5450 }
5451  
5452 # check for inline label following
5453 # /^(redo|last|next|goto)$/
5454 ▶ 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
5455 && ( $is_redo_last_next_goto{$last_nonblank_token} ) )
5456 {
5457 19 $type = 'j';
5458 }
5459  
5460 # something else --
5461 else {
5462 1025 $self->do_UNKNOWN_BAREWORD($next_nonblank_token);
5463 }
5464  
5465 #----------------------------------------------------------------
5466 # Save info for use in later guessing. Even for types 'i' and 'U'
5467 # because those may be marked as type 'w' (barewords) elsewhere.
5468 #----------------------------------------------------------------
5469 6702 ▶ if ( $is_wiUC{$type}
Branch: 1 branch
BranchTrueFalseTotal
if ($is_wiUC{$type} and $statement_type ne "use" and $statement_type ne "_use") 2644 4058 6702
Condition100%6/6
$is_wiUC{$type} and $statement_type ne "use" and $statement_type ne "_use"
!ll&&!rl&&r
405622644
$is_wiUC{$type} and $statement_type ne "use"
!ll&&!rl&&r
38861702646
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
5470 && $statement_type ne 'use'
5471 && $statement_type ne '_use' )
5472 {
5473 2644 my $result = "unknown";
5474  
5475 # Words are marked 'function' if they appear in a role which
5476 # is not consistent with a constant value. Typically they are
5477 # function calls.
5478 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
5479 || $is_function_follower{$next_nonblank_token} )
5480 {
5481  
5482 1019 my $empty_parens = 0;
5483 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
5484 {
5485 594 my $tok_next_p1 = $rtokens->[ $i_next + 1 ];
5486 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
5487 && $i_next + 2 <= $max_token_index )
5488 {
5489 284 $tok_next_p1 = $rtokens->[ $i_next + 2 ];
5490 }
5491 594 $empty_parens = $tok_next_p1 eq ')';
5492 }
5493  
5494 1019 ▶ if ( !$empty_parens ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($empty_parens) 961 58 1019
5495  
5496 # not a constant term - probably a function
5497 961 $result = "function";
5498 961 $self->saw_bareword_function($tok);
5499 }
5500 }
5501  
5502 # Words are marked 'constant' if they appear in a role
5503 # consistent with a constant value. However, they may simply
5504 # be functions which optionally take zero args. So if a word
5505 # appears as both constant and function, it is not a constant.
5506 ▶ 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
5507 || $is_constant_follower{$next_nonblank_token} )
5508 {
5509  
5510 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
5511 && (
5512 $last_nonblank_type eq 'L'
5513 || ( $last_nonblank_type eq 'm'
5514 && $last_last_nonblank_type eq 'L' )
5515 );
5516  
5517 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
5518  
5519 # not a hash key like {bareword} or {-bareword}
5520 !$is_hash_key
5521  
5522 # not a package name, etc
5523 && ( $last_nonblank_type ne 'k'
5524 || !$is_use_require_no{$last_nonblank_token} )
5525  
5526 # skip arrow calls, which can go either way
5527 && $last_nonblank_token ne '->'
5528 )
5529 {
5530 # possibly a constant or constant function
5531 182 $result = "constant";
5532 182 $self->saw_bareword_constant($tok);
5533 }
5534 else {
5535 263 $result = "other bareword";
5536 }
5537 }
5538 else {
5539 ## something else
5540 }
5541  
5542 2644 if ( DEBUG_BAREWORD && $result ne 'other bareword' ) {
5543 print
5544 "$input_line_number: $result: $tok: type=$type : last_tok=$last_nonblank_token : next_tok='$next_nonblank_token'\n";
5545 }
5546 }
5547 6702 return $is_last;
5548  
5549 } ## end sub do_BAREWORD
5550  
5551 # Table of quote types checked for interpolated here targets.
5552 # Issue 310 has extensive test cases.
5553 45 my %is_interpolated_quote = (
5554 q{'} => 0,
5555 q{`} => 1,
5556 q{"} => 1,
5557 qq => 1,
5558 qx => 1,
5559 m => 1,
5560 qr => 1,
5561 q => 0,
5562 qw => 0,
5563 s => 1,
5564 y => 0,
5565 tr => 0,
5566 );
5567  
5568 2 ▶ sub push_here_targets {
Subroutine push_here_targets: called CC=2 SCAR=6.9
Pod undocumented
5569 2 my ($rht) = @_;
5570  
5571 # Push here targets found in a quote onto the here target list
5572 2 push @{$rhere_target_list}, @{$rht};
5573  
5574 # Change type from 'Q' to 'h' for quotes with here-doc targets so that
5575 # the formatter (see sub process_line_of_CODE) will not make any line
5576 # breaks after this point.
5577 2 $type = 'h';
5578 2 ▶ if ( $i_tok < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_tok < 0) 1 1 2
5579 1 my $ilast = $routput_token_list->[-1];
5580 1 $routput_token_type->[$ilast] = $type;
5581 }
5582 2 return;
5583 } ## end sub push_here_targets
5584  
5585 3233 ▶ sub do_FOLLOW_QUOTE {
Subroutine do_FOLLOW_QUOTE: called CC=28 SCAR=34.9
Pod undocumented
5586  
5587 3233 my $self = shift;
5588  
5589 # Continue following a quote on a new line
5590 3233 $type = $quote_type;
5591  
5592 # initialize if continuation line
5593 3233 ▶ if ( !@{$routput_token_list} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$routput_token_list;}) 245 2988 3233
5594 245 push @{$routput_token_list}, $i;
5595 245 $routput_token_type->[$i] = $type;
5596 }
5597  
5598 # Save starting lengths for here target search
5599 3233 my $len_qs1 = length($quoted_string_1);
5600 3233 my $len_qs2 = length($quoted_string_2);
5601 3233 my $in_quote_start = $in_quote;
5602  
5603 # scan for the end of the quote or pattern
5604 (
5605 3233 $i,
5606 $in_quote,
5607 $quote_character,
5608 $quote_pos,
5609 $quote_depth,
5610 $quoted_string_1,
5611 $quoted_string_2,
5612  
5613 ) = $self->do_quote(
5614  
5615 $i,
5616 $in_quote,
5617 $quote_character,
5618 $quote_pos,
5619 $quote_depth,
5620 $quoted_string_1,
5621 $quoted_string_2,
5622 $rtokens,
5623 $rtoken_type,
5624 $rtoken_map,
5625 $max_token_index,
5626  
5627 );
5628  
5629 # Save pattern and replacement text for rescanning for /e
5630 3233 my $qs1_for_e_scan = $quoted_string_1;
5631  
5632 # Check for possible here targets in an interpolated quote
5633 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
5634 && $in_quote < $in_quote_start )
5635 {
5636  
5637 # post any saved target of a 2-part quote if the end is reached
5638 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
5639  
5640 # Safety check
5641 1 ▶ if ( $quote_items{$quote_starting_tok} == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote_items{$quote_starting_tok} == 2) { } 1 0 1
5642 1 push_here_targets($quote_here_target_2);
5643 }
5644 else {
5645 0 DEVEL_MODE
5646 && Fault(
5647 "unexpected saved here target near line $input_line_number\n"
5648 );
5649 }
5650 1 $quote_here_target_2 = undef;
5651 }
5652  
5653 # Single part quotes: use $quoted_string_1, and
5654 # $in_quote drops from 1 to 0 when the end is found
5655 # Dual part quotes ('s'): first part is in $quoted_string_2, and
5656 # $in_quote:
5657 # drops from 2 to 1 when the the first part is found
5658 # drops 1 to 0 when the the second part is found
5659 # drops from 2 to 0 if both parts are found in this call
5660 # The tricky part is that we must search for here targets whenever
5661 # $in_quote drops, but we can only post here targets after the end
5662 # of the last part is found (in_quote==0). See test 'here4.in'.
5663 # Update c310 added interpolated here docs and has many test cases.
5664  
5665 # Initialize for the normal case of a single quote
5666 1478 my $qs = $quoted_string_1;
5667 1478 my $len_qs = $len_qs1;
5668 1478 my $num_quotes = $in_quote_start - $in_quote;
5669  
5670 # Dual part quotes (type 's') have first part in $quoted_string_2
5671 1478 ▶ if ( $in_quote_start == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote_start == 2) 31 1447 1478
5672 31 $qs = $quoted_string_2;
5673 31 $len_qs = $len_qs2;
5674 }
5675  
5676 # Loop to search 1 or 2 quotes for here targets
5677 1478 foreach ( 1 .. $num_quotes ) {
5678  
5679 # Perform quick tests to avoid a sub call:
5680 1507 my $pos_shift = rindex( $qs, '<<' );
5681 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
150502
$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/DC50%2/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 table60%3/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
5682  
5683 # a '<<' in the last line
5684 $pos_shift >= $len_qs
5685  
5686 # and a '}' in the last line (c598: updated to allow
5687 # for the possibility of an extra '<<' after a here doc)
5688 && rindex( $qs, '}' ) >= $len_qs
5689  
5690 # and a '<<' preceded by '$' or '@'
5691 && ( rindex( $qs, '$', $pos_shift ) >= 0
5692 || rindex( $qs, '@', $pos_shift ) >= 0 )
5693 )
5694 {
5695  
5696 # scan the quote for here targets
5697 2 my ( $rht, $qs_mod ) =
5698 $self->find_interpolated_here_targets( $qs, $len_qs );
5699 2 ▶ if ($rht) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rht) 2 0 2
5700  
5701 # only post here targets when end of quote is found
5702 2 ▶ if ($in_quote) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote) { } 1 1 2
5703 1 $quote_here_target_2 = $rht;
5704 }
5705 else {
5706 1 push_here_targets($rht);
5707  
5708 # Replace the string with the modified version
5709 # in case it is re-scanned due to a /e modifier
5710 1 $qs1_for_e_scan = $qs_mod;
5711 }
5712 }
5713 }
5714  
5715 # re-initialize for next pass
5716 1507 $qs = $quoted_string_1;
5717 1507 $len_qs = $len_qs1;
5718 } ## end while ( $num_quotes-- > 0)
5719 }
5720  
5721 3233 ▶ if ($in_quote) { return }
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote) 244 2989 3233
5722  
5723 # All done with this quote...
5724  
5725 # re-initialize for next search
5726 2989 $quote_character = EMPTY_STRING;
5727 2989 $quote_pos = 0;
5728 2989 $quote_type = 'Q';
5729 2989 $quoted_string_1 = EMPTY_STRING;
5730 2989 $quoted_string_2 = EMPTY_STRING;
5731 2989 ▶ if ( ++$i > $max_token_index ) { return }
Branch: 1 branch
BranchTrueFalseTotal
if (++$i > $max_token_index) 126 2863 2989
5732  
5733 # look for any modifiers
5734 2863 ▶ if ($allowed_quote_modifiers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allowed_quote_modifiers) 165 2698 2863
5735  
5736 # check for exact quote modifiers
5737 165 ▶ if ( $rtokens->[$i] =~ /^[A-Za-z_]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rtokens->[$i] =~ /^[A-Za-z_]/) 31 134 165
5738 31 my $str = $rtokens->[$i];
5739 31 my $saw_modifier_e;
5740 31 ▶ while ( $str =~ /\G$allowed_quote_modifiers/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\G$allowed_quote_modifiers/cg) 49 31 80
5741 49 my $pos = pos($str);
5742 49 my $char = substr( $str, $pos - 1, 1 );
5743 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
5744 }
5745  
5746 # For an 'e' quote modifier we must scan the replacement
5747 # text for here-doc targets...
5748 # but if the modifier starts a new line we must skip
5749 # this because either the here doc will be fully
5750 # contained in the replacement text (so we can
5751 # ignore it) or Perl will not find it. The modifier will have a
5752 # pretoken index $i=1 if it starts a new line, so we only look
5753 # for a here doc if $i>1. See test 'here2.in'.
5754 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
5755 0 my $rht = $self->scan_replacement_text($qs1_for_e_scan);
5756 0 ▶ if ($rht) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rht) 0 0 0
5757 0 push_here_targets($rht);
5758 }
5759 }
5760  
5761 31 ▶ if ( defined( pos($str) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined pos $str) { } 31 0 31
5762  
5763 # matched
5764 31 ▶ if ( pos($str) == length($str) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $str == length $str) { } 31 0 31
5765 0 ▶ if ( ++$i > $max_token_index ) { return }
Branch: 1 branch
BranchTrueFalseTotal
if (++$i > $max_token_index) 0 31 31
5766 }
5767  
5768 # Looks like a joined quote modifier
5769 # and keyword, maybe something like
5770 # s/xxx/yyy/gefor @k=...
5771 # Example is "galgen.pl". Would have to split
5772 # the word and insert a new token in the
5773 # pre-token list. This is so rare that I haven't
5774 # done it. Will just issue a warning citation.
5775  
5776 # This error might also be triggered if my quote
5777 # modifier characters are incomplete
5778 else {
5779 0 $self->warning(<<EOM);
5780  
5781 Partial match to quote modifier $allowed_quote_modifiers at word: '$str'
5782 Please put a space between quote modifiers and trailing keywords.
5783 EOM
5784  
5785 # print "token $rtokens->[$i]\n";
5786 # my $num = length($str) - pos($str);
5787 # $rtokens->[$i]=substr($rtokens->[$i],pos($str),$num);
5788 # print "continuing with new token $rtokens->[$i]\n";
5789  
5790 # skipping past this token does least damage
5791 0 ▶ if ( ++$i > $max_token_index ) { return }
Branch: 1 branch
BranchTrueFalseTotal
if (++$i > $max_token_index) 0 0 0
5792 }
5793 }
5794 else {
5795  
5796 # example file: rokicki4.pl
5797 # This error might also be triggered if my quote
5798 # modifier characters are incomplete
5799 0 $self->write_logfile_entry(
5800 "Note: found word $str at quote modifier location\n");
5801 }
5802 }
5803  
5804 # re-initialize
5805 165 $allowed_quote_modifiers = EMPTY_STRING;
5806 }
5807 2863 return;
5808 } ## end sub do_FOLLOW_QUOTE
5809  
5810 # ------------------------------------------------------------
5811 # begin hash of code for handling most token types
5812 # ------------------------------------------------------------
5813 45 my $tokenization_code = {
5814  
5815 '$' => \&do_DOLLAR_SIGN,
5816 '(' => \&do_LEFT_PARENTHESIS,
5817 ')' => \&do_RIGHT_PARENTHESIS,
5818 ',' => \&do_COMMA,
5819 ';' => \&do_SEMICOLON,
5820 '"' => \&do_QUOTATION_MARK,
5821 "'" => \&do_APOSTROPHE,
5822 '`' => \&do_BACKTICK,
5823 '/' => \&do_SLASH,
5824 '{' => \&do_LEFT_CURLY_BRACKET,
5825 '}' => \&do_RIGHT_CURLY_BRACKET,
5826 '&' => \&do_AMPERSAND,
5827 '<' => \&do_LESS_THAN_SIGN,
5828 '?' => \&do_QUESTION_MARK,
5829 '*' => \&do_STAR,
5830 '.' => \&do_DOT,
5831 ':' => \&do_COLON,
5832 '+' => \&do_PLUS_SIGN,
5833 '@' => \&do_AT_SIGN,
5834 '%' => \&do_PERCENT_SIGN,
5835 '[' => \&do_LEFT_SQUARE_BRACKET,
5836 ']' => \&do_RIGHT_SQUARE_BRACKET,
5837 '-' => \&do_MINUS_SIGN,
5838 '^' => \&do_CARAT_SIGN,
5839 '::' => \&do_DOUBLE_COLON,
5840 '<<' => \&do_LEFT_SHIFT,
5841 '<<~' => \&do_NEW_HERE_DOC,
5842 '->' => \&do_POINTER,
5843 '++' => \&do_PLUS_PLUS,
5844 '=>' => \&do_FAT_COMMA,
5845 '--' => \&do_MINUS_MINUS,
5846  
5847 # No special code for these types yet, but syntax checks
5848 # could be added.
5849 ## '&&' => \&do_LOGICAL_AND,
5850 ## '||' => \&do_LOGICAL_OR,
5851 ## '>' => \&do_GREATER_THAN_SIGN,
5852 ## '|' => \&do_VERTICAL_LINE,
5853 ## '//' => \&do_SLASH_SLASH,
5854 ## '!' => undef,
5855 ## '!=' => undef,
5856 ## '!~' => undef,
5857 ## '%=' => undef,
5858 ## '&&=' => undef,
5859 ## '&=' => undef,
5860 ## '+=' => undef,
5861 ## '-=' => undef,
5862 ## '..' => undef,
5863 ## '..' => undef,
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  
5885 };
5886  
5887 # ------------------------------------------------------------
5888 # end hash of code for handling individual token types
5889 # ------------------------------------------------------------
5890  
5891 45 ▶ use constant DEBUG_TOKENIZE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5892  
5893 45 my %is_arrow_or_Z;
5894  
5895 45 ▶ BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
5896 45 my @qZ = qw( -> Z );
5897 45 $is_arrow_or_Z{$_} = 1 for @qZ;
5898 }
5899  
5900 8969 ▶ sub tokenize_this_line {
Subroutine tokenize_this_line: called CC=31 SCAR=34.8
Pod undocumented
5901  
5902 8969 my ( $self, $line_of_tokens, $trimmed_input_line ) = @_;
5903  
5904 # This routine tokenizes one line. The results are stored in
5905 # the hash ref '$line_of_tokens'.
5906  
5907 # Given:
5908 # $line_of_tokens = ref to hash of values being filled for this line
5909 # $trimmed_input_line
5910 # = the input line without leading whitespace, OR
5911 # = undef if not available
5912 # Returns:
5913 # nothing
5914  
5915 8969 my $untrimmed_input_line = $line_of_tokens->{_line_text};
5916  
5917 # Extract line number for use in error messages
5918 8969 $input_line_number = $line_of_tokens->{_line_number};
5919  
5920 #-------------------------------------
5921 # Check for start of pod documentation
5922 #-------------------------------------
5923 8969 ▶ 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 8954 8969
Condition83%5/6
not $in_quote and substr($untrimmed_input_line, 0, 1) eq "=" and $untrimmed_input_line =~ /^=[A-Za-z_]/
!ll&&!rl&&r
8954015
not $in_quote and substr($untrimmed_input_line, 0, 1) eq "="
!ll&&!rl&&r
247870715
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
5924 && substr( $untrimmed_input_line, 0, 1 ) eq '='
5925 && $untrimmed_input_line =~ /^=[A-Za-z_]/ )
5926 {
5927  
5928 # Must not be in an equation where an '=' could be expected.
5929 # Perl has additional restrictions which are not checked here.
5930 15 my $blank_after_Z = 1;
5931 15 $expecting = $self->operator_expected( '=', 'b', $blank_after_Z );
5932 15 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) 15 0 15
5933 15 $self->[_in_pod_] = 1;
5934 15 return;
5935 }
5936 }
5937  
5938 #--------------------------
5939 # Trim leading whitespace ?
5940 #--------------------------
5941 # Use untrimmed line if we are continuing in a type 'Q' quote
5942 8954 ▶ if ( $in_quote && $quote_type eq 'Q' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote and $quote_type eq 'Q') { } 58 8896 8954
Condition100%3/3
$in_quote and $quote_type eq "Q"
!ll&&!rl&&r
870718958
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
5943 58 $line_of_tokens->{_starting_in_quote} = 1;
5944 58 $input_line = $untrimmed_input_line;
5945 58 chomp $input_line;
5946 }
5947  
5948 # Trim start of this line if we are not continuing a quoted line.
5949 # Do not trim end because we might end in a quote (test: deken4.pl)
5950 # Perl::Tidy::Formatter will delete needless trailing blanks
5951 else {
5952 8896 $line_of_tokens->{_starting_in_quote} = 0;
5953  
5954 # Use the pre-computed trimmed line if defined (most efficient)
5955 8896 $input_line = $trimmed_input_line;
5956  
5957 # otherwise trim the raw input line (much less efficient)
5958 8896 ▶ if ( !defined($input_line) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $input_line) 0 8896 8896
5959 0 $input_line = $untrimmed_input_line;
5960 0 $input_line =~ s/^\s+//;
5961 }
5962  
5963 8896 chomp $input_line;
5964  
5965 # define 'guessed_indentation_level' if logfile will be saved
5966 8896 ▶ if ( $self->[_save_logfile_] && length($input_line) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[39] and length $input_line) 3 8893 8896
Condition100%3/3
$self->[39] and length $input_line
!ll&&!rl&&r
889213
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
5967 3 my $guess =
5968 $self->guess_old_indentation_level($untrimmed_input_line);
5969 3 $line_of_tokens->{_guessed_indentation_level} = $guess;
5970 }
5971 }
5972  
5973 #------------
5974 # Blank lines
5975 #------------
5976 8954 ▶ if ( !length($input_line) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $input_line) 1059 7895 8954
5977 1059 $line_of_tokens->{_line_type} = 'CODE';
5978 1059 $line_of_tokens->{_rtokens} = [];
5979 1059 $line_of_tokens->{_rtoken_type} = [];
5980 1059 $line_of_tokens->{_rlevels} = [];
5981 1059 $line_of_tokens->{_rblock_type} = [];
5982 1059 $line_of_tokens->{_nesting_tokens_0} = $nesting_token_string;
5983 1059 $line_of_tokens->{_nesting_blocks_0} = $nesting_block_string;
5984 1059 return;
5985 }
5986  
5987 #---------
5988 # Comments
5989 #---------
5990 7895 ▶ if ( !$in_quote && substr( $input_line, 0, 1 ) eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $in_quote and substr($input_line, 0, 1) eq "#") 898 6997 7895
Condition100%3/3
not $in_quote and substr($input_line, 0, 1) eq "#"
!ll&&!rl&&r
2456752898
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
5991  
5992 # and check for skipped section
5993 898 ▶ 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 896 898
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
89602
substr($input_line, 0, 4) eq "#<<V" || $rOpts_code_skipping_begin and $rOpts_code_skipping
!ll&&!rl&&r
89602
substr($input_line, 0, 4) eq "#<<V" or $rOpts_code_skipping_begin
l!l&&r!l&&!r
20896
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
5994 (
5995 substr( $input_line, 0, 4 ) eq '#<<V'
5996 || $rOpts_code_skipping_begin
5997 )
5998 && $rOpts_code_skipping
5999  
6000 # note that the code_skipping_patterns require a newline
6001 && ( $input_line . SPACE ) =~ /$code_skipping_pattern_begin/
6002 )
6003 {
6004 2 $self->[_in_code_skipping_] = $self->[_last_line_number_];
6005 2 return;
6006 }
6007  
6008 # Look for format skipping tags, but just normal mode.
6009 # It will be used for these purposes:
6010 # - to inform the formatter of an end token with no begin token
6011 # - for making a hint when a brace error is detected
6012 896 ▶ 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 879 896
elsif (substr($input_line, 0, 4) eq '#>>>' || $rOpts_format_skipping_end and $rOpts_format_skipping and ($input_line . ' ') =~ /$format_skipping_pattern_end/) { } 20 859 879
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
879017
substr($input_line, 0, 4) eq "#<<<" || $rOpts_format_skipping_begin and $rOpts_format_skipping and ($input_line . ' ') =~ /$format_skipping_pattern_begin/
!ll&&!rl&&r
8592017
substr($input_line, 0, 4) eq "#<<<" || $rOpts_format_skipping_begin and $rOpts_format_skipping
!ll&&!rl&&r
857237
substr($input_line, 0, 4) eq "#<<<" or $rOpts_format_skipping_begin
l!l&&r!l&&!r
1821857
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
6013 (
6014 substr( $input_line, 0, 4 ) eq '#<<<'
6015 || $rOpts_format_skipping_begin
6016 )
6017 && $rOpts_format_skipping
6018  
6019 # note that the format_skipping_patterns require a space
6020 && ( $input_line . SPACE ) =~ /$format_skipping_pattern_begin/
6021  
6022 # allow same token for begin and end
6023 && (
6024 !$self->[_in_format_skipping_]
6025 || ( $format_skipping_pattern_begin ne
6026 $format_skipping_pattern_end )
6027 )
6028 )
6029 {
6030 17 my $on_off = 1;
6031 17 my $lno = $self->[_last_line_number_];
6032 17 my $rformat_skipping_list = $self->[_rformat_skipping_list_];
6033  
6034 # format markers must alternate between on and off
6035 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
6036 && $rformat_skipping_list->[-1]->[0] == $on_off )
6037 {
6038 0 my $lno_last = $rformat_skipping_list->[-1]->[1];
6039 0 $self->warning_do_not_format(
6040 "consecutive format-skipping start markers - see line $lno_last\n"
6041 );
6042 }
6043 17 push @{$rformat_skipping_list}, [ $on_off, $lno, $input_line ];
6044 17 $self->[_in_format_skipping_] = $lno;
6045 }
6046 ▶ 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
8421720
substr($input_line, 0, 4) eq "#>>>" || $rOpts_format_skipping_end and $rOpts_format_skipping
!ll&&!rl&&r
840237
substr($input_line, 0, 4) eq "#>>>" or $rOpts_format_skipping_end
l!l&&r!l&&!r
2118840
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
6047 (
6048 substr( $input_line, 0, 4 ) eq '#>>>'
6049 || $rOpts_format_skipping_end
6050 )
6051 && $rOpts_format_skipping
6052  
6053 # note that the format_skipping_patterns require a newline
6054 && ( $input_line . SPACE ) =~ /$format_skipping_pattern_end/
6055 )
6056 {
6057 20 my $lno = $self->[_last_line_number_];
6058 20 my $rformat_skipping_list = $self->[_rformat_skipping_list_];
6059 20 my $on_off = -1;
6060  
6061 # markers must alternate between on and off
6062 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
6063 && $rformat_skipping_list->[-1]->[0] == $on_off )
6064 {
6065 0 my $lno_last = $rformat_skipping_list->[-1]->[1];
6066 0 $self->warning_do_not_format(
6067 "consecutive format-skipping end markers - see line $lno_last\n"
6068 );
6069 }
6070  
6071 20 push @{$rformat_skipping_list}, [ $on_off, $lno, $input_line ];
6072 20 $self->[_in_format_skipping_] = 0;
6073 }
6074 else {
6075 ## not a format skipping comment
6076 }
6077  
6078 # Optional fast processing of a block comment
6079 896 $line_of_tokens->{_line_type} = 'CODE';
6080 896 $line_of_tokens->{_rtokens} = [$input_line];
6081 896 $line_of_tokens->{_rtoken_type} = ['#'];
6082 896 $line_of_tokens->{_rlevels} = [$level_in_tokenizer];
6083 896 $line_of_tokens->{_rblock_type} = [EMPTY_STRING];
6084 896 $line_of_tokens->{_nesting_tokens_0} = $nesting_token_string;
6085 896 $line_of_tokens->{_nesting_blocks_0} = $nesting_block_string;
6086 896 return;
6087 }
6088  
6089 #-------------------------------------
6090 # Loop to find all tokens on this line
6091 #-------------------------------------
6092  
6093 # Update the copy of the line for use in error messages
6094 # This must be exactly what we give the pre_tokenizer
6095 6997 $self->[_line_of_text_] = $input_line;
6096  
6097 # re-initialize for the main loop
6098 6997 $routput_token_list = []; # stack of output token indexes
6099 6997 $routput_token_type = []; # token types
6100 6997 $routput_block_type = []; # types of code block
6101 6997 $routput_type_sequence = []; # nesting sequential number
6102  
6103 6997 $rhere_target_list = [];
6104  
6105 6997 $tok = $last_nonblank_token;
6106 6997 $type = $last_nonblank_type;
6107 6997 $prototype = $last_nonblank_prototype;
6108 6997 $last_nonblank_i = -1;
6109 6997 $block_type = $last_nonblank_block_type;
6110 6997 $container_type = $last_nonblank_container_type;
6111 6997 $type_sequence = $last_nonblank_type_sequence;
6112 6997 $indent_flag = 0;
6113 6997 $peeked_ahead = 0;
6114  
6115 6997 $self->tokenizer_main_loop();
6116  
6117 #-------------------------------------------------
6118 # Done tokenizing this line ... package the result
6119 #-------------------------------------------------
6120 6997 $self->tokenizer_wrapup_line($line_of_tokens);
6121  
6122 6997 return;
6123 } ## end sub tokenize_this_line
6124  
6125 6997 ▶ sub tokenizer_main_loop {
Subroutine tokenizer_main_loop: called CC=81 SCAR=45.3
Pod undocumented
6126  
6127 6997 my ($self) = @_;
6128  
6129 # Break one input line into tokens
6130 # We are working on closure variables.
6131  
6132 # Start by breaking the line into pre-tokens
6133 6997 ( $rtokens, $rtoken_map, $rtoken_type ) = pre_tokenize($input_line);
6134  
6135 # Verify that all leading whitespace has been trimmed
6136 # except for quotes of type 'Q' (c273).
6137 6997 ▶ if ( @{$rtokens}
Branch: 1 branch
BranchTrueFalseTotal
if (@{$rtokens;} and $rtoken_type->[0] eq "b" and not $in_quote && $quote_type eq "Q") 0 6997 6997
Condition55%5/9
@{$rtokens;} and $rtoken_type->[0] eq "b" and not $in_quote && $quote_type eq "Q"
!ll&&!rl&&r
6961360
@{$rtokens;} and $rtoken_type->[0] eq "b"
!ll&&!rl&&r
0696136
$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
6138 && $rtoken_type->[0] eq 'b'
6139 && !( $in_quote && $quote_type eq 'Q' ) )
6140 {
6141  
6142 # Shouldn't happen if calling sub did trim operation correctly.
6143 0 DEVEL_MODE && Fault(<<EOM);
6144 leading blank at line
6145 $input_line
6146 EOM
6147  
6148 # Fix by removing the leading blank token. This fix has been
6149 # tested and works correctly even if no whitespaces was trimmed.
6150 # But it is an inefficient way to do things because, for example,
6151 # it forces all comments to be processed by sub pre_tokenize.
6152 # And it may cause indented code-skipping comments to be missed.
6153 0 shift @{$rtokens};
6154 0 shift @{$rtoken_map};
6155 0 shift @{$rtoken_type};
6156 }
6157  
6158 6997 $max_token_index = scalar( @{$rtokens} ) - 1;
6159  
6160 # add extra spaces to simplify logic - they shouldn't be referenced
6161 6997 push @{$rtokens}, ( SPACE, SPACE, SPACE );
6162 6997 push @{$rtoken_map}, qw( 0 0 0 );
6163 6997 push @{$rtoken_type}, qw( b b b );
6164  
6165 # initialize for main loop
6166 6997 if (0) { #<<< this is not necessary
6167 foreach my $ii ( 0 .. $max_token_index + 3 ) {
6168 $routput_token_type->[$ii] = EMPTY_STRING;
6169 $routput_block_type->[$ii] = EMPTY_STRING;
6170 $routput_type_sequence->[$ii] = EMPTY_STRING;
6171 $routput_indent_flag->[$ii] = 0;
6172 }
6173 }
6174  
6175 6997 $i = -1;
6176 6997 $i_tok = -1;
6177  
6178 #-----------------------
6179 # main tokenization loop
6180 #-----------------------
6181  
6182 # we are looking at each pre-token of one line and combining them
6183 # into tokens
6184 6997 ▶ while ( ++$i <= $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$i <= $max_token_index) 57868 6255 64123
6185  
6186 # continue looking for the end of a quote
6187 60602 ▶ if ($in_quote) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote) 3233 57369 60602
6188 3233 $self->do_FOLLOW_QUOTE();
6189 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
6190 }
6191  
6192 60232 ▶ if ( $type ne 'b' && $type ne 'CORE::' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type ne "b" and $type ne "CORE::") 42192 18040 60232
Condition100%3/3
$type ne "b" and $type ne "CORE::"
!ll&&!rl&&r
18037342192
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
6193  
6194 # try to catch some common errors
6195 42192 ▶ if ( ( $type eq 'n' ) && ( $tok ne '0' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "n" and $tok ne 0) 2075 40117 42192
Condition100%3/3
$type eq "n" and $tok ne 0
!ll&&!rl&&r
395715462075
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
6196  
6197 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
6198 9 $self->complain("Should 'eq' be '==' here ?\n");
6199 }
6200 elsif ( $last_nonblank_token eq 'ne' ) {
6201 0 $self->complain("Should 'ne' be '!=' here ?\n");
6202 }
6203 else {
6204 ## that's all
6205 }
6206 }
6207  
6208 # fix c090, only rotate vars if a new token will be stored
6209 42192 ▶ if ( $i_tok >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_tok >= 0) 35384 6808 42192
6210  
6211 35384 $last_last_nonblank_token = $last_nonblank_token;
6212 35384 $last_last_nonblank_type = $last_nonblank_type;
6213  
6214 35384 $last_nonblank_prototype = $prototype;
6215 35384 $last_nonblank_block_type = $block_type;
6216 35384 $last_nonblank_container_type = $container_type;
6217 35384 $last_nonblank_type_sequence = $type_sequence;
6218 35384 $last_nonblank_i = $i_tok;
6219 35384 $last_nonblank_token = $tok;
6220 35384 $last_nonblank_type = $type;
6221 }
6222  
6223 # Check for patches
6224 42192 ▶ if ( $is_arrow_or_Z{$last_last_nonblank_type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_arrow_or_Z{$last_last_nonblank_type}) 1244 40948 42192
6225  
6226 # Patch for c030: Fix things in case a '->' got separated
6227 # from the subsequent identifier by a side comment. We
6228 # need the last_nonblank_token to have a leading -> to
6229 # avoid triggering an operator expected error message at
6230 # the next '('. See also fix for git #63.
6231 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
6232 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
6233 || $last_nonblank_type eq 'i' )
6234 {
6235 793 $last_nonblank_token = '->' . $last_nonblank_token;
6236 793 $last_nonblank_type = 'i';
6237 }
6238 }
6239  
6240 # Fix part #3 for git82: propagate type 'Z' though L-R pair
6241 elsif ( $last_last_nonblank_type eq 'Z' ) {
6242 48 ▶ if ( $last_nonblank_type eq 'R' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq "R") 1 47 48
6243 1 $last_nonblank_type = $last_last_nonblank_type;
6244 1 $last_nonblank_token = $last_last_nonblank_token;
6245 }
6246 }
6247 else {
6248 ## No other patches
6249 }
6250 }
6251 }
6252  
6253 # store previous token type
6254 60232 ▶ if ( $i_tok >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_tok >= 0) 53424 6808 60232
6255 53424 $routput_token_type->[$i_tok] = $type;
6256 53424 $routput_block_type->[$i_tok] = $block_type;
6257 53424 $routput_type_sequence->[$i_tok] = $type_sequence;
6258 53424 $routput_indent_flag->[$i_tok] = $indent_flag;
6259 }
6260  
6261 # get the next pre-token and type
6262 # $tok and $type will be modified to make the output token
6263 60232 my $pre_tok = $tok = $rtokens->[$i]; # get the next pre-token
6264 60232 my $pre_type = $type = $rtoken_type->[$i]; # and type
6265  
6266 # re-initialize various flags for the next output token
6267 (
6268  
6269 # remember the starting index of this token; we will update $i
6270 60232 $i_tok,
6271 $block_type,
6272 $container_type,
6273 $type_sequence,
6274 $indent_flag,
6275 $prototype,
6276 )
6277 = (
6278  
6279 $i,
6280 EMPTY_STRING,
6281 EMPTY_STRING,
6282 EMPTY_STRING,
6283 0,
6284 EMPTY_STRING,
6285 );
6286  
6287 # this pre-token will start an output token
6288 60232 push @{$routput_token_list}, $i_tok;
6289  
6290 #---------------------------------------------------
6291 # The token search leads to one of 5 main END NODES:
6292 #---------------------------------------------------
6293  
6294 #-----------------------
6295 # END NODE 1: whitespace
6296 #-----------------------
6297 60232 ▶ next if ( $pre_type eq 'b' );
Branch: 1 branch
BranchTrueFalseTotal
if $pre_type eq "b" 18185 42047 60232
6298  
6299 #----------------------
6300 # END NODE 2: a comment
6301 #----------------------
6302 42047 ▶ if ( $pre_type eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre_type eq "#") 363 41684 42047
6303  
6304 # push non-indenting brace stack Look for a possible
6305 # non-indenting brace. This is only used to give a hint in
6306 # case the file is unbalanced.
6307 # Hardwired to '#<<<' for efficiency. We will not use the
6308 # result later if the pattern has been changed (very unusual).
6309 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
6310 && $last_nonblank_block_type
6311 && $last_nonblank_type_sequence
6312 && !$self->[_in_format_skipping_]
6313 && $rOpts_non_indenting_braces )
6314 {
6315 46 my $offset = $rtoken_map->[$i_tok];
6316 46 my $text = substr( $input_line, $offset, 5 );
6317 46 my $len = length($text);
6318 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 table42%3/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
6319 || $len > 4 && $text eq '#<<< ' )
6320 {
6321 6 push @{ $self->[_rnon_indenting_brace_stack_] },
6322 $last_nonblank_type_sequence;
6323 }
6324 }
6325 363 last;
6326 }
6327  
6328 # continue gathering identifier if necessary
6329 41684 ▶ if ($id_scan_state) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state) 17 41667 41684
6330  
6331 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
6332 10 $self->scan_id();
6333 }
6334 else {
6335 7 $self->scan_identifier();
6336 }
6337  
6338 17 ▶ if ($id_scan_state) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state) 1 16 17
6339  
6340 # Still scanning ...
6341 # Check for side comment between sub and prototype (c061)
6342  
6343 # done if nothing left to scan on this line
6344 1 ▶ last if ( $i > $max_token_index );
Branch: 1 branch
BranchTrueFalseTotal
if $i > $max_token_index 0 1 1
6345  
6346 1 my ( $next_nonblank_token_uu, $i_next ) =
6347 find_next_nonblank_token_on_this_line( $i, $rtokens,
6348 $max_token_index );
6349  
6350 # done if it was just some trailing space
6351 1 ▶ last if ( $i_next > $max_token_index );
Branch: 1 branch
BranchTrueFalseTotal
if $i_next > $max_token_index 0 1 1
6352  
6353 # something remains on the line ... must be a side comment
6354 1 next;
6355 }
6356  
6357 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
6358  
6359 # didn't find any token; start over
6360 7 $type = $pre_type;
6361 7 $tok = $pre_tok;
6362 }
6363  
6364 #-----------------------------------------------------------
6365 # Combine pre-tokens into digraphs and trigraphs if possible
6366 #-----------------------------------------------------------
6367  
6368 # See if we can make a digraph...
6369 # The following tokens are excluded and handled specially:
6370 # '/=' is excluded because the / might start a pattern.
6371 # 'x=' is excluded since it might be $x=, with $ on previous line
6372 # '**' and *= might be typeglobs of punctuation variables
6373 # I have allowed tokens starting with <, such as <=,
6374 # because I don't think these could be valid angle operators.
6375 # test file: storrs4.pl
6376 41674 ▶ 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]}) 3127 38547 41674
Condition100%6/6
$can_start_digraph{$tok} and $i < $max_token_index and $is_digraph{$tok . $$rtokens[$i + 1]}
!ll&&!rl&&r
3516833793127
$can_start_digraph{$tok} and $i < $max_token_index
!ll&&!rl&&r
350381306506
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
6377 && $i < $max_token_index
6378 && $is_digraph{ $tok . $rtokens->[ $i + 1 ] } )
6379 {
6380  
6381 3127 my $combine_ok = 1;
6382 3127 my $test_tok = $tok . $rtokens->[ $i + 1 ];
6383  
6384 # check for special cases which cannot be combined
6385  
6386 # Smartmatch is being deprecated, but may exist in older
6387 # scripts.
6388 3127 ▶ if ( $test_tok eq '~~' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($test_tok eq '~~') { } 111 3016 3127
elsif ($test_tok eq '//') { } 16 3000 3016
elsif ($test_tok eq '**') { } 45 2955 3000
6389  
6390 # Do not combine if a TERM is required
6391 111 ▶ if ( $self->operator_expected( $tok, '~', undef ) == TERM )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->operator_expected($tok, "~", undef) == -1) 1 110 111
6392 {
6393  
6394 # block types ';' may actually be hash refs, c567
6395 1 ▶ if ( $last_nonblank_type eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq '}') { } 1 0 1
6396 1 my $blk = $rbrace_type->[ $brace_depth + 1 ];
6397 0 ▶ 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
6398 }
6399 else {
6400 0 $combine_ok = 0;
6401 }
6402 }
6403 }
6404  
6405 # '//' must be defined_or operator if an operator is expected.
6406 # TODO: Code for other ambiguous digraphs (/=, x=, **, *=)
6407 # could be migrated here for clarity
6408  
6409 # Patch for RT#102371, misparsing a // in the following snippet:
6410 # state $b //= ccc();
6411 # The solution is to always accept the digraph (or trigraph)
6412 # after type 'Z' (possible file handle). The reason is that
6413 # sub operator_expected gives TERM expected here, which is
6414 # wrong in this case.
6415 elsif ( $test_tok eq '//' ) {
6416 16 ▶ if ( $last_nonblank_type ne 'Z' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type ne "Z") 16 0 16
6417  
6418 # note that here $tok = '/' and the next tok and type
6419 # is '/'
6420 16 my $blank_after_Z;
6421 16 $expecting =
6422 $self->operator_expected( $tok, '/', $blank_after_Z );
6423  
6424 # Patched for RT#101547, was
6425 # 'unless ($expecting==OPERATOR)'
6426 16 ▶ $combine_ok = 0 if ( $expecting == TERM );
Branch: 1 branch
BranchTrueFalseTotal
if $expecting == -1 4 12 16
6427 }
6428 }
6429  
6430 # Patch for RT #114359: mis-parsing of "print $x ** 0.5;
6431 # Accept the digraphs '**' only after type 'Z'
6432 # Otherwise postpone the decision.
6433 elsif ( $test_tok eq '**' ) {
6434 45 ▶ if ( $last_nonblank_type ne 'Z' ) { $combine_ok = 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type ne "Z") 43 2 45
6435 }
6436 else {
6437 ## no other special cases
6438 }
6439  
6440 3127 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($combine_ok and $test_tok ne "/=" and $test_tok ne "x=" and $test_tok ne "*=") 3074 53 3127
Condition88%8/9
$combine_ok and $test_tok ne "/=" and $test_tok ne "x=" and $test_tok ne "*="
!ll&&!rl&&r
5123074
$combine_ok and $test_tok ne "/=" and $test_tok ne "x="
!ll&&!rl&&r
5103076
$combine_ok and $test_tok ne "/="
!ll&&!rl&&r
4743076
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
6441  
6442 # still ok to combine?
6443 $combine_ok
6444  
6445 && ( $test_tok ne '/=' ) # might be pattern
6446 && ( $test_tok ne 'x=' ) # might be $x
6447 && ( $test_tok ne '*=' ) # typeglob?
6448  
6449 # Moved above as part of fix for
6450 # RT #114359: Missparsing of "print $x ** 0.5;
6451 # && ( $test_tok ne '**' ) # typeglob?
6452 )
6453 {
6454 3074 $tok = $test_tok;
6455 3074 $i++;
6456  
6457 # Now try to assemble trigraphs. Note that all possible
6458 # perl trigraphs can be constructed by appending a character
6459 # to a digraph.
6460 3074 $test_tok = $tok . $rtokens->[ $i + 1 ];
6461  
6462 3074 ▶ if ( $is_trigraph{$test_tok} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_trigraph{$test_tok}) { } 105 2969 3074
6463 105 $tok = $test_tok;
6464 105 $i++;
6465 }
6466  
6467 # The only current tetragraph is the double diamond operator
6468 # and its first three characters are NOT a trigraph, so
6469 # we do can do a special test for it
6470 else {
6471 2969 ▶ if ( $test_tok eq '<<>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test_tok eq "<<>") 1 2968 2969
6472 1 $test_tok .= $rtokens->[ $i + 2 ];
6473 1 ▶ if ( $is_tetragraph{$test_tok} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_tetragraph{$test_tok}) 1 0 1
6474 1 $tok = $test_tok;
6475 1 $i += 2;
6476 }
6477 }
6478 }
6479 }
6480 }
6481  
6482 41674 $type = $tok;
6483 41674 $next_tok = $rtokens->[ $i + 1 ];
6484 41674 $next_type = $rtoken_type->[ $i + 1 ];
6485  
6486 # expecting an operator here? first try table lookup, then function
6487 41674 $expecting = $op_expected_table{$last_nonblank_type};
6488 41674 ▶ if ( !defined($expecting) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $expecting) 11882 29792 41674
6489 11882 ▶ 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
118353413
$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
6490 && ( $i == 0 || $rtoken_type->[ $i - 1 ] eq 'b' );
6491 11882 $expecting =
6492 $self->operator_expected( $tok, $next_type, $blank_after_Z );
6493 }
6494  
6495 41674 DEBUG_TOKENIZE && do {
6496 local $LIST_SEPARATOR = ')(';
6497 my @debug_list = (
6498 $last_nonblank_token, $tok,
6499 $next_tok, $brace_depth,
6500 $rbrace_type->[$brace_depth], $paren_depth,
6501 $rparen_type->[$paren_depth],
6502 );
6503 print {*STDOUT} "TOKENIZE:(@debug_list)\n";
6504 };
6505  
6506 # The next token is '$tok'.
6507 # Now we have to define its '$type'
6508  
6509 #------------------------
6510 # END NODE 3: a bare word
6511 #------------------------
6512 41674 ▶ if ( $pre_type eq 'w' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre_type eq "w") 6747 34927 41674
6513 6747 my $is_last = $self->do_BAREWORD();
6514 6747 ▶ last if ($is_last);
Branch: 1 branch
BranchTrueFalseTotal
if $is_last 9 6738 6747
6515 6738 next;
6516 }
6517  
6518 # Turn off attribute list on first non-blank, non-bareword,
6519 # and non-comment (added to fix c038)
6520 34927 $self->[_in_attribute_list_] = 0;
6521  
6522 #-------------------------------
6523 # END NODE 4: a string of digits
6524 #-------------------------------
6525 34927 ▶ if ( $pre_type eq 'd' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre_type eq "d") 2521 32406 34927
6526 2521 $self->do_DIGITS();
6527 2521 next;
6528 }
6529  
6530 #------------------------------------------
6531 # END NODE 5: everything else (punctuation)
6532 #------------------------------------------
6533 32406 my $code = $tokenization_code->{$tok};
6534 32406 ▶ if ($code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code) 30128 2278 32406
6535 30128 $code->($self);
6536 30128 ▶ redo if ($in_quote);
Branch: 1 branch
BranchTrueFalseTotal
if $in_quote 2734 27394 30128
6537 }
6538  
6539 # Check for a non-TERM where a TERM is expected. Note that this
6540 # checks all symbols, even those without a $code (update c566)
6541 29672 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) 11920 17752 29672
6542 my $is_not_term =
6543 $type eq ';'
6544 || $type eq ','
6545 11920 ▶ || $is_binary_operator_type{$type};
Condition100%6/6
$type eq ';' || $type eq ',' || $is_binary_operator_type{$type}
l!l&&r!l&&!r
2611611643
$type eq ";" or $type eq ","
l!l&&r!l&&!r
2154611659
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
6546 11920 ▶ if ($is_not_term) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_not_term) 277 11643 11920
6547 277 $self->error_if_expecting_TERM();
6548 }
6549 }
6550 } ## End main tokenizer loop
6551  
6552 # Store the final token
6553 6997 ▶ if ( $i_tok >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_tok >= 0) 6808 189 6997
6554 6808 $routput_token_type->[$i_tok] = $type;
6555 6808 $routput_block_type->[$i_tok] = $block_type;
6556 6808 $routput_type_sequence->[$i_tok] = $type_sequence;
6557 6808 $routput_indent_flag->[$i_tok] = $indent_flag;
6558 }
6559  
6560 # Remember last nonblank values
6561 6997 ▶ if ( $type ne 'b' && $type ne '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type ne "b" and $type ne "#") 6486 511 6997
Condition100%3/3
$type ne "b" and $type ne "#"
!ll&&!rl&&r
1483636486
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
6562  
6563 6486 $last_last_nonblank_token = $last_nonblank_token;
6564 6486 $last_last_nonblank_type = $last_nonblank_type;
6565  
6566 6486 $last_nonblank_prototype = $prototype;
6567 6486 $last_nonblank_block_type = $block_type;
6568 6486 $last_nonblank_container_type = $container_type;
6569 6486 $last_nonblank_type_sequence = $type_sequence;
6570 6486 $last_nonblank_token = $tok;
6571 6486 $last_nonblank_type = $type;
6572 }
6573  
6574 # reset indentation level if necessary at a sub or package
6575 # in an attempt to recover from a nesting error
6576 6997 ▶ if ( $level_in_tokenizer < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level_in_tokenizer < 0) 0 6997 6997
6577 0 ▶ if ( $input_line =~ /^\s*(sub|package)\s+(\w+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /^\s*(sub|package)\s+(\w+)/) 0 0 0
6578 0 reset_indentation_level(0);
6579 0 $self->brace_warning("resetting level to 0 at $1 $2\n");
6580 }
6581 }
6582  
6583 6997 $self->[_in_quote_] = $in_quote;
6584 $self->[_quote_target_] =
6585 $in_quote
6586 ? (
6587 $matching_end_token{$quote_character}
6588 6997 ▶ ? $matching_end_token{$quote_character}
Branch: 2 branches
BranchTrueFalseTotal
$in_quote ? : 245 6752 6997
$matching_end_token{$quote_character} ? : 187 58 245
6589 : $quote_character
6590 )
6591 : EMPTY_STRING;
6592 6997 $self->[_rhere_target_list_] = $rhere_target_list;
6593  
6594 6997 return;
6595 } ## end sub tokenizer_main_loop
6596  
6597 6997 ▶ sub tokenizer_wrapup_line {
Subroutine tokenizer_wrapup_line: called CC=43 SCAR=38.7
Pod undocumented
6598 6997 my ( $self, $line_of_tokens ) = @_;
6599  
6600 #---------------------------------------------------------
6601 # Package a line of tokens for shipping back to the caller
6602 #---------------------------------------------------------
6603  
6604 # Arrays to hold token values for this line:
6605 my (
6606 6997 @output_levels, @output_block_type, @output_type_sequence,
6607 @output_token_type, @output_tokens,
6608 );
6609  
6610 6997 $line_of_tokens->{_nesting_tokens_0} = $nesting_token_string;
6611  
6612 # Remember starting nesting block string
6613 6997 my $nesting_block_string_0 = $nesting_block_string;
6614  
6615 #-----------------
6616 # Loop over tokens
6617 #-----------------
6618 # $i is the index of the pretoken which starts this full token
6619 6997 foreach my $ii ( @{$routput_token_list} ) {
6620  
6621 60477 my $type_i = $routput_token_type->[$ii];
6622  
6623 #----------------------------------------
6624 # Section 1. Handle a non-sequenced token
6625 #----------------------------------------
6626 60477 ▶ if ( !$routput_type_sequence->[$ii] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $routput_type_sequence->[$ii]) { } 49395 11082 60477
6627  
6628 #-------------------------------
6629 # Section 1.1. types ';' and 't'
6630 #-------------------------------
6631 # - output anonymous 'sub' as keyword (type 'k')
6632 # - output __END__, __DATA__, and format as type 'k' instead
6633 # of ';' to make html colors correct, etc.
6634 49395 ▶ if ( $is_semicolon_or_t{$type_i} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_semicolon_or_t{$type_i}) { } 3232 46163 49395
elsif (not $is_valid_token_type{$type_i}) { } 0 46163 46163
6635 3232 my $tok_i = $rtokens->[$ii];
6636 3232 ▶ if ( $is_END_DATA_format_sub{$tok_i} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_END_DATA_format_sub{$tok_i}) 189 3043 3232
6637 189 $type_i = 'k';
6638 }
6639 }
6640  
6641 #----------------------------------------------
6642 # Section 1.2. Check for an invalid token type.
6643 #----------------------------------------------
6644 # This can happen by running perltidy on non-scripts although
6645 # it could also be bug introduced by programming change. Perl
6646 # silently accepts a 032 (^Z) and takes it as the end
6647 elsif ( !$is_valid_token_type{$type_i} ) {
6648 0 ▶ if ( !$self->[_in_error_] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[7]) 0 0 0
6649 0 my $val = ord($type_i);
6650 0 $self->warning(
6651 "unexpected character decimal $val ($type_i) in script\n"
6652 );
6653 0 $self->[_in_error_] = 1;
6654 }
6655 }
6656 else {
6657 ## valid token type other than ; and t
6658 }
6659  
6660 #----------------------------------------------------
6661 # Section 1.3. Store values for a non-sequenced token
6662 #----------------------------------------------------
6663 49395 push @output_levels, $level_in_tokenizer;
6664 49395 push @output_block_type, EMPTY_STRING;
6665 49395 push @output_type_sequence, EMPTY_STRING;
6666 49395 push @output_token_type, $type_i;
6667  
6668 }
6669  
6670 #------------------------------------
6671 # Section 2. Handle a sequenced token
6672 # One of { [ ( ? : ) ] }
6673 #------------------------------------
6674 else {
6675  
6676 # $level_i is the level we will store. Levels of braces are
6677 # set so that the leading braces have a HIGHER level than their
6678 # CONTENTS, which is convenient for indentation.
6679 11082 my $level_i = $level_in_tokenizer;
6680  
6681 # $tok_i is the PRE-token. It only equals the token for symbols
6682 11082 my $tok_i = $rtokens->[$ii];
6683  
6684 # $routput_indent_flag->[$ii] indicates that we need a change
6685 # in level at a nested ternary, as follows
6686 # 1 => at a nested ternary ?
6687 # -1 => at a nested ternary :
6688 # 0 => otherwise
6689  
6690 #--------------------------------------------
6691 # Section 2.1 Handle a level-increasing token
6692 #--------------------------------------------
6693 11082 ▶ if ( $is_opening_or_ternary_type{$type_i} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_opening_or_ternary_type{$type_i}) { } 5541 5541 11082
elsif ($is_closing_or_ternary_type{$type_i}) { } 5541 0 5541
6694  
6695 5541 ▶ if ( $type_i eq '?' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_i eq '?') { } 193 5348 5541
6696  
6697 193 ▶ if ( $routput_indent_flag->[$ii] > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($routput_indent_flag->[$ii] > 0) 8 185 193
6698 8 $level_in_tokenizer++;
6699  
6700 # break BEFORE '?' in a nested ternary
6701 8 $level_i = $level_in_tokenizer;
6702 8 $nesting_block_string .= "$nesting_block_flag";
6703  
6704 }
6705 }
6706 else {
6707  
6708 5348 $nesting_token_string .= $tok_i;
6709  
6710 5348 ▶ if ( $type_i eq '{' || $type_i eq 'L' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_i eq "{" or $type_i eq "L") 4908 440 5348
Condition100%3/3
$type_i eq "{" or $type_i eq "L"
l!l&&r!l&&!r
4320588440
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
6711  
6712 4908 $level_in_tokenizer++;
6713  
6714 4908 ▶ if ( $routput_block_type->[$ii] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($routput_block_type->[$ii]) { } 1159 3749 4908
6715 1159 $nesting_block_flag = 1;
6716 1159 $nesting_block_string .= '1';
6717 }
6718 else {
6719 3749 $nesting_block_flag = 0;
6720 3749 $nesting_block_string .= '0';
6721 }
6722 }
6723 }
6724 }
6725  
6726 #---------------------------------------------
6727 # Section 2.2. Handle a level-decreasing token
6728 #---------------------------------------------
6729 elsif ( $is_closing_or_ternary_type{$type_i} ) {
6730  
6731 5541 ▶ if ( $type_i ne ':' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_i ne ":") 5348 193 5541
6732 5348 my $char = chop $nesting_token_string;
6733 5348 ▶ if ( $char ne $matching_start_token{$tok_i} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char ne $matching_start_token{$tok_i}) 0 5348 5348
6734 0 $nesting_token_string .= $char . $tok_i;
6735 }
6736 }
6737  
6738 5541 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($type_i eq "}" or $type_i eq "R" or $type_i eq ":" and $routput_indent_flag->[$ii] < 0) 4916 625 5541
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
49088625
$type_i eq "}" or $type_i eq "R"
l!l&&r!l&&!r
4320588633
$type_i eq ":" and $routput_indent_flag->[$ii] < 0
!ll&&!rl&&r
4401858
MC/DC100%4/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 table100%5/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
6739 $type_i eq '}'
6740 || $type_i eq 'R'
6741  
6742 # only the second and higher ? : have levels
6743 || $type_i eq ':' && $routput_indent_flag->[$ii] < 0
6744 )
6745 {
6746  
6747 4916 $level_i = --$level_in_tokenizer;
6748  
6749 4916 ▶ if ( $level_in_tokenizer < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level_in_tokenizer < 0) 0 4916 4916
6750 0 ▶ if ( !$self->[_saw_negative_indentation_] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[34]) 0 0 0
6751 0 $self->[_saw_negative_indentation_] = 1;
6752 0 $self->warning(
6753 "Starting negative indentation\n");
6754 }
6755 }
6756  
6757 # restore previous level values
6758 4916 ▶ if ( length($nesting_block_string) > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (length $nesting_block_string > 1) 4916 0 4916
6759 { # true for valid script
6760 4916 chop $nesting_block_string;
6761 4916 $nesting_block_flag =
6762 substr( $nesting_block_string, -1 ) eq '1';
6763 }
6764  
6765 }
6766 }
6767  
6768 #-----------------------------------------------------
6769 # Section 2.3. Unexpected sequenced token type - error
6770 #-----------------------------------------------------
6771 else {
6772  
6773 # The tokenizer should only be assigning sequence numbers
6774 # to types { [ ( ? ) ] } :
6775 0 DEVEL_MODE && Fault(<<EOM);
6776 unexpected sequence number on token type $type_i with pre-tok=$tok_i
6777 EOM
6778 }
6779  
6780 #------------------------------------------------
6781 # Section 2.4. Store values for a sequenced token
6782 #------------------------------------------------
6783  
6784 # The starting nesting block string, which is used in any .LOG
6785 # output, should include the first token of the line
6786 11082 ▶ if ( !@output_levels ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@output_levels) 1809 9273 11082
6787 1809 $nesting_block_string_0 = $nesting_block_string;
6788 }
6789  
6790 # Store values for a sequenced token
6791 11082 push @output_levels, $level_i;
6792 11082 push @output_block_type, $routput_block_type->[$ii];
6793 11082 push @output_type_sequence, $routput_type_sequence->[$ii];
6794 11082 push @output_token_type, $type_i;
6795  
6796 }
6797 } ## End loop to over tokens
6798  
6799 #---------------------
6800 # Post-loop operations
6801 #---------------------
6802  
6803 6997 $line_of_tokens->{_nesting_blocks_0} = $nesting_block_string_0;
6804  
6805 # Form and store the tokens
6806 6997 ▶ if (@output_levels) {
Branch: 1 branch
BranchTrueFalseTotal
if (@output_levels) 6997 0 6997
6807  
6808 6997 my $im = shift @{$routput_token_list};
6809 6997 my $offset = $rtoken_map->[$im];
6810 6997 foreach my $ii ( @{$routput_token_list} ) {
6811 53480 my $numc = $rtoken_map->[$ii] - $offset;
6812 53480 push @output_tokens, substr( $input_line, $offset, $numc );
6813 53480 $offset += $numc;
6814  
6815 # programming note: it seems most efficient to 'next' out of
6816 # a critical loop like this as early as possible. So instead
6817 # of 'if ( DEVEL_MODE && $numc < 0 )' we write:
6818 53480 next unless (DEVEL_MODE);
6819 0 ▶ next if ( $numc > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $numc > 0 0 0 0
6820  
6821 # Should not happen unless @{$rtoken_map} is corrupted
6822 0 Fault("number of characters is '$numc' but should be >0\n");
6823 }
6824  
6825 # Form and store the final token of this line
6826 6997 my $numc = length($input_line) - $offset;
6827 6997 push @output_tokens, substr( $input_line, $offset, $numc );
6828  
6829 6997 if (DEVEL_MODE) {
6830 if ( $numc <= 0 ) {
6831  
6832 # check '$rtoken_map' and '$routput_token_list'
6833 Fault("Number of Characters is '$numc' but should be >0\n");
6834 }
6835  
6836 # Make sure we didn't gain or lose any characters
6837 my $test_line = join( EMPTY_STRING, @output_tokens );
6838 if ( $test_line ne $input_line ) {
6839 my $len_input = length($input_line);
6840 my $len_test = length($test_line);
6841  
6842 # check '$rtoken_map' and '$routput_token_list'
6843 Fault(<<EOM);
6844 Reconstructed line difers from input; input_length=$len_input test_length=$len_test
6845 input:'$input_line'
6846 test :'$test_line'
6847 EOM
6848 }
6849 }
6850 }
6851  
6852 # Wrap up this line of tokens for shipping to the Formatter
6853 6997 $line_of_tokens->{_rtoken_type} = \@output_token_type;
6854 6997 $line_of_tokens->{_rtokens} = \@output_tokens;
6855 6997 $line_of_tokens->{_rblock_type} = \@output_block_type;
6856 6997 $line_of_tokens->{_rtype_sequence} = \@output_type_sequence;
6857 6997 $line_of_tokens->{_rlevels} = \@output_levels;
6858  
6859 #-----------------------------------------------------------------
6860 # Compare input indentation with computed levels at closing braces
6861 #-----------------------------------------------------------------
6862 # This may provide a useful hint for error location if the file
6863 # is not balanced in braces. Closing braces are used because they
6864 # have a well-defined indentation and can be processed efficiently.
6865 6997 ▶ if ( $output_tokens[0] eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($output_tokens[0] eq "}") 760 6237 6997
6866  
6867 760 my $blk = $output_block_type[0];
6868 760 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($is_zero_continuation_block_type{$blk} || substr($blk, 0, 4) eq "sub " and not $self->[13]) 417 343 760
Condition83%5/6
$is_zero_continuation_block_type{$blk} || substr($blk, 0, 4) eq "sub " and not $self->[13]
!ll&&!rl&&r
3430417
$is_zero_continuation_block_type{$blk} or substr($blk, 0, 4) eq "sub "
l!l&&r!l&&!r
32097343
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
6869 (
6870 # builtin block types without continuation indentation
6871 $is_zero_continuation_block_type{$blk}
6872  
6873 # or a named sub, but skip sub aliases for efficiency,
6874 # since this is just for diagnostic info
6875 || substr( $blk, 0, 4 ) eq 'sub '
6876 )
6877  
6878 # and we are not in format skipping
6879 && !$self->[_in_format_skipping_]
6880 )
6881 {
6882  
6883 # subtract 1 space for newline in untrimmed line
6884 417 my $untrimmed_input_line = $line_of_tokens->{_line_text};
6885 417 my $space_count =
6886 length($untrimmed_input_line) - length($input_line) - 1;
6887  
6888 # check for tabs
6889 417 ▶ if ( $space_count
Branch: 1 branch
BranchTrueFalseTotal
if ($space_count and ord substr($untrimmed_input_line, 0, 1) == 9) 15 402 417
Condition100%3/3
$space_count and ord substr($untrimmed_input_line, 0, 1) == 9
!ll&&!rl&&r
22717515
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
6890 && ord( substr( $untrimmed_input_line, 0, 1 ) ) == ORD_TAB )
6891 {
6892 15 ▶ if ( $untrimmed_input_line =~ /^(\t+)?(\s+)?/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($untrimmed_input_line =~ /^(\t+)?(\s+)?/) 15 0 15
6893 15 ▶ if ($1) { $space_count += length($1) * $tabsize }
Branch: 1 branch
BranchTrueFalseTotal
if ($1) 15 0 15
6894 15 ▶ if ($2) { $space_count += length($2) }
Branch: 1 branch
BranchTrueFalseTotal
if ($2) 1 14 15
6895 }
6896 }
6897  
6898 # '$guess' = the level according to indentation
6899 417 my $guess = int( $space_count / $rOpts_indent_columns );
6900  
6901 # subtract 1 level from guess for --indent-closing-brace
6902 417 ▶ $guess -= 1 if ($rOpts_indent_closing_brace);
Branch: 1 branch
BranchTrueFalseTotal
if $rOpts_indent_closing_brace 3 414 417
6903  
6904 # subtract 1 from $level for each non-indenting brace level
6905 417 my $adjust = @{ $self->[_rnon_indenting_brace_stack_] };
6906  
6907 417 my $level = $output_levels[0];
6908  
6909 # find the difference between expected and indentation guess
6910 417 my $level_diff = $level - $adjust - $guess;
6911  
6912 417 my $rhash = $self->[_rclosing_brace_indentation_hash_];
6913  
6914 # results are only valid if we guess correctly at the
6915 # first spaced brace
6916 417 ▶ if ( $space_count && !defined( $rhash->{valid} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($space_count and not defined $rhash->{"valid"}) 83 334 417
Condition100%3/3
$space_count and not defined $rhash->{"valid"}
!ll&&!rl&&r
22710783
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
6917 83 $rhash->{valid} = !$level_diff;
6918 }
6919  
6920 # save the result
6921 417 my $rhistory_line_number = $rhash->{rhistory_line_number};
6922 417 my $rhistory_level_diff = $rhash->{rhistory_level_diff};
6923 417 my $rhistory_anchor_point = $rhash->{rhistory_anchor_point};
6924  
6925 417 ▶ if ( $rhistory_level_diff->[-1] != $level_diff ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rhistory_level_diff->[-1] != $level_diff) { } 55 362 417
6926  
6927 # Patch for non-indenting-braces: if we guess zero and
6928 # match before all non-indenting braces have been found,
6929 # it means that we would need negative indentation to
6930 # match if/when the brace is found. So we have a problem
6931 # from here on. We indicate this with a value 2 instead
6932 # of 1 as a signal to stop outputting the table here.
6933 55 my $anchor = 1;
6934 0 ▶ 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
6935  
6936 # add an anchor point
6937 55 push @{$rhistory_level_diff}, $level_diff;
6938 55 push @{$rhistory_line_number}, $input_line_number;
6939 55 push @{$rhistory_anchor_point}, $anchor;
6940 }
6941 else {
6942  
6943 # add a movable point following an anchor point
6944 362 ▶ if ( $rhistory_anchor_point->[-1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rhistory_anchor_point->[-1]) { } 164 198 362
6945 164 push @{$rhistory_level_diff}, $level_diff;
6946 164 push @{$rhistory_line_number}, $input_line_number;
6947 164 push @{$rhistory_anchor_point}, 0;
6948 }
6949  
6950 # extend a movable point
6951 else {
6952 198 $rhistory_line_number->[-1] = $input_line_number;
6953 }
6954 }
6955 }
6956 }
6957  
6958 6997 return;
6959 } ## end sub tokenizer_wrapup_line
6960  
6961 } ## end tokenize_this_line
6962  
6963 #######################################################################
6964 # Tokenizer routines which assist in identifying token types
6965 #######################################################################
6966  
6967 # Define Global '%op_expected_table'
6968 # = hash table of operator expected values based on last nonblank token
6969  
6970 # exceptions to perl's weird parsing rules after type 'Z'
6971 45 my %is_weird_parsing_rule_exception;
6972  
6973 my %is_paren_dollar;
6974  
6975 45 my %is_n_v;
6976  
6977 45 ▶BEGIN {
Subroutine BEGIN: called CC=6 SCAR=17.9
6978  
6979 # Always expecting TERM following these types:
6980 # note: this is identical to '@value_requestor_type' defined later.
6981 # Fix for c250: add new type 'P' for package (expecting VERSION or {}
6982 # after package NAMESPACE, so expecting TERM)
6983 # Fix for c250: add new type 'S' for sub (not expecting operator)
6984 45 my @q = qw#
6985 ; ! + x & ? F J - p / Y : % f U ~ A G j L P S * . | ^ < = [ m { > t
6986 || >= != mm *= => .. !~ == && |= .= pp -= =~ += <= %= ^= x= ~~ ** << /=
6987 &= // >> ~. &. |. ^.
6988 ... **= <<= >>= &&= ||= //= <=> !~~ &.= |.= ^.= <<~
6989 #;
6990 45 push @q, BACKSLASH;
6991 45 push @q, COMMA;
6992 45 push @q, '('; # for completeness, not currently a token type
6993 45 push @q, '->'; # was previously in UNKNOWN
6994 45 $op_expected_table{$_} = TERM for @q;
6995  
6996 # No UNKNOWN table types:
6997 # removed '->' for c030, now always TERM
6998 # removed 'w' for c392 to allow use of 'function_count' info in the sub
6999  
7000 # Always expecting OPERATOR ...
7001 # 'n' and 'v' are currently excluded because they might be VERSION numbers
7002 # 'i' is currently excluded because it might be a package
7003 # 'q' is currently excluded because it might be a prototype
7004 # Fix for c030: removed '->' from this list:
7005 # Fix for c250: added 'i' because new type 'P' was added
7006 45 @q = qw( -- C h R ++ ] Q <> i );
7007 45 push @q, ')';
7008 45 $op_expected_table{$_} = OPERATOR for @q;
7009  
7010 # Fix for git #62: added '*' and '%'
7011 45 @q = qw( < ? * % );
7012 45 $is_weird_parsing_rule_exception{$_} = 1 for @q;
7013  
7014 45 @q = qw<) $>;
7015 45 $is_paren_dollar{$_} = 1 for @q;
7016  
7017 45 @q = qw( n v );
7018 45 $is_n_v{$_} = 1 for @q;
7019  
7020 } ## end BEGIN
7021  
7022 45 ▶use constant DEBUG_OPERATOR_EXPECTED => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
7023  
7024 12024 ▶sub operator_expected {
Subroutine operator_expected: called CC=46 SCAR=38.6
Pod undocumented
7025  
7026 12024 my ( $self, $tok, $next_type, $blank_after_Z ) = @_;
7027  
7028 # Returns a parameter indicating what types of tokens can occur next
7029  
7030 # Call format:
7031 # $op_expected =
7032 # $self->operator_expected( $tok, $next_type, $blank_after_Z );
7033 # where
7034 # $tok is the current token
7035 # $next_type is the type of the next token (blank or not)
7036 # $blank_after_Z = flag for guessing after a type 'Z':
7037 # true if $tok follows type 'Z' with intermediate blank
7038 # false if $tok follows type 'Z' with no intermediate blank
7039 # ignored if $tok does not follow type 'Z'
7040  
7041 # Many perl symbols have two or more meanings. For example, '<<'
7042 # can be a shift operator or a here-doc operator. The
7043 # interpretation of these symbols depends on the current state of
7044 # the tokenizer, which may either be expecting a term or an
7045 # operator. For this example, a << would be a shift if an OPERATOR
7046 # is expected, and a here-doc if a TERM is expected. This routine
7047 # is called to make this decision for any current token. It returns
7048 # one of three possible values:
7049 #
7050 # OPERATOR - operator expected (or at least, not a term)
7051 # UNKNOWN - can't tell
7052 # TERM - a term is expected (or at least, not an operator)
7053 #
7054 # The decision is based on what has been seen so far. This
7055 # information is stored in the "$last_nonblank_type" and
7056 # "$last_nonblank_token" variables. For example, if the
7057 # $last_nonblank_type is '=~', then we are expecting a TERM, whereas
7058 # if $last_nonblank_type is 'n' (numeric), we are expecting an
7059 # OPERATOR.
7060 #
7061 # If a UNKNOWN is returned, the calling routine must guess. A major
7062 # goal of this tokenizer is to minimize the possibility of returning
7063 # UNKNOWN, because a wrong guess can spoil the formatting of a
7064 # script.
7065 #
7066 # Adding NEW_TOKENS: it is critically important that this routine be
7067 # updated to allow it to determine if an operator or term is to be
7068 # expected after the new token. Doing this simply involves adding
7069 # the new token character to one of the regexes in this routine or
7070 # to one of the hash lists
7071 # that it uses, which are initialized in the BEGIN section.
7072 # USES GLOBAL VARIABLES: $last_nonblank_type, $last_nonblank_token,
7073 # $statement_type
7074  
7075 # When possible, token types should be selected such that we can determine
7076 # the 'operator_expected' value by a simple hash lookup. If there are
7077 # exceptions, that is an indication that a new type is needed.
7078  
7079 #--------------------------------------------
7080 # Section 1: Table lookup will get most cases
7081 #--------------------------------------------
7082  
7083 # Many types are can be obtained by a table lookup. This typically handles
7084 # more than half of the calls. For speed, the caller may try table lookup
7085 # first before calling this sub.
7086 12024 my $op_expected = $op_expected_table{$last_nonblank_type};
7087 12024 ▶ if ( defined($op_expected) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $op_expected) 78 11946 12024
7088 DEBUG_OPERATOR_EXPECTED
7089 78 && print {*STDOUT}
7090 "OPERATOR_EXPECTED: Table Lookup; returns $op_expected for last type $last_nonblank_type token $last_nonblank_token\n";
7091 78 return $op_expected;
7092 }
7093  
7094 DEBUG_OPERATOR_EXPECTED
7095 11946 && print {*STDOUT}
7096 "OPERATOR_EXPECTED: in hardwired table for last type $last_nonblank_type token $last_nonblank_token\n";
7097  
7098 #---------------------------------------------
7099 # Section 2: Handle special cases if necessary
7100 #---------------------------------------------
7101  
7102 # Types 'k', '}' and 'Z' depend on context
7103 # Types 'n', 'v', 'q' also depend on context.
7104  
7105 # identifier...
7106 # Fix for c250: removed coding for type 'i' because 'i' and new type 'P'
7107 # are now done by hash table lookup
7108  
7109 #--------------------
7110 # Section 2A: keyword
7111 #--------------------
7112 11946 ▶ if ( $last_nonblank_type eq 'k' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq "k") 3145 8801 11946
7113  
7114 # keywords expecting TERM:
7115 3145 ▶ if ( $expecting_term_token{$last_nonblank_token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting_term_token{$last_nonblank_token}) 3022 123 3145
7116  
7117 # Exceptions from TERM:
7118  
7119 # // may follow perl functions which may be unary operators
7120 # see test file dor.t (defined or);
7121 3022 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "/" and $next_type eq "/" and $is_keyword_rejecting_slash_as_pattern_delimiter{$last_nonblank_token}) 1 3021 3022
Condition100%6/6
$tok eq "/" and $next_type eq "/" and $is_keyword_rejecting_slash_as_pattern_delimiter{$last_nonblank_token}
!ll&&!rl&&r
301921
$tok eq "/" and $next_type eq "/"
!ll&&!rl&&r
3008113
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
7122 $tok eq '/'
7123 && $next_type eq '/'
7124 && $is_keyword_rejecting_slash_as_pattern_delimiter{
7125 $last_nonblank_token}
7126 )
7127 {
7128 1 return OPERATOR;
7129 }
7130  
7131 # Patch to allow a ? following 'split' to be a deprecated pattern
7132 # delimiter. This patch is coordinated with the omission of split
7133 # from the list
7134 # %is_keyword_rejecting_question_as_pattern_delimiter. This patch
7135 # will force perltidy to guess.
7136 3021 ▶ if ( $tok eq '?'
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "?" and $last_nonblank_token eq "split") 0 3021 3021
Condition66%2/3
$tok eq "?" and $last_nonblank_token eq "split"
!ll&&!rl&&r
302010
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
7137 && $last_nonblank_token eq 'split' )
7138 {
7139 0 return UNKNOWN;
7140 }
7141  
7142 3021 return TERM;
7143 }
7144  
7145 # keywords expecting OPERATOR:
7146 123 ▶ if ( $expecting_operator_token{$last_nonblank_token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting_operator_token{$last_nonblank_token}) 7 116 123
7147 7 return OPERATOR;
7148 }
7149  
7150 116 return TERM;
7151  
7152 } ## end type 'k'
7153  
7154 #------------------------------------
7155 # Section 2B: Closing container token
7156 #------------------------------------
7157  
7158 # Note that the actual token for type '}' may also be a ')'.
7159  
7160 # Also note that $last_nonblank_token is not the token corresponding to
7161 # $last_nonblank_type when the type is a closing container. In that
7162 # case it is the token before the corresponding opening container token.
7163 # So for example, for this snippet
7164 # $a = do { BLOCK } / 2;
7165 # the $last_nonblank_token is 'do' when $last_nonblank_type eq '}'.
7166  
7167 8801 ▶ if ( $last_nonblank_type eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq "}") 4202 4599 8801
7168  
7169 #-------------------------------------------
7170 # Section 2B1: Closing structural ')' or ']'
7171 #-------------------------------------------
7172 4202 ▶ if ( $last_nonblank_token eq ')' || $last_nonblank_token eq ']' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_token eq ")" or $last_nonblank_token eq "]") 2821 1381 4202
Condition100%3/3
$last_nonblank_token eq ")" or $last_nonblank_token eq "]"
l!l&&r!l&&!r
24463751381
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
7173 2821 return OPERATOR;
7174 }
7175  
7176 #-------------------------------------
7177 # Section 2B2: Closing block brace '}'
7178 #-------------------------------------
7179 1381 my $blk = $rbrace_type->[ $brace_depth + 1 ];
7180  
7181 # Non-blocks
7182 1381 ▶ if ( !defined($blk) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $blk) 2 1379 1381
7183 2 return OPERATOR;
7184 }
7185  
7186 # Unidentified block type
7187 1379 ▶ if ( !$blk ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($blk) 367 1012 1379
7188 367 return UNKNOWN;
7189 }
7190  
7191 # Blocks followed by a TERM
7192 1012 ▶ 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/) 663 349 1012
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
6576349
$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
545112355
$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
52619467
$is_zero_continuation_block_type{$blk} or $is_sort_map_grep{$blk} or $is_grep_alias{$blk}
l!l&&r!l&&!r
5215486
$is_zero_continuation_block_type{$blk} or $is_sort_map_grep{$blk}
l!l&&r!l&&!r
42695491
substr($blk, -1, 1) eq ":" and $blk =~ /^\w+:$/
!ll&&!rl&&r
4541319
substr($blk, 0, 3) eq "sub" and $blk =~ /^sub\s/
!ll&&!rl&&r
163192112
substr($blk, 0, 7) eq "package" and $blk =~ /^package\s/
!ll&&!rl&&r
34906
MC/DC88%8/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 table50%9/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
7193 || $is_sort_map_grep{$blk}
7194 || $is_grep_alias{$blk}
7195 || substr( $blk, -1, 1 ) eq ':' && $blk =~ /^\w+:$/
7196 || substr( $blk, 0, 3 ) eq 'sub' && $blk =~ /^sub\s/
7197 || substr( $blk, 0, 7 ) eq 'package' && $blk =~ /^package\s/ )
7198 {
7199 663 return TERM;
7200 }
7201  
7202 # Blocks followed by an OPERATOR
7203 # do eval sub
7204 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
7205 || $is_sub{$blk} )
7206 {
7207 279 return OPERATOR;
7208 }
7209  
7210 # Any other block type is marked UNKNOWN to be safe (c566).
7211 # For example, a block type marked ';' could be a hash ref:
7212 # { map { $_ => 'x' } keys %main:: } ~~ \%main::;
7213 # The tokenizer would have to analyze the contents to distinguish
7214 # between a block closure and a hash ref brace in this case. So mark
7215 # this as UNKNOWN and let the lower level routines figure it out.
7216 70 return UNKNOWN;
7217 }
7218  
7219 #-------------------------------
7220 # Section 2C: number or v-string
7221 #-------------------------------
7222 # An exception is for VERSION numbers a 'use' statement. It has the format
7223 # use Module VERSION LIST
7224 # We could avoid this exception by writing a special sub to parse 'use'
7225 # statements and perhaps mark these numbers with a new type V (for VERSION)
7226 4599 ▶ if ( $is_n_v{$last_nonblank_type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_n_v{$last_nonblank_type}) 2634 1965 4599
7227 2634 ▶ if ( $statement_type eq 'use' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($statement_type eq "use") 11 2623 2634
7228 11 return UNKNOWN;
7229 }
7230 2623 return OPERATOR;
7231 }
7232  
7233 #---------------------
7234 # Section 2D: qw quote
7235 #---------------------
7236 # TODO: labeled prototype words would better be given type 'A' or maybe
7237 # 'J'; not 'q'; or maybe mark as type 'Y'?
7238 1965 ▶ if ( $last_nonblank_type eq 'q' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq "q") 160 1805 1965
7239 160 ▶ if ( $last_nonblank_token eq 'prototype' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_token eq "prototype") 0 160 160
7240 0 return TERM;
7241 }
7242  
7243 # update for --use-feature=class (rt145706):
7244 # Look for class VERSION after possible attribute, as in
7245 # class Example::Subclass : isa(Example::Base) 1.345 { ... }
7246 160 ▶ if ( $statement_type =~ /^package\b/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($statement_type =~ /^package\b/) 3 157 160
7247 3 return TERM;
7248 }
7249  
7250 # everything else
7251 157 return OPERATOR;
7252 }
7253  
7254 #---------------------
7255 # Section 2E: bareword
7256 #---------------------
7257 1805 ▶ if ( $last_nonblank_type eq 'w' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq "w") 1754 51 1805
7258  
7259 # It is safest to return UNKNOWN if a possible ? pattern delimiter may
7260 # follow (git #32, c469) and let the guess algorithm handle it.
7261 1754 ▶ if ( $tok eq '?' ) { return UNKNOWN }
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "?") 7 1747 1754
7262  
7263 # see if this has been seen in the role of a function taking args
7264 1747 my $rinfo = $self->[_rbareword_info_]->{$current_package};
7265 1747 ▶ if ($rinfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rinfo) 1228 519 1747
7266 1228 $rinfo = $rinfo->{$last_nonblank_token};
7267 1228 ▶ if ($rinfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rinfo) 317 911 1228
7268 317 my $function_count = $rinfo->{function_count};
7269 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
7270 }
7271 }
7272 1612 return UNKNOWN;
7273 }
7274  
7275 #-----------------------------------
7276 # Section 2F: file handle or similar
7277 #-----------------------------------
7278 51 ▶ if ( $last_nonblank_type eq 'Z' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq "Z") 47 4 51
7279  
7280 # angle.t
7281 47 ▶ if ( $last_nonblank_token =~ /^\w/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_token =~ /^\w/) 2 45 47
7282 2 return UNKNOWN;
7283 }
7284  
7285 # Exception to weird parsing rules for 'x(' ... see case b1205:
7286 # In something like 'print $vv x(...' the x is an operator;
7287 # Likewise in 'print $vv x$ww' the x is an operator (case b1207)
7288 # otherwise x follows the weird parsing rules.
7289 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
7290 0 return OPERATOR;
7291 }
7292  
7293 # The 'weird parsing rules' of next section do not work for '<' and '?'
7294 # It is best to mark them as unknown. Test case:
7295 # print $fh <DATA>;
7296 45 ▶ if ( $is_weird_parsing_rule_exception{$tok} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_weird_parsing_rule_exception{$tok}) 4 41 45
7297 4 return UNKNOWN;
7298 }
7299  
7300 # For possible file handle like "$a", Perl uses weird parsing rules.
7301 # For example:
7302 # print $a/2,"/hi"; - division
7303 # print $a / 2,"/hi"; - division
7304 # print $a/ 2,"/hi"; - division
7305 # print $a /2,"/hi"; - pattern (and error)!
7306 # Some examples where this logic works okay, for '&','*','+':
7307 # print $fh &xsi_protos(@mods);
7308 # my $x = new $CompressClass *FH;
7309 # print $OUT +( $count % 15 ? ", " : "\n\t" );
7310 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
7311 && $next_type ne 'b' )
7312 {
7313 0 return TERM;
7314 }
7315  
7316 # Note that '?' and '<' have been moved above
7317 # ( $tok =~ /^([x\/\+\-\*\%\&\.\?\<]|\>\>)$/ ) {
7318 41 ▶ if ( $tok =~ /^([x\/\+\-\*\%\&\.]|\>\>)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok =~ m[^([x/\+\-\*\%\&\.]|\>\>)$]) 9 32 41
7319  
7320 # Do not complain in 'use' statements, which have special syntax.
7321 # For example, from RT#130344:
7322 # use lib $FindBin::Bin . '/lib';
7323 9 ▶ if ( $statement_type ne 'use' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($statement_type ne "use") 9 0 9
7324 9 $self->complain(
7325 "operator in possible indirect object location not recommended\n"
7326 );
7327 }
7328 9 return OPERATOR;
7329 }
7330  
7331 # all other cases
7332  
7333 32 return UNKNOWN;
7334 }
7335  
7336 #--------------------------
7337 # Section 2F: anything else
7338 #--------------------------
7339 4 return UNKNOWN;
7340  
7341 } ## end sub operator_expected
7342  
7343 50 ▶sub new_statement_ok {
Subroutine new_statement_ok: called CC=6 SCAR=18.2
Pod undocumented
7344  
7345 # Returns:
7346 # true if a new statement can begin here
7347 # false otherwise
7348  
7349 # USES GLOBAL VARIABLES: $last_nonblank_token, $last_nonblank_type,
7350 # $brace_depth, $rbrace_type
7351  
7352 # Uses:
7353 # - See if a 'class' statement can occur here
7354 # - See if a keyword begins at a new statement; i.e. is an 'if' a
7355 # block if or a trailing if? Also see if 'format' starts a statement.
7356 # - Decide if a ':' is part of a statement label (not a ternary)
7357  
7358 # Curly braces are tricky because some small blocks do not get marked as
7359 # blocks..
7360  
7361 # if it follows an opening curly brace..
7362 50 ▶ if ( $last_nonblank_token eq '{' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($last_nonblank_token eq '{') { } 4 46 50
elsif ($last_nonblank_token eq '}' and $last_nonblank_type eq $last_nonblank_token) { } 20 26 46
7363  
7364 # The safe thing is to return true in all cases because:
7365 # - a ternary ':' cannot occur here
7366 # - an 'if' here, for example, cannot be a trailing if
7367 # See test case c231 for an example.
7368 # This works but could be improved, if necessary, by returning
7369 # 'false' at obvious non-blocks.
7370 4 return 1;
7371 }
7372  
7373 # if it follows a closing code block curly brace..
7374 ▶ elsif ($last_nonblank_token eq '}'
Condition66%2/3
$last_nonblank_token eq "}" and $last_nonblank_type eq $last_nonblank_token
!ll&&!rl&&r
26020
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
7375 && $last_nonblank_type eq $last_nonblank_token )
7376 {
7377  
7378 # A new statement can follow certain closing block braces ...
7379 # Previously, a true was always returned, and this worked ok.
7380 # Update c443: now we return false for certain blocks which must be
7381 # followed by a ';'. See comments elsewhere on
7382 # '%is_zero_continuation_block_type'. The value of $brace_depth has
7383 # also been corrected, it was off by 1.
7384 20 my $block_type = $rbrace_type->[ $brace_depth + 1 ];
7385 return $block_type
7386 20 ▶ && !$is_sort_map_grep_eval_do_sub{$block_type};
Condition33%1/3
$block_type && !$is_sort_map_grep_eval_do_sub{$block_type}
!ll&&!rl&&r
0020
MC/DC0%0/2
$block_type && !$is_sort_map_grep_eval_do_sub{$block_type}
$block_type !$is_sort_map_grep_eval_do_sub{$block_type}
Truth table33%1/3
A && not(B)
A= $block_typeB= !$is_sort_map_grep_eval_do_sub{$block_type}
ABresult
0X0
100
111
7387 }
7388  
7389 # otherwise, it is a label if and only if it follows a ';' (real or fake)
7390 # or another label
7391 else {
7392 26 ▶ 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
1862
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
7393 }
7394 } ## end sub new_statement_ok
7395  
7396 1488 ▶sub code_block_type {
Subroutine code_block_type: called CC=26 SCAR=34.6
Pod undocumented
7397  
7398 1488 my ( $self, $i, $rtokens, $rtoken_type, $max_token_index ) = @_;
7399  
7400 # Decide if this is a block of code, and its type.
7401 # Must be called only when $type = $token = '{'
7402 # The problem is to distinguish between the start of a block of code
7403 # and the start of an anonymous hash reference
7404 # Returns "" if not code block, otherwise returns 'last_nonblank_token'
7405 # to indicate the type of code block. (For example, 'last_nonblank_token'
7406 # might be 'if' for an if block, 'else' for an else block, etc).
7407 # USES GLOBAL VARIABLES: $last_nonblank_token, $last_nonblank_type,
7408 # $last_nonblank_block_type, $brace_depth, $rbrace_type
7409  
7410 # handle case of multiple '{'s
7411  
7412 #print "BLOCK_TYPE EXAMINING: type=$last_nonblank_type tok=$last_nonblank_token\n";
7413  
7414 1488 ▶ if ( $last_nonblank_token eq '{'
Branch: 11 branches
BranchTrueFalseTotal
if ($last_nonblank_token eq '{' and $last_nonblank_type eq $last_nonblank_token) { } 98 1390 1488
elsif ($last_nonblank_token eq ';') { } 55 1335 1390
elsif ($last_nonblank_token eq '}' and $last_nonblank_type eq $last_nonblank_token) { } 10 1325 1335
elsif ($last_nonblank_type eq 'J') { } 34 1291 1325
elsif ($is_code_block_token{$last_nonblank_token} or $is_grep_alias{$last_nonblank_token}) { } 563 728 1291
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') { } 368 360 728
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
1390098
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
7415 && $last_nonblank_type eq $last_nonblank_token )
7416 {
7417  
7418 # opening brace where a statement may appear is probably
7419 # a code block but might be and anonymous hash reference
7420 98 ▶ if ( $rbrace_type->[$brace_depth] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rbrace_type->[$brace_depth]) { } 98 0 98
7421 98 return $self->decide_if_code_block( $i, $rtokens, $rtoken_type,
7422 $max_token_index );
7423 }
7424  
7425 # cannot start a code block within an anonymous hash
7426 else {
7427 0 return EMPTY_STRING;
7428 }
7429 }
7430  
7431 elsif ( $last_nonblank_token eq ';' ) {
7432  
7433 # an opening brace where a statement may appear is probably
7434 # a code block but might be and anonymous hash reference
7435 55 return $self->decide_if_code_block( $i, $rtokens, $rtoken_type,
7436 $max_token_index );
7437 }
7438  
7439 # handle case of '}{'
7440 ▶ elsif ($last_nonblank_token eq '}'
Condition66%2/3
$last_nonblank_token eq "}" and $last_nonblank_type eq $last_nonblank_token
!ll&&!rl&&r
1325010
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
7441 && $last_nonblank_type eq $last_nonblank_token )
7442 {
7443  
7444 # a } { situation ...
7445 # could be hash reference after code block..(blktype1.t)
7446 10 ▶ if ($last_nonblank_block_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_block_type) { } 10 0 10
7447 10 return $self->decide_if_code_block( $i, $rtokens, $rtoken_type,
7448 $max_token_index );
7449 }
7450  
7451 # must be a block if it follows a closing hash reference
7452 else {
7453 0 return $last_nonblank_token;
7454 }
7455 }
7456  
7457 #--------------------------------------------------------------
7458 # NOTE: braces after type characters start code blocks, but for
7459 # simplicity these are not identified as such. See also
7460 # sub is_non_structural_brace.
7461 #--------------------------------------------------------------
7462  
7463 ## elsif ( $last_nonblank_type eq 't' ) {
7464 ## return $last_nonblank_token;
7465 ## }
7466  
7467 # brace after label:
7468 elsif ( $last_nonblank_type eq 'J' ) {
7469 34 return $last_nonblank_token;
7470 }
7471  
7472 # otherwise, see if a block must follow the previous token (such as 'if'):
7473 ▶ 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
5585728
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
7474 || $is_grep_alias{$last_nonblank_token} )
7475 {
7476  
7477 # Bug Patch: Note that the opening brace after the 'if' in the following
7478 # snippet is an anonymous hash ref and not a code block!
7479 # print 'hi' if { x => 1, }->{x};
7480 # We can identify this situation because the last nonblank type
7481 # will be a keyword (instead of a closing paren)
7482 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
7483 $last_nonblank_type eq 'k'
7484 && ( $last_nonblank_token eq 'if'
7485 || $last_nonblank_token eq 'unless' )
7486 )
7487 {
7488 0 return EMPTY_STRING;
7489 }
7490 else {
7491 563 return $last_nonblank_token;
7492 }
7493 }
7494  
7495 # or a sub or package BLOCK
7496 # Fixed for c250 to include new package type 'P', and change 'i' to 'S'
7497 ▶ 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
200168360
$last_nonblank_type eq "P" or $last_nonblank_type eq "S"
l!l&&r!l&&!r
10190528
$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
7498 $last_nonblank_type eq 'P'
7499 || $last_nonblank_type eq 'S'
7500 || ( $last_nonblank_type eq 't'
7501 && substr( $last_nonblank_token, 0, 3 ) eq 'sub' )
7502 )
7503 {
7504 368 return $last_nonblank_token;
7505 }
7506  
7507 elsif ( $statement_type =~ /^(sub|package)\b/ ) {
7508 0 return $statement_type;
7509 }
7510  
7511 # user-defined subs with block parameters (like grep/map/eval)
7512 elsif ( $last_nonblank_type eq 'G' ) {
7513 0 return $last_nonblank_token;
7514 }
7515  
7516 # check bareword
7517 elsif ( $last_nonblank_type eq 'w' ) {
7518  
7519 # check for syntax 'use MODULE LIST'
7520 # This fixes b1022 b1025 b1027 b1028 b1029 b1030 b1031
7521 24 ▶ return EMPTY_STRING if ( $statement_type eq 'use' );
Branch: 1 branch
BranchTrueFalseTotal
if $statement_type eq "use" 1 23 24
7522  
7523 23 return $self->decide_if_code_block( $i, $rtokens, $rtoken_type,
7524 $max_token_index );
7525 }
7526  
7527 # Patch for bug # RT #94338 reported by Daniel Trizen
7528 # for-loop in a parenthesized block-map triggering an error message:
7529 # map( { foreach my $item ( '0', '1' ) { print $item} } qw(a b c) );
7530 # Check for a code block within a parenthesized function call
7531 elsif ( $last_nonblank_token eq '(' ) {
7532 89 my $paren_type = $rparen_type->[$paren_depth];
7533  
7534 # /^(map|grep|sort)$/
7535 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
7536  
7537 # We will mark this as a code block but use type 't' instead
7538 # of the name of the containing function. This will allow for
7539 # correct parsing but will usually produce better formatting.
7540 # Braces with block type 't' are not broken open automatically
7541 # in the formatter as are other code block types, and this usually
7542 # works best.
7543 3 return 't'; # (Not $paren_type)
7544 }
7545 else {
7546 86 return EMPTY_STRING;
7547 }
7548 }
7549  
7550 # handle unknown syntax ') {'
7551 # we previously appended a '()' to mark this case
7552 elsif ( $last_nonblank_token =~ /\(\)$/ ) {
7553 16 return $last_nonblank_token;
7554 }
7555  
7556 # anything else must be anonymous hash reference
7557 else {
7558 231 return EMPTY_STRING;
7559 }
7560 } ## end sub code_block_type
7561  
7562 186 ▶sub decide_if_code_block {
Subroutine decide_if_code_block: called CC=22 SCAR=31.4
Pod undocumented
7563  
7564 # USES GLOBAL VARIABLES: $last_nonblank_token
7565 186 my ( $self, $i, $rtokens, $rtoken_type, $max_token_index ) = @_;
7566  
7567 186 my ( $next_nonblank_token, $i_next_uu ) =
7568 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
7569  
7570 # we are at a '{' where a statement may appear.
7571 # We must decide if this brace starts an anonymous hash or a code
7572 # block.
7573 # return "" if anonymous hash, and $last_nonblank_token otherwise
7574  
7575 # initialize to be code BLOCK
7576 186 my $code_block_type = $last_nonblank_token;
7577  
7578 # Check for the common case of an empty anonymous hash reference:
7579 # Maybe something like sub { { } }
7580 186 ▶ if ( $next_nonblank_token eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq '}') { } 5 181 186
7581 5 $code_block_type = EMPTY_STRING;
7582 }
7583  
7584 else {
7585  
7586 # To guess if this '{' is an anonymous hash reference, look ahead
7587 # and test as follows:
7588 #
7589 # it is a hash reference if next come:
7590 # - a string or digit followed by a comma or =>
7591 # - bareword followed by =>
7592 # otherwise it is a code block
7593 #
7594 # Examples of anonymous hash ref:
7595 # {'aa',};
7596 # {1,2}
7597 #
7598 # Examples of code blocks:
7599 # {1; print "hello\n", 1;}
7600 # {$a,1};
7601  
7602 # We are only going to look ahead one more (nonblank/comment) line.
7603 # Strange formatting could cause a bad guess, but that's unlikely.
7604 181 my @pre_types;
7605 my @pre_tokens;
7606  
7607 # Ignore the rest of this line if it is a side comment
7608 181 ▶ if ( $next_nonblank_token ne '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token ne "#") 156 25 181
7609 156 @pre_types = @{$rtoken_type}[ $i + 1 .. $max_token_index ];
7610 156 @pre_tokens = @{$rtokens}[ $i + 1 .. $max_token_index ];
7611 }
7612  
7613 # Here 20 is arbitrary but generous, and prevents wasting lots of time
7614 # in mangled files
7615 181 my ( $rpre_tokens, $rpre_types ) =
7616 $self->peek_ahead_for_n_nonblank_pre_tokens(20);
7617 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
7618 173 push @pre_types, @{$rpre_types};
7619 173 push @pre_tokens, @{$rpre_tokens};
7620 }
7621  
7622 # put a sentinel token to simplify stopping the search
7623 181 push @pre_types, '}';
7624 181 push @pre_types, '}';
7625  
7626 181 my $jbeg = 0;
7627 181 ▶ $jbeg = 1 if ( $pre_types[0] eq 'b' );
Branch: 1 branch
BranchTrueFalseTotal
if $pre_types[0] eq "b" 64 117 181
7628  
7629 # first look for one of these
7630 # - bareword
7631 # - bareword with leading -
7632 # - digit
7633 # - quoted string
7634 181 my $j = $jbeg;
7635 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
7636  
7637 # find the closing quote; don't worry about escapes
7638 1 my $quote_mark = $pre_types[$j];
7639 1 foreach my $k ( $j + 1 .. @pre_types - 2 ) {
7640 1 ▶ if ( $pre_types[$k] eq $quote_mark ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre_types[$k] eq $quote_mark) 1 0 1
7641 1 $j = $k + 1;
7642 1 last;
7643 }
7644 }
7645 }
7646 elsif ( $pre_types[$j] eq 'd' ) {
7647 8 $j++;
7648 }
7649 elsif ( $pre_types[$j] eq 'w' ) {
7650 78 $j++;
7651 }
7652 ▶ 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
7653 0 $j++;
7654 }
7655 else {
7656 ## none of the above
7657 }
7658 181 ▶ if ( $j > $jbeg ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j > $jbeg) 87 94 181
7659  
7660 87 ▶ $j++ if ( $pre_types[$j] eq 'b' );
Branch: 1 branch
BranchTrueFalseTotal
if $pre_types[$j] eq "b" 80 7 87
7661  
7662 # Patched for RT #95708
7663 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
01869
$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/DC25%1/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 table28%2/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
7664  
7665 # it is a comma which is not a pattern delimiter except for qw
7666 (
7667 $pre_types[$j] eq COMMA
7668 && !$is_q_qq_qx_qr_s_y_tr_m{ $pre_tokens[$jbeg] }
7669 )
7670  
7671 # or a =>
7672 || ( $pre_types[$j] eq '=' && $pre_types[ ++$j ] eq '>' )
7673 )
7674 {
7675 18 $code_block_type = EMPTY_STRING;
7676 }
7677 }
7678  
7679 181 ▶ if ($code_block_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code_block_type) 163 18 181
7680  
7681 # Patch for cases b1085 b1128: It is uncertain if this is a block.
7682 # If this brace follows a bareword, then append a space as a signal
7683 # to the formatter that this may not be a block brace. To find the
7684 # corresponding code in Formatter.pm search for 'b1085'.
7685 # But not for the word 'method': fixes c534; this will cause the
7686 # formatter to mark an asub block instead of a sub block.
7687 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
7688 20 $code_block_type .= SPACE;
7689 }
7690 }
7691 }
7692  
7693 186 return $code_block_type;
7694 } ## end sub decide_if_code_block
7695  
7696 0 ▶sub report_unexpected {
Subroutine report_unexpected: not called CC=6 SCAR=37.4
Pod undocumented
7697  
7698 # report unexpected token type and show where it is
7699 # USES GLOBAL VARIABLES: (none)
7700 0 my ( $self, $rcall_hash ) = @_;
7701  
7702 0 my $found = $rcall_hash->{found};
7703 0 my $expecting = $rcall_hash->{expecting};
7704 0 my $i_tok = $rcall_hash->{i_tok};
7705 0 my $last_nonblank_i = $rcall_hash->{last_nonblank_i};
7706 0 my $rpretoken_map = $rcall_hash->{rpretoken_map};
7707 0 my $rpretoken_type = $rcall_hash->{rpretoken_type};
7708 0 my $input_line = $rcall_hash->{input_line};
7709  
7710 0 ▶ if ( ++$self->[_unexpected_error_count_] <= MAX_NAG_MESSAGES ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$self->[40] <= 6) 0 0 0
7711 0 my $msg = "found $found where $expecting expected";
7712 0 my $pos = $rpretoken_map->[$i_tok];
7713 0 $self->interrupt_logfile();
7714 0 my $input_line_number = $self->[_last_line_number_];
7715 0 my ( $offset, $numbered_line, $underline ) =
7716 make_numbered_line( $input_line_number, $input_line, $pos );
7717 0 $underline = write_on_underline( $underline, $pos - $offset, '^' );
7718  
7719 0 my $trailer = EMPTY_STRING;
7720 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
7721 0 my $pos_prev = $rpretoken_map->[$last_nonblank_i];
7722 0 my $num;
7723 0 ▶ if ( $rpretoken_type->[ $i_tok - 1 ] eq 'b' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$rpretoken_type[$i_tok - 1] eq 'b') { } 0 0 0
7724 0 $num = $rpretoken_map->[ $i_tok - 1 ] - $pos_prev;
7725 }
7726 else {
7727 0 $num = $pos - $pos_prev;
7728 }
7729 0 ▶ if ( $num > 40 ) { $num = 40; $pos_prev = $pos - 40; }
Branch: 1 branch
BranchTrueFalseTotal
if ($num > 40) 0 0 0
7730  
7731 $underline =
7732 0 write_on_underline( $underline, $pos_prev - $offset, '-' x $num );
7733 0 $trailer = " (previous token underlined)";
7734 }
7735 0 $underline =~ s/\s+$//;
7736 0 $self->warning( $numbered_line . "\n" );
7737 0 $self->warning( $underline . "\n" );
7738 0 $self->warning( $msg . $trailer . "\n" );
7739 0 $self->resume_logfile();
7740 }
7741 0 return;
7742 } ## end sub report_unexpected
7743  
7744 45 my %is_sigil_or_paren;
7745 45 my %is_R_closing_sb;
7746  
7747 45 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.0
7748  
7749 45 my @q = qw< $ & % * @ ) >;
7750 45 $is_sigil_or_paren{$_} = 1 for @q;
7751  
7752 45 @q = qw( R ] );
7753 45 $is_R_closing_sb{$_} = 1 for @q;
7754 } ## end BEGIN
7755  
7756 2893 ▶sub is_non_structural_brace {
Subroutine is_non_structural_brace: called CC=3 SCAR=11.0
Pod undocumented
7757  
7758 # Decide if a brace or bracket is structural or non-structural
7759 # by looking at the previous token and type
7760 # USES GLOBAL VARIABLES: $last_nonblank_type, $last_nonblank_token
7761  
7762 # EXPERIMENTAL: Mark slices as structural; idea was to improve formatting.
7763 # Tentatively deactivated because it caused the wrong operator expectation
7764 # for this code:
7765 # $user = @vars[1] / 100;
7766 # Must update sub operator_expected before re-implementing.
7767 # if ( $last_nonblank_type eq 'i' && $last_nonblank_token =~ /^@/ ) {
7768 # return 0;
7769 # }
7770  
7771 #--------------------------------------------------------------
7772 # NOTE: braces after type characters start code blocks, but for
7773 # simplicity these are not identified as such. See also
7774 # sub code_block_type
7775 #--------------------------------------------------------------
7776  
7777 ##if ($last_nonblank_type eq 't') {return 0}
7778  
7779 # otherwise, it is non-structural if it is decorated
7780 # by type information.
7781 # For example, the '{' here is non-structural: ${xxx}
7782 # Removed '::' to fix c074
7783 ## $last_nonblank_token =~ /^([\$\@\*\&\%\)]|->|::)/
7784 return (
7785 ## $last_nonblank_token =~ /^([\$\@\*\&\%\)]|->)/
7786 $is_sigil_or_paren{ substr( $last_nonblank_token, 0, 1 ) }
7787 || substr( $last_nonblank_token, 0, 2 ) eq '->'
7788  
7789 # or if we follow a hash or array closing curly brace or bracket
7790 # For example, the second '{' in this is non-structural: $a{'x'}{'y'}
7791 # because the first '}' would have been given type 'R'
7792 ##|| $last_nonblank_type =~ /^([R\]])$/
7793 2893 ▶ || $is_R_closing_sb{$last_nonblank_type}
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
9091191865
$is_sigil_or_paren{substr($last_nonblank_token, 0, 1)} or substr($last_nonblank_token, 0, 2) eq "->"
l!l&&r!l&&!r
5153941984
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
7794 );
7795 } ## end sub is_non_structural_brace
7796  
7797 #######################################################################
7798 # Tokenizer routines for tracking container nesting depths
7799 #######################################################################
7800  
7801 # The following routines keep track of nesting depths of the nesting
7802 # types, ( [ { and ?. This is necessary for determining the indentation
7803 # level, and also for debugging programs. Not only do they keep track of
7804 # nesting depths of the individual brace types, but they check that each
7805 # of the other brace types is balanced within matching pairs. For
7806 # example, if the program sees this sequence:
7807 #
7808 # { ( ( ) }
7809 #
7810 # then it can determine that there is an extra left paren somewhere
7811 # between the { and the }. And so on with every other possible
7812 # combination of outer and inner brace types. For another
7813 # example:
7814 #
7815 # ( [ ..... ] ] )
7816 #
7817 # which has an extra ] within the parens.
7818 #
7819 # The brace types have indexes 0 .. 3 which are indexes into
7820 # the matrices.
7821 #
7822 # The pair ? : are treated as just another nesting type, with ? acting
7823 # as the opening brace and : acting as the closing brace.
7824 #
7825 # The matrix
7826 #
7827 # $rdepth_array->[$a][$b][ $rcurrent_depth->[$a] ] = $rcurrent_depth->[$b];
7828 #
7829 # saves the nesting depth of brace type $b (where $b is either of the other
7830 # nesting types) when brace type $a enters a new depth. When this depth
7831 # decreases, a check is made that the current depth of brace types $b is
7832 # unchanged, or otherwise there must have been an error. This can
7833 # be very useful for localizing errors, particularly when perl runs to
7834 # the end of a large file (such as this one) and announces that there
7835 # is a problem somewhere.
7836 #
7837 # A numerical sequence number is maintained for every nesting type,
7838 # so that each matching pair can be uniquely identified in a simple
7839 # way.
7840  
7841 5541 ▶sub increase_nesting_depth {
Subroutine increase_nesting_depth: called CC=8 SCAR=20.8
Pod undocumented
7842 5541 my ( $self, $aa, $pos ) = @_;
7843  
7844 # Given:
7845 # $aa = integer code of container type, 0-3
7846 # $pos = position of character, for error message
7847  
7848 # USES GLOBAL VARIABLES: $rcurrent_depth,
7849 # $rcurrent_sequence_number, $rdepth_array,
7850 # $rstarting_line_of_current_depth, $statement_type
7851 5541 my $cd_aa = ++$rcurrent_depth->[$aa];
7852 5541 $total_depth++;
7853 5541 $rtotal_depth->[$aa]->[$cd_aa] = $total_depth;
7854 5541 my $input_line_number = $self->[_last_line_number_];
7855 5541 my $input_line = $self->[_line_of_text_];
7856  
7857 # Sequence numbers increment by number of items. This keeps
7858 # a unique set of numbers but still allows the relative location
7859 # of any type to be determined.
7860  
7861 # make a new unique sequence number
7862 5541 my $seqno = $next_sequence_number++;
7863  
7864 # Remember the type sequence number at the current depth,
7865 # but do not overwrite the root sequence number.
7866 5541 ▶ if ( $total_depth > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($total_depth > 0) 5541 0 5541
7867 5541 $self->[_rseqno_at_depth_]->[$total_depth] = $seqno;
7868 }
7869  
7870 5541 $rcurrent_sequence_number->[$aa]->[$cd_aa] = $seqno;
7871  
7872 5541 $rstarting_line_of_current_depth->[$aa]->[$cd_aa] =
7873 [ $input_line_number, $input_line, $pos ];
7874  
7875 5541 for my $bb ( 0 .. @closing_brace_names - 1 ) {
7876 22164 ▶ next if ( $bb == $aa );
Branch: 1 branch
BranchTrueFalseTotal
if $bb == $aa 5541 16623 22164
7877 16623 $rdepth_array->[$aa]->[$bb]->[$cd_aa] = $rcurrent_depth->[$bb];
7878 }
7879  
7880 # set a flag for indenting a nested ternary statement
7881 5541 my $indent = 0;
7882 5541 ▶ if ( $aa == QUESTION_COLON ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aa == 3) 193 5348 5541
7883 193 $rnested_ternary_flag->[$cd_aa] = 0;
7884 193 ▶ if ( $cd_aa > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cd_aa > 1) 17 176 193
7885 17 ▶ if ( $rnested_ternary_flag->[ $cd_aa - 1 ] == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$rnested_ternary_flag[$cd_aa - 1] == 0) 16 1 17
7886 16 my $pdepth = $rtotal_depth->[$aa]->[ $cd_aa - 1 ];
7887 16 ▶ if ( $pdepth == $total_depth - 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pdepth == $total_depth - 1) 8 8 16
7888 8 $indent = 1;
7889 8 $rnested_ternary_flag->[ $cd_aa - 1 ] = -1;
7890 }
7891 }
7892 }
7893 }
7894  
7895 # Fix part #1 for git82: save last token type for propagation of type 'Z'
7896 5541 $rnested_statement_type->[$aa]->[$cd_aa] =
7897 [ $statement_type, $last_nonblank_type, $last_nonblank_token ];
7898 5541 $statement_type = EMPTY_STRING;
7899 5541 return ( $seqno, $indent );
7900 } ## end sub increase_nesting_depth
7901  
7902 47 ▶sub is_balanced_closing_container {
Subroutine is_balanced_closing_container: called CC=5 SCAR=16.7
Pod undocumented
7903  
7904 47 my ($aa) = @_;
7905  
7906 # Return true if a closing container can go here without error
7907 # Return false if not
7908 # Given:
7909 # $aa = integer code of container type, 0-3
7910  
7911 # cannot close if there was no opening
7912 47 my $cd_aa = $rcurrent_depth->[$aa];
7913 47 ▶ return if ( $cd_aa <= 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $cd_aa <= 0 39 8 47
7914  
7915 # check that any other brace types $bb contained within would be balanced
7916 8 for my $bb ( 0 .. @closing_brace_names - 1 ) {
7917 8 ▶ next if ( $bb == $aa );
Branch: 1 branch
BranchTrueFalseTotal
if $bb == $aa 0 8 8
7918 return
7919 if (
7920 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
7921 }
7922  
7923 # OK, everything will be balanced
7924 0 return 1;
7925 } ## end sub is_balanced_closing_container
7926  
7927 5541 ▶sub decrease_nesting_depth {
Subroutine decrease_nesting_depth: called CC=21 SCAR=49.7
Pod undocumented
7928  
7929 5541 my ( $self, $aa, $pos ) = @_;
7930  
7931 # Given:
7932 # $aa = integer code of container type, 0-3
7933 # $pos = position of character, for error message
7934  
7935 # USES GLOBAL VARIABLES: $rcurrent_depth,
7936 # $rcurrent_sequence_number, $rdepth_array, $rstarting_line_of_current_depth
7937 # $statement_type
7938 5541 my $seqno = 0;
7939 5541 my $input_line_number = $self->[_last_line_number_];
7940 5541 my $input_line = $self->[_line_of_text_];
7941  
7942 5541 my $outdent = 0;
7943 5541 $total_depth--;
7944 5541 my $cd_aa = $rcurrent_depth->[$aa];
7945 5541 ▶ if ( $cd_aa > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cd_aa > 0) { } 5541 0 5541
7946  
7947 # set a flag for un-indenting after seeing a nested ternary statement
7948 5541 $seqno = $rcurrent_sequence_number->[$aa]->[$cd_aa];
7949 5541 ▶ if ( $aa == QUESTION_COLON ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($aa == 3) 193 5348 5541
7950 193 $outdent = $rnested_ternary_flag->[$cd_aa];
7951 }
7952  
7953 # Fix part #2 for git82: use saved type for propagation of type 'Z'
7954 # through type L-R braces. Perl seems to allow ${bareword}
7955 # as an indirect object, but nothing much more complex than that.
7956 ( $statement_type, my $saved_type, my $saved_token_uu ) =
7957 5541 @{ $rnested_statement_type->[$aa]->[ $rcurrent_depth->[$aa] ] };
7958 5541 ▶ 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 5540 5541
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
554001
$aa == 0 and $saved_type eq "Z" and $last_nonblank_type eq "w"
!ll&&!rl&&r
554001
$aa == 0 and $saved_type eq "Z"
!ll&&!rl&&r
345720831
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
7959 && $saved_type eq 'Z'
7960 && $last_nonblank_type eq 'w'
7961 && $rbrace_structural_type->[$brace_depth] eq 'L' )
7962 {
7963 1 $last_nonblank_type = $saved_type;
7964 }
7965  
7966 # check that any brace types $bb contained within are balanced
7967 5541 for my $bb ( 0 .. @closing_brace_names - 1 ) {
7968 22164 ▶ next if ( $bb == $aa );
Branch: 1 branch
BranchTrueFalseTotal
if $bb == $aa 5541 16623 22164
7969  
7970 16623 ▶ if ( $rdepth_array->[$aa]->[$bb]->[$cd_aa] !=
Branch: 1 branch
BranchTrueFalseTotal
if ($rdepth_array->[$aa][$bb][$cd_aa] != $rcurrent_depth->[$bb]) 0 16623 16623
7971 $rcurrent_depth->[$bb] )
7972 {
7973 0 my $diff =
7974 $rcurrent_depth->[$bb] -
7975 $rdepth_array->[$aa]->[$bb]->[$cd_aa];
7976  
7977 # don't whine too many times
7978 0 my $saw_brace_error = $self->get_saw_brace_error();
7979 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
7980 $saw_brace_error <= MAX_NAG_MESSAGES
7981  
7982 # if too many closing types have occurred, we probably
7983 # already caught this error
7984 && ( ( $diff > 0 ) || ( $saw_brace_error <= 0 ) )
7985 )
7986 {
7987 0 $self->interrupt_logfile();
7988 0 my $rsl = $rstarting_line_of_current_depth->[$aa]->[$cd_aa];
7989 0 my $sl = $rsl->[0];
7990 0 my $rel = [ $input_line_number, $input_line, $pos ];
7991 0 my $el = $rel->[0];
7992 0 my ($ess);
7993  
7994 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
7995 0 $ess = EMPTY_STRING;
7996 }
7997 else {
7998 0 $ess = 's';
7999 }
8000 0 ▶ my $bname =
Branch: 1 branch
BranchTrueFalseTotal
$diff > 0 ? : 0 0 0
8001 ( $diff > 0 )
8002 ? $opening_brace_names[$bb]
8003 : $closing_brace_names[$bb];
8004 0 $self->write_error_indicator_pair( @{$rsl}, '^' );
8005 0 my $msg = <<"EOM";
8006 Found $diff extra $bname$ess between $opening_brace_names[$aa] on line $sl and $closing_brace_names[$aa] on line $el
8007 EOM
8008  
8009 0 ▶ if ( $diff > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diff > 0) 0 0 0
8010 0 my $rml =
8011 $rstarting_line_of_current_depth->[$bb]
8012 ->[ $rcurrent_depth->[$bb] ];
8013 0 my $ml = $rml->[0];
8014 0 $msg .=
8015 " The most recent un-matched $bname is on line $ml\n";
8016 0 $self->write_error_indicator_pair( @{$rml}, '^' );
8017 }
8018 0 $self->write_error_indicator_pair( @{$rel}, '^' );
8019 0 $self->warning($msg);
8020 0 $self->resume_logfile();
8021 }
8022 0 $self->increment_brace_error();
8023 0 ▶ if ( $bb eq BRACE ) { $self->[_show_indentation_table_] = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($bb eq 0) 0 0 0
8024 }
8025 }
8026 5541 $rcurrent_depth->[$aa]--;
8027 }
8028 else {
8029  
8030 0 my $saw_brace_error = $self->get_saw_brace_error();
8031 0 ▶ if ( $saw_brace_error <= MAX_NAG_MESSAGES ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($saw_brace_error <= 6) 0 0 0
8032 0 my $msg = <<"EOM";
8033 There is no previous $opening_brace_names[$aa] to match a $closing_brace_names[$aa] on line $input_line_number
8034 EOM
8035 0 $self->indicate_error( $msg, $input_line_number, $input_line, $pos,
8036 '^' );
8037 }
8038 0 $self->increment_brace_error();
8039 0 ▶ if ( $aa eq BRACE ) { $self->[_show_indentation_table_] = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($aa eq 0) 0 0 0
8040  
8041 # keep track of errors in braces alone (ignoring ternary nesting errors)
8042 0 ▶ $self->[_true_brace_error_count_]++
Branch: 1 branch
BranchTrueFalseTotal
if $closing_brace_names[$aa] ne "':'" 0 0 0
8043 if ( $closing_brace_names[$aa] ne "':'" );
8044 }
8045 5541 return ( $seqno, $outdent );
8046 } ## end sub decrease_nesting_depth
8047  
8048 666 ▶sub check_final_nesting_depths {
Subroutine check_final_nesting_depths: called CC=5 SCAR=26.8
Pod undocumented
8049  
8050 # USES GLOBAL VARIABLES: $rcurrent_depth, $rstarting_line_of_current_depth
8051 666 my $self = shift;
8052  
8053 666 for my $aa ( 0 .. @closing_brace_names - 1 ) {
8054  
8055 2664 my $cd_aa = $rcurrent_depth->[$aa];
8056 2664 ▶ if ($cd_aa) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cd_aa) 0 2664 2664
8057 0 my $rsl = $rstarting_line_of_current_depth->[$aa]->[$cd_aa];
8058 0 my $sl = $rsl->[0];
8059  
8060 # Add hint for something like a missing terminal ':' of a ternary
8061 0 my $hint = EMPTY_STRING;
8062 0 ▶ if ( $cd_aa == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cd_aa == 1) 0 0 0
8063 0 $hint =
8064 " .. did not find its closing $closing_brace_names[$aa]";
8065 }
8066 0 my $msg = <<"EOM";
8067 Final nesting depth of $opening_brace_names[$aa]s is $cd_aa
8068 The most recent un-matched $opening_brace_names[$aa] is on line $sl$hint
8069 EOM
8070 0 $self->indicate_error( $msg, @{$rsl}, '^' );
8071 0 $self->increment_brace_error();
8072 0 ▶ if ( $aa eq BRACE ) { $self->[_show_indentation_table_] = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($aa eq 0) 0 0 0
8073 }
8074 }
8075 666 return;
8076 } ## end sub check_final_nesting_depths
8077  
8078 #######################################################################
8079 # Tokenizer routines for looking ahead in input stream
8080 #######################################################################
8081  
8082 188 ▶sub peek_ahead_for_n_nonblank_pre_tokens {
Subroutine peek_ahead_for_n_nonblank_pre_tokens: called CC=4 SCAR=13.9
Pod undocumented
8083  
8084 188 my ( $self, $max_pretokens ) = @_;
8085  
8086 # Given:
8087 # $max_pretokens = number of pretokens wanted
8088 # Return:
8089 # next $max_pretokens pretokens if they exist
8090 # undef's if hits eof without seeing any pretokens
8091  
8092 # USES GLOBAL VARIABLES: (none)
8093 188 my $line;
8094 188 my $i = 0;
8095 188 my ( $rpre_tokens, $rmap, $rpre_types );
8096  
8097 188 ▶ while ( defined( $line = $self->peek_ahead( $i++ ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->peek_ahead($i++))) 206 8 214
8098 206 $line =~ s/^\s+//; # trim leading blanks
8099 206 ▶ next if ( length($line) <= 0 ); # skip blank
Branch: 1 branch
BranchTrueFalseTotal
if length $line <= 0 6 200 206
8100 200 ▶ next if ( $line =~ /^#/ ); # skip comment
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^#/ 20 180 200
8101 180 ( $rpre_tokens, $rmap, $rpre_types ) =
8102 pre_tokenize( $line, $max_pretokens );
8103 180 last;
8104 } ## end while ( defined( $line = ...))
8105 188 return ( $rpre_tokens, $rpre_types );
8106 } ## end sub peek_ahead_for_n_nonblank_pre_tokens
8107  
8108 # look ahead for next non-blank, non-comment line of code
8109 143 ▶sub peek_ahead_for_nonblank_token {
Subroutine peek_ahead_for_nonblank_token: called CC=6 SCAR=17.9
Pod undocumented
8110  
8111 143 my ( $self, $rtokens, $max_token_index ) = @_;
8112  
8113 # Given:
8114 # $rtokens = ref to token array
8115 # $max_token_index = index of last token in $rtokens
8116 # Task:
8117 # Update $rtokens with next nonblank token
8118  
8119 # USES GLOBAL VARIABLES: (none)
8120 143 my $line;
8121 143 my $i = 0;
8122  
8123 143 ▶ while ( defined( $line = $self->peek_ahead( $i++ ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->peek_ahead($i++))) 194 2 196
8124 194 $line =~ s/^\s+//; # trim leading blanks
8125 194 ▶ next if ( length($line) <= 0 ); # skip blank
Branch: 1 branch
BranchTrueFalseTotal
if length $line <= 0 29 165 194
8126 165 ▶ next if ( $line =~ /^#/ ); # skip comment
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^#/ 24 141 165
8127  
8128 # Updated from 2 to 3 to get trigraphs, added for case b1175
8129 141 my ( $rtok, $rmap_uu, $rtype_uu ) = pre_tokenize( $line, 3 );
8130 141 my $j = $max_token_index + 1;
8131  
8132 141 foreach my $tok ( @{$rtok} ) {
8133 406 ▶ last if ( $tok =~ "\n" );
Branch: 1 branch
BranchTrueFalseTotal
if $tok =~ / / 43 363 406
8134 363 $rtokens->[ ++$j ] = $tok;
8135 }
8136 141 last;
8137 } ## end while ( defined( $line = ...))
8138 143 return;
8139 } ## end sub peek_ahead_for_nonblank_token
8140  
8141 #######################################################################
8142 # Tokenizer guessing routines for ambiguous situations
8143 #######################################################################
8144  
8145 45 my %is_non_ternary_pretok;
8146  
8147 45 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8148  
8149 # Some pre-tokens which cannot immediately follow a ternary '?'
8150 45 my @q = qw# ; ? : ) } ] = > #;
8151 45 push @q, COMMA;
8152 45 %is_non_ternary_pretok = map { $_ => 1 } @q;
8153 }
8154  
8155 12 ▶sub guess_if_pattern_or_conditional {
Subroutine guess_if_pattern_or_conditional: called CC=14 SCAR=48.1
Pod undocumented
8156  
8157 12 my ( $self, $i, $rtokens, $rtoken_type, $rtoken_map_uu, $max_token_index )
8158 = @_;
8159  
8160 # This routine is called when we have encountered a ? following an
8161 # unknown bareword, and we must decide if it starts a pattern or not
8162 # Given:
8163 # $i - token index of the ? starting possible pattern
8164 # $rtokens ... = the token arrays
8165 # Return:
8166 # $is_pattern = 0 if probably not pattern, =1 if probably a pattern
8167 # msg = a warning or diagnostic message
8168  
8169 # USES GLOBAL VARIABLES: $last_nonblank_token
8170  
8171 12 my $is_pattern = 0;
8172 12 my $msg =
8173 "guessing that ? after type='$last_nonblank_type' token='$last_nonblank_token' starts a ";
8174  
8175 12 ▶ if ( $i >= $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $max_token_index) 0 12 12
8176 0 $msg .= "conditional (no end to pattern found on the line)\n";
8177 0 $is_pattern = 0;
8178 0 return ( $is_pattern, $msg );
8179 }
8180  
8181 # See if we can rule out a ternary operator here before proceeding. c547.
8182 12 my ( $next_nonblank_token, $i_next_uu ) =
8183 find_next_nonblank_token_on_this_line( $i, $rtokens, $max_token_index );
8184 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 table25%1/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
8185 !(
8186 $is_non_ternary_pretok{$next_nonblank_token}
8187 || ( $last_nonblank_type eq 'k' && $last_nonblank_token eq 'split' )
8188 )
8189 )
8190 {
8191 # A ternary cannot be ruled out here. We will assume this is a ternary
8192 # operator since '?' as pattern delimiter is deprecated.
8193 12 $is_pattern = 0;
8194 12 $msg .= "conditional (cannot rule it out)";
8195 12 return ( $is_pattern, $msg );
8196 }
8197  
8198 # If we get here, then we either have a ternary with a syntax error or some
8199 # ancient code which uses ? as a pattern delimiter. We will only select the
8200 # pattern delimiter if we can find its matching closing delimiter.
8201  
8202 0 my $ibeg = $i;
8203 0 $i = $ibeg + 1;
8204 ##my $next_token = $rtokens->[$i]; # first token after ?
8205  
8206 # look for a possible ending ? on this line..
8207 0 my $in_quote = 1;
8208 0 my $quote_depth = 0;
8209 0 my $quote_character = EMPTY_STRING;
8210 0 my $quote_pos = 0;
8211 0 my $quoted_string;
8212 (
8213  
8214 0 $i,
8215 $in_quote,
8216 $quote_character,
8217 $quote_pos,
8218 $quote_depth,
8219 $quoted_string,
8220  
8221 ) = $self->follow_quoted_string(
8222  
8223 $ibeg,
8224 $in_quote,
8225 $rtokens,
8226 $rtoken_type,
8227 $quote_character,
8228 $quote_pos,
8229 $quote_depth,
8230 $max_token_index,
8231  
8232 );
8233  
8234 0 ▶ if ($in_quote) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote) 0 0 0
8235  
8236 # we didn't find an ending ? on this line,
8237 # so we bias towards conditional
8238 0 $is_pattern = 0;
8239 0 $msg .= "conditional (no ending ? on this line)\n";
8240 0 return ( $is_pattern, $msg );
8241 }
8242  
8243 # we found an ending ?, so we bias towards a pattern
8244  
8245 # Watch out for an ending ? in quotes, like this
8246 # my $case_flag = File::Spec->case_tolerant ? '(?i)' : '';
8247 0 my $s_quote = 0;
8248 0 my $d_quote = 0;
8249 0 my $colons = 0;
8250 0 foreach my $ii ( $ibeg + 1 .. $i - 1 ) {
8251 0 my $tok = $rtokens->[$ii];
8252 0 ▶ if ( $tok eq ":" ) { $colons++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq ":") 0 0 0
8253 0 ▶ if ( $tok eq "'" ) { $s_quote++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "'") 0 0 0
8254 0 ▶ if ( $tok eq '"' ) { $d_quote++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "\"") 0 0 0
8255 }
8256 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
8257 0 $is_pattern = 0;
8258 0 $msg .= "conditional: found ending ? but unbalanced quote chars\n";
8259 0 return ( $is_pattern, $msg );
8260 }
8261 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
8262 0 $is_pattern = 1;
8263 0 $msg .= "pattern (found ending ? and pattern expected)\n";
8264 0 return ( $is_pattern, $msg );
8265 }
8266  
8267 # NOTE: An ultimate decision could be made on version, since ? is a ternary
8268 # after version 5.22. But we may be formatting an ancient script with a
8269 # newer perl, and it might run on an older perl, so we cannot be certain.
8270 # if ($] >=5.022) {$is_pattern=0} else { ... not sure
8271  
8272 0 $msg .= "conditional (but uncertain)\n";
8273 0 return ( $is_pattern, $msg );
8274 } ## end sub guess_if_pattern_or_conditional
8275  
8276 45 my %is_known_constant;
8277 45 my %is_known_function;
8278  
8279 45 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.0
8280  
8281 # Constants like 'pi' in Trig.pm are common
8282 45 my @q = qw( pi pi2 pi4 pip2 pip4 );
8283 45 $is_known_constant{$_} = 1 for @q;
8284  
8285 # parenless calls of 'ok' are common
8286 45 @q = qw( ok );
8287 45 $is_known_function{$_} = 1 for @q;
8288 } ## end BEGIN
8289  
8290 0 ▶sub guess_if_pattern_or_division {
Subroutine guess_if_pattern_or_division: not called CC=13 SCAR=52.0
Pod undocumented
8291  
8292 0 my ( $self, $i, $rtokens, $rtoken_type, $rtoken_map, $max_token_index ) =
8293 @_;
8294  
8295 # This routine is called when we have encountered a / following an
8296 # unknown bareword, and we must decide if it starts a pattern or is a
8297 # division.
8298 # Given:
8299 # $i - token index of the / starting possible pattern
8300 # $rtokens ... = the token arrays
8301 # Return:
8302 # $is_pattern = 0 if probably division, =1 if probably a pattern
8303 # msg = a warning or diagnostic message
8304 # USES GLOBAL VARIABLES: $last_nonblank_token
8305 0 my $msg = "guessing that / after '$last_nonblank_token' starts a ";
8306 0 my $ibeg = $i;
8307 0 my $is_pattern = 0;
8308  
8309 0 my $divide_possible =
8310 $self->is_possible_numerator( $i, $rtokens, $max_token_index );
8311  
8312 0 ▶ if ( $divide_possible < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($divide_possible < 0) 0 0 0
8313 0 $msg .= "pattern (division not possible here)\n";
8314 0 $is_pattern = 1;
8315 0 $self->saw_bareword_function($last_nonblank_token);
8316 0 return ( $is_pattern, $msg );
8317 }
8318 0 ▶ if ( $divide_possible == 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($divide_possible == 4) 0 0 0
8319 0 $msg .= "division (pattern not possible here)\n";
8320 0 $is_pattern = 0;
8321 0 return ( $is_pattern, $msg );
8322 }
8323  
8324 # anything left on line?
8325 0 ▶ if ( $i >= $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $max_token_index) 0 0 0
8326 0 $msg .= "division (line ends with this /)\n";
8327 0 $is_pattern = 0;
8328 0 return ( $is_pattern, $msg );
8329 }
8330  
8331 # quick check for no pattern-ending slash on this line
8332 0 my $pos_beg = $rtoken_map->[$ibeg];
8333 0 my $input_line = $self->[_line_of_text_];
8334 0 ▶ if ( index( $input_line, '/', $pos_beg + 1 ) < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($input_line, "/", $pos_beg + 1) == -1) 0 0 0
8335 0 $msg .= "division (no ending / on this line)\n";
8336 0 $is_pattern = 0;
8337 0 return ( $is_pattern, $msg );
8338 }
8339  
8340 # Setup spacing rule before we change $i below..
8341 0 $i = $ibeg + 1;
8342 0 my $next_token = $rtokens->[$i]; # first token after slash
8343  
8344 # There are four possible spacings around the first slash:
8345 #
8346 # return pi/two;#/; -/-
8347 # return pi/ two;#/; -/+
8348 # return pi / two;#/; +/+
8349 # return pi /two;#/; +/- <-- possible pattern
8350 #
8351 # Spacing rule: a space before the slash but not after the slash
8352 # usually indicates a pattern. We can use this to break ties.
8353 # Note: perl seems to take a newline as a space in this rule (c243)
8354 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
8355 0 my $space_after = $next_token =~ m/^\s/;
8356 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
8357  
8358 # Make an accurate search for a possible terminating / on this line..
8359 0 my $in_quote = 1;
8360 0 my $quote_depth = 0;
8361 0 my $quote_character = EMPTY_STRING;
8362 0 my $quote_pos = 0;
8363 0 my $quoted_string;
8364 (
8365  
8366 0 $i,
8367 $in_quote,
8368 $quote_character,
8369 $quote_pos,
8370 $quote_depth,
8371 $quoted_string,
8372 )
8373 = $self->follow_quoted_string(
8374  
8375 $ibeg,
8376 $in_quote,
8377 $rtokens,
8378 $rtoken_type,
8379 $quote_character,
8380 $quote_pos,
8381 $quote_depth,
8382 $max_token_index,
8383 );
8384  
8385 # if we didn't find an ending / on this line ..
8386 0 ▶ if ($in_quote) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote) 0 0 0
8387 0 $is_pattern = 0;
8388 0 $msg .= "division (no ending / on this line)\n";
8389 0 return ( $is_pattern, $msg );
8390 }
8391  
8392 # we found an ending /, see if it might terminate a pattern
8393 0 my $pattern_expected =
8394 $self->pattern_expected( $i, $rtokens, $max_token_index );
8395  
8396 0 ▶ if ( $pattern_expected < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern_expected < 0) 0 0 0
8397 0 $is_pattern = 0;
8398 0 $msg .= "division (pattern not possible)\n";
8399 0 return ( $is_pattern, $msg );
8400 }
8401  
8402 # Both pattern and divide can work here...
8403 # Check for known constants in the numerator, like 'pi'
8404 0 ▶ if ( $is_known_constant{$last_nonblank_token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_known_constant{$last_nonblank_token}) 0 0 0
8405 0 $msg .=
8406 "division (pattern works too but saw known constant '$last_nonblank_token')\n";
8407 0 $is_pattern = 0;
8408 0 return ( $is_pattern, $msg );
8409 }
8410  
8411 # Check for known functions like 'ok'
8412 0 ▶ if ( $is_known_function{$last_nonblank_token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_known_function{$last_nonblank_token}) 0 0 0
8413 0 $msg .= "pattern (division works too but saw '$last_nonblank_token')\n";
8414 0 $is_pattern = 1;
8415 0 return ( $is_pattern, $msg );
8416 }
8417  
8418 # If one rule is more probable, use it
8419 0 ▶ if ( $divide_possible > $pattern_expected ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($divide_possible > $pattern_expected) 0 0 0
8420 0 $msg .= "division (more likely based on following tokens)\n";
8421 0 $is_pattern = 0;
8422 0 return ( $is_pattern, $msg );
8423 }
8424  
8425 # finally, we have to use the spacing rule
8426 0 ▶ if ($is_pattern_by_spacing) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_pattern_by_spacing) { } 0 0 0
8427 0 $msg .= "pattern (guess on spacing, but division possible too)\n";
8428 0 $is_pattern = 1;
8429 }
8430 else {
8431 0 $msg .= "division (guess on spacing, but pattern is possible too)\n";
8432 0 $is_pattern = 0;
8433 }
8434  
8435 0 return ( $is_pattern, $msg );
8436 } ## end sub guess_if_pattern_or_division
8437  
8438 0 ▶sub guess_if_here_doc {
Subroutine guess_if_here_doc: not called CC=7 SCAR=40.3
Pod undocumented
8439  
8440 0 my ( $self, $next_token ) = @_;
8441  
8442 # Try to resolve here-doc vs. shift by looking ahead for
8443 # non-code or the end token (currently only looks for end token)
8444  
8445 # Given:
8446 # $next_token = the next token after '<<'
8447  
8448 # Return:
8449 # 1 if it is probably a here doc
8450 # 0 if not
8451  
8452 # USES GLOBAL VARIABLES: $current_package $ris_constant,
8453  
8454 # This is how many lines we will search for a target as part of the
8455 # guessing strategy. There is probably little reason to change it.
8456 0 my $HERE_DOC_WINDOW = 40;
8457  
8458 0 my $here_doc_expected = 0;
8459 0 my $line;
8460 0 my $k = 0;
8461 0 my $msg = "checking <<";
8462  
8463 0 ▶ while ( defined( $line = $self->peek_ahead( $k++ ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = $self->peek_ahead($k++))) 0 0 0
8464 0 chomp $line;
8465 0 ▶ if ( $line eq $next_token ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq $next_token) 0 0 0
8466 0 $msg .= " -- found target $next_token ahead $k lines\n";
8467 0 $here_doc_expected = 1; # got it
8468 0 last;
8469 }
8470 0 ▶ last if ( $k >= $HERE_DOC_WINDOW );
Branch: 1 branch
BranchTrueFalseTotal
if $k >= $HERE_DOC_WINDOW 0 0 0
8471 } ## end while ( defined( $line = ...))
8472  
8473 0 ▶ if ( !$here_doc_expected ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($here_doc_expected) 0 0 0
8474  
8475 0 ▶ if ( !defined($line) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $line) { } 0 0 0
8476 0 $here_doc_expected = -1; # hit eof without seeing target
8477 0 $msg .= " -- must be shift; target $next_token not in file\n";
8478 }
8479 else { # still unsure..taking a wild guess
8480  
8481 0 ▶ if ( !$ris_constant->{$current_package}->{$next_token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ris_constant->{$current_package}{$next_token}) { } 0 0 0
8482 0 $here_doc_expected = 1;
8483 0 $msg .=
8484 " -- guessing it's a here-doc ($next_token not a constant)\n";
8485 }
8486 else {
8487 0 $msg .=
8488 " -- guessing it's a shift ($next_token is a constant)\n";
8489 }
8490 0 if (DEBUG_GUESS_MODE) {
8491 $self->warning("DEBUG_GUESS_MODE message:\n$msg\n");
8492 }
8493 }
8494 }
8495 0 $self->write_logfile_entry($msg);
8496 0 return $here_doc_expected;
8497 } ## end sub guess_if_here_doc
8498  
8499 #######################################################################
8500 # Tokenizer Routines for scanning identifiers and related items
8501 #######################################################################
8502  
8503 1870 ▶sub scan_bare_identifier_do {
Subroutine scan_bare_identifier_do: called CC=33 SCAR=37.3
Pod undocumented
8504  
8505 my (
8506  
8507 1870 $self,
8508  
8509 $input_line,
8510 $i,
8511 $tok,
8512 $type,
8513 $prototype,
8514 $rtoken_map,
8515 $max_token_index,
8516  
8517 ) = @_;
8518  
8519 # This routine is called to scan a token starting with an alphanumeric
8520 # variable or package separator, :: or '.
8521  
8522 # Given:
8523 # current scan state variables
8524  
8525 # USES GLOBAL VARIABLES: $current_package, $last_nonblank_token,
8526 # $last_nonblank_type, $rparen_type, $paren_depth
8527  
8528 1870 my $package = undef;
8529  
8530 1870 my $i_beg = $i;
8531  
8532 # we have to back up one pretoken at a :: since each : is one pretoken
8533 1870 ▶ if ( $tok eq '::' ) { $i_beg-- }
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "::") 9 1861 1870
8534 1870 my $pos_beg = $rtoken_map->[$i_beg];
8535 1870 pos($input_line) = $pos_beg;
8536  
8537 # Examples:
8538 # A::B::C
8539 # A::
8540 # ::A
8541 # A'B
8542 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
8543 $input_line =~ m{
8544 \G\s* # start at pos
8545 ( (?:\w*(?:'|::))* ) # $1 = maybe package name like A:: A::B:: or A'
8546 (\w+)? # $2 = maybe followed by sub name
8547 }gcx
8548 )
8549 {
8550 1870 my $pos = pos($input_line);
8551 1870 my $numc = $pos - $pos_beg;
8552 1870 $tok = substr( $input_line, $pos_beg, $numc );
8553  
8554 # type 'w' includes anything without leading type info
8555 # ($,%,@,*) including something like abc::def::ghi
8556 1870 $type = 'w';
8557  
8558 1870 my $sub_name = EMPTY_STRING;
8559 1870 ▶ if ( defined($2) ) { $sub_name = $2; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $2) 1865 5 1870
8560 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
8561 280 $package = $1;
8562  
8563 # patch: check for package call A::B::C->
8564 # in this case, C is part of the package name
8565 280 ▶ if ($sub_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub_name) 275 5 280
8566 275 ▶ if ( $input_line =~ m{ \G\s*(?:->) }gcx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ / \G\s*(?:->) /cgx) 117 158 275
8567 117 $package .= $sub_name;
8568 117 $sub_name = EMPTY_STRING;
8569 }
8570 275 pos($input_line) = $pos;
8571 }
8572  
8573 # patch: don't allow isolated package name which just ends
8574 # in the old style package separator (single quote). Example:
8575 # use CGI':all';
8576 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
8577 0 $pos--;
8578 }
8579  
8580 280 $package =~ s/\'/::/g;
8581 280 ▶ if ( $package =~ /^\:/ ) { $package = 'main' . $package }
Branch: 1 branch
BranchTrueFalseTotal
if ($package =~ /^\:/) 9 271 280
8582 280 $package =~ s/::$//;
8583 }
8584 else {
8585 1590 $package = $current_package;
8586  
8587 # patched for c043, part 1: keyword does not follow '->'
8588 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
8589 0 $type = 'k';
8590 }
8591 }
8592  
8593 # if it is a bareword.. patched for c043, part 2: not following '->'
8594 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
8595  
8596 # check for v-string with leading 'v' type character
8597 # (This seems to have precedence over filehandle, type 'Y')
8598 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
8599  
8600 # we only have the first part - something like 'v101' -
8601 # look for more
8602 2 ▶ if ( $input_line =~ m/\G(\.\d[_\d]*)+/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /\G(\.\d[_\d]*)+/cg) 2 0 2
8603 2 $pos = pos($input_line);
8604 2 $numc = $pos - $pos_beg;
8605 2 $tok = substr( $input_line, $pos_beg, $numc );
8606 }
8607 2 $type = 'v';
8608 }
8609  
8610 # bareword after sort has implied empty prototype; for example:
8611 # @sorted = sort numerically ( 53, 29, 11, 32, 7 );
8612 # This has priority over whatever the user has specified.
8613 ▶ 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
8614 && $last_nonblank_type eq 'k' )
8615 {
8616 1 $type = 'Z';
8617 }
8618  
8619 # issue c382: this elsif statement moved from above because
8620 # previous check for type 'Z' after sort has priority.
8621 elsif ( $ris_constant->{$package}->{$sub_name} ) {
8622 14 $type = 'C';
8623 }
8624  
8625 # Note: strangely, perl does not seem to really let you create
8626 # functions which act like eval and do, in the sense that eval
8627 # and do may have operators following the final }, but any operators
8628 # that you create with prototype (&) apparently do not allow
8629 # trailing operators, only terms. This seems strange.
8630 # If this ever changes, here is the update
8631 # to make perltidy behave accordingly:
8632  
8633 # elsif ( $ris_block_function->{$package}{$tok} ) {
8634 # $tok='eval'; # patch to do braces like eval - doesn't work
8635 # $type = 'k';
8636 #}
8637 # TODO: This could become a separate type to allow for different
8638 # future behavior:
8639 elsif ( $ris_block_function->{$package}->{$sub_name} ) {
8640 0 $type = 'G';
8641 }
8642 elsif ( $ris_block_list_function->{$package}->{$sub_name} ) {
8643 0 $type = 'G';
8644 }
8645 elsif ( $ris_user_function->{$package}->{$sub_name} ) {
8646 6 $type = 'U';
8647 6 $prototype = $ruser_function_prototype->{$package}->{$sub_name};
8648 }
8649  
8650 # check for indirect object
8651 ▶ 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
8652  
8653 # added 2001-03-27: must not be followed immediately by '('
8654 # see fhandle.t
8655 ( $input_line !~ m/\G\(/gc )
8656  
8657 # and
8658 && (
8659  
8660 # preceded by keyword like 'print', 'printf' and friends
8661 $is_indirect_object_taker{$last_nonblank_token}
8662  
8663 # or preceded by something like 'print(' or 'printf('
8664 || (
8665 ( $last_nonblank_token eq '(' )
8666 && $is_indirect_object_taker{
8667 $rparen_type->[$paren_depth]
8668 }
8669  
8670 )
8671 )
8672 )
8673 {
8674  
8675 # may not be indirect object unless followed by a space;
8676 # updated 2021-01-16 to consider newline to be a space.
8677 # updated for case b990 to look for either ';' or space
8678 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
8679 || $input_line =~ m/\G[;\s]/gc )
8680 {
8681 4 $type = 'Y';
8682  
8683 # Abandon Hope ...
8684 # Perl's indirect object notation is a very bad
8685 # thing and can cause subtle bugs, especially for
8686 # beginning programmers. And I haven't even been
8687 # able to figure out a sane warning scheme which
8688 # doesn't get in the way of good scripts.
8689  
8690 # Complain if a filehandle has any lower case
8691 # letters. This is suggested good practice.
8692 # Use 'sub_name' because something like
8693 # main::MYHANDLE is ok for filehandle
8694 4 ▶ if ( $sub_name =~ /[a-z]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub_name =~ /[a-z]/) 1 3 4
8695  
8696 # could be bug caused by older perltidy if
8697 # followed by '('
8698 1 ▶ if ( $input_line =~ m/\G\s*\(/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /\G\s*\(/cg) 1 0 1
8699 1 $self->complain(
8700 "Caution: unknown word '$tok' in indirect object slot\n"
8701 );
8702 }
8703 }
8704 }
8705  
8706 # bareword not followed by a space -- may not be filehandle
8707 # (may be function call defined in a 'use' statement)
8708 else {
8709 0 $type = 'Z';
8710 }
8711 }
8712 else {
8713 ## none of the above special types
8714 }
8715 }
8716  
8717 # Now we must convert back from character position
8718 # to pre_token index.
8719 # I don't think an error flag can occur here ..but who knows
8720 1870 my $error;
8721 1870 ( $i, $error ) =
8722 inverse_pretoken_map( $i, $pos, $rtoken_map, $max_token_index );
8723 1870 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 1870 1870
8724 0 $self->warning(
8725 "scan_bare_identifier: Possibly invalid tokenization\n");
8726 }
8727 }
8728  
8729 # no match but line not blank - could be syntax error
8730 # perl will take '::' alone without complaint
8731 else {
8732 0 $type = 'w';
8733  
8734 # change this warning to log message if it becomes annoying
8735 0 $self->warning("didn't find identifier after leading ::\n");
8736 }
8737 1870 return ( $i, $tok, $type, $prototype );
8738 } ## end sub scan_bare_identifier_do
8739  
8740 427 ▶sub scan_id_do {
Subroutine scan_id_do: called CC=16 SCAR=29.2
Pod undocumented
8741  
8742 my (
8743  
8744 427 $self,
8745  
8746 $input_line,
8747 $i,
8748 $tok,
8749 $rtokens,
8750 $rtoken_map,
8751 $id_scan_state,
8752 $max_token_index,
8753  
8754 ) = @_;
8755  
8756 # Scan identifier following a type token.
8757 # Given:
8758 # current scan state variables
8759  
8760 # This is the new scanner and may eventually replace scan_identifier.
8761 # Only type 'sub' and 'package' are implemented.
8762 # Token types $ * % @ & -> are not yet implemented.
8763 #
8764 # The type of call depends on $id_scan_state: $id_scan_state = ''
8765 # for starting call, in which case $tok must be the token defining
8766 # the type.
8767 #
8768 # If the type token is the last nonblank token on the line, a value
8769 # of $id_scan_state = $tok is returned, indicating that further
8770 # calls must be made to get the identifier. If the type token is
8771 # not the last nonblank token on the line, the identifier is
8772 # scanned and handled and a value of '' is returned.
8773  
8774 45 ▶ use constant DEBUG_NSCAN => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
8775 427 my $type = EMPTY_STRING;
8776 427 my $i_beg;
8777  
8778 #print "NSCAN:entering i=$i, tok=$tok, type=$type, state=$id_scan_state\n";
8779 #my ($a,$b,$c) = caller;
8780 #print "NSCAN: scan_id called with tok=$tok $a $b $c\n";
8781  
8782 # on re-entry, start scanning at first token on the line
8783 427 ▶ if ($id_scan_state) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state) { } 10 417 427
8784 10 $i_beg = $i;
8785 10 $type = EMPTY_STRING;
8786 }
8787  
8788 # on initial entry, start scanning just after type token
8789 else {
8790 417 $i_beg = $i + 1;
8791 417 $id_scan_state = $tok;
8792 417 $type = 't';
8793 }
8794  
8795 # find $i_beg = index of next nonblank token,
8796 # and handle empty lines
8797 427 my $blank_line = 0;
8798 427 my $is_lexical_method = 0;
8799 427 my $next_nonblank_token = $rtokens->[$i_beg];
8800 427 ▶ if ( $i_beg > $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i_beg > $max_token_index) { } 2 425 427
8801 2 $blank_line = 1;
8802 }
8803 else {
8804  
8805 # only a '#' immediately after a '$' is not a comment
8806 425 ▶ if ( $next_nonblank_token eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "#") 0 425 425
8807 0 ▶ if ( $tok ne '$' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok ne "\$") 0 0 0
8808 0 $blank_line = 1;
8809 }
8810 }
8811  
8812 425 ▶ if ( $next_nonblank_token =~ /^\s/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token =~ /^\s/) 405 20 425
8813 405 ( $next_nonblank_token, $i_beg ) =
8814 find_next_nonblank_token_on_this_line( $i_beg, $rtokens,
8815 $max_token_index );
8816 405 ▶ if ( $next_nonblank_token =~ /(^#|^\s*$)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token =~ /(^#|^\s*$)/) 4 401 405
8817 4 $blank_line = 1;
8818 }
8819 }
8820  
8821 # Patch for Object::Pad lexical method like 'method $var {':
8822 # Skip past a '$'
8823 425 ▶ if ( !$blank_line
Branch: 1 branch
BranchTrueFalseTotal
if (not $blank_line and $next_nonblank_token eq "\$" and $id_scan_state eq "method") 2 423 425
Condition83%5/6
not $blank_line and $next_nonblank_token eq "\$" and $id_scan_state eq "method"
!ll&&!rl&&r
42302
not $blank_line and $next_nonblank_token eq "\$"
!ll&&!rl&&r
44192
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
8824 && $next_nonblank_token eq '$'
8825 && $id_scan_state eq 'method' )
8826 {
8827 2 ( $next_nonblank_token, $i_beg ) =
8828 find_next_nonblank_token_on_this_line( $i_beg, $rtokens,
8829 $max_token_index );
8830 2 $is_lexical_method = 1;
8831 }
8832 }
8833  
8834 # handle non-blank line; identifier, if any, must follow
8835 427 ▶ if ( !$blank_line ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($blank_line) 421 6 427
8836  
8837 421 ▶ if ( $is_sub{$id_scan_state} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_sub{$id_scan_state}) { } 371 50 421
elsif ($is_package{$id_scan_state}) { } 50 0 50
8838 371 ( $i, $tok, $type, $id_scan_state ) = $self->do_scan_sub(
8839 {
8840 input_line => $input_line,
8841 i => $i,
8842 i_beg => $i_beg,
8843 tok => $tok,
8844 type => $type,
8845 rtokens => $rtokens,
8846 rtoken_map => $rtoken_map,
8847 id_scan_state => $id_scan_state,
8848 max_token_index => $max_token_index,
8849 is_lexical_method => $is_lexical_method,
8850 }
8851 );
8852 }
8853  
8854 elsif ( $is_package{$id_scan_state} ) {
8855 50 ( $i, $tok, $type ) = $self->do_scan_package(
8856 {
8857 input_line => $input_line,
8858 i => $i,
8859 i_beg => $i_beg,
8860 tok => $tok,
8861 type => $type,
8862 rtokens => $rtokens,
8863 rtoken_map => $rtoken_map,
8864 max_token_index => $max_token_index,
8865 }
8866 );
8867 50 $id_scan_state = EMPTY_STRING;
8868 }
8869  
8870 else {
8871 0 $self->warning("invalid token in scan_id: $tok\n");
8872 0 $id_scan_state = EMPTY_STRING;
8873 }
8874 }
8875  
8876 427 ▶ if ( $id_scan_state && ( !defined($type) || !$type ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state and not defined $type && $type) 0 427 427
Condition50%3/6
$id_scan_state and not defined $type && $type
!ll&&!rl&&r
417100
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
8877  
8878 # shouldn't happen:
8879 0 if (DEVEL_MODE) {
8880 Fault(<<EOM);
8881 Program bug in scan_id: undefined type but scan_state=$id_scan_state
8882 EOM
8883 }
8884 $self->warning(
8885 0 "Possible program bug in sub scan_id: undefined type but scan_state=$id_scan_state\n"
8886 );
8887 0 $self->report_definite_bug();
8888 }
8889  
8890 427 DEBUG_NSCAN && do {
8891 print {*STDOUT}
8892 "NSCAN: returns i=$i, tok=$tok, type=$type, state=$id_scan_state\n";
8893 };
8894 427 return ( $i, $tok, $type, $id_scan_state );
8895 } ## end sub scan_id_do
8896  
8897 193 ▶sub check_prototype {
Subroutine check_prototype: called CC=7 SCAR=19.7
Pod undocumented
8898 193 my ( $proto, $package, $subname ) = @_;
8899  
8900 # Classify a sub based on its prototype
8901 193 ▶ return if ( !defined($package) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $package 0 193 193
8902 193 ▶ return if ( !defined($subname) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $subname 0 193 193
8903 193 ▶ if ( defined($proto) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $proto) { } 34 159 193
8904 34 $proto =~ s/^\s*\(\s*//;
8905 34 $proto =~ s/\s*\)$//;
8906 34 ▶ if ($proto) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proto) { } 5 29 34
8907 5 $ris_user_function->{$package}->{$subname} = 1;
8908 5 $ruser_function_prototype->{$package}->{$subname} = "($proto)";
8909  
8910 # prototypes containing '&' must be treated specially..
8911 5 ▶ if ( $proto =~ /\&/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proto =~ /\&/) 1 4 5
8912  
8913 # right curly braces of prototypes ending in
8914 # '&' may be followed by an operator
8915 1 ▶ if ( $proto =~ /\&$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proto =~ /\&$/) { } 0 1 1
8916 0 $ris_block_function->{$package}->{$subname} = 1;
8917 }
8918  
8919 # right curly braces of prototypes NOT ending in
8920 # '&' may NOT be followed by an operator
8921 else {
8922 1 $ris_block_list_function->{$package}->{$subname} = 1;
8923 }
8924 }
8925 }
8926 else {
8927 29 $ris_constant->{$package}->{$subname} = 1;
8928 }
8929 }
8930 else {
8931 159 $ris_user_function->{$package}->{$subname} = 1;
8932 }
8933 193 return;
8934 } ## end sub check_prototype
8935  
8936 50 ▶sub do_scan_package {
Subroutine do_scan_package: called CC=7 SCAR=20.3
Pod undocumented
8937  
8938 50 my ( $self, $rcall_hash ) = @_;
8939  
8940 # Parse a package name.
8941  
8942 50 my $input_line = $rcall_hash->{input_line};
8943 50 my $i = $rcall_hash->{i};
8944 50 my $i_beg = $rcall_hash->{i_beg};
8945 50 my $tok = $rcall_hash->{tok};
8946 50 my $type = $rcall_hash->{type};
8947 50 my $rtokens = $rcall_hash->{rtokens};
8948 50 my $rtoken_map = $rcall_hash->{rtoken_map};
8949 50 my $max_token_index = $rcall_hash->{max_token_index};
8950  
8951 # This is called with $i_beg equal to the index of the first nonblank
8952 # token following a 'package' token.
8953 # USES GLOBAL VARIABLES: $current_package,
8954  
8955 # package NAMESPACE
8956 # package NAMESPACE VERSION
8957 # package NAMESPACE BLOCK
8958 # package NAMESPACE VERSION BLOCK
8959 #
8960 # If VERSION is provided, package sets the $VERSION variable in the given
8961 # namespace to a version object with the VERSION provided. VERSION must be
8962 # a "strict" style version number as defined by the version module: a
8963 # positive decimal number (integer or decimal-fraction) without
8964 # exponentiation or else a dotted-decimal v-string with a leading 'v'
8965 # character and at least three components.
8966 # reference http://perldoc.perl.org/functions/package.html
8967  
8968 50 my $package = undef;
8969 50 my $pos_beg = $rtoken_map->[$i_beg];
8970 50 pos($input_line) = $pos_beg;
8971  
8972 # handle non-blank line; package name, if any, must follow
8973 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
8974 50 $package = $1;
8975 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
8976 50 $package =~ s/\'/::/g;
8977 0 ▶ if ( $package =~ /^\:/ ) { $package = 'main' . $package }
Branch: 1 branch
BranchTrueFalseTotal
if ($package =~ /^\:/) 0 50 50
8978 50 $package =~ s/::$//;
8979 50 my $pos = pos($input_line);
8980 50 my $numc = $pos - $pos_beg;
8981 50 $tok = 'package ' . substr( $input_line, $pos_beg, $numc );
8982 50 $type = 'P'; # Fix for c250, previously 'i'
8983  
8984 # Now we must convert back from character position
8985 # to pre_token index.
8986 # I don't think an error flag can occur here ..but ?
8987 50 my $error;
8988 50 ( $i, $error ) =
8989 inverse_pretoken_map( $i, $pos, $rtoken_map, $max_token_index );
8990 0 ▶ if ($error) { $self->warning("Possibly invalid package\n") }
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 50 50
8991 50 $current_package = $package;
8992  
8993 # we should now have package NAMESPACE
8994 # now expecting VERSION, BLOCK, or ; to follow ...
8995 # package NAMESPACE VERSION
8996 # package NAMESPACE BLOCK
8997 # package NAMESPACE VERSION BLOCK
8998 50 my ( $next_nonblank_token, $i_next_uu ) =
8999 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
9000  
9001 # check that something recognizable follows, but do not parse.
9002 # A VERSION number will be parsed later as a number or v-string in the
9003 # normal way. What is important is to set the statement type if
9004 # everything looks okay so that the operator_expected() routine
9005 # knows that the number is in a package statement.
9006 # Examples of valid primitive tokens that might follow are:
9007 # 1235 . ; { } v3 v
9008 # FIX: added a '#' since a side comment may also follow
9009 # Added ':' for class attributes (for --use-feature=class, rt145706)
9010 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
9011 50 $statement_type = $tok;
9012 }
9013 else {
9014 0 $self->warning(
9015 "Unexpected '$next_nonblank_token' after package name '$tok'\n"
9016 );
9017 }
9018 }
9019  
9020 # no match but line not blank --
9021 # could be a label with name package, like package: , for example.
9022 else {
9023 0 $type = 'k';
9024 }
9025  
9026 50 return ( $i, $tok, $type );
9027 } ## end sub do_scan_package
9028  
9029 { ## begin closure for sub scan_complex_identifier
9030  
9031 45 ▶ use constant DEBUG_SCAN_ID => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
9032  
9033 # Constant hash:
9034 45 my %is_special_variable_char;
9035  
9036 45 ▶ BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
9037  
9038 # These are the only characters which can (currently) form special
9039 # variables, like $^W: (issue c066).
9040 45 my @q = qw{
9041 ? 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 [ ] ^ _
9042 };
9043 45 push @q, BACKSLASH;
9044 45 $is_special_variable_char{$_} = 1 for @q;
9045 } ## end BEGIN
9046  
9047 # These are the possible states for this scanner:
9048 45 my $scan_state_SIGIL = '$';
9049 45 my $scan_state_ALPHA = 'A';
9050 45 my $scan_state_COLON = ':';
9051 45 my $scan_state_LPAREN = '(';
9052 45 my $scan_state_RPAREN = ')';
9053 45 my $scan_state_AMPERSAND = '&';
9054 45 my $scan_state_SPLIT = '^';
9055  
9056 # Only these non-blank states may be returned to caller:
9057 45 my %is_returnable_scan_state = (
9058 $scan_state_SIGIL => 1,
9059 $scan_state_AMPERSAND => 1,
9060 );
9061  
9062 # USES GLOBAL VARIABLES:
9063 # $context, $last_nonblank_token, $last_nonblank_type
9064  
9065 #-----------
9066 # call args:
9067 #-----------
9068 45 my ( $i, $id_scan_state, $identifier, $rtokens, $max_token_index,
9069 $expecting, $container_type );
9070  
9071 #-------------------------------------------
9072 # my variables, re-initialized on each call:
9073 #-------------------------------------------
9074 45 my $i_begin; # starting index $i
9075 45 my $type; # returned identifier type
9076 45 my $tok_begin; # starting token
9077 45 my $tok; # returned token
9078 45 my $id_scan_state_begin; # starting scan state
9079 45 my $identifier_begin; # starting identifier
9080 45 my $i_save; # a last good index, in case of error
9081 45 my $message; # hold error message for log file
9082 45 my $tok_is_blank;
9083 45 my $last_tok_is_blank;
9084 45 my $in_prototype_or_signature;
9085 45 my $saw_alpha;
9086 45 my $saw_type;
9087 45 my $allow_tick;
9088  
9089 557 ▶ sub initialize_my_scan_id_vars {
Subroutine initialize_my_scan_id_vars: called CC=3 SCAR=11.0
Pod undocumented
9090  
9091 # Initialize all 'my' vars on entry
9092 557 $i_begin = $i;
9093 557 $type = EMPTY_STRING;
9094 557 $tok_begin = $rtokens->[$i_begin];
9095 557 $tok = $tok_begin;
9096 0 ▶ if ( $tok_begin eq ':' ) { $tok_begin = '::' }
Branch: 1 branch
BranchTrueFalseTotal
if ($tok_begin eq ":") 0 557 557
9097 557 $id_scan_state_begin = $id_scan_state;
9098 557 $identifier_begin = $identifier;
9099 557 $i_save = undef;
9100  
9101 557 $message = EMPTY_STRING;
9102 557 $tok_is_blank = undef; # a flag to speed things up
9103 557 $last_tok_is_blank = undef;
9104  
9105 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
9106 $container_type && $container_type =~ /^sub\b/;
9107  
9108 # these flags will be used to help figure out the type:
9109 557 $saw_alpha = undef;
9110 557 $saw_type = undef;
9111  
9112 # allow old package separator (') except in 'use' statement
9113 557 $allow_tick = ( $last_nonblank_token ne 'use' );
9114 557 return;
9115 } ## end sub initialize_my_scan_id_vars
9116  
9117 #----------------------------------
9118 # Routines for handling scan states
9119 #----------------------------------
9120 621 ▶ sub do_id_scan_state_dollar {
Subroutine do_id_scan_state_dollar: called CC=54 SCAR=49.9
Pod undocumented
9121  
9122 621 my $self = shift;
9123  
9124 # We saw a sigil, now looking to start a variable name
9125 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
9126  
9127 65 $identifier .= $tok;
9128  
9129 # we've got a punctuation variable if end of line (punct.t)
9130 65 ▶ if ( $i == $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $max_token_index) 0 65 65
9131 0 $type = 'i';
9132 0 $id_scan_state = EMPTY_STRING;
9133 }
9134 }
9135 elsif ( $tok =~ /^\w/ ) { # alphanumeric ..
9136 316 $saw_alpha = 1;
9137 316 $identifier .= $tok;
9138  
9139 # now need :: except for special digit vars like '$1' (c208)
9140 316 ▶ $id_scan_state = $tok =~ /^\d/ ? EMPTY_STRING : $scan_state_COLON;
Branch: 1 branch
BranchTrueFalseTotal
$tok =~ /^\d/ ? : 51 265 316
9141 }
9142 elsif ( $tok eq '::' ) {
9143 16 $id_scan_state = $scan_state_ALPHA;
9144 16 $identifier .= $tok;
9145 }
9146  
9147 # POSTDEFREF ->@ ->% ->& ->*
9148 ▶ 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
9149 0 $identifier .= $tok;
9150 }
9151 ▶ 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
9152 0 $saw_alpha = 1;
9153 0 $id_scan_state = $scan_state_COLON; # now need ::
9154 0 $identifier .= $tok;
9155  
9156 # Perl will accept leading digits in identifiers,
9157 # although they may not always produce useful results.
9158 # Something like $main::0 is ok. But this also works:
9159 #
9160 # sub howdy::123::bubba{ print "bubba $54321!\n" }
9161 # howdy::123::bubba();
9162 #
9163 }
9164 elsif ( $tok eq '#' ) {
9165  
9166 100 my $is_punct_var = $identifier eq '$$';
9167  
9168 # side comment or identifier?
9169 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
9170  
9171 # A '#' starts a comment if it follows a space. For example,
9172 # the following is equivalent to $ans=40.
9173 # my $ #
9174 # ans = 40;
9175 !$last_tok_is_blank
9176  
9177 # a # inside a prototype or signature can only start a
9178 # comment
9179 && !$in_prototype_or_signature
9180  
9181 # these are valid punctuation vars: *# %# @# $#
9182 # May also be '$#array' or POSTDEFREF ->$#
9183 && ( $identifier =~ /^[\%\@\$\*]$/
9184 || $identifier =~ /\$$/ )
9185  
9186 # but a '#' after '$$' is a side comment; see c147
9187 && !$is_punct_var
9188  
9189 )
9190 {
9191 96 $identifier .= $tok; # keep same state, a $ could follow
9192 }
9193 else {
9194  
9195 # otherwise it is a side comment
9196 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
9197 0 elsif ($is_punct_var) { $type = 'i' }
9198 4 elsif ( $id_scan_state eq $scan_state_SIGIL ) { $type = 't' }
9199 0 else { $type = 'i' }
9200 4 $i = $i_save;
9201 4 $id_scan_state = EMPTY_STRING;
9202 }
9203 }
9204  
9205 elsif ( $tok eq '{' ) {
9206  
9207 # check for something like ${#} or ${?}, where ? is a special char
9208 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
9209 (
9210 $identifier eq '$'
9211 || $identifier eq '@'
9212 || $identifier eq '$#'
9213 )
9214 && $i + 2 <= $max_token_index
9215 && $rtokens->[ $i + 2 ] eq '}'
9216 && $rtokens->[ $i + 1 ] !~ /[\s\w]/
9217 )
9218 {
9219 1 my $next2 = $rtokens->[ $i + 2 ];
9220 1 my $next1 = $rtokens->[ $i + 1 ];
9221 1 $identifier .= $tok . $next1 . $next2;
9222 1 $i += 2;
9223 1 $id_scan_state = EMPTY_STRING;
9224 }
9225 else {
9226  
9227 # skip something like ${xxx} or ->{
9228 46 $id_scan_state = EMPTY_STRING;
9229  
9230 # if this is the first token of a line, any tokens for this
9231 # identifier have already been accumulated
9232 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
9233 31 $identifier = EMPTY_STRING;
9234 }
9235 46 $i = $i_save;
9236 }
9237 }
9238  
9239 # space ok after leading $ % * & @
9240 elsif ( $tok =~ /^\s*$/ ) {
9241  
9242 20 $tok_is_blank = 1;
9243  
9244 # note: an id with a leading '&' does not actually come this way
9245 20 ▶ if ( $identifier =~ /^[\$\%\*\&\@]/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($identifier =~ /^[\$\%\*\&\@]/) { } 20 0 20
elsif ($identifier eq '->') { } 0 0 0
9246  
9247 20 ▶ if ( length($identifier) > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $identifier > 1) { } 8 12 20
9248 8 $id_scan_state = EMPTY_STRING;
9249 8 $i = $i_save;
9250 8 $type = 'i'; # probably punctuation variable
9251 }
9252 else {
9253  
9254 # fix c139: trim line-ending type 't'
9255 12 ▶ if ( $i == $max_token_index ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i == $max_token_index) { } 1 11 12
elsif (not $identifier =~ /^[\@\$]$/) { } 1 10 11
9256 1 $i = $i_save;
9257 1 $type = 't';
9258 }
9259  
9260 # spaces after $'s are common, and space after @
9261 # is harmless, so only complain about space
9262 # after other type characters. Space after $ and
9263 # @ will be removed in formatting. Report space
9264 # after % and * because they might indicate a
9265 # parsing error. In other words '% ' might be a
9266 # modulo operator. Delete this warning if it
9267 # gets annoying.
9268 elsif ( $identifier !~ /^[\@\$]$/ ) {
9269 1 $message =
9270 "Space in identifier, following $identifier\n";
9271 }
9272 else {
9273 ## silently accept space after '$' and '@' sigils
9274 }
9275 }
9276 }
9277  
9278 elsif ( $identifier eq '->' ) {
9279  
9280 # space after '->' is ok except at line end ..
9281 # so trim line-ending in type '->' (fixes c139)
9282 0 ▶ if ( $i == $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $max_token_index) 0 0 0
9283 0 $i = $i_save;
9284 0 $type = '->';
9285 }
9286 }
9287  
9288 # stop at space after something other than -> or sigil
9289 # Example of what can arrive here:
9290 # eval { $MyClass->$$ };
9291 else {
9292 0 $id_scan_state = EMPTY_STRING;
9293 0 $i = $i_save;
9294 0 $type = 'i';
9295 }
9296 }
9297 elsif ( $tok eq '^' ) {
9298  
9299 # check for some special variables like $^ $^W
9300 11 ▶ if ( $identifier =~ /^[\$\*\@\%]$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($identifier =~ /^[\$\*\@\%]$/) { } 11 0 11
9301 11 $identifier .= $tok;
9302 11 $type = 'i';
9303  
9304 # There may be one more character, not a space, after the ^
9305 11 my $next1 = $rtokens->[ $i + 1 ];
9306 11 my $chr = substr( $next1, 0, 1 );
9307 11 ▶ if ( $is_special_variable_char{$chr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_special_variable_char{$chr}) { } 9 2 11
9308  
9309 # It is something like $^W
9310 # Test case (c066) : $^Oeq'linux'
9311 9 $i++;
9312 9 $identifier .= $next1;
9313  
9314 # If pretoken $next1 is more than one character long,
9315 # set a flag indicating that it needs to be split.
9316 9 ▶ $id_scan_state =
Branch: 1 branch
BranchTrueFalseTotal
length $next1 > 1 ? : 3 6 9
9317 ( length($next1) > 1 ) ? $scan_state_SPLIT : EMPTY_STRING;
9318 }
9319 else {
9320  
9321 # it is just $^
9322 # Simple test case (c065): '$aa=$^if($bb)';
9323 2 $id_scan_state = EMPTY_STRING;
9324 }
9325 }
9326 else {
9327 0 $id_scan_state = EMPTY_STRING;
9328 0 $i = $i_save;
9329 }
9330 }
9331 else { # something else
9332  
9333 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
9334  
9335 # We might be in an extrusion of
9336 # sub foo2 ( $first, $, $third ) {
9337 # looking at a line starting with a comma, like
9338 # $
9339 # ,
9340 # in this case the comma ends the signature variable
9341 # '$' which will have been previously marked type 't'
9342 # rather than 'i'.
9343 3 ▶ if ( $i == $i_begin ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $i_begin) { } 1 2 3
9344 1 $identifier = EMPTY_STRING;
9345 1 $type = EMPTY_STRING;
9346 }
9347  
9348 # at a # we have to mark as type 't' because more may
9349 # follow, otherwise, in a signature we can let '$' be an
9350 # identifier here for better formatting.
9351 # See 'mangle4.in' for a test case.
9352 else {
9353 2 $type = 'i';
9354 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
9355 0 $type = 't';
9356 }
9357 2 $i = $i_save;
9358 }
9359 3 $id_scan_state = EMPTY_STRING;
9360 }
9361  
9362 # check for various punctuation variables
9363 elsif ( $identifier =~ /^[\$\*\@\%]$/ ) {
9364 35 $identifier .= $tok;
9365 }
9366  
9367 # POSTDEFREF: Postfix reference ->$* ->%* ->@* ->** ->&* ->$#*
9368 ▶ 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
9369 && $identifier =~ /\-\>([\@\%\$\*\&]|\$\#)$/ )
9370 {
9371 6 $identifier .= $tok;
9372 }
9373  
9374 elsif ( $identifier eq '$#' ) {
9375  
9376 0 ▶ if ( $tok eq '{' ) { $type = 'i'; $i = $i_save }
Branch: 2 branches
BranchTrueFalseTotal
if ($tok eq '{') { } 0 2 2
elsif ($tok =~ /^[\:\-\+]$/) { } 0 2 2
9377  
9378 # perl seems to allow just these: $#: $#- $#+
9379 elsif ( $tok =~ /^[\:\-\+]$/ ) {
9380 0 $type = 'i';
9381 0 $identifier .= $tok;
9382 }
9383 else {
9384 2 $i = $i_save;
9385 2 $self->write_logfile_entry(
9386 'Use of $# is deprecated' . "\n" );
9387 }
9388 }
9389 elsif ( $identifier eq '$$' ) {
9390  
9391 # perl does not allow references to punctuation
9392 # variables without braces. For example, this
9393 # won't work:
9394 # $:=\4;
9395 # $a = $$:;
9396 # You would have to use
9397 # $a = ${$:};
9398  
9399 # '$$' alone is punctuation variable for PID
9400 0 $i = $i_save;
9401 0 ▶ if ( $tok eq '{' ) { $type = 't' }
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq '{') { } 0 0 0
9402 0 else { $type = 'i' }
9403 }
9404 elsif ( $identifier eq '->' ) {
9405 0 $i = $i_save;
9406 }
9407 else {
9408 0 $i = $i_save;
9409 0 ▶ if ( length($identifier) == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $identifier == 1) 0 0 0
9410 0 $identifier = EMPTY_STRING;
9411 }
9412 }
9413 46 $id_scan_state = EMPTY_STRING;
9414 }
9415 621 return;
9416 } ## end sub do_id_scan_state_dollar
9417  
9418 119 ▶ sub do_id_scan_state_alpha {
Subroutine do_id_scan_state_alpha: called CC=8 SCAR=26.4
Pod undocumented
9419  
9420 119 my $self = shift;
9421  
9422 # looking for alphanumeric after ::
9423 119 $tok_is_blank = $tok =~ /^\s*$/;
9424  
9425 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
9426 106 $identifier .= $tok;
9427 106 $id_scan_state = $scan_state_COLON; # now need ::
9428 106 $saw_alpha = 1;
9429 }
9430 ▶ 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
9431 0 $identifier .= $tok;
9432 0 $id_scan_state = $scan_state_COLON; # now need ::
9433 0 $saw_alpha = 1;
9434 }
9435 ▶ 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
9436 0 $id_scan_state = $scan_state_LPAREN;
9437 0 $identifier .= $tok;
9438 }
9439 ▶ 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
9440 0 $id_scan_state = $scan_state_RPAREN;
9441 0 $identifier .= $tok;
9442 }
9443 else {
9444 13 $id_scan_state = EMPTY_STRING;
9445 13 $i = $i_save;
9446 }
9447 119 return;
9448 } ## end sub do_id_scan_state_alpha
9449  
9450 476 ▶ sub do_id_scan_state_colon {
Subroutine do_id_scan_state_colon: called CC=10 SCAR=25.4
Pod undocumented
9451  
9452 476 my $self = shift;
9453  
9454 # looking for possible :: after alphanumeric
9455  
9456 476 $tok_is_blank = $tok =~ /^\s*$/;
9457  
9458 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
9459 103 $identifier .= $tok;
9460 103 $id_scan_state = $scan_state_ALPHA; # now require alpha
9461 }
9462 elsif ( $tok =~ /^\w/ ) { # more alphanumeric is ok here
9463 20 $identifier .= $tok;
9464 20 $id_scan_state = $scan_state_COLON; # now need ::
9465 20 $saw_alpha = 1;
9466 }
9467 ▶ 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
9468  
9469 12 ▶ if ( $is_keyword{$identifier} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_keyword{$identifier}) { } 0 12 12
9470 0 $id_scan_state = EMPTY_STRING; # that's all
9471 0 $i = $i_save;
9472 }
9473 else {
9474 12 $identifier .= $tok;
9475 }
9476 }
9477 ▶ 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
9478 0 $id_scan_state = $scan_state_LPAREN;
9479 0 $identifier .= $tok;
9480 }
9481 ▶ 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
9482 0 $id_scan_state = $scan_state_RPAREN;
9483 0 $identifier .= $tok;
9484 }
9485 else {
9486 341 $id_scan_state = EMPTY_STRING; # that's all
9487 341 $i = $i_save;
9488 }
9489 476 return;
9490 } ## end sub do_id_scan_state_colon
9491  
9492 0 ▶ sub do_id_scan_state_left_paren {
Subroutine do_id_scan_state_left_paren: not called CC=3 SCAR=24.8
Pod undocumented
9493  
9494 0 my $self = shift;
9495  
9496 # looking for possible '(' of a prototype
9497  
9498 0 ▶ if ( $tok eq '(' ) { # got it
Branch: 2 branches
BranchTrueFalseTotal
if ($tok eq '(') { } 0 0 0
elsif ($tok =~ /^\s*$/) { } 0 0 0
9499 0 $identifier .= $tok;
9500 0 $id_scan_state = $scan_state_RPAREN; # now find the end of it
9501 }
9502 elsif ( $tok =~ /^\s*$/ ) { # blank - keep going
9503 0 $identifier .= $tok;
9504 0 $tok_is_blank = 1;
9505 }
9506 else {
9507 0 $id_scan_state = EMPTY_STRING; # that's all - no prototype
9508 0 $i = $i_save;
9509 }
9510 0 return;
9511 } ## end sub do_id_scan_state_left_paren
9512  
9513 0 ▶ sub do_id_scan_state_right_paren {
Subroutine do_id_scan_state_right_paren: not called CC=3 SCAR=24.8
Pod undocumented
9514  
9515 0 my $self = shift;
9516  
9517 # looking for a ')' of prototype to close a '('
9518  
9519 0 $tok_is_blank = $tok =~ /^\s*$/;
9520  
9521 0 ▶ if ( $tok eq ')' ) { # got it
Branch: 2 branches
BranchTrueFalseTotal
if ($tok eq ')') { } 0 0 0
elsif ($tok =~ /^[\s\$\%\\\*\@\&\;]/) { } 0 0 0
9522 0 $identifier .= $tok;
9523 0 $id_scan_state = EMPTY_STRING; # all done
9524 }
9525 elsif ( $tok =~ /^[\s\$\%\\\*\@\&\;]/ ) {
9526 0 $identifier .= $tok;
9527 }
9528 else { # probable error in script, but keep going
9529 0 $self->warning(
9530 "Unexpected '$tok' while seeking end of prototype\n");
9531 0 $identifier .= $tok;
9532 }
9533 0 return;
9534 } ## end sub do_id_scan_state_right_paren
9535  
9536 104 ▶ sub do_id_scan_state_ampersand {
Subroutine do_id_scan_state_ampersand: called CC=18 SCAR=47.0
Pod undocumented
9537  
9538 104 my $self = shift;
9539  
9540 # Starting sub call after seeing an '&'
9541 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
9542 87 $id_scan_state = $scan_state_COLON; # now need ::
9543 87 $saw_alpha = 1;
9544 87 $identifier .= $tok;
9545 }
9546 ▶ 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
9547 0 $id_scan_state = $scan_state_COLON; # now need ::
9548 0 $saw_alpha = 1;
9549 0 $identifier .= $tok;
9550 }
9551 elsif ( $tok =~ /^\s*$/ ) { # allow space
9552 2 $tok_is_blank = 1;
9553  
9554 # fix c139: trim line-ending type 't'
9555 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
9556 2 $i = $i_save;
9557 2 $type = 't';
9558 }
9559 }
9560 elsif ( $tok eq '::' ) { # leading ::
9561 0 $id_scan_state = $scan_state_ALPHA; # accept alpha next
9562 0 $identifier .= $tok;
9563 }
9564 elsif ( $tok eq '{' ) {
9565 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
9566 15 $identifier = EMPTY_STRING;
9567 }
9568 15 $i = $i_save;
9569 15 $id_scan_state = EMPTY_STRING;
9570 }
9571 elsif ( $tok eq '^' ) {
9572 0 ▶ if ( $identifier eq '&' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($identifier eq '&') { } 0 0 0
9573  
9574 # Special variable (c066)
9575 0 $identifier .= $tok;
9576 0 $type = 'i';
9577  
9578 # To be a special $^ variable, there may be one more character,
9579 # not a space, after the ^
9580 0 my $next1 = $rtokens->[ $i + 1 ];
9581 0 my $chr = substr( $next1, 0, 1 );
9582 0 ▶ if ( $is_special_variable_char{$chr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_special_variable_char{$chr}) { } 0 0 0
9583  
9584 # It is something like &^O
9585 0 $i++;
9586 0 $identifier .= $next1;
9587  
9588 # If pretoken $next1 is more than one character long,
9589 # set a flag indicating that it needs to be split.
9590 0 ▶ $id_scan_state =
Branch: 1 branch
BranchTrueFalseTotal
length $next1 > 1 ? : 0 0 0
9591 ( length($next1) > 1 ) ? $scan_state_SPLIT : EMPTY_STRING;
9592 }
9593 else {
9594  
9595 # It is &^. This is parsed by perl as a call to sub '^',
9596 # even though it would be difficult to create a sub '^'.
9597 # So we mark it as an identifier (c068).
9598 0 $id_scan_state = EMPTY_STRING;
9599 }
9600 }
9601 else {
9602 0 $identifier = EMPTY_STRING;
9603 0 $i = $i_save;
9604 }
9605 }
9606 else {
9607  
9608 # punctuation variable?
9609 # testfile: cunningham4.pl
9610 #
9611 # We have to be careful here. If we are in an unknown state,
9612 # we will reject the punctuation variable. In the following
9613 # example the '&' is a binary operator but we are in an unknown
9614 # state because there is no sigil on 'Prima', so we don't
9615 # know what it is. But it is a bad guess that
9616 # '&~' is a function variable.
9617 # $self->{text}->{colorMap}->[
9618 # Prima::PodView::COLOR_CODE_FOREGROUND
9619 # & ~tb::COLOR_INDEX ] =
9620 # $sec->{ColorCode}
9621  
9622 # Fix for case c033: a '#' here starts a side comment
9623 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
9624 0 $identifier .= $tok;
9625 }
9626 else {
9627 0 $identifier = EMPTY_STRING;
9628 0 $i = $i_save;
9629 0 $type = '&';
9630 }
9631 0 $id_scan_state = EMPTY_STRING;
9632 }
9633 104 return;
9634 } ## end sub do_id_scan_state_ampersand
9635  
9636 #-------------------
9637 # hash of scanner subs
9638 #-------------------
9639 45 my $scan_identifier_code = {
9640 $scan_state_SIGIL => \&do_id_scan_state_dollar,
9641 $scan_state_ALPHA => \&do_id_scan_state_alpha,
9642 $scan_state_COLON => \&do_id_scan_state_colon,
9643 $scan_state_LPAREN => \&do_id_scan_state_left_paren,
9644 $scan_state_RPAREN => \&do_id_scan_state_right_paren,
9645 $scan_state_AMPERSAND => \&do_id_scan_state_ampersand,
9646 };
9647  
9648 557 ▶ sub scan_complex_identifier {
Subroutine scan_complex_identifier: called CC=46 SCAR=45.5
Pod undocumented
9649  
9650 (
9651 557 my $self,
9652  
9653 $i,
9654 $id_scan_state,
9655 $identifier,
9656 $rtokens,
9657 $max_token_index,
9658 $expecting,
9659 $container_type,
9660  
9661 ) = @_;
9662  
9663 # This routine assembles tokens into identifiers. It maintains a
9664 # scan state, id_scan_state. It updates id_scan_state based upon
9665 # current id_scan_state and token, and returns an updated
9666 # id_scan_state and the next index after the identifier.
9667  
9668 # This routine now serves a backup for sub scan_simple_identifier
9669 # which handles most identifiers.
9670  
9671 # Note that $self must be a 'my' variable and not be a closure
9672 # variables like the other args. Otherwise it will not get
9673 # deleted by a DESTROY call at the end of a file. Then an
9674 # attempt to create multiple tokenizers can occur when multiple
9675 # files are processed, causing an error.
9676  
9677 # return flag telling caller to split the pretoken
9678 557 my $split_pretoken_flag;
9679  
9680 #-------------------
9681 # Initialize my vars
9682 #-------------------
9683  
9684 557 initialize_my_scan_id_vars();
9685  
9686 #--------------------------------------------------------
9687 # get started by defining a type and a state if necessary
9688 #--------------------------------------------------------
9689  
9690 557 ▶ if ( !$id_scan_state ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $id_scan_state) { } 550 7 557
9691 550 $context = UNKNOWN_CONTEXT;
9692  
9693 # fixup for digraph
9694 550 ▶ if ( $tok eq '>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq ">") 0 550 550
9695 0 $tok = '->';
9696 0 $tok_begin = $tok;
9697 }
9698 550 $identifier = $tok;
9699  
9700 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
9701 8 $identifier = '->' . $identifier;
9702 8 $id_scan_state = $scan_state_SIGIL;
9703 }
9704 ▶ 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
9705 355 $id_scan_state = $scan_state_SIGIL;
9706 355 $context = SCALAR_CONTEXT;
9707 }
9708 ▶ 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
9709 85 $id_scan_state = $scan_state_SIGIL;
9710 85 $context = LIST_CONTEXT;
9711 }
9712 elsif ( $tok eq '&' ) {
9713 102 $id_scan_state = $scan_state_AMPERSAND;
9714 }
9715 ▶ 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
9716 0 $saw_alpha = 0; # 'sub' is considered type info here
9717 0 $id_scan_state = $scan_state_SIGIL;
9718 0 $identifier .=
9719 SPACE; # need a space to separate sub from sub name
9720 }
9721 elsif ( $tok eq '::' ) {
9722 0 $id_scan_state = $scan_state_ALPHA;
9723 }
9724 elsif ( $tok =~ /^\w/ ) {
9725 0 $id_scan_state = $scan_state_COLON;
9726 0 $saw_alpha = 1;
9727 }
9728 elsif ( $tok eq '->' ) {
9729 0 $id_scan_state = $scan_state_SIGIL;
9730 }
9731 else {
9732  
9733 # shouldn't happen: bad call parameter
9734 0 my $msg =
9735 "Program bug detected: scan_complex_identifier received bad starting token = '$tok'\n";
9736 0 if (DEVEL_MODE) { Fault($msg) }
9737 0 ▶ if ( !$self->[_in_error_] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->[7]) 0 0 0
9738 0 $self->warning($msg);
9739 0 $self->[_in_error_] = 1;
9740 }
9741 0 $id_scan_state = EMPTY_STRING;
9742  
9743 # emergency return
9744 0 goto SCAN_ID_EMERGENCY_RETURN;
9745 }
9746 550 $saw_type = !$saw_alpha;
9747 }
9748 else {
9749 7 $i--;
9750 7 $saw_alpha = ( $tok =~ /^\w/ );
9751 7 $saw_type = ( $tok =~ /([\$\%\@\*\&])/ );
9752  
9753 # check for a valid starting state
9754 7 if ( DEVEL_MODE && !$is_returnable_scan_state{$id_scan_state} ) {
9755 Fault(<<EOM);
9756 Unexpected starting scan state in sub scan_complex_identifier: '$id_scan_state'
9757 EOM
9758 }
9759 }
9760  
9761 #------------------------------
9762 # loop to gather the identifier
9763 #------------------------------
9764  
9765 557 $i_save = $i;
9766  
9767 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
9768  
9769 # Be sure we have code to handle this state before we proceed
9770 1323 my $code = $scan_identifier_code->{$id_scan_state};
9771 1323 ▶ if ( !$code ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($code) 3 1320 1323
9772  
9773 3 ▶ if ( $id_scan_state eq $scan_state_SPLIT ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state eq $scan_state_SPLIT) { } 3 0 3
9774 ## OK: this is the signal to exit and split the pretoken
9775 }
9776  
9777 # unknown state - should not happen
9778 else {
9779 0 if (DEVEL_MODE) {
9780 Fault(<<EOM);
9781 Unknown scan state in sub scan_complex_identifier: '$id_scan_state'
9782 Scan state at sub entry was '$id_scan_state_begin'
9783 EOM
9784 }
9785 0 $id_scan_state = EMPTY_STRING;
9786 0 $i = $i_save;
9787 }
9788 3 last;
9789 }
9790  
9791 # Remember the starting index for progress check below
9792 1320 my $i_start_loop = $i;
9793  
9794 1320 $last_tok_is_blank = $tok_is_blank;
9795 1320 ▶ if ($tok_is_blank) { $tok_is_blank = undef }
Branch: 1 branch
BranchTrueFalseTotal
if ($tok_is_blank) { } 11 1309 1320
9796 1309 else { $i_save = $i }
9797  
9798 1320 $tok = $rtokens->[ ++$i ];
9799  
9800 # patch to make digraph :: if necessary
9801 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
9802 119 $tok = '::';
9803 119 $i++;
9804 }
9805  
9806 1320 $code->($self);
9807  
9808 # check for forward progress: a decrease in the index $i
9809 # implies that scanning has finished
9810 1320 ▶ last if ( $i <= $i_start_loop );
Branch: 1 branch
BranchTrueFalseTotal
if $i <= $i_start_loop 434 886 1320
9811  
9812 } ## end while ( $i < $max_token_index...)
9813  
9814 #-------------
9815 # Check result
9816 #-------------
9817  
9818 # Be sure a valid state is returned
9819 557 ▶ if ($id_scan_state) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state) 24 533 557
9820  
9821 24 ▶ if ( !$is_returnable_scan_state{$id_scan_state} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_returnable_scan_state{$id_scan_state}) 17 7 24
9822  
9823 17 ▶ if ( $id_scan_state eq $scan_state_SPLIT ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state eq $scan_state_SPLIT) 3 14 17
9824 3 $split_pretoken_flag = 1;
9825 }
9826  
9827 17 ▶ if ( $id_scan_state eq $scan_state_RPAREN ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_scan_state eq $scan_state_RPAREN) 0 17 17
9828 0 $self->warning(
9829 "Hit end of line while seeking ) to end prototype\n");
9830 }
9831  
9832 17 $id_scan_state = EMPTY_STRING;
9833 }
9834  
9835 # Patch: the deprecated variable $# does not combine with anything
9836 # on the next line.
9837 0 ▶ if ( $identifier eq '$#' ) { $id_scan_state = EMPTY_STRING }
Branch: 1 branch
BranchTrueFalseTotal
if ($identifier eq "\$#") 0 24 24
9838 }
9839  
9840 # Be sure the token index is valid
9841 0 ▶ if ( $i < 0 ) { $i = 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 0) 0 557 557
9842  
9843 # Be sure a token type is defined
9844 557 ▶ if ( !$type ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type) 529 28 557
9845  
9846 529 ▶ if ($saw_type) {
Branch: 2 branches
BranchTrueFalseTotal
if ($saw_type) { } 523 6 529
elsif ($saw_alpha) { } 5 1 6
9847  
9848 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
9849  
9850 # The type without the -> should be the same as with the -> so
9851 # that if they get separated we get the same bond strengths,
9852 # etc. See b1234
9853 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
9854 && $last_nonblank_type eq 'w'
9855 && substr( $identifier, 2, 1 ) =~ /^\w/ )
9856 {
9857 0 $type = 'w';
9858 }
9859 410 else { $type = 'i' }
9860 }
9861 elsif ( $identifier eq '->' ) {
9862 0 $type = '->';
9863 }
9864 ▶ 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
9865 ( length($identifier) > 1 )
9866  
9867 # In something like '@$=' we have an identifier '@$'
9868 # In something like '$${' we have type '$$' (and only
9869 # part of an identifier)
9870 && !( $identifier =~ /\$$/ && $tok eq '{' )
9871 && $identifier ne 'sub '
9872 && $identifier ne 'package '
9873 )
9874 {
9875 53 $type = 'i';
9876 }
9877 60 else { $type = 't' }
9878 }
9879 elsif ($saw_alpha) {
9880  
9881 # type 'w' includes anything without leading type info
9882 # ($,%,@,*) including something like abc::def::ghi
9883 5 $type = 'w';
9884  
9885 # Fix for b1337, if restarting scan after line break between
9886 # '->' or sigil and identifier name, use type 'i'
9887 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
9888 && $identifier =~ /^([\$\%\@\*\&]|->)/ )
9889 {
9890 5 $type = 'i';
9891 }
9892 }
9893 else {
9894 1 $type = EMPTY_STRING;
9895 } # this can happen on a restart
9896 }
9897  
9898 # See if we formed an identifier...
9899 557 ▶ if ($identifier) {
Branch: 1 branch
BranchTrueFalseTotal
if ($identifier) { } 510 47 557
9900 510 $tok = $identifier;
9901 510 ▶ if ($message) { $self->write_logfile_entry($message) }
Branch: 1 branch
BranchTrueFalseTotal
if ($message) 1 509 510
9902 }
9903  
9904 # did not find an identifier, back up
9905 else {
9906 47 $tok = $tok_begin;
9907 47 $i = $i_begin;
9908 }
9909  
9910 SCAN_ID_EMERGENCY_RETURN:
9911  
9912 557 DEBUG_SCAN_ID && do {
9913 my ( $a, $b, $c ) = caller();
9914 print {*STDOUT}
9915 "SCANID: called from $a $b $c with tok, i, state, identifier =$tok_begin, $i_begin, $id_scan_state_begin, $identifier_begin\n";
9916 print {*STDOUT}
9917 "SCANID: returned with tok, i, state, identifier =$tok, $i, $id_scan_state, $identifier\n";
9918 };
9919  
9920 return (
9921  
9922 557 $i,
9923 $tok,
9924 $type,
9925 $id_scan_state,
9926 $identifier,
9927 $split_pretoken_flag,
9928 );
9929 } ## end sub scan_complex_identifier
9930 } ## end closure for sub scan_complex_identifier
9931  
9932 { ## closure for sub do_scan_sub
9933  
9934 # saved package and subnames in case prototype is on separate line
9935 45 my ( $package_saved, $subname_saved );
9936  
9937 # initialize subname each time a new 'sub' keyword is encountered
9938 367 ▶ sub initialize_subname {
Subroutine initialize_subname: called CC=1 SCAR=0.0
Pod undocumented
9939 367 $package_saved = EMPTY_STRING;
9940 367 $subname_saved = EMPTY_STRING;
9941 367 return;
9942 }
9943  
9944 45 ▶ use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
9945 45 SUB_CALL => 1,
9946 PAREN_CALL => 2,
9947 PROTOTYPE_CALL => 3,
9948 45 };
9949  
9950 373 ▶ sub do_scan_sub {
Subroutine do_scan_sub: called CC=55 SCAR=46.8
Pod undocumented
9951  
9952 373 my ( $self, $rcall_hash ) = @_;
9953  
9954 # Parse a sub name and prototype.
9955  
9956 373 my $input_line = $rcall_hash->{input_line};
9957 373 my $i = $rcall_hash->{i};
9958 373 my $i_beg = $rcall_hash->{i_beg};
9959 373 my $tok = $rcall_hash->{tok};
9960 373 my $type = $rcall_hash->{type};
9961 373 my $rtokens = $rcall_hash->{rtokens};
9962 373 my $rtoken_map = $rcall_hash->{rtoken_map};
9963 373 my $id_scan_state = $rcall_hash->{id_scan_state};
9964 373 my $max_token_index = $rcall_hash->{max_token_index};
9965  
9966 373 ▶ my $id_prefix = $rcall_hash->{is_lexical_method} ? '$' : EMPTY_STRING;
Branch: 1 branch
BranchTrueFalseTotal
$rcall_hash->{'is_lexical_method'} ? : 2 371 373
9967  
9968 # At present there are three basic CALL TYPES which are
9969 # distinguished by the starting value of '$tok':
9970 # 1. $tok='sub', id_scan_state='sub'
9971 # it is called with $i_beg equal to the index of the first nonblank
9972 # token following a 'sub' token.
9973 # 2. $tok='(', id_scan_state='sub',
9974 # it is called with $i_beg equal to the index of a '(' which may
9975 # start a prototype.
9976 # 3. $tok='prototype', id_scan_state='prototype'
9977 # it is called with $i_beg equal to the index of a '(' which is
9978 # preceded by ': prototype' and has $id_scan_state eq 'prototype'
9979  
9980 # Examples:
9981  
9982 # A single type 1 call will get both the sub and prototype
9983 # sub foo1 ( $$ ) { }
9984 # ^
9985  
9986 # The subname will be obtained with a 'sub' call
9987 # The prototype on line 2 will be obtained with a '(' call
9988 # sub foo1
9989 # ^ <---call type 1
9990 # ( $$ ) { }
9991 # ^ <---call type 2
9992  
9993 # The subname will be obtained with a 'sub' call
9994 # The prototype will be obtained with a 'prototype' call
9995 # sub foo1 ( $x, $y ) : prototype ( $$ ) { }
9996 # ^ <---type 1 ^ <---type 3
9997  
9998 # TODO: add future error checks to be sure we have a valid
9999 # sub name. For example, 'sub &doit' is wrong. Also, be sure
10000 # a name is given if and only if a non-anonymous sub is
10001 # appropriate.
10002 # USES GLOBAL VARS: $current_package, $last_nonblank_token,
10003 # $rsaw_function_definition,
10004 # $statement_type
10005  
10006 373 my $i_entry = $i;
10007  
10008 # Determine the CALL TYPE
10009 # 1=sub
10010 # 2=(
10011 # 3=prototype
10012 373 ▶ my $call_type =
Branch: 2 branches
BranchTrueFalseTotal
$tok eq 'prototype' ? : 2 371 373
$tok eq '(' ? : 5 366 371
10013 $tok eq 'prototype' ? PROTOTYPE_CALL
10014 : $tok eq '(' ? PAREN_CALL
10015 : SUB_CALL;
10016  
10017 373 $id_scan_state = EMPTY_STRING; # normally we get everything in one call
10018 373 my $subname = $subname_saved;
10019 373 my $package = $package_saved;
10020 373 my $proto = undef;
10021 373 my $attrs = undef;
10022 373 my $match;
10023  
10024 373 my $pos_beg = $rtoken_map->[$i_beg];
10025 373 pos($input_line) = $pos_beg;
10026  
10027 # Look for the sub NAME if this is a SUB call
10028 373 ▶ 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) 178 195 373
Condition100%3/3
$call_type == 1 and $input_line =~ /\G\s* ((?:\w*(?:'|::))*) # package - something that ends in :: or ' (\w+) # NAME - required /cgx
!ll&&!rl&&r
7188178
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
10029 $call_type == SUB_CALL
10030 && $input_line =~ m{\G\s*
10031 ((?:\w*(?:'|::))*) # package - something that ends in :: or '
10032 (\w+) # NAME - required
10033 }gcx
10034 )
10035 {
10036 178 $match = 1;
10037 178 $subname = $2;
10038 my $is_lexical_sub = $last_nonblank_type eq 'k'
10039 178 ▶ && $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
17800
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
10040 178 ▶ if ( $is_lexical_sub && $1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_lexical_sub and $1) 0 178 178
Condition33%1/3
$is_lexical_sub and $1
!ll&&!rl&&r
17800
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
10041 0 $self->warning(
10042 "'$last_nonblank_token' sub $subname cannot be in package '$1'\n"
10043 );
10044 0 $is_lexical_sub = 0;
10045 }
10046  
10047 178 ▶ if ($is_lexical_sub) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_lexical_sub) { } 0 178 178
10048  
10049 # Lexical subs use the containing block sequence number as a
10050 # package name.
10051 0 my $seqno =
10052 $rcurrent_sequence_number->[BRACE]
10053 ->[ $rcurrent_depth->[BRACE] ];
10054 0 ▶ $seqno = SEQ_ROOT if ( !defined($seqno) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seqno 0 0 0
10055 0 $package = $seqno;
10056  
10057 # The value will eventually be the sequence number of the
10058 # opening curly brace of the definition (if any). We use -1
10059 # until we find it.
10060 0 $ris_lexical_sub->{$subname}->{$package} = -1;
10061  
10062 # Set a special signal to tell sub do_LEFT_CURLY_BRACKET to
10063 # update this value if the next opening sub block brace is for
10064 # this sub. The reason we need this value is to avoid applying
10065 # this new sub in its own definition block. Note that '911' is
10066 # not a possible sub name. Search for '911' for related code.
10067 0 $ris_lexical_sub->{911} = [ $subname, $package ];
10068  
10069 # Complain if lexical sub name hides a quote operator
10070 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
10071 0 $self->complain(
10072 "'my' sub '$subname' matches a builtin quote operator\n"
10073 );
10074 ## OLD CODING, before improved handling of lexical subs:
10075 ## This may end badly, it is safest to avoid formatting.
10076 ## For an example, see perl527/lexsub.t (issue c203)
10077 ## $self->[_do_not_format_] = 1;
10078 }
10079 }
10080 else {
10081 178 ▶ $package = ( defined($1) && $1 ) ? $1 : $current_package;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 && $1 ? : 6 172 178
Condition66%2/3
defined $1 and $1
!ll&&!rl&&r
01726
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
10082 178 $package =~ s/\'/::/g;
10083 0 ▶ if ( $package =~ /^\:/ ) { $package = 'main' . $package }
Branch: 1 branch
BranchTrueFalseTotal
if ($package =~ /^\:/) 0 178 178
10084 178 $package =~ s/::$//;
10085 }
10086  
10087 178 my $pos = pos($input_line);
10088 178 my $numc = $pos - $pos_beg;
10089 178 $tok = 'sub ' . $id_prefix . substr( $input_line, $pos_beg, $numc );
10090 178 $type = 'S'; ## Fix for c250, was 'i';
10091  
10092 # remember the sub name in case another call is needed to
10093 # get the prototype
10094 178 $package_saved = $package;
10095 178 $subname_saved = $subname;
10096 }
10097  
10098 # Now look for PROTO ATTRS for all call types
10099 # Look for prototype/attributes which are usually on the same
10100 # line as the sub name but which might be on a separate line.
10101 # For example, we might have an anonymous sub with attributes,
10102 # or a prototype on a separate line from its sub name
10103  
10104 # NOTE: We only want to parse PROTOTYPES here. If we see anything that
10105 # does not look like a prototype, we assume it is a SIGNATURE and we
10106 # will stop and let the standard tokenizer handle it. In
10107 # particular, we stop if we see any nested parens, braces, or commas.
10108 # Also note, a valid prototype cannot contain any alphabetic character
10109 # -- see https://perldoc.perl.org/perlsub
10110 # But it appears that an underscore is valid in a prototype, so the
10111 # regex below uses [A-Za-z] rather than \w
10112 # This is the old regex which has been replaced:
10113 # $input_line =~ m/\G(\s*\([^\)\(\}\{\,#]*\))? # PROTO
10114 # Added '=' for issue c362
10115 373 my $saw_opening_paren = $input_line =~ /\G\s*\(/;
10116 373 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /\G(\s*\([^\)\(\}\{\,#A-Za-z=]*\))? # PROTO (\s*:)? # ATTRS leading ':' /cgx and $1 || $2) 45 328 373
Condition83%5/6
$input_line =~ /\G(\s*\([^\)\(\}\{\,#A-Za-z=]*\))? # PROTO (\s*:)? # ATTRS leading ':' /cgx and $1 || $2
!ll&&!rl&&r
032845
$1 or $2
l!l&&r!l&&!r
3411328
MC/DC66%2/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 table75%3/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
10117 $input_line =~ m{\G(\s*\([^\)\(\}\{\,#A-Za-z=]*\))? # PROTO
10118 (\s*:)? # ATTRS leading ':'
10119 }gcx
10120 && ( $1 || $2 )
10121 )
10122 {
10123 45 $proto = $1;
10124 45 $attrs = $2;
10125  
10126 # Append the prototype to the starting token if it is 'sub' or
10127 # 'prototype'. This is not necessary but for compatibility with
10128 # previous versions when the -csc flag is used:
10129 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
10130 24 $tok .= $proto;
10131 }
10132  
10133 # If we just entered the sub at an opening paren on this call, not
10134 # a following :prototype, label it with the previous token. This is
10135 # necessary to propagate the sub name to its opening block.
10136 elsif ( $call_type == PAREN_CALL ) {
10137 2 $tok = $last_nonblank_token;
10138 }
10139 else {
10140 ##
10141 }
10142  
10143 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
10144  
10145 # Patch part #1 to fixes cases b994 and b1053:
10146 # Mark an anonymous sub keyword without prototype as type 'k', i.e.
10147 # 'sub : lvalue { ...'
10148 45 $type = 'S'; ## C250, was 'i';
10149 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
10150 }
10151  
10152 373 ▶ if ($match) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match) { } 193 180 373
10153  
10154 # ATTRS: if there are attributes, back up and let the ':' be
10155 # found later by the scanner.
10156 193 my $pos = pos($input_line);
10157 193 ▶ if ($attrs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrs) 15 178 193
10158 15 $pos -= length($attrs);
10159 }
10160  
10161 193 my $next_nonblank_token = $tok;
10162  
10163 # catch case of line with leading ATTR ':' after anonymous sub
10164 193 ▶ if ( $pos == $pos_beg && $tok eq ':' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos == $pos_beg and $tok eq ':') { } 1 192 193
Condition100%3/3
$pos == $pos_beg and $tok eq ":"
!ll&&!rl&&r
19021
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
10165 1 $type = 'A';
10166 1 $self->[_in_attribute_list_] = 1;
10167 }
10168  
10169 # Otherwise, if we found a match we must convert back from
10170 # string position to the pre_token index for continued parsing.
10171 else {
10172  
10173 # I don't think an error flag can occur here ..but ?
10174 192 my $error;
10175 192 ( $i, $error ) = inverse_pretoken_map( $i, $pos, $rtoken_map,
10176 $max_token_index );
10177 0 ▶ if ($error) { $self->warning("Possibly invalid sub\n") }
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 192 192
10178  
10179 # Patch part #2 to fixes cases b994 and b1053:
10180 # Do not let spaces be part of the token of an anonymous sub
10181 # keyword which we marked as type 'k' above...i.e. for
10182 # something like:
10183 # 'sub : lvalue { ...'
10184 # Back up and let it be parsed as a blank
10185 192 ▶ 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 190 192
Condition66%6/9
$type eq "k" and $attrs and $i > $i_entry and substr($rtokens->[$i], 0, 1) =~ /\s/
!ll&&!rl&&r
19002
$type eq "k" and $attrs and $i > $i_entry
!ll&&!rl&&r
19002
$type eq "k" and $attrs
!ll&&!rl&&r
19002
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
10186 && $attrs
10187 && $i > $i_entry
10188 && substr( $rtokens->[$i], 0, 1 ) =~ m/\s/ )
10189 {
10190 2 $i--;
10191 }
10192  
10193 # check for multiple definitions of a sub
10194 192 ( $next_nonblank_token, my $i_next_uu ) =
10195 find_next_nonblank_token_on_this_line( $i, $rtokens,
10196 $max_token_index );
10197 }
10198  
10199 193 ▶ if ( $next_nonblank_token =~ /^(\s*|#)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token =~ /^(\s*|#)$/) 7 186 193
10200 { # skip blank or side comment
10201 7 my ( $rpre_tokens, $rpre_types_uu ) =
10202 $self->peek_ahead_for_n_nonblank_pre_tokens(1);
10203 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
10204 7 $next_nonblank_token = $rpre_tokens->[0];
10205 }
10206 else {
10207 0 $next_nonblank_token = '}';
10208 }
10209 }
10210  
10211 # See what's next...
10212 193 ▶ if ( $next_nonblank_token eq '{' ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($next_nonblank_token eq '{') { } 155 38 193
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
10213 155 ▶ if ($subname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subname) 145 10 155
10214  
10215 # Check for multiple definitions of a sub, but
10216 # it is ok to have multiple sub BEGIN, etc,
10217 # so we do not complain if name is all caps
10218 145 ▶ if ( $rsaw_function_definition->{$subname}->{$package}
Branch: 1 branch
BranchTrueFalseTotal
if ($rsaw_function_definition->{$subname}{$package} and not $subname =~ /^[A-Z]+$/) 0 145 145
Condition33%1/3
$rsaw_function_definition->{$subname}{$package} and not $subname =~ /^[A-Z]+$/
!ll&&!rl&&r
14500
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
10219 && $subname !~ /^[A-Z]+$/ )
10220 {
10221 my $lno =
10222 0 $rsaw_function_definition->{$subname}->{$package};
10223 0 ▶ if ( $package =~ /^\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package =~ /^\d/) { } 0 0 0
10224 0 $self->warning(
10225 "already saw definition of lexical 'sub $subname' at line $lno\n"
10226 );
10227  
10228 }
10229 else {
10230 0 if ( !DEVEL_MODE ) {
10231 0 $self->warning(
10232 "already saw definition of 'sub $subname' in package '$package' at line $lno\n"
10233 );
10234 }
10235 }
10236 }
10237 145 $rsaw_function_definition->{$subname}->{$package} =
10238 $self->[_last_line_number_];
10239 }
10240 }
10241 elsif ( $next_nonblank_token eq ';' ) {
10242 }
10243 elsif ( $next_nonblank_token eq '}' ) {
10244 }
10245  
10246 # ATTRS - if an attribute list follows, remember the name
10247 # of the sub so the next opening brace can be labeled.
10248 # Setting 'statement_type' causes any ':'s to introduce
10249 # attributes.
10250 elsif ( $next_nonblank_token eq ':' ) {
10251 16 ▶ if ( $call_type == SUB_CALL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call_type == 1) 14 2 16
10252 14 ▶ $statement_type =
Branch: 1 branch
BranchTrueFalseTotal
substr($tok, 0, 3) eq 'sub' ? : 13 1 14
10253 substr( $tok, 0, 3 ) eq 'sub' ? $tok : 'sub';
10254 }
10255 }
10256  
10257 # if we stopped before an open paren ...
10258 elsif ( $next_nonblank_token eq '(' ) {
10259  
10260 # If we DID NOT see this paren above then it must be on the
10261 # next line so we will set a flag to come back here and see if
10262 # it is a PROTOTYPE
10263  
10264 # Otherwise, we assume it is a SIGNATURE rather than a
10265 # PROTOTYPE and let the normal tokenizer handle it as a list
10266 21 ▶ if ( !$saw_opening_paren ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($saw_opening_paren) 4 17 21
10267 4 $id_scan_state = 'sub'; # we must come back to get proto
10268 }
10269 21 ▶ if ( $call_type == SUB_CALL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call_type == 1) 21 0 21
10270 21 ▶ $statement_type =
Branch: 1 branch
BranchTrueFalseTotal
substr($tok, 0, 3) eq 'sub' ? : 21 0 21
10271 substr( $tok, 0, 3 ) eq 'sub' ? $tok : 'sub';
10272 }
10273 }
10274  
10275 # something else..
10276 elsif ($next_nonblank_token) {
10277  
10278 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
10279 {
10280 # For a method call, silently ignore this error (rt145706)
10281 # to avoid needless warnings. Example which can produce it:
10282 # test(method Pack (), "method");
10283  
10284 # TODO: scan for use feature 'class' and:
10285 # - if we saw 'use feature 'class' then issue the warning.
10286 # - if we did not see use feature 'class' then issue the
10287 # warning and suggest turning off --use-feature=class
10288 }
10289 else {
10290 0 ▶ $subname = EMPTY_STRING unless ( defined($subname) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $subname 0 0 0
10291 0 $self->warning(
10292 "expecting ':' or ';' or '{' after definition or declaration of sub '$subname' but saw '$next_nonblank_token'\n"
10293 );
10294 }
10295 }
10296 else {
10297 ## EOF technically ok
10298 }
10299  
10300 193 check_prototype( $proto, $package, $subname );
10301 }
10302  
10303 # no match to either sub name or prototype, but line not blank
10304 else {
10305 ##
10306 }
10307 373 return ( $i, $tok, $type, $id_scan_state );
10308 } ## end sub do_scan_sub
10309 }
10310  
10311 #########################################################################
10312 # Tokenizer utility routines which may use CONSTANTS but no other GLOBALS
10313 #########################################################################
10314  
10315 45 ▶sub find_next_nonblank_token {
Subroutine find_next_nonblank_token: called CC=13 SCAR=27.0
Pod undocumented
10316 470 my ( $self, $i, $rtokens, $max_token_index ) = @_;
10317  
10318 # Returns the next nonblank token after the token at index $i
10319 # To skip past a side comment, and any subsequent block comments
10320 # and blank lines, call with i=$max_token_index
10321  
10322 # Skip any ending blank (fix c258). It would be cleaner if caller passed
10323 # $rtoken_map, so we could check for type 'b', and avoid a regex test, but
10324 # benchmarking shows that this test does not take significant time. So
10325 # that would be a nice update but not essential. Also note that ending
10326 # blanks will not occur for text previously processed by perltidy.
10327 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
10328 && $rtokens->[$max_token_index] =~ /^\s+$/ )
10329 {
10330 9 $i++;
10331 }
10332  
10333 470 ▶ if ( $i >= $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $max_token_index) 145 325 470
10334 145 ▶ if ( !peeked_ahead() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (peeked_ahead()) 143 2 145
10335 143 peeked_ahead(1);
10336 143 $self->peek_ahead_for_nonblank_token( $rtokens, $max_token_index );
10337 }
10338 }
10339  
10340 470 my $next_nonblank_token = $rtokens->[ ++$i ];
10341  
10342 # Any more tokens?
10343 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
10344 if ( !defined($next_nonblank_token) || !length($next_nonblank_token) );
10345  
10346 # Skip over whitespace
10347 470 my $ord = ord( substr( $next_nonblank_token, 0, 1 ) );
10348 470 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($ord <= 33 || $ord >= 126 and $ord == 32 || $ord == 9 || $next_nonblank_token =~ /^\s+$/) 309 161 470
Condition50%6/12
$ord <= 33 || $ord >= 126 and $ord == 32 || $ord == 9 || $next_nonblank_token =~ /^\s+$/
!ll&&!rl&&r
1610309
$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/DC20%1/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 table22%2/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
10349  
10350 ( $ord <= ORD_PRINTABLE_MIN || $ord >= ORD_PRINTABLE_MAX )
10351  
10352 # Quick test for ascii space or tab
10353 && (
10354 ( $ord == ORD_SPACE || $ord == ORD_TAB )
10355  
10356 # Slow test to for something else identified as whitespace
10357 || $next_nonblank_token =~ /^\s+$/
10358 )
10359 )
10360 {
10361 309 $next_nonblank_token = $rtokens->[ ++$i ];
10362 309 ▶ return ( SPACE, $i ) unless ( defined($next_nonblank_token) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next_nonblank_token 0 309 309
10363 }
10364  
10365 # We should be at a nonblank now
10366 470 return ( $next_nonblank_token, $i );
10367  
10368 } ## end sub find_next_nonblank_token
10369  
10370 110 ▶sub find_next_noncomment_token {
Subroutine find_next_noncomment_token: called CC=8 SCAR=23.9
Pod undocumented
10371 110 my ( $self, $i, $rtokens, $max_token_index ) = @_;
10372  
10373 # Given the current character position, look ahead past any comments
10374 # and blank lines and return the next token, including digraphs and
10375 # trigraphs.
10376  
10377 110 my ( $next_nonblank_token, $i_next ) =
10378 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
10379  
10380 # skip past any side comment
10381 110 ▶ if ( $next_nonblank_token eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "#") 0 110 110
10382 0 ( $next_nonblank_token, $i_next ) =
10383 $self->find_next_nonblank_token( $i_next, $rtokens,
10384 $max_token_index );
10385 }
10386  
10387 # check for a digraph
10388 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
10389 && $next_nonblank_token ne SPACE
10390 && defined( $rtokens->[ $i_next + 1 ] ) )
10391 {
10392 110 my $test2 = $next_nonblank_token . $rtokens->[ $i_next + 1 ];
10393 110 ▶ if ( $is_digraph{$test2} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_digraph{$test2}) 17 93 110
10394 17 $next_nonblank_token = $test2;
10395 17 $i_next = $i_next + 1;
10396  
10397 # check for a trigraph
10398 17 ▶ if ( defined( $rtokens->[ $i_next + 1 ] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$rtokens[$i_next + 1]) 17 0 17
10399 17 my $test3 = $next_nonblank_token . $rtokens->[ $i_next + 1 ];
10400 17 ▶ if ( $is_trigraph{$test3} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_trigraph{$test3}) 0 17 17
10401 0 $next_nonblank_token = $test3;
10402 0 $i_next = $i_next + 1;
10403 }
10404 }
10405 }
10406 }
10407  
10408 110 return ( $next_nonblank_token, $i_next );
10409 } ## end sub find_next_noncomment_token
10410  
10411 0 ▶sub is_possible_numerator {
Subroutine is_possible_numerator: not called CC=10 SCAR=47.0
Pod undocumented
10412  
10413 0 my ( $self, $i, $rtokens, $max_token_index ) = @_;
10414  
10415 # Look at the next non-comment character and decide if it could be a
10416 # numerator. Returns the following code:
10417 # -1 - division not possible
10418 # 0 - can't tell if division possible
10419 # 1 - division possible
10420 # 2 - division probable: number follows
10421 # 3 - division very probable: number and one of ; ] } follow
10422 # 4 - is division, not pattern: number and ) follow
10423  
10424 0 my $divide_possible_code = 0;
10425  
10426 0 my $next_token = $rtokens->[ $i + 1 ];
10427 0 ▶ if ( $next_token eq '=' ) { $i++; } # handle /=
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token eq "=") 0 0 0
10428 0 my ( $next_nonblank_token, $i_next ) =
10429 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
10430  
10431 0 ▶ if ( $next_nonblank_token eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token eq "#") 0 0 0
10432 0 ( $next_nonblank_token, $i_next ) =
10433 $self->find_next_nonblank_token( $max_token_index, $rtokens,
10434 $max_token_index );
10435 }
10436  
10437 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
10438 0 $divide_possible_code = 1;
10439  
10440 # look ahead one more token for some common patterns, such as
10441 # pi/2) pi/2; pi/2}
10442 0 ▶ if ( $next_nonblank_token =~ /^\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token =~ /^\d/) 0 0 0
10443 0 my ( $next_next_nonblank_token, $i_next_next_uu ) =
10444 $self->find_next_nonblank_token( $i_next, $rtokens,
10445 $max_token_index );
10446 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
10447 0 $divide_possible_code = 4;
10448 }
10449 ▶ 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
10450 || $next_next_nonblank_token eq ']'
10451 || $next_next_nonblank_token eq '}' )
10452 {
10453 0 $divide_possible_code = 3;
10454 }
10455 else {
10456 0 $divide_possible_code = 2;
10457 }
10458 }
10459 }
10460 elsif ( $next_nonblank_token =~ /^\s*$/ ) {
10461 0 $divide_possible_code = 0;
10462 }
10463 else {
10464 0 $divide_possible_code = -1;
10465 }
10466  
10467 0 return $divide_possible_code;
10468 } ## end sub is_possible_numerator
10469  
10470 { ## closure for sub pattern_expected
10471 45 my %pattern_test;
10472  
10473 45 ▶ BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
10474  
10475 # List of tokens which may follow a pattern. Note that we will not
10476 # have formed digraphs at this point, so we will see '&' instead of
10477 # '&&' and '|' instead of '||'
10478  
10479 # /(\)|\}|\;|\&\&|\|\||and|or|while|if|unless)/
10480 45 my @q = qw( & && | || ? : + - * and or while if unless );
10481 45 push @q, ')', '}', ']', '>', COMMA, ';';
10482 45 $pattern_test{$_} = 1 for @q;
10483 } ## end BEGIN
10484  
10485 0 ▶ sub pattern_expected {
Subroutine pattern_expected: not called CC=5 SCAR=34.0
Pod undocumented
10486  
10487 0 my ( $self, $i, $rtokens, $max_token_index ) = @_;
10488  
10489 # This a filter for a possible pattern.
10490 # It looks at the token after a possible pattern and tries to
10491 # determine if that token could end a pattern.
10492 # returns -
10493 # 1 - yes
10494 # 0 - can't tell
10495 # -1 - no
10496 0 my $is_pattern = 0;
10497  
10498 0 my $next_token = $rtokens->[ $i + 1 ];
10499  
10500 # skip a possible quote modifier
10501 0 my $possible_modifiers = $quote_modifiers{'m'};
10502 0 ▶ if ( $next_token =~ /^$possible_modifiers/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token =~ /^$possible_modifiers/) 0 0 0
10503 0 $i++;
10504 }
10505  
10506 0 my ( $next_nonblank_token, $i_next_uu ) =
10507 $self->find_next_nonblank_token( $i, $rtokens, $max_token_index );
10508  
10509 0 ▶ if ( $pattern_test{$next_nonblank_token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern_test{$next_nonblank_token}) { } 0 0 0
10510 0 $is_pattern = 1;
10511 }
10512 else {
10513  
10514 # Added '#' to fix issue c044
10515 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
10516 || $next_nonblank_token eq '#' )
10517 {
10518 0 $is_pattern = 0;
10519 }
10520 else {
10521 0 $is_pattern = -1;
10522 }
10523 }
10524 0 return $is_pattern;
10525 } ## end sub pattern_expected
10526 }
10527  
10528 45 ▶sub find_next_nonblank_token_on_this_line {
Subroutine find_next_nonblank_token_on_this_line: called CC=4 SCAR=13.9
Pod undocumented
10529 657 my ( $i, $rtokens, $max_token_index ) = @_;
10530 657 my $next_nonblank_token;
10531  
10532 657 ▶ if ( $i < $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $max_token_index) { } 649 8 657
10533 649 $next_nonblank_token = $rtokens->[ ++$i ];
10534  
10535 649 ▶ if ( $next_nonblank_token =~ /^\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_nonblank_token =~ /^\s*$/) 190 459 649
10536  
10537 190 ▶ if ( $i < $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $max_token_index) 188 2 190
10538 188 $next_nonblank_token = $rtokens->[ ++$i ];
10539 }
10540 }
10541 }
10542 else {
10543 8 $next_nonblank_token = EMPTY_STRING;
10544 }
10545 657 return ( $next_nonblank_token, $i );
10546 } ## end sub find_next_nonblank_token_on_this_line
10547  
10548 8 ▶sub find_angle_operator_termination {
Subroutine find_angle_operator_termination: called CC=29 SCAR=47.8
Pod undocumented
10549  
10550 8 my ( $self, $input_line, $i_beg, $rtoken_map, $expecting, $max_token_index )
10551 = @_;
10552  
10553 # We are looking at a '<' and want to know if it is an angle operator.
10554 # Return:
10555 # $i = pretoken index of ending '>' if found, current $i otherwise
10556 # $type = 'Q' if found, '>' otherwise
10557  
10558 8 my $i = $i_beg;
10559 8 my $type = '<';
10560 8 pos($input_line) = 1 + $rtoken_map->[$i];
10561  
10562 # The token sequence '><' implies a markup language
10563 8 ▶ if ( $last_nonblank_token eq '>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_token eq ">") 0 8 8
10564 0 $self->[_html_tag_count_]++;
10565 }
10566  
10567 8 my $filter;
10568  
10569 8 my $expecting_TERM = $expecting == TERM;
10570  
10571 # we just have to find the next '>' if a term is expected
10572 8 ▶ if ($expecting_TERM) { $filter = '[\>]' }
Branch: 2 branches
BranchTrueFalseTotal
if ($expecting_TERM) { } 6 2 8
elsif ($expecting == 0) { } 2 0 2
10573  
10574 # we have to guess if we don't know what is expected
10575 2 elsif ( $expecting == UNKNOWN ) { $filter = '[\>\;\=\#\|\<]' }
10576  
10577 # shouldn't happen - we shouldn't be here if operator is expected
10578 else {
10579 0 if (DEVEL_MODE) {
10580 Fault(<<EOM);
10581 Bad call to find_angle_operator_termination
10582 EOM
10583 }
10584 0 return ( $i, $type );
10585 }
10586  
10587 # To illustrate what we might be looking at, in case we are
10588 # guessing, here are some examples of valid angle operators
10589 # (or file globs):
10590 # <tmp_imp/*>
10591 # <FH>
10592 # <$fh>
10593 # <*.c *.h>
10594 # <_>
10595 # <jskdfjskdfj* op/* jskdjfjkosvk*> ( glob.t)
10596 # <${PREFIX}*img*.$IMAGE_TYPE>
10597 # <img*.$IMAGE_TYPE>
10598 # <Timg*.$IMAGE_TYPE>
10599 # <$LATEX2HTMLVERSIONS${dd}html[1-9].[0-9].pl>
10600 #
10601 # Here are some examples of lines which do not have angle operators:
10602 # return unless $self->[2]++ < $#{$self->[1]};
10603 # < 2 || @$t >
10604 #
10605 # the following line from dlister.pl caused trouble:
10606 # print'~'x79,"\n",$D<1024?"0.$D":$D>>10,"K, $C files\n\n\n";
10607 #
10608 # If the '<' starts an angle operator, it must end on this line and
10609 # it must not have certain characters like ';' and '=' in it. I use
10610 # this to limit the testing. This filter should be improved if
10611 # possible.
10612  
10613 8 ▶ if ( $input_line =~ /($filter)/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($input_line =~ /($filter)/g) 8 0 8
10614  
10615 8 ▶ if ( $1 eq '>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq '>') { } 8 0 8
10616  
10617 # We MAY have found an angle operator termination if we get
10618 # here, but we need to do more to be sure we haven't been
10619 # fooled.
10620 8 my $pos = pos($input_line);
10621  
10622 8 my $pos_beg = $rtoken_map->[$i];
10623 8 my $str = substr( $input_line, $pos_beg, ( $pos - $pos_beg ) );
10624  
10625 # Test for '<' after possible filehandle, issue c103
10626 # print $fh <>; # syntax error
10627 # print $fh <DATA>; # ok
10628 # print $fh < DATA>; # syntax error at '>'
10629 # print STDERR < DATA>; # ok, prints word 'DATA'
10630 # print BLABLA <DATA>; # ok; does nothing unless BLABLA is defined
10631 8 ▶ if ( $last_nonblank_type eq 'Z' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_nonblank_type eq "Z") 1 7 8
10632  
10633 # $str includes brackets; something like '<DATA>'
10634 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
10635 && substr( $str, 1, 1 ) !~ /[A-Za-z_]/ )
10636 {
10637 0 return ( $i, $type );
10638 }
10639 }
10640  
10641 # Reject if the closing '>' follows a '-' as in:
10642 # if ( VERSION < 5.009 && $op-> name eq 'assign' ) { }
10643 8 ▶ if ( $expecting eq UNKNOWN ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting eq 0) 2 6 8
10644 2 my $check = substr( $input_line, $pos - 2, 1 );
10645 2 ▶ if ( $check eq '-' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check eq "-") 1 1 2
10646 1 return ( $i, $type );
10647 }
10648 }
10649  
10650 ######################################debug#####
10651 #$self->write_diagnostics( "ANGLE? :$str\n");
10652 #print "ANGLE: found $1 at pos=$pos str=$str check=$check\n";
10653 ######################################debug#####
10654 7 $type = 'Q';
10655 7 my $error;
10656 7 ( $i, $error ) =
10657 inverse_pretoken_map( $i, $pos, $rtoken_map, $max_token_index );
10658  
10659 # It may be possible that a quote ends midway in a pretoken.
10660 # If this happens, it may be necessary to split the pretoken.
10661 7 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 7 7
10662 0 if (DEVEL_MODE) {
10663 Fault(<<EOM);
10664 unexpected error condition returned by inverse_pretoken_map
10665 EOM
10666 }
10667 $self->warning(
10668 0 "Possible tokenization error..please check this line\n");
10669 }
10670  
10671 # Check for accidental formatting of a markup language doc...
10672 # Formatting will be skipped if we set _html_tag_count_ and
10673 # also set a warning of any kind.
10674 7 my $is_html_tag;
10675 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
10676 $i_beg == 0 && $self->[_last_line_number_] == 1;
10677  
10678 # html comment '<!...' of any type
10679 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
10680 0 $is_html_tag = 1;
10681 0 ▶ if ($is_first_string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_first_string) 0 0 0
10682 0 $self->warning(
10683 "looks like a markup language, continuing error checks\n"
10684 );
10685 }
10686 }
10687  
10688 # html end tag, something like </h1>
10689 elsif ( $str =~ /^<\s*\/\w+\s*>$/ ) {
10690 0 $is_html_tag = 1;
10691 }
10692  
10693 # xml prolog?
10694 ▶ 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
10695 0 $is_html_tag = 1;
10696 0 $self->warning(
10697 "looks like a markup language, continuing error checks\n");
10698 }
10699 else {
10700 ## doesn't look like a markup tag
10701 }
10702  
10703 7 ▶ if ($is_html_tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_html_tag) 0 7 7
10704 0 $self->[_html_tag_count_]++;
10705 }
10706  
10707 # count blanks on inside of brackets
10708 7 my $blank_count = 0;
10709 7 ▶ $blank_count++ if ( $str =~ /<\s+/ );
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /<\s+/ 1 6 7
10710 7 ▶ $blank_count++ if ( $str =~ /\s+>/ );
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /\s+>/ 1 6 7
10711  
10712 # Now let's see where we stand....
10713 # OK if math op not possible
10714 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
10715 }
10716  
10717 elsif ($is_html_tag) {
10718 }
10719  
10720 # OK if there are no more than 2 non-blank pre-tokens inside
10721 # (not possible to write 2 token math between < and >)
10722 # This catches most common cases
10723 elsif ( $i <= $i_beg + 3 + $blank_count ) {
10724  
10725 # No longer any need to document this common case
10726 ## $self->write_diagnostics("ANGLE(1 or 2 tokens): $str\n");
10727 }
10728  
10729 # OK if there is some kind of identifier inside
10730 # print $fh <tvg::INPUT>;
10731 elsif ( $str =~ /^<\s*\$?(\w|::|\s)+\s*>$/ ) {
10732 0 $self->write_diagnostics("ANGLE (contains identifier): $str\n");
10733 }
10734  
10735 # Not sure..
10736 else {
10737  
10738 # Let's try a Brace Test: any braces inside must balance
10739 0 my $br = $str =~ tr/\{/{/ - $str =~ tr/\}/}/;
10740 0 my $sb = $str =~ tr/\[/[/ - $str =~ tr/\]/]/;
10741 0 my $pr = $str =~ tr/\(/(/ - $str =~ tr/\)/)/;
10742  
10743 # if braces do not balance - not angle operator
10744 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
10745 0 $i = $i_beg;
10746 0 $type = '<';
10747 0 $self->write_diagnostics(
10748 "NOT ANGLE (BRACE={$br ($pr [$sb ):$str\n");
10749 }
10750  
10751 # we should keep doing more checks here...to be continued
10752 # Tentatively accepting this as a valid angle operator.
10753 # There are lots more things that can be checked.
10754 else {
10755 0 $self->write_diagnostics(
10756 "ANGLE-Guessing yes: $str expecting=$expecting\n");
10757 0 $self->write_logfile_entry(
10758 "Guessing angle operator here: $str\n");
10759 }
10760 }
10761 }
10762  
10763 # didn't find ending >
10764 else {
10765 0 ▶ if ($expecting_TERM) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting_TERM) 0 0 0
10766 0 $self->warning("No ending > for angle operator\n");
10767 }
10768 }
10769 }
10770 7 return ( $i, $type );
10771 } ## end sub find_angle_operator_termination
10772  
10773 687 ▶sub scan_number_do {
Subroutine scan_number_do: called CC=13 SCAR=26.8
Pod undocumented
10774  
10775 687 my ( $self, $input_line, $i, $rtoken_map, $input_type, $max_token_index ) =
10776 @_;
10777  
10778 # Scan a number in any of the formats that Perl accepts
10779 # Underbars (_) are allowed in decimal numbers.
10780 # Given:
10781 # $input_line - the string to scan
10782 # $i - pre_token index to start scanning
10783 # $rtoken_map - reference to the pre_token map giving starting
10784 # character position in $input_line of token $i
10785 # Return:
10786 # $i - last pre_token index of the number just scanned
10787 # $type - the token type ('v' or 'n')
10788 # number - the number (characters); or undef if not a number
10789  
10790 687 my $pos_beg = $rtoken_map->[$i];
10791 687 my $pos;
10792 ##my $i_begin = $i;
10793 687 my $number = undef;
10794 687 my $type = $input_type;
10795  
10796 687 my $first_char = substr( $input_line, $pos_beg, 1 );
10797  
10798 # Look for bad starting characters; Shouldn't happen..
10799 687 ▶ if ( $first_char !~ /[\d\.\+\-Ee]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($first_char =~ /[\d\.\+\-Ee]/) 0 687 687
10800 0 if (DEVEL_MODE) {
10801 Fault(<<EOM);
10802 Program bug - scan_number given bad first character = '$first_char'
10803 EOM
10804 }
10805 0 return ( $i, $type, $number );
10806 }
10807  
10808 # handle v-string without leading 'v' character ('Two Dot' rule)
10809 # (vstring.t)
10810 # Here is the format prior to including underscores:
10811 ## if ( $input_line =~ /\G((\d+)?\.\d+(\.\d+)+)/g ) {
10812 687 pos($input_line) = $pos_beg;
10813 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
10814 0 $pos = pos($input_line);
10815 0 my $numc = $pos - $pos_beg;
10816 0 $number = substr( $input_line, $pos_beg, $numc );
10817 0 $type = 'v';
10818 }
10819  
10820 # handle octal, hex, binary
10821 687 ▶ if ( !defined($number) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $number) 687 0 687
10822 687 pos($input_line) = $pos_beg;
10823  
10824 # Perl 5.22 added floating point literals, like '0x0.b17217f7d1cf78p0'
10825 # For reference, the format prior to hex floating point is:
10826 # /\G[+-]?0(([xX][0-9a-fA-F_]+)|([0-7_]+)|([bB][01_]+))/g )
10827 # (hex) (octal) (binary)
10828 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
10829 $input_line =~ m{
10830  
10831 \G[+-]?0( # leading [signed] 0
10832  
10833 # a hex float, i.e. '0x0.b17217f7d1cf78p0'
10834 ([xX][0-9a-fA-F_]* # X and optional leading digits
10835 (\.([0-9a-fA-F][0-9a-fA-F_]*)?)? # optional decimal and fraction
10836 [Pp][+-]?[0-9a-fA-F] # REQUIRED exponent with digit
10837 [0-9a-fA-F_]*) # optional Additional exponent digits
10838  
10839 # or hex integer
10840 |([xX][0-9a-fA-F_]+)
10841  
10842 # or octal fraction
10843 |([oO]?[0-7_]+ # string of octal digits
10844 (\.([0-7][0-7_]*)?)? # optional decimal and fraction
10845 [Pp][+-]?[0-7] # REQUIRED exponent, no underscore
10846 [0-7_]*) # Additional exponent digits with underscores
10847  
10848 # or octal integer
10849 |([oO]?[0-7_]+) # string of octal digits
10850  
10851 # or a binary float
10852 |([bB][01_]* # 'b' with string of binary digits
10853 (\.([01][01_]*)?)? # optional decimal and fraction
10854 [Pp][+-]?[01] # Required exponent indicator, no underscore
10855 [01_]*) # additional exponent bits
10856  
10857 # or binary integer
10858 |([bB][01_]+) # 'b' with string of binary digits
10859  
10860 )}gx
10861 )
10862 {
10863 72 $pos = pos($input_line);
10864 72 my $numc = $pos - $pos_beg;
10865 72 $number = substr( $input_line, $pos_beg, $numc );
10866 72 $type = 'n';
10867 }
10868 }
10869  
10870 # handle decimal
10871 687 ▶ if ( !defined($number) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $number) 615 72 687
10872 615 pos($input_line) = $pos_beg;
10873  
10874 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
10875 615 $pos = pos($input_line);
10876  
10877 # watch out for things like 0..40 which would give 0. by this;
10878 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
10879 && ( substr( $input_line, $pos, 1 ) eq '.' ) )
10880 {
10881 38 $pos--;
10882 }
10883 615 my $numc = $pos - $pos_beg;
10884 615 $number = substr( $input_line, $pos_beg, $numc );
10885 615 $type = 'n';
10886 }
10887 }
10888  
10889 # filter out non-numbers like e + - . e2 .e3 +e6
10890 # the rule: at least one digit, and any 'e' must be preceded by a digit
10891 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 table75%3/4
not(A) or B and not(C)
A= not $number =~ /\d/B= $number =~ /^(.*)[eE]/C= not $1 =~ /\d/
ABCresult
1XX1
0111
00X0
0100
10892 $number !~ /\d/ # no digits
10893 || ( $number =~ /^(.*)[eE]/
10894 && $1 !~ /\d/ ) # or no digits before the 'e'
10895 )
10896 {
10897 304 $number = undef;
10898 304 $type = $input_type;
10899 304 return ( $i, $type, $number );
10900 }
10901  
10902 # Found a number; now we must convert back from character position
10903 # to pre_token index. An error here implies user syntax error.
10904 # An example would be an invalid octal number like '009'.
10905 383 my $error;
10906 383 ( $i, $error ) =
10907 inverse_pretoken_map( $i, $pos, $rtoken_map, $max_token_index );
10908 0 ▶ if ($error) { $self->warning("Possibly invalid number\n") }
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 383 383
10909  
10910 383 return ( $i, $type, $number );
10911 } ## end sub scan_number_do
10912  
10913 2502 ▶sub inverse_pretoken_map {
Subroutine inverse_pretoken_map: called CC=4 SCAR=14.0
Pod undocumented
10914  
10915 # Starting with the current pre_token index $i, scan forward until
10916 # finding the index of the next pre_token whose position is $pos.
10917 2502 my ( $i, $pos, $rtoken_map, $max_token_index ) = @_;
10918 2502 my $error = 0;
10919  
10920 2502 ▶ while ( ++$i <= $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$i <= $max_token_index) 4711 44 4755
10921  
10922 4711 ▶ if ( $pos <= $rtoken_map->[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos <= $rtoken_map->[$i]) 2458 2253 4711
10923  
10924 # Let the calling routine handle errors in which we do not
10925 # land on a pre-token boundary. It can happen by running
10926 # perltidy on some non-perl scripts, for example.
10927 0 ▶ if ( $pos < $rtoken_map->[$i] ) { $error = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < $rtoken_map->[$i]) 0 2458 2458
10928 2458 $i--;
10929 2458 last;
10930 }
10931 } ## end while ( ++$i <= $max_token_index)
10932 2502 return ( $i, $error );
10933 } ## end sub inverse_pretoken_map
10934  
10935 45 ▶sub find_here_doc {
Subroutine find_here_doc: called CC=17 SCAR=32.3
Pod undocumented
10936  
10937 my (
10938  
10939 45 $self,
10940  
10941 $expecting,
10942 $i,
10943 $rtokens,
10944 $rtoken_type,
10945 $rtoken_map_uu,
10946 $max_token_index,
10947  
10948 ) = @_;
10949  
10950 # Find the target of a here document, if any
10951 # Given:
10952 # $i - token index of the second < of <<
10953 # ($i must be less than the last token index if this is called)
10954 # Return:
10955 # $found_target = 0 didn't find target; =1 found target
10956 # HERE_TARGET - the target string (may be empty string)
10957 # $i - unchanged if not here doc,
10958 # or index of the last token of the here target
10959 # $saw_error - flag noting unbalanced quote on here target
10960 45 my $ibeg = $i;
10961 45 my $found_target = 0;
10962 45 my $here_doc_target = EMPTY_STRING;
10963 45 my $here_quote_character = EMPTY_STRING;
10964 45 my $saw_error = 0;
10965 45 my ( $next_nonblank_token, $i_next_nonblank, $next_token );
10966 45 $next_token = $rtokens->[ $i + 1 ];
10967  
10968 # perl allows a backslash before the target string (heredoc.t)
10969 45 my $backslash = 0;
10970 45 ▶ if ( $next_token eq BACKSLASH ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token eq "\\") 0 45 45
10971 0 $backslash = 1;
10972 0 $next_token = $rtokens->[ $i + 2 ];
10973 }
10974  
10975 45 ( $next_nonblank_token, $i_next_nonblank ) =
10976 find_next_nonblank_token_on_this_line( $i, $rtokens, $max_token_index );
10977  
10978 45 ▶ if ( $next_nonblank_token =~ /[\'\"\`]/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($next_nonblank_token =~ /[\'\"\`]/) { } 28 17 45
elsif ($next_token =~ /^\s*$/ and $expecting == -1) { } 0 17 17
elsif ($next_token =~ /^\w/) { } 15 2 17
10979  
10980 28 my $in_quote = 1;
10981 28 my $quote_depth = 0;
10982 28 my $quote_pos = 0;
10983 28 my $quoted_string;
10984  
10985 (
10986  
10987 28 $i,
10988 $in_quote,
10989 $here_quote_character,
10990 $quote_pos,
10991 $quote_depth,
10992 $quoted_string,
10993 )
10994 = $self->follow_quoted_string(
10995  
10996 $i_next_nonblank,
10997 $in_quote,
10998 $rtokens,
10999 $rtoken_type,
11000 $here_quote_character,
11001 $quote_pos,
11002 $quote_depth,
11003 $max_token_index,
11004 );
11005  
11006 28 ▶ if ($in_quote) { # didn't find end of quote, so no target found
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote) { } 0 28 28
11007 0 $i = $ibeg;
11008 0 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) 0 0 0
11009 0 $self->warning(
11010 "Did not find here-doc string terminator ($here_quote_character) before end of line \n"
11011 );
11012 0 $saw_error = 1;
11013 }
11014 }
11015 else { # found ending quote
11016 28 $found_target = 1;
11017  
11018 28 my $tokj;
11019 28 foreach my $j ( $i_next_nonblank + 1 .. $i - 1 ) {
11020 84 $tokj = $rtokens->[$j];
11021  
11022 # we have to remove any backslash before the quote character
11023 # so that the here-doc-target exactly matches this string
11024 next
11025 84 ▶ if ( $tokj eq BACKSLASH
Branch: 1 branch
BranchTrueFalseTotal
if $tokj eq "\\" and $j < $i - 1 and $$rtokens[$j + 1] eq $here_quote_character 8 76 84
Condition83%5/6
$tokj eq "\\" and $j < $i - 1 and $$rtokens[$j + 1] eq $here_quote_character
!ll&&!rl&&r
7248
$tokj eq "\\" and $j < $i - 1
!ll&&!rl&&r
72012
MC/DC66%2/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 table75%3/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
11026 && $j < $i - 1
11027 && $rtokens->[ $j + 1 ] eq $here_quote_character );
11028 76 $here_doc_target .= $tokj;
11029 }
11030 }
11031 }
11032  
11033 ▶ 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
11034 0 $found_target = 1;
11035 0 $self->write_logfile_entry(
11036 "found blank here-target after <<; suggest using \"\"\n");
11037 0 $i = $ibeg;
11038 }
11039 elsif ( $next_token =~ /^\w/ ) { # simple bareword or integer after <<
11040  
11041 15 my $here_doc_expected;
11042 15 ▶ if ( $expecting == UNKNOWN ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == 0) { } 0 15 15
11043 0 $here_doc_expected = $self->guess_if_here_doc($next_token);
11044 }
11045 else {
11046 15 $here_doc_expected = 1;
11047 }
11048  
11049 15 ▶ if ($here_doc_expected) {
Branch: 1 branch
BranchTrueFalseTotal
if ($here_doc_expected) 15 0 15
11050 15 $found_target = 1;
11051 15 $here_doc_target = $next_token;
11052 15 $i = $ibeg + 1;
11053 }
11054  
11055 }
11056 else {
11057  
11058 2 ▶ if ( $expecting == TERM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expecting == -1) { } 0 2 2
11059 0 $found_target = 1;
11060 0 $self->write_logfile_entry("Note: bare here-doc operator <<\n");
11061 }
11062 else {
11063 2 $i = $ibeg;
11064 }
11065 }
11066  
11067 # patch to neglect any prepended backslash
11068 0 ▶ if ( $found_target && $backslash ) { $i++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($found_target and $backslash) 0 45 45
Condition66%2/3
$found_target and $backslash
!ll&&!rl&&r
2430
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
11069  
11070 45 return ( $found_target, $here_doc_target, $here_quote_character, $i,
11071 $saw_error );
11072 } ## end sub find_here_doc
11073  
11074 3233 ▶sub do_quote {
Subroutine do_quote: called CC=6 SCAR=18.0
Pod undocumented
11075  
11076 my (
11077  
11078 3233 $self,
11079  
11080 $i,
11081 $in_quote,
11082 $quote_character,
11083 $quote_pos,
11084 $quote_depth,
11085 $quoted_string_1,
11086 $quoted_string_2,
11087 $rtokens,
11088 $rtoken_type,
11089 $rtoken_map_uu,
11090 $max_token_index,
11091  
11092 ) = @_;
11093  
11094 # Follow (or continue following) quoted string(s)
11095 # $in_quote = return code:
11096 # 0 - ok, found end
11097 # 1 - still must find end of quote whose target is $quote_character
11098 # 2 - still looking for end of first of two quotes
11099 #
11100 # Returns updated strings:
11101 # $quoted_string_1 = quoted string seen while in_quote=1
11102 # $quoted_string_2 = quoted string seen while in_quote=2
11103  
11104 3233 my $quoted_string;
11105 3233 ▶ if ( $in_quote == 2 ) { # two quotes/quoted_string_1s to follow
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote == 2) 31 3202 3233
11106 31 my $ibeg = $i;
11107 (
11108  
11109 31 $i,
11110 $in_quote,
11111 $quote_character,
11112 $quote_pos,
11113 $quote_depth,
11114 $quoted_string,
11115 )
11116 = $self->follow_quoted_string(
11117  
11118 $ibeg,
11119 $in_quote,
11120 $rtokens,
11121 $rtoken_type,
11122 $quote_character,
11123 $quote_pos,
11124 $quote_depth,
11125 $max_token_index,
11126 );
11127 31 $quoted_string_2 .= $quoted_string;
11128 31 ▶ if ( $in_quote == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote == 1) { } 31 0 31
11129 31 ▶ if ( $quote_character =~ /[\{\[\<\(]/ ) { $i++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($quote_character =~ /[\{\[\<\(]/) 1 30 31
11130 31 $quote_character = EMPTY_STRING;
11131 }
11132 else {
11133 0 $quoted_string_2 .= "\n";
11134 }
11135 }
11136  
11137 3233 ▶ if ( $in_quote == 1 ) { # one (more) quote to follow
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote == 1) 3233 0 3233
11138 3233 my $ibeg = $i;
11139 (
11140  
11141 3233 $i,
11142 $in_quote,
11143 $quote_character,
11144 $quote_pos,
11145 $quote_depth,
11146 $quoted_string,
11147 )
11148 = $self->follow_quoted_string(
11149  
11150 $ibeg,
11151 $in_quote,
11152 $rtokens,
11153 $rtoken_type,
11154 $quote_character,
11155 $quote_pos,
11156 $quote_depth,
11157 $max_token_index,
11158 );
11159 3233 $quoted_string_1 .= $quoted_string;
11160 3233 ▶ if ( $in_quote == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote == 1) 244 2989 3233
11161 244 $quoted_string_1 .= "\n";
11162 }
11163 }
11164 return (
11165  
11166 3233 $i,
11167 $in_quote,
11168 $quote_character,
11169 $quote_pos,
11170 $quote_depth,
11171 $quoted_string_1,
11172 $quoted_string_2,
11173  
11174 );
11175 } ## end sub do_quote
11176  
11177 45 ▶use constant DEBUG_FIND_INTERPOLATED_HERE_TARGETS => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
11178  
11179 2 ▶sub find_interpolated_here_targets {
Subroutine find_interpolated_here_targets: called CC=36 SCAR=40.8
Pod undocumented
11180 2 my ( $self, $quoted_string, $len_starting_lines ) = @_;
11181  
11182 # Search for here targets in a quoted string
11183 # Given:
11184 # $quoted_string = the complete string of an interpolated quote
11185 # $len_starting_lines = number of characters of the first n-1 lines
11186 # (=0 if this is a single-line quote)
11187 # Task:
11188 # Find and return a list of all here targets on the last line;
11189 # i.e., if here target is index ii, we only return the
11190 # target if $rmap->[$ii]>=$len_starting_lines
11191  
11192 # The items returned are the format needed for @{$rhere_target_list};
11193 # [ $here_doc_target, $here_quote_character ]
11194 # there can be multiple here targets.
11195  
11196 2 my $rht;
11197  
11198 # Break the entire quote into pre-tokens, even if multi-line, because we
11199 # have to determine which parts are in single quotes
11200 2 my ( $rtokens, $rmap, $rtoken_type ) = pre_tokenize($quoted_string);
11201 2 my $max_ii = @{$rtokens} - 1;
11202  
11203 # Depth of braces controlled by a sigil
11204 2 my $code_depth = 0;
11205  
11206 # Loop over pre-tokens
11207 2 my $ii = -1;
11208 2 ▶ while ( ++$ii <= $max_ii ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$ii <= $max_ii) 21 2 23
11209 21 my $token = $rtokens->[$ii];
11210 21 if (DEBUG_FIND_INTERPOLATED_HERE_TARGETS) {
11211 print "i=$ii tok=$token block=$code_depth\n";
11212 }
11213  
11214 21 ▶ if ( $token eq BACKSLASH ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq "\\") 4 17 21
11215 0 ▶ if ( !$code_depth ) { $ii++ }
Branch: 1 branch
BranchTrueFalseTotal
unless ($code_depth) 0 4 4
11216 4 next;
11217 }
11218  
11219 # Look for start of interpolation code block, '${', '@{', '$var{', etc
11220 17 ▶ if ( !$code_depth ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($code_depth) 4 13 17
11221 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
11222  
11223 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
11224 if ( $ii < $max_ii && $rtoken_type->[ $ii + 1 ] eq 'b' );
11225  
11226 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
11227 $ii < $max_ii
11228 && ( $rtoken_type->[ $ii + 1 ] eq 'w'
11229 || $rtoken_type->[ $ii + 1 ] eq '::' )
11230 )
11231 {
11232 0 $ii++;
11233 } ## end while ( $ii < $max_ii && ...)
11234  
11235 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
11236 if ( $ii < $max_ii && $rtoken_type->[ $ii + 1 ] eq 'b' );
11237  
11238 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
11239 4 $ii++;
11240 4 $code_depth++;
11241 }
11242 }
11243 4 next;
11244 }
11245  
11246 # Continue interpolating while $code_depth > 0..
11247 13 ▶ if ( $token eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq "{") 0 13 13
11248 0 $code_depth++;
11249 0 next;
11250 }
11251 13 ▶ if ( $token eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq "}") 4 9 13
11252 4 $code_depth--;
11253 4 next;
11254 }
11255  
11256 # Look for '<<'
11257 9 ▶ if ( $token ne '<'
Branch: 1 branch
BranchTrueFalseTotal
if ($token ne "<" or $ii >= $max_ii - 1 or $$rtokens[$ii + 1] ne "<") 5 4 9
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
11258 || $ii >= $max_ii - 1
11259 || $rtokens->[ $ii + 1 ] ne '<' )
11260 {
11261 5 next;
11262 }
11263  
11264 # Remember the location of the first '<' so it can be modified
11265 4 my $ii_left_shift = $ii;
11266  
11267 4 $ii++;
11268  
11269 # or '<<~'
11270 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
11271 0 $ii++;
11272 }
11273  
11274 # blanks ok before targets in quotes
11275 4 my $saw_blank;
11276 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
11277 2 $saw_blank = 1;
11278 2 $ii++;
11279 }
11280  
11281 4 my $next_type = $rtoken_type->[ $ii + 1 ];
11282  
11283 # Look for unquoted targets like "${ \<<END1 }"
11284 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
11285 2 ▶ if ($saw_blank) {
Branch: 1 branch
BranchTrueFalseTotal
if ($saw_blank) { } 0 2 2
11286 ## error: blank target is deprecated
11287 }
11288 else {
11289 2 $ii++;
11290 2 ▶ if ( $rmap->[$ii] >= $len_starting_lines ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rmap->[$ii] >= $len_starting_lines) 2 0 2
11291 2 push @{$rht}, [ $rtokens->[$ii], EMPTY_STRING ];
11292  
11293 # Modify the string so the target is not found again
11294 2 my $pos_left_shift = $rmap->[$ii_left_shift];
11295 2 substr( $quoted_string, $pos_left_shift, 1, SPACE );
11296 2 substr( $quoted_string, $pos_left_shift + 1, 1, SPACE );
11297 }
11298 }
11299 }
11300  
11301 # Look for quoted targets like "${ \<< 'END1' }${ \<<\"END2\" }";
11302 ▶ 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
11303 2 my $quote_char = $next_type;
11304 2 $ii++;
11305 2 my $here_target = EMPTY_STRING;
11306 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
11307 next
11308 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
11309 2 $here_target .= $rtokens->[$ii];
11310 }
11311 2 ▶ if ( $rmap->[$ii] >= $len_starting_lines ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rmap->[$ii] >= $len_starting_lines) 2 0 2
11312 2 push @{$rht}, [ $here_target, $quote_char ];
11313 }
11314 }
11315 else {
11316 ## no here target found
11317 }
11318 4 next;
11319 } ## end while ( ++$ii <= $max_ii )
11320 2 return ( $rht, $quoted_string );
11321 } ## end sub find_interpolated_here_targets
11322  
11323 # Some possible non-word quote delimiters, for preliminary checking
11324 45 my %is_punct_char;
11325  
11326 45 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
11327  
11328 45 my @q = qw# / " ' { } ( ) [ ] < > ; + - * | % ! x ~ = ? : . ^ & #;
11329 45 push @q, '#';
11330 45 push @q, COMMA;
11331 45 $is_punct_char{$_} = 1 for @q;
11332 }
11333  
11334 3292 ▶sub follow_quoted_string {
Subroutine follow_quoted_string: called CC=33 SCAR=35.5
Pod undocumented
11335  
11336 my (
11337  
11338 3292 $self,
11339  
11340 $i_beg,
11341 $in_quote,
11342 $rtokens,
11343 $rtoken_type,
11344 $beginning_tok,
11345 $quote_pos,
11346 $quote_depth,
11347 $max_token_index,
11348  
11349 ) = @_;
11350  
11351 # Scan for a specific token, skipping escaped characters.
11352 # If the quote character is blank, use the first non-blank character.
11353 # Given:
11354 # $rtokens = reference to the array of tokens
11355 # $i = the token index of the first character to search
11356 # $in_quote = number of quoted strings being followed
11357 # $beginning_tok = the starting quote character
11358 # $quote_pos = index to check next for alphanumeric delimiter
11359 # Return:
11360 # $i = the token index of the ending quote character
11361 # $in_quote = decremented if found end, unchanged if not
11362 # $beginning_tok = the starting quote character
11363 # $quote_pos = index to check next for alphanumeric delimiter
11364 # $quote_depth = nesting depth, since delimiters '{ ( [ <' can be nested.
11365 # $quoted_string = the text of the quote (without quotation tokens)
11366 3292 my ( $tok, $end_tok );
11367 3292 my $i = $i_beg - 1;
11368 3292 my $quoted_string = EMPTY_STRING;
11369  
11370 3292 0 && do {
11371 print {*STDOUT}
11372 "QUOTE entering with quote_pos = $quote_pos i=$i beginning_tok =$beginning_tok\n";
11373 };
11374  
11375 # for a non-blank token, get the corresponding end token
11376 3292 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($is_punct_char{$beginning_tok} or length $beginning_tok and not $beginning_tok =~ /^\s+$/) { } 244 3048 3292
Condition50%3/6
$is_punct_char{$beginning_tok} or length $beginning_tok and not $beginning_tok =~ /^\s+$/
l!l&&r!l&&!r
24403048
length $beginning_tok and not $beginning_tok =~ /^\s+$/
!ll&&!rl&&r
304800
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
11377 $is_punct_char{$beginning_tok}
11378 || ( length($beginning_tok)
11379 && $beginning_tok !~ /^\s+$/ )
11380 )
11381 {
11382 $end_tok =
11383 $matching_end_token{$beginning_tok}
11384 244 ▶ ? $matching_end_token{$beginning_tok}
Branch: 1 branch
BranchTrueFalseTotal
$matching_end_token{$beginning_tok} ? : 187 57 244
11385 : $beginning_tok;
11386 }
11387  
11388 # for a blank token, find and use the first non-blank one
11389 else {
11390 3048 ▶ my $allow_quote_comments = ( $i < 0 ) ? 1 : 0; # i<0 means we saw a <cr>
Branch: 1 branch
BranchTrueFalseTotal
$i < 0 ? : 295 2753 3048
11391  
11392 3048 ▶ while ( $i < $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $max_token_index) 3050 0 3050
11393 3050 $tok = $rtokens->[ ++$i ];
11394  
11395 3050 ▶ if ( $rtoken_type->[$i] ne 'b' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rtoken_type->[$i] ne 'b') { } 3048 2 3050
11396  
11397 3048 ▶ if ( ( $tok eq '#' ) && ($allow_quote_comments) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq '#' and $allow_quote_comments) { } 0 3048 3048
Condition66%2/3
$tok eq "#" and $allow_quote_comments
!ll&&!rl&&r
304440
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
11398 0 $i = $max_token_index;
11399 }
11400 else {
11401  
11402 3048 ▶ if ( length($tok) > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $tok > 1) { } 1 3047 3048
11403 1 ▶ if ( $quote_pos <= 0 ) { $quote_pos = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($quote_pos <= 0) 1 0 1
11404 1 $beginning_tok = substr( $tok, $quote_pos - 1, 1 );
11405 }
11406 else {
11407 3047 $beginning_tok = $tok;
11408 3047 $quote_pos = 0;
11409 }
11410 $end_tok =
11411 $matching_end_token{$beginning_tok}
11412 3048 ▶ ? $matching_end_token{$beginning_tok}
Branch: 1 branch
BranchTrueFalseTotal
$matching_end_token{$beginning_tok} ? : 140 2908 3048
11413 : $beginning_tok;
11414 3048 $quote_depth = 1;
11415 3048 last;
11416 }
11417 }
11418 else {
11419 2 $allow_quote_comments = 1;
11420 }
11421 } ## end while ( $i < $max_token_index)
11422 }
11423  
11424 # There are two different loops which search for the ending quote
11425 # character. In the rare case of an alphanumeric quote delimiter, we
11426 # have to look through alphanumeric tokens character-by-character, since
11427 # the pre-tokenization process combines multiple alphanumeric
11428 # characters, whereas for a non-alphanumeric delimiter, only tokens of
11429 # length 1 can match.
11430  
11431 #----------------------------------------------------------------
11432 # Case 1 (rare): loop for case of alphanumeric quote delimiter..
11433 # "quote_pos" is the position the current word to begin searching
11434 #----------------------------------------------------------------
11435 3292 ▶ 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 3291 3292
Condition100%3/3
not $is_punct_char{$beginning_tok} and $beginning_tok =~ /\w/
!ll&&!rl&&r
328921
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
11436  
11437 # Note this because it is not recommended practice except
11438 # for obfuscated perl contests
11439 1 ▶ if ( $in_quote == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_quote == 1) 1 0 1
11440 1 $self->write_logfile_entry(
11441 "Note: alphanumeric quote delimiter ($beginning_tok) \n");
11442 }
11443  
11444 # Note: changed < to <= here to fix c109. Relying on extra end blanks.
11445 1 ▶ while ( $i <= $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $max_token_index) 4 0 4
11446  
11447 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
11448 3 $tok = $rtokens->[ ++$i ];
11449  
11450 3 ▶ if ( $tok eq BACKSLASH ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "\\") 1 2 3
11451  
11452 # retain backslash unless it hides the end token
11453 1 ▶ $quoted_string .= $tok
Branch: 1 branch
BranchTrueFalseTotal
unless $$rtokens[$i + 1] eq $end_tok 1 0 1
11454 unless ( $rtokens->[ $i + 1 ] eq $end_tok );
11455 1 $quote_pos++;
11456 1 ▶ last if ( $i >= $max_token_index );
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $max_token_index 0 1 1
11457 1 $tok = $rtokens->[ ++$i ];
11458 }
11459 }
11460 4 my $old_pos = $quote_pos;
11461  
11462 4 $quote_pos = 1 + index( $tok, $end_tok, $quote_pos );
11463  
11464 4 ▶ if ( $quote_pos > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote_pos > 0) { } 1 3 4
11465  
11466 1 $quoted_string .=
11467 substr( $tok, $old_pos, $quote_pos - $old_pos - 1 );
11468  
11469 # NOTE: any quote modifiers will be at the end of '$tok'. If we
11470 # wanted to check them, this is the place to get them. But
11471 # this quote form is rarely used in practice, so it isn't
11472 # worthwhile.
11473  
11474 1 $quote_depth--;
11475  
11476 1 ▶ if ( $quote_depth == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote_depth == 0) 1 0 1
11477 1 $in_quote--;
11478 1 last;
11479 }
11480 }
11481 else {
11482 3 ▶ if ( $old_pos <= length($tok) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_pos <= length $tok) 3 0 3
11483 3 $quoted_string .= substr( $tok, $old_pos );
11484 }
11485 }
11486 } ## end while ( $i <= $max_token_index)
11487 }
11488  
11489 #-----------------------------------------------------------------------
11490 # Case 2 (normal): loop for case of a non-alphanumeric quote delimiter..
11491 #-----------------------------------------------------------------------
11492 else {
11493  
11494 3291 ▶ while ( $i < $max_token_index ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $max_token_index) 12627 244 12871
11495 12627 $tok = $rtokens->[ ++$i ];
11496  
11497 12627 ▶ if ( $tok eq $end_tok ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($tok eq $end_tok) { } 3048 9579 12627
elsif ($tok eq $beginning_tok) { } 1 9578 9579
elsif ($tok eq '\\') { } 475 9103 9578
11498 3048 $quote_depth--;
11499  
11500 3048 ▶ if ( $quote_depth == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote_depth == 0) 3047 1 3048
11501 3047 $in_quote--;
11502 3047 last;
11503 }
11504 }
11505 elsif ( $tok eq $beginning_tok ) {
11506 1 $quote_depth++;
11507 }
11508 elsif ( $tok eq BACKSLASH ) {
11509  
11510 # retain backslash unless it hides the beginning or end token
11511 475 $tok = $rtokens->[ ++$i ];
11512 475 ▶ $quoted_string .= BACKSLASH
Branch: 1 branch
BranchTrueFalseTotal
if $tok ne $end_tok and $tok ne $beginning_tok 447 28 475
Condition100%3/3
$tok ne $end_tok and $tok ne $beginning_tok
!ll&&!rl&&r
271447
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
11513 if ( $tok ne $end_tok && $tok ne $beginning_tok );
11514 }
11515 else {
11516 ## nothing special
11517 }
11518 9580 $quoted_string .= $tok;
11519 } ## end while ( $i < $max_token_index)
11520 }
11521 3292 ▶ if ( $i > $max_token_index ) { $i = $max_token_index }
Branch: 1 branch
BranchTrueFalseTotal
if ($i > $max_token_index) 10 3282 3292
11522 return (
11523  
11524 3292 $i,
11525 $in_quote,
11526 $beginning_tok,
11527 $quote_pos,
11528 $quote_depth,
11529 $quoted_string,
11530  
11531 );
11532 } ## end sub follow_quoted_string
11533  
11534 0 ▶sub indicate_error {
Subroutine indicate_error: not called CC=1 SCAR=6.9
Pod undocumented
11535 0 my ( $self, $msg, $line_number, $input_line, $pos, $caret ) = @_;
11536  
11537 # write input line and line with carat's showing where error was detected
11538 0 $self->interrupt_logfile();
11539 0 $self->warning($msg);
11540 0 $self->write_error_indicator_pair( $line_number, $input_line, $pos,
11541 $caret );
11542 0 $self->resume_logfile();
11543 0 return;
11544 } ## end sub indicate_error
11545  
11546 0 ▶sub write_error_indicator_pair {
Subroutine write_error_indicator_pair: not called CC=1 SCAR=6.9
Pod undocumented
11547 0 my ( $self, $line_number, $input_line, $pos, $caret ) = @_;
11548 0 my ( $offset, $numbered_line, $underline ) =
11549 make_numbered_line( $line_number, $input_line, $pos );
11550 0 $underline = write_on_underline( $underline, $pos - $offset, $caret );
11551 0 $self->warning( $numbered_line . "\n" );
11552 0 $underline =~ s/\s+$//;
11553 0 $self->warning( $underline . "\n" );
11554 0 return;
11555 } ## end sub write_error_indicator_pair
11556  
11557 0 ▶sub make_numbered_line {
Subroutine make_numbered_line: not called CC=6 SCAR=37.4
Pod undocumented
11558  
11559 0 my ( $lineno, $str, $pos ) = @_;
11560  
11561 # Given:
11562 # $lineno=line number
11563 # $str = an input line
11564 # $pos = character position of interest
11565 # Create a string not longer than 80 characters of the form:
11566 # $lineno: sub_string
11567 # such that the sub_string of $str contains the position of interest
11568 #
11569 # Here is an example of what we want, in this case we add trailing
11570 # '...' because the line is long.
11571 #
11572 # 2: (One of QAML 2.0's authors is a member of the World Wide Web Con ...
11573 #
11574 # Here is another example, this time in which we used leading '...'
11575 # because of excessive length:
11576 #
11577 # 2: ... er of the World Wide Web Consortium's
11578 #
11579 # input parameters are:
11580 # $lineno = line number
11581 # $str = the text of the line
11582 # $pos = position of interest (the error) : 0 = first character
11583 #
11584 # We return :
11585 # - $offset = an offset which corrects the position in case we only
11586 # display part of a line, such that $pos-$offset is the effective
11587 # position from the start of the displayed line.
11588 # - $numbered_line = the numbered line as above,
11589 # - $underline = a blank 'underline' which is all spaces with the same
11590 # number of characters as the numbered line.
11591  
11592 0 ▶ my $offset = ( $pos < 60 ) ? 0 : $pos - 40;
Branch: 1 branch
BranchTrueFalseTotal
$pos < 60 ? : 0 0 0
11593 0 my $excess = length($str) - $offset - 68;
11594 0 ▶ my $numc = ( $excess > 0 ) ? 68 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$excess > 0 ? : 0 0 0
11595  
11596 0 ▶ if ( defined($numc) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $numc) { } 0 0 0
11597 0 ▶ if ( $offset == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset == 0) { } 0 0 0
11598 0 $str = substr( $str, $offset, $numc - 4 ) . " ...";
11599 }
11600 else {
11601 0 $str = "... " . substr( $str, $offset + 4, $numc - 4 ) . " ...";
11602 }
11603 }
11604 else {
11605  
11606 0 ▶ if ( $offset == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset == 0) { } 0 0 0
11607 }
11608 else {
11609 0 $str = "... " . substr( $str, $offset + 4 );
11610 }
11611 }
11612  
11613 0 my $numbered_line = sprintf( "%d: ", $lineno );
11614 0 $offset -= length($numbered_line);
11615 0 $numbered_line .= $str;
11616 0 my $underline = SPACE x length($numbered_line);
11617 0 return ( $offset, $numbered_line, $underline );
11618 } ## end sub make_numbered_line
11619  
11620 0 ▶sub write_on_underline {
Subroutine write_on_underline: not called CC=4 SCAR=30.0
Pod undocumented
11621  
11622 0 my ( $underline, $pos, $pos_chr ) = @_;
11623  
11624 # The "underline" is a string that shows where an error is; it starts
11625 # out as a string of blanks with the same length as the numbered line of
11626 # code above it, and we have to add marking to show where an error is.
11627 # In the example below, we want to write the string '--^' just below
11628 # the line of bad code:
11629 #
11630 # 2: (One of QAML 2.0's authors is a member of the World Wide Web Con ...
11631 # ---^
11632 # We are given the current underline string, plus a position and a
11633 # string to write on it.
11634 #
11635 # In the above example, there will be 2 calls to do this:
11636 # First call: $pos=19, pos_chr=^
11637 # Second call: $pos=16, pos_chr=---
11638 #
11639 # This is a trivial thing to do with substr, but there is some
11640 # checking to do.
11641  
11642 # check for error..shouldn't happen
11643 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
11644 0 return $underline;
11645 }
11646 0 my $excess = length($pos_chr) + $pos - length($underline);
11647 0 ▶ if ( $excess > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($excess > 0) 0 0 0
11648 0 $pos_chr = substr( $pos_chr, 0, length($pos_chr) - $excess );
11649 }
11650 0 substr( $underline, $pos, length($pos_chr), $pos_chr );
11651 0 return ($underline);
11652 } ## end sub write_on_underline
11653  
11654 7320 ▶sub pre_tokenize {
Subroutine pre_tokenize: called CC=7 SCAR=19.5
Pod undocumented
11655  
11656 7320 my ( $str, ($max_tokens_wanted) ) = @_;
11657  
11658 # Input parameters:
11659 # $str = string to be parsed
11660 # $max_tokens_wanted > 0 to stop on reaching this many tokens.
11661 # = undef or 0 means get all tokens
11662  
11663 # Break a string, $str, into a sequence of preliminary tokens (pre-tokens).
11664 # We look for these types of tokens:
11665 # words (type='w'), example: 'max_tokens_wanted'
11666 # digits (type = 'd'), example: '0755'
11667 # whitespace (type = 'b'), example: ' '
11668 # single character punct (type = char) example: '='
11669  
11670 # Later operations will combine one or more of these pre-tokens into final
11671 # tokens. We cannot do better than this yet because we might be in a
11672 # quoted string or pattern.
11673  
11674 # An advantage of doing this pre-tokenization step is that it keeps almost
11675 # all of the regex parsing very simple and localized right here. A
11676 # disadvantage is that in some extremely rare instances we will have to go
11677 # back and split a pre-token.
11678  
11679 # Return parameters:
11680 7320 my @tokens = (); # array of the tokens themselves
11681 7320 my @token_map = (0); # string position of start of each token
11682 7320 my @type = (); # 'b'=whitespace, 'd'=digits, 'w'=alpha, or punct
11683  
11684 7320 ▶ if ( !$max_tokens_wanted ) { $max_tokens_wanted = -1 }
Branch: 1 branch
BranchTrueFalseTotal
unless ($max_tokens_wanted) 6999 321 7320
11685  
11686 7320 ▶ while ( $max_tokens_wanted-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max_tokens_wanted--) 97853 162 98015
11687  
11688 97853 ▶ 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) { } 90695 7158 97853
11689 $str =~ m{
11690 \G(
11691 (\s+) # type 'b' = whitespace - this must come before \W
11692 | (\W) # or type=char = single-character, non-whitespace punct
11693 | (\d+) # or type 'd' = sequence of digits - must come before \w
11694 | (\w+) # or type 'w' = words not starting with a digit
11695 )
11696 }gcx
11697 )
11698 {
11699 90695 push @tokens, $1;
11700 90695 ▶ push @type,
Branch: 3 branches
BranchTrueFalseTotal
defined $2 ? : 22188 68507 90695
defined $3 ? : 45595 22912 68507
defined $4 ? : 3393 19519 22912
11701 defined($2) ? 'b' : defined($3) ? $1 : defined($4) ? 'd' : 'w';
11702 90695 push @token_map, pos($str);
11703 }
11704  
11705 # that's all..
11706 else {
11707 7158 return ( \@tokens, \@token_map, \@type );
11708 }
11709 } ## end while ( $max_tokens_wanted...)
11710  
11711 162 return ( \@tokens, \@token_map, \@type );
11712 } ## end sub pre_tokenize
11713  
11714 0 ▶sub show_tokens {
Subroutine show_tokens: not called CC=2 SCAR=17.9
Pod undocumented
11715  
11716 # This is an uncalled debug routine, saved for reference
11717 0 my ( $rtokens, $rtoken_map ) = @_;
11718 0 my $num = scalar( @{$rtokens} );
11719  
11720 0 foreach my $i ( 0 .. $num - 1 ) {
11721 0 my $len = length( $rtokens->[$i] );
11722 0 print {*STDOUT} "$i:$len:$rtoken_map->[$i]:$rtokens->[$i]:\n";
11723 }
11724 0 return;
11725 } ## end sub show_tokens
11726  
11727 0 ▶sub dump_token_types {
Subroutine dump_token_types: not called CC=1 SCAR=6.9
Pod undocumented
11728 0 my ( $class, $fh ) = @_;
11729  
11730 # This should be the latest list of token types in use
11731 # adding NEW_TOKENS: add a comment here
11732 0 $fh->print(<<'END_OF_LIST');
11733  
11734 Here is a list of the token types currently used for lines of type 'CODE'.
11735 For the following tokens, the "type" of a token is just the token itself.
11736  
11737 .. :: << >> ** && .. || // -> => += -= .= %= &= |= ^= *= <>
11738 ( ) <= >= == =~ !~ != ++ -- /= x=
11739 ... **= <<= >>= &&= ||= //= <=>
11740 , + - / * | % ! x ~ = \ ? : . < > ^ & ^^
11741  
11742 The following additional token types are defined:
11743  
11744 type meaning
11745 b blank (white space)
11746 { indent: opening structural curly brace or square bracket or paren
11747 (code block, anonymous hash reference, or anonymous array reference)
11748 } outdent: right structural curly brace or square bracket or paren
11749 [ left non-structural square bracket (enclosing an array index)
11750 ] right non-structural square bracket
11751 ( left non-structural paren (all but a list right of an =)
11752 ) right non-structural paren
11753 L left non-structural curly brace (enclosing a key)
11754 R right non-structural curly brace
11755 ; terminal semicolon
11756 f indicates a semicolon in a "for" statement
11757 h here_doc operator <<
11758 # a comment
11759 Q indicates a quote or pattern
11760 q indicates a qw quote block
11761 k a perl keyword
11762 C user-defined constant or constant function (with void prototype = ())
11763 U user-defined function taking parameters
11764 G user-defined function taking block parameter (like grep/map/eval)
11765 S sub definition (reported as type 'i' in older versions)
11766 P package definition (reported as type 'i' in older versions)
11767 t type indicator such as %,$,@,*,&,sub
11768 w bare word (perhaps a subroutine call)
11769 i identifier of some type (with leading %, $, @, *, &, sub, -> )
11770 n a number
11771 v a v-string
11772 F a file test operator (like -e)
11773 Y File handle
11774 Z identifier in indirect object slot: may be file handle, object
11775 J LABEL: code block label
11776 j LABEL after next, last, redo, goto
11777 p unary +
11778 m unary -
11779 pp pre-increment operator ++
11780 mm pre-decrement operator --
11781 A : used as attribute separator
11782  
11783 Here are the '_line_type' codes used internally:
11784 SYSTEM - system-specific code before hash-bang line
11785 CODE - line of perl code (including comments)
11786 POD_START - line starting pod, such as '=head'
11787 POD - pod documentation text
11788 POD_END - last line of pod section, '=cut'
11789 HERE - text of here-document
11790 HERE_END - last line of here-doc (target word)
11791 FORMAT - format section
11792 FORMAT_END - last line of format section, '.'
11793 SKIP - code skipping section
11794 SKIP_END - last line of code skipping section, '#>>V'
11795 DATA_START - __DATA__ line
11796 DATA - unidentified text following __DATA__
11797 END_START - __END__ line
11798 END - unidentified text following __END__
11799 ERROR - we are in big trouble, probably not a perl script
11800 END_OF_LIST
11801  
11802 0 return;
11803 } ## end sub dump_token_types
11804  
11805 #------------------
11806 # About Token Types
11807 #------------------
11808  
11809 # The array "valid_token_types" in the BEGIN section has an up-to-date list
11810 # of token types. Sub 'dump_token_types' should be kept up to date with
11811 # token types.
11812  
11813 # Ideally, tokens are the smallest pieces of text
11814 # such that a newline may be inserted between any pair of tokens without
11815 # changing or invalidating the program. This version comes close to this,
11816 # although there are necessarily a few exceptions which must be caught by
11817 # the formatter. Many of these involve the treatment of bare words.
11818 #
11819 # To simplify things, token types are either a single character, or they
11820 # are identical to the tokens themselves.
11821 #
11822 # As a debugging aid, the -D flag creates a file containing a side-by-side
11823 # comparison of the input string and its tokenization for each line of a file.
11824 # This is an invaluable debugging aid.
11825 #
11826 # In addition to tokens, and some associated quantities, the tokenizer
11827 # also returns flags indication any special line types. These include
11828 # quotes, here_docs, formats.
11829 #
11830 #------------------
11831 # Adding NEW_TOKENS
11832 #------------------
11833 #
11834 # Here are some notes on the minimal steps. I wrote these notes while
11835 # adding the 'v' token type for v-strings, which are things like version
11836 # numbers 5.6.0, and ip addresses, and will use that as an example. ( You
11837 # can use your editor to search for the string "NEW_TOKENS" to find the
11838 # appropriate sections to change):
11839  
11840 # *. For another example, search for the smartmatch operator '~~'
11841 # with your editor to see where updates were made for it.
11842  
11843 # *. For another example, search for the string 'c250', which shows
11844 # locations where changes for new types 'P' and 'S' were made.
11845  
11846 # *. Think of a new, unused character for the token type, and add to
11847 # the array @valid_token_types in the BEGIN section of this package.
11848 # For example, I used 'v' for v-strings.
11849 #
11850 # *. Implement coding to recognize the $type of the token in this routine.
11851 # This is the hardest part, and is best done by imitating or modifying
11852 # some of the existing coding. For example, to recognize v-strings, I
11853 # patched 'sub scan_bare_identifier' to recognize v-strings beginning with
11854 # 'v' and 'sub scan_number' to recognize v-strings without the leading 'v'.
11855 #
11856 # *. Update sub operator_expected. This update is critically important but
11857 # the coding is trivial. Look at the comments in that routine for help.
11858 # For v-strings, which should behave like numbers, I just added 'v' to the
11859 # regex used to handle numbers and strings (types 'n' and 'Q').
11860 #
11861 # *. Implement a 'bond strength' rule in sub set_bond_strengths in
11862 # Perl::Tidy::Formatter for breaking lines around this token type. You can
11863 # skip this step and take the default at first, then adjust later to get
11864 # desired results. For adding type 'v', I looked at sub bond_strength and
11865 # saw that number type 'n' was using default strengths, so I didn't do
11866 # anything. I may tune it up someday if I don't like the way line
11867 # breaks with v-strings look.
11868 #
11869 # *. Implement a 'whitespace' rule in sub set_whitespace_flags in
11870 # Perl::Tidy::Formatter. For adding type 'v', I looked at this routine
11871 # and saw that type 'n' used spaces on both sides, so I just added 'v'
11872 # to the array @spaces_both_sides.
11873 #
11874 # *. Update HtmlWriter package so that users can colorize the token as
11875 # desired. This is quite easy; see comments identified by 'NEW_TOKENS' in
11876 # that package. For v-strings, I initially chose to use a default color
11877 # equal to the default for numbers, but it might be nice to change that
11878 # eventually.
11879 #
11880 # *. Update comments in Perl::Tidy::Tokenizer::dump_token_types.
11881 #
11882 # *. Run lots and lots of debug tests. Start with special files designed
11883 # to test the new token type. Run with the -D flag to create a .DEBUG
11884 # file which shows the tokenization. When these work ok, test as many old
11885 # scripts as possible. Start with all of the '.t' files in the 'test'
11886 # directory of the distribution file. Compare .tdy output with previous
11887 # version and updated version to see the differences. Then include as
11888 # many more files as possible. My own technique has been to collect a huge
11889 # number of perl scripts (thousands!) into one directory and run perltidy
11890 # *, then run diff between the output of the previous version and the
11891 # current version.
11892  
11893 45 ▶BEGIN {
Subroutine BEGIN: called CC=38 SCAR=36.4
11894  
11895 # These names are used in error messages
11896 45 @opening_brace_names = qw# '{' '[' '(' '?' #;
11897 45 @closing_brace_names = qw# '}' ']' ')' ':' #;
11898  
11899 45 my @q;
11900  
11901 45 my @digraphs = qw#
11902 .. :: << >> ** && || // -> => += -= .= %= &= |= ^= *= <>
11903 <= >= == =~ !~ != ++ -- /= x= ~~ ~. |. &. ^. ^^
11904 #;
11905 45 $is_digraph{$_} = 1 for @digraphs;
11906  
11907 45 @q = qw(
11908 . : < > * & | / - = + - % ^ ! x ~
11909 );
11910 45 $can_start_digraph{$_} = 1 for @q;
11911  
11912 45 my @trigraphs =
11913 qw( ... **= <<= >>= &&= ||= //= <=> !~~ &.= |.= ^.= <<~ ^^= );
11914 45 $is_trigraph{$_} = 1 for @trigraphs;
11915  
11916 45 my @tetragraphs = qw( <<>> );
11917 45 $is_tetragraph{$_} = 1 for @tetragraphs;
11918  
11919 # make a hash of all valid token types for self-checking the tokenizer
11920 # (adding NEW_TOKENS : select a new character and add to this list)
11921 # fix for c250: added new token type 'P' and 'S'
11922 45 my @valid_token_types = qw#
11923 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
11924 { } ( ) [ ] ; + - / * | % ! x ~ = ? : . < > ^ &
11925 #;
11926 45 push @valid_token_types, BACKSLASH;
11927 45 push @valid_token_types, @digraphs;
11928 45 push @valid_token_types, @trigraphs;
11929 45 push @valid_token_types, @tetragraphs;
11930 45 push @valid_token_types, ( '#', COMMA, 'CORE::' );
11931 45 $is_valid_token_type{$_} = 1 for @valid_token_types;
11932  
11933 # a list of file test letters, as in -e (Table 3-4 of 'camel 3')
11934 45 my @file_test_operators =
11935 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 );
11936 45 $is_file_test_operator{$_} = 1 for @file_test_operators;
11937  
11938 # these functions have prototypes of the form (&), so when they are
11939 # followed by a block, that block MAY BE followed by an operator.
11940 # Smartmatch operator ~~ may be followed by anonymous hash or array ref
11941 45 @q = qw( do eval );
11942 45 $is_block_operator{$_} = 1 for @q;
11943  
11944 # These functions allow an identifier in the indirect object slot:
11945 45 @q = qw( print printf sort exec system say );
11946 45 $is_indirect_object_taker{$_} = 1 for @q;
11947  
11948 # Keywords which definitely produce error if an OPERATOR is expected
11949 # The following small list was used until version 20260705:
11950 # @q = qw( my our state local use require );
11951 # This list was expanded to the list below to catch more errors (c613).
11952 45 @q = qw(
11953 AUTOLOAD BEGIN CHECK DESTROY
11954 END INIT UNITCHECK abs
11955 accept alarm atan2 bind
11956 binmode bless break caller
11957 catch chdir chmod chomp
11958 chop chown chr chroot
11959 close closedir connect continue
11960 cos crypt dbmclose dbmopen
11961 default defined delete die
11962 do dump each else
11963 elsif endgrent endhostent endnetent
11964 endprotoent endpwent endservent eof
11965 eval evalbytes exec exists
11966 exit exp fc fcntl
11967 fileno flock fork format
11968 formline getc getgrent getgrgid
11969 getgrnam gethostbyaddr gethostbyname gethostent
11970 getlogin getnetbyaddr getnetbyname getnetent
11971 getpeername getpgrp getppid getpriority
11972 getprotobyname getprotobynumber getprotoent getpwent
11973 getpwnam getpwuid getservbyname getservbyport
11974 getservent getsockname getsockopt given
11975 glob gmtime goto grep
11976 hex index int ioctl
11977 join keys kill last
11978 lc lcfirst length link
11979 listen local localtime lock
11980 log lstat m map
11981 mkdir msgctl msgget msgrcv
11982 msgsnd my next no
11983 not oct open opendir
11984 ord our pack package
11985 pipe pop pos print
11986 printf prototype push q
11987 qq qr quotemeta qw
11988 qx rand read readdir
11989 readline readlink readpipe recv
11990 redo ref rename require
11991 reset return reverse rewinddir
11992 rindex rmdir s say
11993 scalar seek seekdir select
11994 semctl semget semop send
11995 setgrent sethostent setnetent setpgrp
11996 setpriority setprotoent setpwent setservent
11997 setsockopt shift shmctl shmget
11998 shmread shmwrite shutdown sin
11999 sleep socket socketpair sort
12000 splice split sprintf sqrt
12001 srand stat state study
12002 sub substr switch symlink
12003 syscall sysopen sysread sysseek
12004 system syswrite tell telldir
12005 tie tied time times
12006 tr truncate uc ucfirst
12007 umask undef unlink unpack
12008 unshift untie use utime
12009 values vec wait waitpid
12010 wantarray warn write y
12011 );
12012 45 $is_TERM_keyword{$_} = 1 for @q;
12013  
12014 # Stable keyword infix operators which produce error if a TERM is expected
12015 45 @q = qw( and or xor eq ne ge gt le lt );
12016 45 $is_OPERATOR_keyword{$_} = 1 for @q;
12017  
12018 # Keywords which are omitted from the above TERM or OPERATOR lists.
12019 # Note that 'cmp' is here since it can be re-defined by File::Compare.
12020 # qw( isa err cmp if unless for foreach when while until case
12021 # EQ GE GT LE LT NE );
12022  
12023 # Note: 'field' will be added by sub check_options if --use-feature=class
12024 45 @q = qw( my our state );
12025 45 $is_my_our_state{$_} = 1 for @q;
12026  
12027 # These tokens may precede a code block
12028 # patched for SWITCH/CASE/CATCH. Actually these could be removed
12029 # now and we could let the extended-syntax coding handle them.
12030 # Added 'default' for Switch::Plain.
12031 # Note: 'ADJUST' will be added by sub check_options if --use-feature=class
12032 45 @q = qw(
12033 BEGIN END CHECK INIT AUTOLOAD DESTROY
12034 UNITCHECK continue if elsif else unless
12035 do while until eval for foreach
12036 map grep sort switch case given
12037 when default catch try finally
12038 );
12039 45 $is_code_block_token{$_} = 1 for @q;
12040  
12041 # These block types terminate statements and do not need a trailing
12042 # semicolon; patched for SWITCH/CASE/; This may be updated in sub
12043 # check_options.
12044 45 @q = qw( } { BEGIN END CHECK INIT AUTOLOAD DESTROY UNITCHECK continue ;
12045 if elsif else unless while until for foreach switch case given when );
12046 45 $is_zero_continuation_block_type{$_} = 1 for @q;
12047  
12048 # Note: this hash was formerly named '%is_not_zero_continuation_block_type'
12049 # to contrast it with the block types in '%is_zero_continuation_block_type'
12050 # Note: added 'sub' for anonymous sub blocks (c443)
12051 45 @q = qw( sort map grep eval do sub );
12052 45 $is_sort_map_grep_eval_do_sub{$_} = 1 for @q;
12053  
12054 45 @q = qw( sort map grep );
12055 45 $is_sort_map_grep{$_} = 1 for @q;
12056  
12057 45 %is_grep_alias = ();
12058  
12059 # I'll build the list of keywords incrementally
12060 45 my @Keywords = ();
12061  
12062 # keywords and tokens after which a value or pattern is expected,
12063 # but not an operator. In other words, these should consume terms
12064 # to their right, or at least they are not expected to be followed
12065 # immediately by operators.
12066 45 my @value_requestor = qw(
12067 AUTOLOAD BEGIN CHECK DESTROY
12068 END EQ GE GT
12069 INIT LE LT NE
12070 UNITCHECK abs accept alarm
12071 and atan2 bind binmode
12072 bless break caller chdir
12073 chmod chomp chop chown
12074 chr chroot close closedir
12075 cmp connect continue cos
12076 crypt dbmclose dbmopen defined
12077 delete die dump each
12078 else elsif eof eq
12079 evalbytes exec exists exit
12080 exp fc fcntl fileno
12081 flock for foreach formline
12082 ge getc getgrgid getgrnam
12083 gethostbyaddr gethostbyname getnetbyaddr getnetbyname
12084 getpeername getpgrp getpriority getprotobyname
12085 getprotobynumber getpwnam getpwuid getservbyname
12086 getservbyport getsockname getsockopt glob
12087 gmtime goto grep gt
12088 hex if index int
12089 ioctl join keys kill
12090 last lc lcfirst le
12091 length link listen local
12092 localtime lock log lstat
12093 lt map mkdir msgctl
12094 msgget msgrcv msgsnd my
12095 ne next no not
12096 oct open opendir or
12097 ord our pack pipe
12098 pop pos print printf
12099 prototype push quotemeta rand
12100 read readdir readlink readline
12101 readpipe recv redo ref
12102 rename require reset return
12103 reverse rewinddir rindex rmdir
12104 scalar seek seekdir select
12105 semctl semget semop send
12106 sethostent setnetent setpgrp setpriority
12107 setprotoent setservent setsockopt shift
12108 shmctl shmget shmread shmwrite
12109 shutdown sin sleep socket
12110 socketpair sort splice split
12111 sprintf sqrt srand stat
12112 state study substr symlink
12113 syscall sysopen sysread sysseek
12114 system syswrite tell telldir
12115 tie tied truncate uc
12116 ucfirst umask undef unless
12117 unlink unpack unshift untie
12118 until use utime values
12119 vec waitpid warn while
12120 write xor case catch
12121 default err given isa
12122 say switch when
12123 );
12124  
12125 # Note: 'ADJUST', 'field' are added by sub check_options
12126 # if --use-feature=class
12127  
12128 # patched above for SWITCH/CASE given/when err say
12129 # 'err' is a fairly safe addition.
12130 # Added 'default' for Switch::Plain. Note that we could also have
12131 # a separate set of keywords to include if we see 'use Switch::Plain'
12132 45 push @Keywords, @value_requestor;
12133  
12134 # These are treated the same but are not keywords:
12135 45 my @extra_vr = qw( constant vars );
12136 45 push @value_requestor, @extra_vr;
12137  
12138 45 $expecting_term_token{$_} = 1 for @value_requestor;
12139  
12140 # this list contains keywords which do not look for arguments,
12141 # so that they might be followed by an operator, or at least
12142 # not a term.
12143 45 my @operator_requestor = qw(
12144 endgrent endhostent endnetent endprotoent
12145 endpwent endservent fork getgrent
12146 gethostent getlogin getnetent getppid
12147 getprotoent getpwent getservent setgrent
12148 setpwent time times wait
12149 wantarray
12150 );
12151  
12152 45 push @Keywords, @operator_requestor;
12153  
12154 # These are treated the same but are not considered keywords:
12155 45 my @extra_or = qw( STDERR STDIN STDOUT );
12156  
12157 45 push @operator_requestor, @extra_or;
12158  
12159 45 $expecting_operator_token{$_} = 1 for @operator_requestor;
12160  
12161 # these token TYPES expect trailing operator but not a term
12162 # note: ++ and -- are post-increment and decrement, 'C' = constant
12163 45 my @operator_requestor_types = qw( ++ -- C <> q );
12164  
12165 # NOTE: This hash is available but not currently used
12166 45 $expecting_operator_types{$_} = 1 for @operator_requestor_types;
12167  
12168 # these token TYPES consume values (terms)
12169 # note: pp and mm are pre-increment and decrement
12170 # f=semicolon in for, F=file test operator
12171 45 my @value_requestor_type = qw#
12172 L { ( [ ~ !~ =~ ; . .. ... A : && ! || // = + - x
12173 **= += -= .= /= *= %= x= &= |= ^= <<= >>= &&= ||= //=
12174 <= >= == != => > < % * / ? & | ** <=> ~~ !~~ <<~
12175 f F pp mm Y p m U J G j >> << ^ t
12176 ~. ^. |. &. ^.= |.= &.= ^^
12177 #;
12178 45 push @value_requestor_type, BACKSLASH;
12179 45 push @value_requestor_type, COMMA;
12180  
12181 # NOTE: This hash is available but not currently used
12182 45 $expecting_term_types{$_} = 1 for @value_requestor_type;
12183  
12184 # Note: the following valid token types are not assigned here to
12185 # hashes requesting to be followed by values or terms, but are
12186 # instead currently hard-coded into sub operator_expected:
12187 # ) -> :: Q R Z ] b h i k n v w } #
12188  
12189 # A syntax error will occur if following operators are not followed by a
12190 # TERM (with an exception made for tokens in sub signatures).
12191 # NOTE: this list does not include unary operator '!'
12192  
12193 # Note the following omissions from the syntax checking operators below
12194 # 'U' = user sub, depends on prototype
12195 # 'F' = file test works on $_ if no following term
12196 # 'Y' = indirect object, too risky to check syntax
12197  
12198 45 my @binary_ops = qw#
12199 !~ =~ . .. : && || // = + - x
12200 **= += -= .= /= *= %= x= &= |= ^= <<= >>= &&= ||= //=
12201 <= >= == != > < % * / ? & | ** <=> ~~ !~~ <<~
12202 >> << ^
12203 ^. |. &. ^.= |.= &.= ^^
12204 #;
12205 45 $is_binary_operator_type{$_} = 1 for @binary_ops;
12206  
12207 # Note: omitting unary file test type 'F' here because it assumes $_
12208 45 my @unary_ops = qw# ! ~ ~. m p mm pp #;
12209 45 $is_binary_operator_type{$_} = 1 for @binary_ops;
12210 45 push @unary_ops, BACKSLASH;
12211 45 $is_binary_or_unary_operator_type{$_} = 1 for ( @binary_ops, @unary_ops );
12212  
12213 # added xor ge gt le lt ( git #206 )
12214 45 my @binary_keywords = qw( and or err eq ne cmp xor ge gt le lt );
12215 45 $is_binary_keyword{$_} = 1 for @binary_keywords;
12216  
12217 45 $is_binary_or_unary_keyword{$_} = 1 for ( @binary_keywords, 'not' );
12218  
12219 # A syntax error occurs if a binary operator follows any of these types:
12220 # NOTE: a ',' cannot be included because of parenless calls (c015).
12221 # For example this is valid: print "hello\n", && print "goodbye\n";
12222 # NOTE: the 'not' keyword could be added to a corresponding _keyword list
12223 # NOTE: label 'j' omitted, for example: -f $file ? redo BLOCK : last BLOCK;
12224 # NOTE: Removed 'A': fixes git162.t
12225 45 @q = qw< L { [ ( ; f J t >;
12226 45 $is_not_a_TERM_producer_type{$_} = 1 for ( @q, @unary_ops );
12227  
12228 45 @q = qw( q qq qx qr s y tr m );
12229 45 $is_q_qq_qx_qr_s_y_tr_m{$_} = 1 for @q;
12230  
12231 # Note added 'qw' here
12232 45 @q = qw( q qq qw qx qr s y tr m );
12233 45 $is_q_qq_qw_qx_qr_s_y_tr_m{$_} = 1 for @q;
12234  
12235 # Quote modifiers:
12236 # original ref: camel 3 p 147,
12237 # but perl may accept undocumented flags
12238 # perl 5.10 adds 'p' (preserve)
12239 # Perl version 5.22 added 'n'
12240 # From http://perldoc.perl.org/perlop.html we have
12241 # /PATTERN/msixpodualngc or m?PATTERN?msixpodualngc
12242 # s/PATTERN/REPLACEMENT/msixpodualngcer
12243 # y/SEARCHLIST/REPLACEMENTLIST/cdsr
12244 # tr/SEARCHLIST/REPLACEMENTLIST/cdsr
12245 # qr/STRING/msixpodualn
12246 45 %quote_modifiers = (
12247 's' => '[msixpodualngcer]',
12248 'y' => '[cdsr]',
12249 'tr' => '[cdsr]',
12250 'm' => '[msixpodualngc]',
12251 'qr' => '[msixpodualn]',
12252 'q' => EMPTY_STRING,
12253 'qq' => EMPTY_STRING,
12254 'qw' => EMPTY_STRING,
12255 'qx' => EMPTY_STRING,
12256 );
12257  
12258 # Note: 'class' will be added by sub check_options if -use-feature=class
12259 45 @q = qw( package );
12260 45 $is_package{$_} = 1 for @q;
12261  
12262 45 @q = qw( if elsif unless );
12263 45 $is_if_elsif_unless{$_} = 1 for @q;
12264  
12265 45 @q = qw( ; t );
12266 45 $is_semicolon_or_t{$_} = 1 for @q;
12267  
12268 45 @q = qw( if elsif unless case when );
12269 45 $is_if_elsif_unless_case_when{$_} = 1 for @q;
12270  
12271 # Hash of other possible line endings which may occur.
12272 # Keep these coordinated with the regex where this is used.
12273 # Note: chr(13) = chr(015)="\r".
12274 45 @q = ( chr(13), chr(29), chr(26) );
12275 45 $other_line_endings{$_} = 1 for @q;
12276  
12277 # These keywords are handled specially in the tokenizer code:
12278 45 my @special_keywords =
12279 qw( do eval format m package q qq qr qw qx s sub tr y );
12280 45 push @Keywords, @special_keywords;
12281  
12282 # Keywords after which list formatting may be used
12283 # WARNING: do not include |map|grep|eval or perl may die on
12284 # syntax errors (map1.t).
12285 45 my @keyword_taking_list = qw(
12286 and chmod chomp chop
12287 chown dbmopen die elsif
12288 exec fcntl for foreach
12289 formline getsockopt given if
12290 index ioctl join kill
12291 local msgctl msgrcv msgsnd
12292 my open or our
12293 pack print printf push
12294 read readpipe recv return
12295 reverse rindex seek select
12296 semctl semget send setpriority
12297 setsockopt shmctl shmget shmread
12298 shmwrite socket socketpair sort
12299 splice split sprintf state
12300 substr syscall sysopen sysread
12301 sysseek system syswrite tie
12302 unless unlink unpack unshift
12303 until vec warn when
12304 while
12305 );
12306  
12307 # NOTE: This hash is available but not currently used
12308 45 $is_keyword_taking_list{$_} = 1 for @keyword_taking_list;
12309  
12310 # perl functions which may be unary operators.
12311  
12312 # This list is used to decide if a pattern delimited by slashes, /pattern/,
12313 # can follow one of these keywords.
12314 45 @q = qw( chomp eof eval fc lc pop shift uc undef );
12315  
12316 45 $is_keyword_rejecting_slash_as_pattern_delimiter{$_} = 1 for @q;
12317  
12318 # These are keywords for which an arg may optionally be omitted. They are
12319 # currently only used to disambiguate a ? used as a ternary from one used
12320 # as a (deprecated) pattern delimiter. In the future, they might be used
12321 # to give a warning about ambiguous syntax before a /.
12322 # Note: split has been omitted (see note below).
12323 45 my @keywords_taking_optional_arg = qw(
12324 abs alarm caller chdir chomp chop
12325 chr chroot close cos defined die
12326 eof eval evalbytes exit exp fc
12327 getc glob gmtime hex int last
12328 lc lcfirst length localtime log lstat
12329 mkdir next oct ord pop pos
12330 print printf prototype quotemeta rand readline
12331 readlink readpipe redo ref require reset
12332 reverse rmdir say select shift sin
12333 sleep sqrt srand stat study tell
12334 uc ucfirst umask undef unlink warn
12335 write
12336 );
12337 45 $is_keyword_taking_optional_arg{$_} = 1 for @keywords_taking_optional_arg;
12338  
12339 # This list is used to decide if a pattern delimited by question marks,
12340 # ?pattern?, can follow one of these keywords. Note that from perl 5.22
12341 # on, a ?pattern? is not recognized, so we can be much more strict than
12342 # with a /pattern/. Note that 'split' is not in this list. In current
12343 # versions of perl a question following split must be a ternary, but
12344 # in older versions it could be a pattern. The guessing algorithm will
12345 # decide. We are combining two lists here to simplify the test.
12346 45 @q = ( @keywords_taking_optional_arg, @operator_requestor );
12347 45 $is_keyword_rejecting_question_as_pattern_delimiter{$_} = 1 for @q;
12348  
12349 # These are not used in any way yet
12350 # my @unused_keywords = qw(
12351 # __FILE__
12352 # __LINE__
12353 # __PACKAGE__
12354 # );
12355  
12356 # The list of keywords was originally extracted from function 'keyword' in
12357 # perl file toke.c version 5.005.03, using this utility, plus a
12358 # little editing: (file getkwd.pl):
12359 # while (<>) { while (/\"(.*)\"/g) { print "$1\n"; } }
12360 # Add 'get' prefix where necessary, then split into the above lists.
12361 # This list should be updated as necessary.
12362 # The list should not contain these special variables:
12363 # ARGV DATA ENV SIG STDERR STDIN STDOUT
12364 # __DATA__ __END__
12365  
12366 45 $is_keyword{$_} = 1 for @Keywords;
12367  
12368 45 %matching_end_token = (
12369 '{' => '}',
12370 '(' => ')',
12371 '[' => ']',
12372 '<' => '>',
12373 );
12374 } ## end BEGIN
12375  
12376 } ## end package Perl::Tidy::Tokenizer
12377 45 1;
« Tidy.pm ↑ Summary Tidy/Logger.pm »