lib/Zuzu/Tidy.pm

filter: Statementstmt 95.8% 887 / 925 Branchbran 81.6% 593 / 726 Conditioncond 72.1% 662 / 917 MC/DCmcdc 52.4% 238 / 454 Subroutinesub 100% 50 / 50 Podpod 100% 1 / 1 totaltotal 79.1% 2431 / 3073 CC 696 SCAR 41.8
CC
696
Cov
83%
_need_space_before
160.2
_tidy_code_chunk
120.5
_is_inline_brace
112.2
CRAP 65.2
« blib/lib/Zuzu/Module/Archive.pm ↑ Summary blib/lib/Zuzu/Module/Math/BigNum.pm »
1 package Zuzu::Tidy;
2  
3 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 our $VERSION = '0.007002';
8  
9 5 ▶use Zuzu::Lexer;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Zuzu::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Zuzu::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 my %BINARY_OP = map { $_ => 1 } qw(
14 + - * / × ÷ ** mod
15 _ ~
16 = == != < > <= >= <=> eq ne gt ge lt le cmp eqi nei gti gei lti lei cmpi
17 and and? or or? xor xor? nand nand? nor nor? xnor xnor? onlyif onlyif? butnot butnot?
18 × ÷ ≠ ≤ ≥ ≡ ≢ ≶ ≷ ⋀ ⋀? ⋁ ⋁? ⊻ ⊻? ⊼ ⊼? ⊽ ⊽? ↔ ↔? ⊨ ⊨? ⊭ ⊭?
19 in ∈ ∉ union ⋃ intersection ⋂ subsetof ⊂ supersetof ⊃ equivalentof ⊂⊃ ∖
20 instanceof does can
21 default
22 & | ^
23 << >> « »
24 ∣ ∤ divides
25 @ @? @@
26 ▷ ◁ |> <|
27 := ~= += -= *= /= ×= ÷= **= _= ?:=
28 =
29 );
30 5 $BINARY_OP{'\\'} = 1;
31  
32 5 my %UNARY_PREFIX_OP = map { $_ => 1 } qw(
33 + - ! not ¬ ~ √ \ ++ --
34 abs sqrt floor ceil round int uc lc length typeof new
35 );
36 5 $UNARY_PREFIX_OP{'#'} = 1;
37 5 my %NO_SPACE_BEFORE = map { $_ => 1 } ( ',', ';', ')', ']', '}', '⌋', '⌉', '.', ':' );
38 5 my %NO_SPACE_AFTER = map { $_ => 1 } ( '(', '[', '{', '⌊', '⌈', '.' );
39 5 my %CONTROL_KW = map { $_ => 1 } qw( if else while for switch catch unless );
40  
41 # Delimiter types that can open/close a comma-separated sequence body
42 # (array/dict/pairlist literal, set/bag/guillemet-set literal, or a
43 # call/parameter argument list). << and « are ambiguous with the binary
44 # "shift" operator of the same spelling, so they (and their closes >> and
45 # ») only engage this tracking when _build_pair_map judged them to be a
46 # genuine literal delimiter -- i.e. when they have an entry in %pair_for.
47 5 my %_SEQUENCE_OPEN = ( '(' => 1, '[' => 1, '{' => 1, '<<' => 1, '<<<' => 1, '«' => 1 );
48 5 my %_SEQUENCE_CLOSE = ( ')' => 1, ']' => 1, '>>' => 1, '>>>' => 1, '»' => 1 );
49 5 my %_AMBIGUOUS_ANGLE = ( '<<' => 1, '«' => 1, '>>' => 1, '»' => 1 );
50 5 my %CANONICAL_OPERATOR_SPELLING = (
51 '*' => '×',
52 '/' => '÷',
53 '<=' => '≤',
54 '>=' => '≥',
55 '<=>' => '≶',
56 '≷' => '≶',
57 '==' => '≡',
58 '!=' => '≢',
59 'not' => '¬',
60 'sqrt' => '√',
61 'divides' => '∣',
62 'and' => '⋀',
63 'and?' => '⋀?',
64 'nand' => '⊼',
65 'nand?' => '⊼?',
66 'nor' => '⊽',
67 'nor?' => '⊽?',
68 'xor' => '⊻',
69 'xor?' => '⊻?',
70 'xnor' => '↔',
71 'xnor?' => '↔?',
72 'or' => '⋁',
73 'or?' => '⋁?',
74 'onlyif' => '⊨',
75 'onlyif?' => '⊨?',
76 'butnot' => '⊭',
77 'butnot?' => '⊭?',
78 'union' => '⋃',
79 'intersection' => '⋂',
80 '\\' => '∖',
81 'in' => '∈',
82 'subsetof' => '⊂',
83 'supersetof' => '⊃',
84 'equivalentof' => '⊂⊃',
85 '|>' => '▷',
86 '<|' => '◁',
87 '*=' => '×=',
88 '/=' => '÷=',
89 );
90  
91 38 ▶sub tidy {
Subroutine tidy: called CC=6 SCAR=17.9
Pod documented
92 38 my ( $class, $src, %opts ) = @_;
93 38 ▶ $src //= '';
Condition50%1/2
$src //= ""
l!l
380
MC/DC0%0/1
$src //= ""
$src
Truth table50%1/2
A
A= $src
Aresult
11
00
94 38 my $comment_map = {};
95 38 $src = _stash_multiline_comments( $src, $comment_map );
96  
97 38 my @segments = _split_pod_segments($src);
98 38 my @out;
99 38 for my $segment ( @segments ) {
100 44 ▶ if ( $segment->{is_pod} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($segment->{"is_pod"}) 4 40 44
101 4 push @out, { is_pod => 1, text => $segment->{text} };
102 4 next;
103 }
104  
105 40 my $chunk = $segment->{text};
106 40 ▶ next if $chunk eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $chunk eq "" 0 40 40
107  
108 40 my $tidied = _tidy_code_chunk( $chunk, %opts );
109 40 $tidied = _restore_multiline_comments( $tidied, $comment_map );
110 40 $tidied = _apply_vertical_spacing_rules($tidied);
111 40 $tidied = _normalize_split_sequence_literals($tidied);
112 40 my $parser = Zuzu::Parser->new;
113 40 eval {
114 $parser->parse(
115 _strip_multiline_comments_for_parse($tidied),
116 40 ▶ $opts{filename} // '<tidy>'
Condition100%2/2
$opts{"filename"} // "<tidy>"
l!l
382
MC/DC100%1/1
$opts{"filename"} // "<tidy>"
$opts{"filename"}
Truth table100%2/2
A
A= $opts{"filename"}
Aresult
11
00
117 );
118 16 1;
119 };
120 40 push @out, { is_pod => 0, text => $tidied };
121 }
122  
123 38 return _join_segments_with_pod_spacing(@out);
124 }
125  
126 38 ▶sub _join_segments_with_pod_spacing {
Subroutine _join_segments_with_pod_spacing: called CC=9 SCAR=22.8
127 38 my ( @segments ) = @_;
128 38 my $out = '';
129  
130 38 ▶ for ( my $i = 0; $i <= $#segments; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#segments) 44 38 82
131 44 my $segment = $segments[$i];
132 44 ▶ my $text = $segment->{text} // '';
Condition50%1/2
$segment->{"text"} // ""
l!l
440
MC/DC0%0/1
$segment->{"text"} // ""
$segment->{"text"}
Truth table50%1/2
A
A= $segment->{"text"}
Aresult
11
00
133 44 ▶ next if $text eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $text eq "" 0 44 44
134  
135 44 ▶ if ( $i > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0) 6 38 44
136 6 my $prev = $segments[$i - 1];
137 my $crosses_pod_boundary
138 = ( ( $prev->{is_pod} and ! $segment->{is_pod} )
139 6 ▶ or ( ! $prev->{is_pod} and $segment->{is_pod} ) );
Condition55%5/9
$prev->{'is_pod'} && !$segment->{'is_pod'} || !$prev->{'is_pod'} && $segment->{'is_pod'}
l!l&&r!l&&!r
330
$prev->{"is_pod"} and not $segment->{"is_pod"}
!ll&&!rl&&r
303
not $prev->{"is_pod"} and $segment->{"is_pod"}
!ll&&!rl&&r
003
MC/DC0%0/4
$prev->{'is_pod'} && !$segment->{'is_pod'} || !$prev->{'is_pod'} && $segment->{'is_pod'}
$prev->{"is_pod"} not $segment->{"is_pod"} not $prev->{"is_pod"} $segment->{"is_pod"}
Truth table28%2/7
A and not(B) || not(C) and D
A= $prev->{"is_pod"}B= not $segment->{"is_pod"}C= not $prev->{"is_pod"}D= $segment->{"is_pod"}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
140 6 ▶ if ( $crosses_pod_boundary ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($crosses_pod_boundary) 6 0 6
141 6 $out =~ s/\n*\z/\n\n/s;
142 6 $text =~ s/\A\n+//s;
143 }
144 }
145  
146 44 $out .= $text;
147 }
148  
149 38 return $out;
150 }
151  
152 40 ▶sub _tidy_code_chunk {
Subroutine _tidy_code_chunk: called CC=108 SCAR=47.9
153 40 my ( $src, %opts ) = @_;
154  
155 40 ▶ my $lexer = Zuzu::Lexer->new( src => $src, filename => $opts{filename} // '<tidy>' );
Condition100%2/2
$opts{"filename"} // "<tidy>"
l!l
382
MC/DC100%1/1
$opts{"filename"} // "<tidy>"
$opts{"filename"}
Truth table100%2/2
A
A= $opts{"filename"}
Aresult
11
00
156 40 my @tokens;
157 40 while (1) {
158 3519 my $tok = $lexer->next_token;
159 3519 ▶ last if $tok->is_EOF;
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_EOF 40 3479 3519
160 3479 push @tokens, $tok;
161 }
162 40 @tokens = _normalize_tokens(@tokens);
163 40 _tag_declaration_block_braces( \@tokens );
164  
165 40 my %pair_for = _build_pair_map( \@tokens );
166 40 _tag_trailing_comma_sequences( \@tokens, \%pair_for );
167  
168 40 my $indent = 0;
169 40 my $paren_depth = 0;
170 40 my $bracket_depth = 0;
171 40 my $brace_depth = 0;
172 40 my $inline_brace_depth = 0;
173 40 my $angle_depth = 0;
174 40 my @brace_kind_stack;
175 my @sequence_stack;
176 40 my $line = '';
177 40 my @out_lines;
178 40 my $pending_indent = 1;
179 40 my $continuation_indent = 0;
180  
181 40 ▶ for ( my $i = 0; $i <= $#tokens; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#tokens) 3482 40 3522
182 3482 my $tok = $tokens[$i];
183 3482 my $val = _token_text($tok);
184 3482 my $emit_val = _display_token_text( \@tokens, $i, %opts );
185 3482 ▶ my $prev = $i > 0 ? $tokens[$i - 1] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$i > 0 ? : 3442 40 3482
186 3482 ▶ my $next = $i < $#tokens ? $tokens[$i + 1] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$i < $#tokens ? : 3442 40 3482
187 3482 my $just_closed_inline = 0;
188  
189 3482 ▶ my $close_kind = ( $val eq '}' and @brace_kind_stack ) ? $brace_kind_stack[-1] : 'block';
Branch: 1 branch
BranchTrueFalseTotal
$val eq '}' && @brace_kind_stack ? : 121 3361 3482
Condition66%2/3
$val eq "}" and @brace_kind_stack
!ll&&!rl&&r
33610121
MC/DC50%1/2
$val eq "}" and @brace_kind_stack
$val eq "}" @brace_kind_stack
Truth table66%2/3
A and B
A= $val eq "}"B= @brace_kind_stack
ABresult
0X0
100
111
190 my $is_other_sequence_close = (
191 $_SEQUENCE_CLOSE{$val}
192 and $val ne '}'
193 3482 ▶ and ( ! $_AMBIGUOUS_ANGLE{$val} or exists $pair_for{$i} )
Condition73%11/15
$_SEQUENCE_CLOSE{$val} && $val ne '}' && (!$_AMBIGUOUS_ANGLE{$val} || exists $pair_for{$i}) && @sequence_stack && $sequence_stack[-1]
!ll&&!rl&&r
315630323
$_SEQUENCE_CLOSE{$val} and $val ne "}" and !$_AMBIGUOUS_ANGLE{$val} || exists $pair_for{$i} and @sequence_stack
!ll&&!rl&&r
31560326
$_SEQUENCE_CLOSE{$val} and $val ne "}" and !$_AMBIGUOUS_ANGLE{$val} || exists $pair_for{$i}
!ll&&!rl&&r
31560326
$_SEQUENCE_CLOSE{$val} and $val ne "}"
!ll&&!rl&&r
31560326
not $_AMBIGUOUS_ANGLE{$val} or exists $pair_for{$i}
l!l&&r!l&&!r
306200
MC/DC33%2/6
$_SEQUENCE_CLOSE{$val} && $val ne '}' && (!$_AMBIGUOUS_ANGLE{$val} || exists $pair_for{$i}) && @sequence_stack && $sequence_stack[-1]
$_SEQUENCE_CLOSE{$val} $val ne "}" not $_AMBIGUOUS_ANGLE{$val} exists $pair_for{$i} @sequence_stack $sequence_stack[-1]
Truth table55%5/9
A and B and not(C) or D and E && F
A= $_SEQUENCE_CLOSE{$val}B= $val ne "}"C= not $_AMBIGUOUS_ANGLE{$val}D= exists $pair_for{$i}E= @sequence_stackF= $sequence_stack[-1]
ABCDEFresult
0XXXXX0
10XXXX0
1100XX0
111X0X0
11010X0
111X100
1101100
111X111
1101111
194 and @sequence_stack
195 and $sequence_stack[-1]
196 );
197  
198 3482 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($val eq "}" and $close_kind eq "block" || $close_kind eq "expr_block" or $is_other_sequence_close) 120 3362 3482
Condition100%9/9
$val eq "}" and $close_kind eq "block" || $close_kind eq "expr_block" or $is_other_sequence_close
l!l&&r!l&&!r
97233362
$val eq "}" and $close_kind eq "block" || $close_kind eq "expr_block"
!ll&&!rl&&r
33612497
$close_kind eq "block" or $close_kind eq "expr_block"
l!l&&r!l&&!r
772024
MC/DC100%4/4
$val eq "}" and $close_kind eq "block" || $close_kind eq "expr_block" or $is_other_sequence_close
$val eq "}" $close_kind eq "block" $close_kind eq "expr_block" $is_other_sequence_close
Truth table83%5/6
A and B or C or D
A= $val eq "}"B= $close_kind eq "block"C= $close_kind eq "expr_block"D= $is_other_sequence_close
ABCDresult
11XX1
101X1
0XX11
10011
0XX00
10000
199 ( $val eq '}' and ( $close_kind eq 'block' or $close_kind eq 'expr_block' ) )
200 or $is_other_sequence_close
201 ) {
202 120 ▶ if ( @sequence_stack and $sequence_stack[-1] and $line =~ /\S/ and $line !~ /,\s*\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sequence_stack and $sequence_stack[-1] and $line =~ /\S/ and not $line =~ /,\s*\z/) 4 116 120
Condition77%7/9
@sequence_stack and $sequence_stack[-1] and $line =~ /\S/ and not $line =~ /,\s*\z/
!ll&&!rl&&r
11604
@sequence_stack and $sequence_stack[-1] and $line =~ /\S/
!ll&&!rl&&r
91254
@sequence_stack and $sequence_stack[-1]
!ll&&!rl&&r
09129
MC/DC50%2/4
@sequence_stack and $sequence_stack[-1] and $line =~ /\S/ and not $line =~ /,\s*\z/
@sequence_stack $sequence_stack[-1] $line =~ /\S/ not $line =~ /,\s*\z/
Truth table60%3/5
A and B and C and not(D)
A= @sequence_stackB= $sequence_stack[-1]C= $line =~ /\S/D= not $line =~ /,\s*\z/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
203 # Every entry, including the last, gets a trailing comma
204 # when the body is split one-entry-per-line below.
205 4 $line .= ',';
206 }
207 120 ▶ if ( $line =~ /\S/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\S/) 10 110 120
208 10 push @out_lines, _rstrip($line);
209 10 $line = '';
210 }
211 120 ▶ $indent-- if $indent > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $indent > 0 120 0 120
212 120 $pending_indent = 1;
213 }
214  
215 3482 ▶ if ( $pending_indent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pending_indent) 609 2873 3482
216 609 $line .= ("\t" x $indent);
217 609 ▶ $line .= (' ' x $continuation_indent) if $continuation_indent > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $continuation_indent > 0 4 605 609
218 609 $pending_indent = 0;
219 }
220  
221 3482 ▶ if ( _is_chain_op($val) and $line =~ /\S/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_chain_op($val) and $line =~ /\S/) 14 3468 3482
Condition66%2/3
_is_chain_op($val) and $line =~ /\S/
!ll&&!rl&&r
3468014
MC/DC50%1/2
_is_chain_op($val) and $line =~ /\S/
_is_chain_op($val) $line =~ /\S/
Truth table66%2/3
A and B
A= _is_chain_op($val)B= $line =~ /\S/
ABresult
0X0
100
111
222 14 push @out_lines, _rstrip($line);
223 14 $line = ("\t" x ( $indent + 1 ));
224 }
225  
226 3482 my $need_before = _need_space_before( \@tokens, $i, \%pair_for );
227 3482 ▶ $line .= ' ' if $need_before and $line =~ /\S/ and $line !~ /[ \t]\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $need_before and $line =~ /\S/ and not $line =~ /[ \t]\z/ 1774 1708 3482
Condition83%5/6
$need_before and $line =~ /\S/ and not $line =~ /[ \t]\z/
!ll&&!rl&&r
170801774
$need_before and $line =~ /\S/
!ll&&!rl&&r
11335751774
MC/DC66%2/3
$need_before and $line =~ /\S/ and not $line =~ /[ \t]\z/
$need_before $line =~ /\S/ not $line =~ /[ \t]\z/
Truth table75%3/4
A and B and not(C)
A= $need_beforeB= $line =~ /\S/C= not $line =~ /[ \t]\z/
ABCresult
0XX0
10X0
1100
1111
228 3482 $line .= $emit_val;
229  
230 3482 ▶ if ( $_SEQUENCE_OPEN{$val} and ( ! $_AMBIGUOUS_ANGLE{$val} or exists $pair_for{$i} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_SEQUENCE_OPEN{$val} and !$_AMBIGUOUS_ANGLE{$val} || exists $pair_for{$i}) 447 3035 3482
Condition100%6/6
$_SEQUENCE_OPEN{$val} and !$_AMBIGUOUS_ANGLE{$val} || exists $pair_for{$i}
!ll&&!rl&&r
30332447
not $_AMBIGUOUS_ANGLE{$val} or exists $pair_for{$i}
l!l&&r!l&&!r
427202
MC/DC100%3/3
$_SEQUENCE_OPEN{$val} and !$_AMBIGUOUS_ANGLE{$val} || exists $pair_for{$i}
$_SEQUENCE_OPEN{$val} not $_AMBIGUOUS_ANGLE{$val} exists $pair_for{$i}
Truth table100%4/4
A and not(B) or C
A= $_SEQUENCE_OPEN{$val}B= not $_AMBIGUOUS_ANGLE{$val}C= exists $pair_for{$i}
ABCresult
0XX0
1000
11X1
1011
231 447 my $is_inline = 1;
232 447 my $kind = 'inline';
233 447 ▶ if ( $val eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val eq "{") 121 326 447
234 121 $is_inline = _is_inline_brace( \@tokens, $i, \%pair_for );
235 121 ▶ $kind = $is_inline ? 'inline'
Branch: 2 branches
BranchTrueFalseTotal
$is_inline ? : 24 97 121
_is_expression_block_brace(\@tokens, $i) ? : 20 77 97
236 : _is_expression_block_brace( \@tokens, $i ) ? 'expr_block'
237 : 'block';
238 121 push @brace_kind_stack, $kind;
239 }
240  
241 447 ▶ my $is_pairlist_body = ( $val eq '{' and defined $tok->{_pairlist_half} and $tok->{_pairlist_half} eq 'open2' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$val eq '{' && defined $tok->{'_pairlist_half'} && $tok->{'_pairlist_half'} eq 'open2' ? : 4 443 447
Condition100%6/6
$val eq "{" and defined $tok->{"_pairlist_half"} and $tok->{"_pairlist_half"} eq "open2"
!ll&&!rl&&r
43944
$val eq "{" and defined $tok->{"_pairlist_half"}
!ll&&!rl&&r
3261138
MC/DC100%3/3
$val eq "{" and defined $tok->{"_pairlist_half"} and $tok->{"_pairlist_half"} eq "open2"
$val eq "{" defined $tok->{"_pairlist_half"} $tok->{"_pairlist_half"} eq "open2"
Truth table100%4/4
A and B and C
A= $val eq "{"B= defined $tok->{"_pairlist_half"}C= $tok->{"_pairlist_half"} eq "open2"
ABCresult
0XX0
10X0
1100
1111
242 447 ▶ my $is_sequence_body = $is_pairlist_body || ( $tok->{_force_sequence} ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$tok->{'_force_sequence'} ? : 25 418 443
Condition100%3/3
$is_pairlist_body || ($tok->{'_force_sequence'} ? 1 : 0)
l!l&&r!l&&!r
425418
MC/DC100%2/2
$is_pairlist_body || ($tok->{'_force_sequence'} ? 1 : 0)
$is_pairlist_body ($tok->{'_force_sequence'} ? 1 : 0)
Truth table100%3/3
A || B
A= $is_pairlist_bodyB= ($tok->{'_force_sequence'} ? 1 : 0)
ABresult
1X1
011
000
243 447 push @sequence_stack, $is_sequence_body;
244  
245 447 ▶ if ( $val eq '(' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($val eq '(') { } 238 209 447
elsif ($val eq '[') { } 62 147 209
elsif ($val eq '{') { } 121 26 147
246 238 $paren_depth++;
247 }
248 elsif ( $val eq '[' ) {
249 62 $bracket_depth++;
250 }
251 elsif ( $val eq '{' ) {
252 121 $brace_depth++;
253 121 ▶ $inline_brace_depth++ if $is_inline;
Branch: 1 branch
BranchTrueFalseTotal
if $is_inline 24 97 121
254 }
255 else {
256 # << <<< «
257 26 $angle_depth++;
258 }
259  
260 447 ▶ my $forces_newline = ( $val eq '{' ) ? ( ! $is_inline ) : ( $is_sequence_body ? 1 : 0 );
Branch: 2 branches
BranchTrueFalseTotal
$val eq '{' ? : 121 326 447
$is_sequence_body ? : 23 303 326
261 447 ▶ if ( $forces_newline ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($forces_newline) 120 327 447
262 120 push @out_lines, _rstrip($line);
263 120 $line = '';
264 120 $indent++;
265 120 $pending_indent = 1;
266 120 $continuation_indent = 0;
267 120 next;
268 }
269 }
270 3362 ▶ if ( $val eq ';' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val eq ";") 208 3154 3362
271 208 push @out_lines, _rstrip($line);
272 208 $line = '';
273 208 $pending_indent = 1;
274 208 $continuation_indent = 0;
275 208 next;
276 }
277 3154 ▶ if ( $val eq ',' and @sequence_stack and $sequence_stack[-1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val eq "," and @sequence_stack and $sequence_stack[-1]) 68 3086 3154
Condition100%6/6
$val eq "," and @sequence_stack and $sequence_stack[-1]
!ll&&!rl&&r
291916768
$val eq "," and @sequence_stack
!ll&&!rl&&r
29163235
MC/DC100%3/3
$val eq "," and @sequence_stack and $sequence_stack[-1]
$val eq "," @sequence_stack $sequence_stack[-1]
Truth table100%4/4
A and B and C
A= $val eq ","B= @sequence_stackC= $sequence_stack[-1]
ABCresult
0XX0
10X0
1100
1111
278 # Inside any sequence body (pairlist, dict, array, set, bag,
279 # guillemet-set, or argument/parameter list) that must be
280 # rendered one-item-per-line, each entry -- including the
281 # last -- is placed on its own line, separated by the literal
282 # commas already present in the source.
283 68 push @out_lines, _rstrip($line);
284 68 $line = '';
285 68 $pending_indent = 1;
286 68 $continuation_indent = 0;
287 68 next;
288 }
289 3086 ▶ if ( $val eq '}' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val eq '}') { } 121 2965 3086
elsif ($_SEQUENCE_CLOSE{$val} and !$_AMBIGUOUS_ANGLE{$val} || exists $pair_for{$i}) { } 326 5278 5604
290 121 ▶ my $kind = @brace_kind_stack ? pop @brace_kind_stack : 'block';
Branch: 1 branch
BranchTrueFalseTotal
@brace_kind_stack ? : 121 0 121
291 121 ▶ my $is_sequence_body = @sequence_stack ? pop @sequence_stack : 0;
Branch: 1 branch
BranchTrueFalseTotal
@sequence_stack ? : 121 0 121
292 # A forced dict literal's } ends a value, not a statement
293 # block, so (like pairlist close2, which is already 'inline'
294 # kind) it must remain eligible for the same generic
295 # end-of-value auto-semicolon treatment that _needs_auto_semicolon
296 # otherwise blanket-excludes for 'block'/'expr_block' closes.
297 121 ▶ $just_closed_inline = 1 if $kind eq 'inline' or $is_sequence_body;
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "inline" or $is_sequence_body 30 91 121
Condition100%3/3
$kind eq "inline" or $is_sequence_body
l!l&&r!l&&!r
24691
MC/DC100%2/2
$kind eq "inline" or $is_sequence_body
$kind eq "inline" $is_sequence_body
Truth table100%3/3
A or B
A= $kind eq "inline"B= $is_sequence_body
ABresult
1X1
011
000
298 121 ▶ $brace_depth-- if $brace_depth > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $brace_depth > 0 121 0 121
299 121 ▶ $inline_brace_depth-- if $kind eq 'inline' and $inline_brace_depth > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "inline" and $inline_brace_depth > 0 24 97 121
Condition66%2/3
$kind eq "inline" and $inline_brace_depth > 0
!ll&&!rl&&r
97024
MC/DC50%1/2
$kind eq "inline" and $inline_brace_depth > 0
$kind eq "inline" $inline_brace_depth > 0
Truth table66%2/3
A and B
A= $kind eq "inline"B= $inline_brace_depth > 0
ABresult
0X0
100
111
300 121 ▶ my $is_pairlist_close1 = ( defined $tok->{_pairlist_half} && $tok->{_pairlist_half} eq 'close1' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $tok->{'_pairlist_half'} && $tok->{'_pairlist_half'} eq 'close1' ? : 10 111 121
Condition100%3/3
defined $tok->{"_pairlist_half"} and $tok->{"_pairlist_half"} eq "close1"
!ll&&!rl&&r
1011010
MC/DC100%2/2
defined $tok->{"_pairlist_half"} and $tok->{"_pairlist_half"} eq "close1"
defined $tok->{"_pairlist_half"} $tok->{"_pairlist_half"} eq "close1"
Truth table100%3/3
A and B
A= defined $tok->{"_pairlist_half"}B= $tok->{"_pairlist_half"} eq "close1"
ABresult
0X0
100
111
301 121 ▶ if ( ( $kind eq 'block' or $kind eq 'expr_block' ) and ! $is_pairlist_close1 and ! $is_sequence_body ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "block" || $kind eq "expr_block" and not $is_pairlist_close1 and not $is_sequence_body) 86 35 121
Condition100%9/9
$kind eq "block" || $kind eq "expr_block" and not $is_pairlist_close1 and not $is_sequence_body
!ll&&!rl&&r
33286
$kind eq "block" || $kind eq "expr_block" and not $is_pairlist_close1
!ll&&!rl&&r
24988
$kind eq "block" or $kind eq "expr_block"
l!l&&r!l&&!r
772024
MC/DC100%4/4
$kind eq "block" || $kind eq "expr_block" and not $is_pairlist_close1 and not $is_sequence_body
$kind eq "block" $kind eq "expr_block" not $is_pairlist_close1 not $is_sequence_body
Truth table85%6/7
A or B and not(C) and not(D)
A= $kind eq "block"B= $kind eq "expr_block"C= not $is_pairlist_close1D= not $is_sequence_body
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
302 86 ▶ if ( $kind eq 'expr_block' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "expr_block") 19 67 86
303 19 ▶ if ( $next and $next->is_OP(';') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($next and $next->is_OP(';')) { } 10 9 19
elsif (not $next or $next->is_OP and $next->value eq '}' or _can_start_statement($next)) { } 2 7 9
Condition66%2/3
$next and $next->is_OP(";")
!ll&&!rl&&r
0910
MC/DC50%1/2
$next and $next->is_OP(";")
$next $next->is_OP(";")
Truth table66%2/3
A and B
A= $nextB= $next->is_OP(";")
ABresult
0X0
100
111
304 10 $line .= ';';
305 10 $i++;
306 }
307 ▶ elsif (
Condition55%5/9
not $next or $next->is_OP and $next->value eq "}" or _can_start_statement($next)
l!l&&r!l&&!r
027
not $next or $next->is_OP and $next->value eq "}"
l!l&&r!l&&!r
009
$next->is_OP and $next->value eq "}"
!ll&&!rl&&r
270
MC/DC0%0/4
not $next or $next->is_OP and $next->value eq "}" or _can_start_statement($next)
not $next $next->is_OP $next->value eq "}" _can_start_statement($next)
Truth table33%2/6
not(A) or B and C or D
A= not $nextB= $next->is_OPC= $next->value eq "}"D= _can_start_statement($next)
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
308 !$next
309 or ( $next->is_OP and $next->value eq '}' )
310 or _can_start_statement($next)
311 ) {
312 2 $line .= ';';
313 }
314 }
315 86 ▶ if ( $next and $next->is_KW('else') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next and $next->is_KW("else")) 6 80 86
Condition100%3/3
$next and $next->is_KW("else")
!ll&&!rl&&r
12686
MC/DC100%2/2
$next and $next->is_KW("else")
$next $next->is_KW("else")
Truth table100%3/3
A and B
A= $nextB= $next->is_KW("else")
ABresult
0X0
100
111
316 6 push @out_lines, _rstrip($line);
317 6 $line = '';
318 6 $pending_indent = 1;
319 6 next;
320 }
321 80 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "block" || $kind eq "expr_block" and $paren_depth > 0 || $bracket_depth > 0 and $next and $next->is_OP and $next->value eq "," || $next->value eq ")" || $next->value eq "]") 13 67 80
Condition66%16/24
$kind eq "block" || $kind eq "expr_block" and $paren_depth > 0 || $bracket_depth > 0 and $next and $next->is_OP and $next->value eq "," || $next->value eq ")" || $next->value eq "]"
!ll&&!rl&&r
67013
$kind eq "block" || $kind eq "expr_block" and $paren_depth > 0 || $bracket_depth > 0 and $next and $next->is_OP
!ll&&!rl&&r
67013
$kind eq "block" || $kind eq "expr_block" and $paren_depth > 0 || $bracket_depth > 0 and $next
!ll&&!rl&&r
67013
$kind eq "block" || $kind eq "expr_block" and $paren_depth > 0 || $bracket_depth > 0
!ll&&!rl&&r
06713
$kind eq "block" or $kind eq "expr_block"
l!l&&r!l&&!r
61190
$paren_depth > 0 or $bracket_depth > 0
l!l&&r!l&&!r
5867
$next->value eq "," or $next->value eq ")" or $next->value eq "]"
l!l&&r!l&&!r
1300
$next->value eq "," or $next->value eq ")"
l!l&&r!l&&!r
1120
MC/DC22%2/9
$kind eq "block" || $kind eq "expr_block" and $paren_depth > 0 || $bracket_depth > 0 and $next and $next->is_OP and $next->value eq "," || $next->value eq ")" || $next->value eq "]"
$kind eq "block" $kind eq "expr_block" $paren_depth > 0 $bracket_depth > 0 $next $next->is_OP $next->value eq "," $next->value eq ")" $next->value eq "]"
Truth table25%7/27
A or B and C or D and E and F and G or H or I
A= $kind eq "block"B= $kind eq "expr_block"C= $paren_depth > 0D= $bracket_depth > 0E= $nextF= $next->is_OPG= $next->value eq ","H= $next->value eq ")"I= $next->value eq "]"
ABCDEFGHIresult
00XXXXXXX0
1X00XXXXX0
0100XXXXX0
1X1X0XXXX0
1X010XXXX0
011X0XXXX0
01010XXXX0
1X1X10XXX0
1X0110XXX0
011X10XXX0
010110XXX0
1X1X110000
1X01110000
011X110000
0101110000
1X1X111XX1
1X1X1101X1
1X1X110011
1X01111XX1
1X011101X1
1X01110011
011X111XX1
011X1101X1
011X110011
0101111XX1
01011101X1
0101110011
322 ( $kind eq 'block' or $kind eq 'expr_block' )
323 and ( $paren_depth > 0 or $bracket_depth > 0 )
324 and $next
325 and $next->is_OP
326 and ( $next->value eq ',' or $next->value eq ')' or $next->value eq ']' )
327 ) {
328 # A callback/anonymous-function body that is itself a
329 # call argument or array item: keep its closing } glued
330 # to the `,`, `)`, or `]` that follows, instead of
331 # stranding the rest of the argument list or array on
332 # its own line (`}, 4 );` rather than `}\n, 4, );`).
333 # Falling through without flushing here, rather than
334 # consuming $next directly, lets that token's own
335 # normal handling run on the next iteration -- so if
336 # the enclosing sequence is itself forced
337 # one-item-per-line, the generic comma separator (or
338 # the enclosing close's own pre-emission flush) still
339 # fires for it exactly as for every other item.
340 13 next;
341 }
342 67 ▶ if ( $kind eq 'block' and $next and $next->is_OP(';') and ! ( @sequence_stack and $sequence_stack[-1] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "block" and $next and $next->is_OP(";") and not @sequence_stack && $sequence_stack[-1]) 1 66 67
Condition75%9/12
$kind eq "block" and $next and $next->is_OP(";") and not @sequence_stack && $sequence_stack[-1]
!ll&&!rl&&r
6601
$kind eq "block" and $next and $next->is_OP(";")
!ll&&!rl&&r
24421
$kind eq "block" and $next
!ll&&!rl&&r
121243
@sequence_stack && $sequence_stack[-1]
!ll&&!rl&&r
100
MC/DC60%3/5
$kind eq "block" and $next and $next->is_OP(";") and not @sequence_stack && $sequence_stack[-1]
$kind eq "block" $next $next->is_OP(";") @sequence_stack $sequence_stack[-1]
Truth table66%4/6
A and B and C and not(D && E)
A= $kind eq "block"B= $nextC= $next->is_OP(";")D= @sequence_stackE= $sequence_stack[-1]
ABCDEresult
0XXXX0
10XXX0
110XX0
111110
1110X1
111101
343 # A control construct (e.g. try/catch) used as an
344 # expression value, terminated by an explicit `;`:
345 # glue the semicolon to the closing } instead of
346 # stranding it alone on the next line.
347 1 $line .= ';';
348 1 $i++;
349 }
350 67 push @out_lines, _rstrip($line);
351 67 $line = '';
352 67 $pending_indent = 1;
353 67 next;
354 }
355 }
356 ▶ elsif ( $_SEQUENCE_CLOSE{$val} and ( ! $_AMBIGUOUS_ANGLE{$val} or exists $pair_for{$i} ) ) {
Condition66%4/6
$_SEQUENCE_CLOSE{$val} and !$_AMBIGUOUS_ANGLE{$val} || exists $pair_for{$i}
!ll&&!rl&&r
26390326
not $_AMBIGUOUS_ANGLE{$val} or exists $pair_for{$i}
l!l&&r!l&&!r
306200
MC/DC33%1/3
$_SEQUENCE_CLOSE{$val} and !$_AMBIGUOUS_ANGLE{$val} || exists $pair_for{$i}
$_SEQUENCE_CLOSE{$val} not $_AMBIGUOUS_ANGLE{$val} exists $pair_for{$i}
Truth table75%3/4
A and not(B) or C
A= $_SEQUENCE_CLOSE{$val}B= not $_AMBIGUOUS_ANGLE{$val}C= exists $pair_for{$i}
ABCresult
0XX0
1000
11X1
1011
357 # A forced sequence's own closing delimiter never forces a new
358 # line to start for whatever follows it (unlike the pre-emission
359 # flush above, which only dedents the close itself onto its own
360 # line). Falling through lets the close glue naturally to a
361 # following `,`/`)`/`;` exactly as an ordinary, non-forced close
362 # already does, and lets the bottom-of-loop auto-semicolon check
363 # supply a `;` when this is the last token of a statement.
364 326 ▶ pop @sequence_stack if @sequence_stack;
Branch: 1 branch
BranchTrueFalseTotal
if @sequence_stack 326 0 326
365 326 ▶ if ( $val eq ')' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val eq ')') { } 238 88 326
elsif ($val eq ']') { } 62 26 88
366 238 ▶ $paren_depth-- if $paren_depth > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $paren_depth > 0 238 0 238
367 }
368 elsif ( $val eq ']' ) {
369 62 ▶ $bracket_depth-- if $bracket_depth > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $bracket_depth > 0 62 0 62
370 }
371 else {
372 # >> >>> »
373 26 ▶ $angle_depth-- if $angle_depth > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $angle_depth > 0 26 0 26
374 }
375 }
376  
377 # wrap long lines conservatively at commas and binary operators.
378 3000 my $col = _visual_length($line);
379 3000 ▶ my $wrap_limit = $continuation_indent > 0 ? 80 : 100;
Branch: 1 branch
BranchTrueFalseTotal
$continuation_indent > 0 ? : 13 2987 3000
380 3000 ▶ if ( $col > $wrap_limit and ( $val eq ',' or _is_binary_op( \@tokens, $i ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col > $wrap_limit and $val eq "," || _is_binary_op(\@tokens, $i)) 5 2995 3000
Condition100%6/6
$col > $wrap_limit and $val eq "," || _is_binary_op(\@tokens, $i)
!ll&&!rl&&r
2985105
$val eq "," or _is_binary_op(\@tokens, $i)
l!l&&r!l&&!r
3210
MC/DC100%3/3
$col > $wrap_limit and $val eq "," || _is_binary_op(\@tokens, $i)
$col > $wrap_limit $val eq "," _is_binary_op(\@tokens, $i)
Truth table100%4/4
A and B or C
A= $col > $wrap_limitB= $val eq ","C= _is_binary_op(\@tokens, $i)
ABCresult
0XX0
1000
11X1
1011
381 5 push @out_lines, _rstrip($line);
382 5 $line = '';
383 5 $pending_indent = 1;
384 5 $continuation_indent = 4;
385 }
386  
387 3000 ▶ if ( $next and _needs_auto_semicolon( $tok, $next, $paren_depth, $bracket_depth, $brace_depth, $inline_brace_depth, $just_closed_inline, $angle_depth ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next and _needs_auto_semicolon($tok, $next, $paren_depth, $bracket_depth, $brace_depth, $inline_brace_depth, $just_closed_inline, $angle_depth)) 111 2889 3000
Condition100%3/3
$next and _needs_auto_semicolon($tok, $next, $paren_depth, $bracket_depth, $brace_depth, $inline_brace_depth, $just_closed_inline, $angle_depth)
!ll&&!rl&&r
152874111
MC/DC100%2/2
$next and _needs_auto_semicolon($tok, $next, $paren_depth, $bracket_depth, $brace_depth, $inline_brace_depth, $just_closed_inline, $angle_depth)
$next _needs_auto_semicolon($tok, $next, $paren_depth, $bracket_depth, $brace_depth, $inline_brace_depth, $just_closed_inline, $angle_depth)
Truth table100%3/3
A and B
A= $nextB= _needs_auto_semicolon($tok, $next, $paren_depth, $bracket_depth, $brace_depth, $inline_brace_depth, $just_closed_inline, $angle_depth)
ABresult
0X0
100
111
388 111 $line .= ';';
389 111 push @out_lines, _rstrip($line);
390 111 $line = '';
391 111 $pending_indent = 1;
392 111 $continuation_indent = 0;
393 }
394 }
395  
396 40 ▶ if ( $line =~ /\S/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\S/) 15 25 40
397 15 ▶ if ( $line !~ /;\z/ and @tokens and _can_end_statement( $tokens[-1] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $line =~ /;\z/ and @tokens and _can_end_statement($tokens[-1])) 15 0 15
Condition33%2/6
not $line =~ /;\z/ and @tokens and _can_end_statement($tokens[-1])
!ll&&!rl&&r
0015
not $line =~ /;\z/ and @tokens
!ll&&!rl&&r
0015
MC/DC0%0/3
not $line =~ /;\z/ and @tokens and _can_end_statement($tokens[-1])
not $line =~ /;\z/ @tokens _can_end_statement($tokens[-1])
Truth table25%1/4
not(A) and B and C
A= not $line =~ /;\z/B= @tokensC= _can_end_statement($tokens[-1])
ABCresult
0XX0
10X0
1100
1111
398 15 $line .= ';';
399 }
400 15 push @out_lines, _rstrip($line);
401 }
402  
403 40 return join( "\n", @out_lines ) . "\n";
404 }
405  
406 38 ▶sub _split_pod_segments {
Subroutine _split_pod_segments: called CC=10 SCAR=23.0
407 38 my ( $src ) = @_;
408 38 my @lines = split /(?<=\n)/, $src;
409 38 my @segments;
410 38 my $buf = '';
411 38 my $in_pod = 0;
412  
413 38 for my $line ( @lines ) {
414 376 ▶ if ( ! $in_pod and $line =~ /^=(\w+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $in_pod and $line =~ /^=(\w+)/) 4 372 376
Condition100%3/3
not $in_pod and $line =~ /^=(\w+)/
!ll&&!rl&&r
123604
MC/DC100%2/2
not $in_pod and $line =~ /^=(\w+)/
not $in_pod $line =~ /^=(\w+)/
Truth table100%3/3
not(A) and B
A= not $in_podB= $line =~ /^=(\w+)/
ABresult
0X0
100
111
415 4 my $word = $1;
416 4 ▶ if ( $word ne 'cut' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word ne "cut") 4 0 4
417 4 ▶ if ( $buf ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf ne "") 3 1 4
418 3 push @segments, { is_pod => 0, text => $buf };
419 3 $buf = '';
420 }
421 4 $in_pod = 1;
422 }
423 }
424  
425 376 $buf .= $line;
426  
427 376 ▶ if ( $in_pod and $line =~ /^=cut(?:\r?\n)?\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_pod and $line =~ /^=cut(?:\r?\n)?\z/) 4 372 376
Condition100%3/3
$in_pod and $line =~ /^=cut(?:\r?\n)?\z/
!ll&&!rl&&r
360124
MC/DC100%2/2
$in_pod and $line =~ /^=cut(?:\r?\n)?\z/
$in_pod $line =~ /^=cut(?:\r?\n)?\z/
Truth table100%3/3
A and B
A= $in_podB= $line =~ /^=cut(?:\r?\n)?\z/
ABresult
0X0
100
111
428 4 push @segments, { is_pod => 1, text => $buf };
429 4 $buf = '';
430 4 $in_pod = 0;
431 }
432 }
433  
434 38 ▶ if ( $buf ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf ne "") 37 1 38
435 37 ▶ push @segments, { is_pod => ( $in_pod ? 1 : 0 ), text => $buf };
Branch: 1 branch
BranchTrueFalseTotal
$in_pod ? : 0 37 37
436 }
437  
438 38 return @segments;
439 }
440  
441 3506 ▶sub _is_chain_op {
Subroutine _is_chain_op: called CC=4 SCAR=13.9
442 3506 my ( $val ) = @_;
443  
444 3506 ▶ return $val eq '▷' || $val eq '◁' || $val eq '|>' || $val eq '<|';
Condition88%8/9
$val eq "\x{25b7}" || $val eq "\x{25c1}" || $val eq '|>' || $val eq '<|'
l!l&&r!l&&!r
1513490
$val eq "\x{25b7}" or $val eq "\x{25c1}" or $val eq "|>"
l!l&&r!l&&!r
5103491
$val eq "\x{25b7}" or $val eq "\x{25c1}"
l!l&&r!l&&!r
503501
MC/DC75%3/4
$val eq "\x{25b7}" || $val eq "\x{25c1}" || $val eq '|>' || $val eq '<|'
$val eq "\x{25b7}" $val eq "\x{25c1}" $val eq "|>" $val eq '<|'
Truth table80%4/5
A or B or C || D
A= $val eq "\x{25b7}"B= $val eq "\x{25c1}"C= $val eq "|>"D= $val eq '<|'
ABCDresult
1XXX1
01XX1
001X1
00011
00000
445 }
446  
447 40 ▶sub _normalize_tokens {
Subroutine _normalize_tokens: called CC=4 SCAR=13.9
448 40 my ( @tokens ) = @_;
449 40 my @out;
450  
451 40 for my $tok ( @tokens ) {
452 3479 ▶ if ( $tok->is_OP('{{') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->is_OP("{{")) 4 3475 3479
453 4 my $open1 = Zuzu::Token->new(
454 type => 'OP',
455 value => '{',
456 file => $tok->file,
457 line => $tok->line,
458 col => $tok->col,
459 );
460 4 my $open2 = Zuzu::Token->new(
461 type => 'OP',
462 value => '{',
463 file => $tok->file,
464 line => $tok->line,
465 col => $tok->col,
466 );
467 # Pairlist delimiter halves are tagged so formatting decisions
468 # (inline-vs-block brace classification) never depend on
469 # guessing from surrounding context, which previously broke
470 # down for contexts such as `...{{ ... }}` spreads.
471 4 $open1->{_pairlist_half} = 'open1';
472 4 $open2->{_pairlist_half} = 'open2';
473 4 push @out, $open1, $open2;
474 4 next;
475 }
476 3475 ▶ if ( $tok->is_OP('}}') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->is_OP("}}")) 10 3465 3475
477 10 my $close1 = Zuzu::Token->new(
478 type => 'OP',
479 value => '}',
480 file => $tok->file,
481 line => $tok->line,
482 col => $tok->col,
483 );
484 10 my $close2 = Zuzu::Token->new(
485 type => 'OP',
486 value => '}',
487 file => $tok->file,
488 line => $tok->line,
489 col => $tok->col,
490 );
491 10 $close1->{_pairlist_half} = 'close1';
492 10 $close2->{_pairlist_half} = 'close2';
493 10 push @out, $close1, $close2;
494 10 next;
495 }
496 3465 push @out, $tok;
497 }
498  
499 40 return @out;
500 }
501  
502 40 ▶sub _tag_declaration_block_braces {
Subroutine _tag_declaration_block_braces: called CC=41 SCAR=40.8
503 # Marks the `{` that opens a class/trait/function/method body, even
504 # when separated from the keyword by a variable-length clause such as
505 # a return-type arrow (`-> Type`) or a trait list (`with A, B`). A
506 # fixed-distance backward look from the brace can't see far enough
507 # back to find the keyword in those cases, which used to leave
508 # declaration bodies classified as inline. This scans forward from
509 # each keyword instead, so the gap can be any length.
510 40 my ( $tokens ) = @_;
511  
512 40 for my $i ( 0 .. $#$tokens ) {
513 3493 my $tok = $tokens->[$i];
514 3493 ▶ next if ! $tok->is_KW;
Branch: 1 branch
BranchTrueFalseTotal
unless $tok->is_KW 3065 428 3493
515 428 my $kw = $tok->value;
516  
517 428 ▶ if ( $kw eq 'class' or $kw eq 'trait' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "class" or $kw eq "trait") 10 418 428
Condition100%3/3
$kw eq "class" or $kw eq "trait"
l!l&&r!l&&!r
82418
MC/DC100%2/2
$kw eq "class" or $kw eq "trait"
$kw eq "class" $kw eq "trait"
Truth table100%3/3
A or B
A= $kw eq "class"B= $kw eq "trait"
ABresult
1X1
011
000
518 10 my $k = $i + 1;
519 10 ▶ next if $k > $#$tokens or ! $tokens->[$k]->is_IDENT;
Branch: 1 branch
BranchTrueFalseTotal
if $k > $tokens->$#* or not $tokens->[$k]->is_IDENT 0 10 10
Condition33%1/3
$k > $tokens->$#* or not $tokens->[$k]->is_IDENT
l!l&&r!l&&!r
0010
MC/DC0%0/2
$k > $tokens->$#* or not $tokens->[$k]->is_IDENT
$k > $tokens->$#* not $tokens->[$k]->is_IDENT
Truth table33%1/3
A or not(B)
A= $k > $tokens->$#*B= not $tokens->[$k]->is_IDENT
ABresult
1X1
011
000
520 10 $k++;
521  
522 10 my $changed = 1;
523 10 ▶ while ( $changed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($changed) 14 10 24
524 14 $changed = 0;
525 14 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($k <= $tokens->$#* and $tokens->[$k]->is_KW("extends") and $k + 1 <= $tokens->$#* and $$tokens[$k + 1]->is_IDENT) 2 12 14
Condition66%6/9
$k <= $tokens->$#* and $tokens->[$k]->is_KW("extends") and $k + 1 <= $tokens->$#* and $$tokens[$k + 1]->is_IDENT
!ll&&!rl&&r
1202
$k <= $tokens->$#* and $tokens->[$k]->is_KW("extends") and $k + 1 <= $tokens->$#*
!ll&&!rl&&r
1202
$k <= $tokens->$#* and $tokens->[$k]->is_KW("extends")
!ll&&!rl&&r
0122
MC/DC25%1/4
$k <= $tokens->$#* and $tokens->[$k]->is_KW("extends") and $k + 1 <= $tokens->$#* and $$tokens[$k + 1]->is_IDENT
$k <= $tokens->$#* $tokens->[$k]->is_KW("extends") $k + 1 <= $tokens->$#* $$tokens[$k + 1]->is_IDENT
Truth table40%2/5
A and B and C and D
A= $k <= $tokens->$#*B= $tokens->[$k]->is_KW("extends")C= $k + 1 <= $tokens->$#*D= $$tokens[$k + 1]->is_IDENT
ABCDresult
0XXX0
10XX0
110X0
11100
11111
526 $k <= $#$tokens and $tokens->[$k]->is_KW('extends')
527 and $k + 1 <= $#$tokens and $tokens->[ $k + 1 ]->is_IDENT
528 ) {
529 2 $k += 2;
530 2 $changed = 1;
531 }
532 14 ▶ if ( $k <= $#$tokens and ( $tokens->[$k]->is_KW('with') or $tokens->[$k]->is_KW('but') ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k <= $tokens->$#* and $tokens->[$k]->is_KW("with") || $tokens->[$k]->is_KW("but")) 4 10 14
Condition83%5/6
$k <= $tokens->$#* and $tokens->[$k]->is_KW("with") || $tokens->[$k]->is_KW("but")
!ll&&!rl&&r
0104
$tokens->[$k]->is_KW("with") or $tokens->[$k]->is_KW("but")
l!l&&r!l&&!r
3110
MC/DC66%2/3
$k <= $tokens->$#* and $tokens->[$k]->is_KW("with") || $tokens->[$k]->is_KW("but")
$k <= $tokens->$#* $tokens->[$k]->is_KW("with") $tokens->[$k]->is_KW("but")
Truth table75%3/4
A and B or C
A= $k <= $tokens->$#*B= $tokens->[$k]->is_KW("with")C= $tokens->[$k]->is_KW("but")
ABCresult
0XX0
1000
11X1
1011
533 4 my $j = $k + 1;
534 4 ▶ if ( $j <= $#$tokens and $tokens->[$j]->is_IDENT ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $tokens->$#* and $tokens->[$j]->is_IDENT) 4 0 4
Condition33%1/3
$j <= $tokens->$#* and $tokens->[$j]->is_IDENT
!ll&&!rl&&r
004
MC/DC0%0/2
$j <= $tokens->$#* and $tokens->[$j]->is_IDENT
$j <= $tokens->$#* $tokens->[$j]->is_IDENT
Truth table33%1/3
A and B
A= $j <= $tokens->$#*B= $tokens->[$j]->is_IDENT
ABresult
0X0
100
111
535 4 $j++;
536 4 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if ($j + 1 <= $tokens->$#* and $tokens->[$j]->is_OP(",") and $$tokens[$j + 1]->is_IDENT) 0 4 4
Condition33%2/6
$j + 1 <= $tokens->$#* and $tokens->[$j]->is_OP(",") and $$tokens[$j + 1]->is_IDENT
!ll&&!rl&&r
400
$j + 1 <= $tokens->$#* and $tokens->[$j]->is_OP(",")
!ll&&!rl&&r
040
MC/DC0%0/3
$j + 1 <= $tokens->$#* and $tokens->[$j]->is_OP(",") and $$tokens[$j + 1]->is_IDENT
$j + 1 <= $tokens->$#* $tokens->[$j]->is_OP(",") $$tokens[$j + 1]->is_IDENT
Truth table25%1/4
A and B and C
A= $j + 1 <= $tokens->$#*B= $tokens->[$j]->is_OP(",")C= $$tokens[$j + 1]->is_IDENT
ABCresult
0XX0
10X0
1100
1111
537 $j + 1 <= $#$tokens
538 and $tokens->[$j]->is_OP(',')
539 and $tokens->[ $j + 1 ]->is_IDENT
540 ) {
541 0 $j += 2;
542 }
543 4 $k = $j;
544 4 $changed = 1;
545 }
546 }
547 }
548  
549 10 ▶ $tokens->[$k]{_forced_block} = 1 if $k <= $#$tokens and $tokens->[$k]->is_OP('{');
Branch: 1 branch
BranchTrueFalseTotal
if $k <= $tokens->$#* and $tokens->[$k]->is_OP("{") 8 2 10
Condition66%2/3
$k <= $tokens->$#* and $tokens->[$k]->is_OP("{")
!ll&&!rl&&r
028
MC/DC50%1/2
$k <= $tokens->$#* and $tokens->[$k]->is_OP("{")
$k <= $tokens->$#* $tokens->[$k]->is_OP("{")
Truth table66%2/3
A and B
A= $k <= $tokens->$#*B= $tokens->[$k]->is_OP("{")
ABresult
0X0
100
111
550 10 next;
551 }
552  
553 418 ▶ if ( $kw eq 'function' or $kw eq 'method' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "function" or $kw eq "method") 37 381 418
Condition100%3/3
$kw eq "function" or $kw eq "method"
l!l&&r!l&&!r
2512381
MC/DC100%2/2
$kw eq "function" or $kw eq "method"
$kw eq "function" $kw eq "method"
Truth table100%3/3
A or B
A= $kw eq "function"B= $kw eq "method"
ABresult
1X1
011
000
554 37 my $k = $i + 1;
555 37 ▶ $k++ if $k <= $#$tokens and $tokens->[$k]->is_IDENT;
Branch: 1 branch
BranchTrueFalseTotal
if $k <= $tokens->$#* and $tokens->[$k]->is_IDENT 31 6 37
Condition66%2/3
$k <= $tokens->$#* and $tokens->[$k]->is_IDENT
!ll&&!rl&&r
0631
MC/DC50%1/2
$k <= $tokens->$#* and $tokens->[$k]->is_IDENT
$k <= $tokens->$#* $tokens->[$k]->is_IDENT
Truth table66%2/3
A and B
A= $k <= $tokens->$#*B= $tokens->[$k]->is_IDENT
ABresult
0X0
100
111
556 37 ▶ next if $k > $#$tokens or ! $tokens->[$k]->is_OP('(');
Branch: 1 branch
BranchTrueFalseTotal
if $k > $tokens->$#* or not $tokens->[$k]->is_OP("(") 4 33 37
Condition66%2/3
$k > $tokens->$#* or not $tokens->[$k]->is_OP("(")
l!l&&r!l&&!r
0433
MC/DC50%1/2
$k > $tokens->$#* or not $tokens->[$k]->is_OP("(")
$k > $tokens->$#* not $tokens->[$k]->is_OP("(")
Truth table66%2/3
A or not(B)
A= $k > $tokens->$#*B= not $tokens->[$k]->is_OP("(")
ABresult
1X1
011
000
557  
558 33 my $depth = 0;
559 33 my $j = $k;
560 33 ▶ while ( $j <= $#$tokens ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $tokens->$#*) 119 0 119
561 119 ▶ $depth++ if $tokens->[$j]->is_OP('(');
Branch: 1 branch
BranchTrueFalseTotal
if $tokens->[$j]->is_OP("(") 33 86 119
562 119 ▶ if ( $tokens->[$j]->is_OP(')') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens->[$j]->is_OP(")")) 33 86 119
563 33 $depth--;
564 33 ▶ last if $depth == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $depth == 0 33 0 33
565 }
566 86 $j++;
567 }
568 33 ▶ next if $j > $#$tokens;
Branch: 1 branch
BranchTrueFalseTotal
if $j > $tokens->$#* 0 33 33
569 33 $k = $j + 1;
570  
571 33 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($k <= $tokens->$#* and $tokens->[$k]->is_OP and $tokens->[$k]->value eq "->" || $tokens->[$k]->value eq "\x{2192}") 9 24 33
Condition66%6/9
$k <= $tokens->$#* and $tokens->[$k]->is_OP and $tokens->[$k]->value eq "->" || $tokens->[$k]->value eq "\x{2192}"
!ll&&!rl&&r
0249
$k <= $tokens->$#* and $tokens->[$k]->is_OP
!ll&&!rl&&r
0033
$tokens->[$k]->value eq "->" or $tokens->[$k]->value eq "\x{2192}"
l!l&&r!l&&!r
6324
MC/DC50%2/4
$k <= $tokens->$#* and $tokens->[$k]->is_OP and $tokens->[$k]->value eq "->" || $tokens->[$k]->value eq "\x{2192}"
$k <= $tokens->$#* $tokens->[$k]->is_OP $tokens->[$k]->value eq "->" $tokens->[$k]->value eq "\x{2192}"
Truth table60%3/5
A and B and C or D
A= $k <= $tokens->$#*B= $tokens->[$k]->is_OPC= $tokens->[$k]->value eq "->"D= $tokens->[$k]->value eq "\x{2192}"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
572 $k <= $#$tokens and $tokens->[$k]->is_OP
573 and ( $tokens->[$k]->value eq '->' or $tokens->[$k]->value eq '→' )
574 ) {
575 9 $k++;
576 9 ▶ $k++ if $k <= $#$tokens and $tokens->[$k]->is_IDENT;
Branch: 1 branch
BranchTrueFalseTotal
if $k <= $tokens->$#* and $tokens->[$k]->is_IDENT 9 0 9
Condition33%1/3
$k <= $tokens->$#* and $tokens->[$k]->is_IDENT
!ll&&!rl&&r
009
MC/DC0%0/2
$k <= $tokens->$#* and $tokens->[$k]->is_IDENT
$k <= $tokens->$#* $tokens->[$k]->is_IDENT
Truth table33%1/3
A and B
A= $k <= $tokens->$#*B= $tokens->[$k]->is_IDENT
ABresult
0X0
100
111
577 }
578  
579 33 ▶ $tokens->[$k]{_forced_block} = 1 if $k <= $#$tokens and $tokens->[$k]->is_OP('{');
Branch: 1 branch
BranchTrueFalseTotal
if $k <= $tokens->$#* and $tokens->[$k]->is_OP("{") 33 0 33
Condition33%1/3
$k <= $tokens->$#* and $tokens->[$k]->is_OP("{")
!ll&&!rl&&r
0033
MC/DC0%0/2
$k <= $tokens->$#* and $tokens->[$k]->is_OP("{")
$k <= $tokens->$#* $tokens->[$k]->is_OP("{")
Truth table33%1/3
A and B
A= $k <= $tokens->$#*B= $tokens->[$k]->is_OP("{")
ABresult
0X0
100
111
580 }
581 }
582  
583 40 return;
584 }
585  
586 5 my %_PAIR_CLOSE_FOR_OPEN = (
587 '(' => ')', '[' => ']', '{' => '}', '⌊' => '⌋', '⌈' => '⌉',
588 '<<' => '>>', '<<<' => '>>>', '«' => '»',
589 );
590 5 my %_PAIR_OPEN_FOR_CLOSE = reverse %_PAIR_CLOSE_FOR_OPEN;
591  
592 40 ▶sub _build_pair_map {
Subroutine _build_pair_map: called CC=11 SCAR=24.0
593 40 my ( $tokens ) = @_;
594 40 my @stack;
595 my %pair;
596  
597 40 for my $i ( 0 .. $#$tokens ) {
598 # Guarded by is_OP so a string/binary-string literal whose decoded
599 # content happens to equal a bracket character (e.g. the literal
600 # string "(" in `left:"("`) isn't mistaken for that bracket.
601 3493 ▶ next if ! $tokens->[$i]->is_OP;
Branch: 1 branch
BranchTrueFalseTotal
unless $tokens->[$i]->is_OP 1694 1799 3493
602 1799 my $v = $tokens->[$i]->value;
603  
604 # << and « are genuinely dual-use: the real parser treats them as a
605 # set/guillemet-set literal opener in primary/operand position, but
606 # they also have real binary-operator ("shift") precedence in infix
607 # position (see _Impl.pm's precedence table). Only push them as
608 # pairable openers when they're in operand position -- i.e. NOT
609 # immediately after a token that could end an expression -- so a
610 # shift expression never corrupts the stack for surrounding
611 # brackets. <<< (bag) has no such binary-operator meaning and is
612 # always pushed.
613 1799 ▶ if ( ( $v eq '<<' or $v eq '«' ) and $i > 0 and _can_end_statement( $tokens->[ $i - 1 ] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq "<<" || $v eq "\x{ab}" and $i > 0 and _can_end_statement($$tokens[$i - 1])) 2 1797 1799
Condition88%8/9
$v eq "<<" || $v eq "\x{ab}" and $i > 0 and _can_end_statement($$tokens[$i - 1])
!ll&&!rl&&r
1777202
$v eq "<<" || $v eq "\x{ab}" and $i > 0
!ll&&!rl&&r
1777022
$v eq "<<" or $v eq "\x{ab}"
l!l&&r!l&&!r
2111777
MC/DC50%2/4
$v eq "<<" || $v eq "\x{ab}" and $i > 0 and _can_end_statement($$tokens[$i - 1])
$v eq "<<" $v eq "\x{ab}" $i > 0 _can_end_statement($$tokens[$i - 1])
Truth table57%4/7
A or B and C and D
A= $v eq "<<"B= $v eq "\x{ab}"C= $i > 0D= _can_end_statement($$tokens[$i - 1])
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
614 2 next;
615 }
616  
617 1797 ▶ if ( $_PAIR_CLOSE_FOR_OPEN{$v} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_PAIR_CLOSE_FOR_OPEN{$v}) 451 1346 1797
618 451 push @stack, [ $v, $i ];
619 451 next;
620 }
621 1346 ▶ if ( $_PAIR_OPEN_FOR_CLOSE{$v} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_PAIR_OPEN_FOR_CLOSE{$v}) 451 895 1346
622 451 ▶ next if ! @stack;
Branch: 1 branch
BranchTrueFalseTotal
unless @stack 0 451 451
623 451 my ( $open, $open_i ) = @{ $stack[-1] };
624 451 ▶ next if $_PAIR_CLOSE_FOR_OPEN{$open} ne $v;
Branch: 1 branch
BranchTrueFalseTotal
if $_PAIR_CLOSE_FOR_OPEN{$open} ne $v 0 451 451
625 451 pop @stack;
626 451 $pair{$open_i} = $i;
627 451 $pair{$i} = $open_i;
628 }
629 }
630  
631 40 return %pair;
632 }
633  
634 40 ▶sub _tag_trailing_comma_sequences {
Subroutine _tag_trailing_comma_sequences: called CC=14 SCAR=26.4
635 # Marks an open delimiter of a comma-separated sequence (call/parameter
636 # argument list, array, dict, set, bag, or guillemet-set literal) when
637 # the token immediately before its matching close is a literal comma.
638 # A literal trailing comma is a strong signal that the sequence should
639 # be rendered one item per line, so this is decided once up front (like
640 # _tag_declaration_block_braces) rather than guessed at format time.
641 # Bare { is included for dict literals; pairlist {{ ... }} is left
642 # alone since it is already unconditionally forced via _pairlist_half.
643 40 my ( $tokens, $pair_for ) = @_;
644  
645 40 for my $i ( 0 .. $#$tokens ) {
646 3493 my $tok = $tokens->[$i];
647 3493 ▶ next if ! $tok->is_OP;
Branch: 1 branch
BranchTrueFalseTotal
unless $tok->is_OP 1694 1799 3493
648 1799 my $v = $tok->value;
649 1799 ▶ next if $v ne '(' and $v ne '[' and $v ne '<<' and $v ne '<<<' and $v ne '«' and $v ne '{';
Branch: 1 branch
BranchTrueFalseTotal
if $v ne "(" and $v ne "[" and $v ne "<<" and $v ne "<<<" and $v ne "\x{ab}" and $v ne "{" 1350 449 1799
Condition100%15/15
$v ne "(" and $v ne "[" and $v ne "<<" and $v ne "<<<" and $v ne "\x{ab}" and $v ne "{"
!ll&&!rl&&r
3281211350
$v ne "(" and $v ne "[" and $v ne "<<" and $v ne "<<<" and $v ne "\x{ab}"
!ll&&!rl&&r
32711471
$v ne "(" and $v ne "[" and $v ne "<<" and $v ne "<<<"
!ll&&!rl&&r
32161472
$v ne "(" and $v ne "[" and $v ne "<<"
!ll&&!rl&&r
300211478
$v ne "(" and $v ne "["
!ll&&!rl&&r
238621499
MC/DC100%6/6
$v ne "(" and $v ne "[" and $v ne "<<" and $v ne "<<<" and $v ne "\x{ab}" and $v ne "{"
$v ne "(" $v ne "[" $v ne "<<" $v ne "<<<" $v ne "\x{ab}" $v ne "{"
Truth table100%7/7
A and B and C and D and E and F
A= $v ne "("B= $v ne "["C= $v ne "<<"D= $v ne "<<<"E= $v ne "\x{ab}"F= $v ne "{"
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
650 449 ▶ next if $v eq '{' and defined $tok->{_pairlist_half};
Branch: 1 branch
BranchTrueFalseTotal
if $v eq "{" and defined $tok->{"_pairlist_half"} 8 441 449
Condition100%3/3
$v eq "{" and defined $tok->{"_pairlist_half"}
!ll&&!rl&&r
3281138
MC/DC100%2/2
$v eq "{" and defined $tok->{"_pairlist_half"}
$v eq "{" defined $tok->{"_pairlist_half"}
Truth table100%3/3
A and B
A= $v eq "{"B= defined $tok->{"_pairlist_half"}
ABresult
0X0
100
111
651  
652 441 ▶ next if ! exists $pair_for->{$i};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $pair_for->{$i} 2 439 441
653 439 my $close_i = $pair_for->{$i};
654 439 ▶ next if $close_i <= $i + 1;
Branch: 1 branch
BranchTrueFalseTotal
if $close_i <= $i + 1 58 381 439
655  
656 381 my $before_close = $tokens->[ $close_i - 1 ];
657 381 ▶ next if ! $before_close->is_OP(',');
Branch: 1 branch
BranchTrueFalseTotal
unless $before_close->is_OP(",") 356 25 381
658  
659 25 $tok->{_force_sequence} = 1;
660 }
661  
662 40 return;
663 }
664  
665 3482 ▶sub _need_space_before {
Subroutine _need_space_before: called CC=101 SCAR=50.8
666 3482 my ( $tokens, $i, $pair_for ) = @_;
667 3482 my $tok = $tokens->[$i];
668 3482 ▶ my $v = defined $tok->value ? $tok->value : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $tok->value ? : 3478 4 3482
669 3482 ▶ return 0 if $i == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i == 0 40 3442 3482
670  
671 3442 my $prev = $tokens->[ $i - 1 ];
672 3442 ▶ my $pv = defined $prev->value ? $prev->value : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $prev->value ? : 3438 4 3442
673  
674 3442 ▶ if ( _is_module_path_slash( $tokens, $i ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_module_path_slash($tokens, $i)) 12 3430 3442
675 12 return 0;
676 }
677 3430 ▶ if ( _is_module_path_slash( $tokens, $i - 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_module_path_slash($tokens, $i - 1)) 12 3418 3430
678 12 return 0;
679 }
680  
681 3418 ▶ if ( $v eq '...' and _is_call_spread_operator( $tokens, $i ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq "..." and _is_call_spread_operator($tokens, $i)) 5 3413 3418
Condition100%3/3
$v eq "..." and _is_call_spread_operator($tokens, $i)
!ll&&!rl&&r
340945
MC/DC100%2/2
$v eq "..." and _is_call_spread_operator($tokens, $i)
$v eq "..." _is_call_spread_operator($tokens, $i)
Truth table100%3/3
A and B
A= $v eq "..."B= _is_call_spread_operator($tokens, $i)
ABresult
0X0
100
111
682 5 return 0;
683 }
684 3413 ▶ if ( $pv eq '...' and _is_call_spread_operator( $tokens, $i - 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pv eq "..." and _is_call_spread_operator($tokens, $i - 1)) 5 3408 3413
Condition100%3/3
$pv eq "..." and _is_call_spread_operator($tokens, $i - 1)
!ll&&!rl&&r
340445
MC/DC100%2/2
$pv eq "..." and _is_call_spread_operator($tokens, $i - 1)
$pv eq "..." _is_call_spread_operator($tokens, $i - 1)
Truth table100%3/3
A and B
A= $pv eq "..."B= _is_call_spread_operator($tokens, $i - 1)
ABresult
0X0
100
111
685 5 return 0;
686 }
687  
688 3408 ▶ if ( $v eq '{' and $pv eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq "{" and $pv eq "{") 4 3404 3408
Condition100%3/3
$v eq "{" and $pv eq "{"
!ll&&!rl&&r
32871174
MC/DC100%2/2
$v eq "{" and $pv eq "{"
$v eq "{" $pv eq "{"
Truth table100%3/3
A and B
A= $v eq "{"B= $pv eq "{"
ABresult
0X0
100
111
689 4 return 0;
690 }
691 3404 ▶ if ( $v eq '}' and $pv eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq "}" and $pv eq "}") 15 3389 3404
Condition100%3/3
$v eq "}" and $pv eq "}"
!ll&&!rl&&r
328310615
MC/DC100%2/2
$v eq "}" and $pv eq "}"
$v eq "}" $pv eq "}"
Truth table100%3/3
A and B
A= $v eq "}"B= $pv eq "}"
ABresult
0X0
100
111
692 # Two genuinely independent adjacent closing braces (e.g. nested
693 # dict literals) need a space, since re-lexing "}}" with no space
694 # would produce a single pairlist-close token instead. The two
695 # halves of an actual split {{ ... }} pairlist delimiter must stay
696 # tight, since that is what they were before splitting.
697 return 0 if defined $tok->{_pairlist_half} and $tok->{_pairlist_half} eq 'close2'
698 15 ▶ and defined $prev->{_pairlist_half} and $prev->{_pairlist_half} eq 'close1';
Branch: 1 branch
BranchTrueFalseTotal
if defined $tok->{"_pairlist_half"} and $tok->{"_pairlist_half"} eq "close2" and defined $prev->{"_pairlist_half"} and $prev->{"_pairlist_half"} eq "close1" 10 5 15
Condition66%6/9
defined $tok->{"_pairlist_half"} and $tok->{"_pairlist_half"} eq "close2" and defined $prev->{"_pairlist_half"} and $prev->{"_pairlist_half"} eq "close1"
!ll&&!rl&&r
5010
defined $tok->{"_pairlist_half"} and $tok->{"_pairlist_half"} eq "close2" and defined $prev->{"_pairlist_half"}
!ll&&!rl&&r
5010
defined $tok->{"_pairlist_half"} and $tok->{"_pairlist_half"} eq "close2"
!ll&&!rl&&r
5010
MC/DC25%1/4
defined $tok->{"_pairlist_half"} and $tok->{"_pairlist_half"} eq "close2" and defined $prev->{"_pairlist_half"} and $prev->{"_pairlist_half"} eq "close1"
defined $tok->{"_pairlist_half"} $tok->{"_pairlist_half"} eq "close2" defined $prev->{"_pairlist_half"} $prev->{"_pairlist_half"} eq "close1"
Truth table40%2/5
A and B and C and D
A= defined $tok->{"_pairlist_half"}B= $tok->{"_pairlist_half"} eq "close2"C= defined $prev->{"_pairlist_half"}D= $prev->{"_pairlist_half"} eq "close1"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
699 5 return 1;
700 }
701  
702 3389 ▶ if ( $v eq '?' and $prev->is_IDENT ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq "?" and $prev->is_IDENT) 1 3388 3389
Condition100%3/3
$v eq "?" and $prev->is_IDENT
!ll&&!rl&&r
338711
MC/DC100%2/2
$v eq "?" and $prev->is_IDENT
$v eq "?" $prev->is_IDENT
Truth table100%3/3
A and B
A= $v eq "?"B= $prev->is_IDENT
ABresult
0X0
100
111
703 1 ▶ my $next = $i < $#$tokens ? $tokens->[ $i + 1 ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$i < $tokens->$#* ? : 1 0 1
704 1 ▶ if ( $next and $next->is_OP and ( $next->value eq ',' or $next->value eq ')' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next and $next->is_OP and $next->value eq "," || $next->value eq ")") 1 0 1
Condition33%3/9
$next and $next->is_OP and $next->value eq "," || $next->value eq ")"
!ll&&!rl&&r
001
$next and $next->is_OP
!ll&&!rl&&r
001
$next->value eq "," or $next->value eq ")"
l!l&&r!l&&!r
010
MC/DC0%0/4
$next and $next->is_OP and $next->value eq "," || $next->value eq ")"
$next $next->is_OP $next->value eq "," $next->value eq ")"
Truth table20%1/5
A and B and C or D
A= $nextB= $next->is_OPC= $next->value eq ","D= $next->value eq ")"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
705 1 return 0;
706 }
707 }
708  
709 3388 ▶ return 0 if _is_unary_punct_operator( $tokens, $i - 1 );
Branch: 1 branch
BranchTrueFalseTotal
if _is_unary_punct_operator($tokens, $i - 1) 4 3384 3388
710 3384 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq "++" || $v eq "--" and $prev->is_IDENT || $prev->is_OP && ($pv eq ")" || $pv eq "]" || $pv eq "}")) 2 3382 3384
Condition33%6/18
$v eq "++" || $v eq "--" and $prev->is_IDENT || $prev->is_OP && ($pv eq ")" || $pv eq "]" || $pv eq "}")
!ll&&!rl&&r
338202
$v eq "++" or $v eq "--"
l!l&&r!l&&!r
113382
$prev->is_IDENT or $prev->is_OP and $pv eq ")" || $pv eq "]" || $pv eq "}"
l!l&&r!l&&!r
200
$prev->is_OP and $pv eq ")" || $pv eq "]" || $pv eq "}"
!ll&&!rl&&r
000
$pv eq ")" or $pv eq "]" or $pv eq "}"
l!l&&r!l&&!r
000
$pv eq ")" or $pv eq "]"
l!l&&r!l&&!r
000
MC/DC28%2/7
$v eq "++" || $v eq "--" and $prev->is_IDENT || $prev->is_OP && ($pv eq ")" || $pv eq "]" || $pv eq "}")
$v eq "++" $v eq "--" $prev->is_IDENT $prev->is_OP $pv eq ")" $pv eq "]" $pv eq "}"
Truth table23%3/13
A or B and C or D and E or F or G
A= $v eq "++"B= $v eq "--"C= $prev->is_IDENTD= $prev->is_OPE= $pv eq ")"F= $pv eq "]"G= $pv eq "}"
ABCDEFGresult
00XXXXX0
1X00XXX0
1X010000
0100XXX0
01010000
1X1XXXX1
1X011XX1
1X0101X1
1X010011
011XXXX1
01011XX1
010101X1
01010011
711 ( $v eq '++' or $v eq '--' )
712 and (
713 $prev->is_IDENT
714 or ( $prev->is_OP and ( $pv eq ')' or $pv eq ']' or $pv eq '}' ) )
715 )
716 ) {
717 2 return 0;
718 }
719  
720 3382 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq "{" and _is_inline_brace($tokens, $i, $pair_for) and $prev->is_IDENT || $prev->is_OP && ($pv eq ")" || $pv eq "]" || $pv eq "}")) 10 3372 3382
Condition88%16/18
$v eq "{" and _is_inline_brace($tokens, $i, $pair_for) and $prev->is_IDENT || $prev->is_OP && ($pv eq ")" || $pv eq "]" || $pv eq "}")
!ll&&!rl&&r
33581410
$v eq "{" and _is_inline_brace($tokens, $i, $pair_for)
!ll&&!rl&&r
32659324
$prev->is_IDENT or $prev->is_OP and $pv eq ")" || $pv eq "]" || $pv eq "}"
l!l&&r!l&&!r
6414
$prev->is_OP and $pv eq ")" || $pv eq "]" || $pv eq "}"
!ll&&!rl&&r
4104
$pv eq ")" or $pv eq "]" or $pv eq "}"
l!l&&r!l&&!r
4010
$pv eq ")" or $pv eq "]"
l!l&&r!l&&!r
0410
MC/DC71%5/7
$v eq "{" and _is_inline_brace($tokens, $i, $pair_for) and $prev->is_IDENT || $prev->is_OP && ($pv eq ")" || $pv eq "]" || $pv eq "}")
$v eq "{" _is_inline_brace($tokens, $i, $pair_for) $prev->is_IDENT $prev->is_OP $pv eq ")" $pv eq "]" $pv eq "}"
Truth table75%6/8
A and B and C or D and E or F or G
A= $v eq "{"B= _is_inline_brace($tokens, $i, $pair_for)C= $prev->is_IDENTD= $prev->is_OPE= $pv eq ")"F= $pv eq "]"G= $pv eq "}"
ABCDEFGresult
0XXXXXX0
10XXXXX0
1100XXX0
11010000
111XXXX1
11011XX1
110101X1
11010011
721 $v eq '{'
722 and _is_inline_brace( $tokens, $i, $pair_for )
723 and (
724 $prev->is_IDENT
725 or ( $prev->is_OP and ( $pv eq ')' or $pv eq ']' or $pv eq '}' ) )
726 )
727 ) {
728 10 return 0;
729 }
730  
731 3372 ▶ if ( $pv eq '{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pv eq "{") 119 3253 3372
732 119 my $open_i = $i - 1;
733 119 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pair_for->{$open_i} and _is_inline_brace($tokens, $open_i, $pair_for) and not _brace_needs_inner_space($tokens, $open_i, $pair_for->{$open_i})) 10 109 119
Condition100%6/6
defined $pair_for->{$open_i} and _is_inline_brace($tokens, $open_i, $pair_for) and not _brace_needs_inner_space($tokens, $open_i, $pair_for->{$open_i})
!ll&&!rl&&r
991010
defined $pair_for->{$open_i} and _is_inline_brace($tokens, $open_i, $pair_for)
!ll&&!rl&&r
29720
MC/DC100%3/3
defined $pair_for->{$open_i} and _is_inline_brace($tokens, $open_i, $pair_for) and not _brace_needs_inner_space($tokens, $open_i, $pair_for->{$open_i})
defined $pair_for->{$open_i} _is_inline_brace($tokens, $open_i, $pair_for) not _brace_needs_inner_space($tokens, $open_i, $pair_for->{$open_i})
Truth table100%4/4
A and B and not(C)
A= defined $pair_for->{$open_i}B= _is_inline_brace($tokens, $open_i, $pair_for)C= not _brace_needs_inner_space($tokens, $open_i, $pair_for->{$open_i})
ABCresult
0XX0
10X0
1100
1111
734 defined $pair_for->{$open_i}
735 and _is_inline_brace( $tokens, $open_i, $pair_for )
736 and ! _brace_needs_inner_space( $tokens, $open_i, $pair_for->{$open_i} )
737 ) {
738 10 return 0;
739 }
740 109 return 1;
741 }
742  
743 3253 ▶ if ( $v eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq "}") 104 3149 3253
744 104 my $open_i = $pair_for->{$i};
745 104 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $open_i and _is_inline_brace($tokens, $open_i, $pair_for) and not _brace_needs_inner_space($tokens, $open_i, $i)) 10 94 104
Condition83%5/6
defined $open_i and _is_inline_brace($tokens, $open_i, $pair_for) and not _brace_needs_inner_space($tokens, $open_i, $i)
!ll&&!rl&&r
85910
defined $open_i and _is_inline_brace($tokens, $open_i, $pair_for)
!ll&&!rl&&r
08519
MC/DC66%2/3
defined $open_i and _is_inline_brace($tokens, $open_i, $pair_for) and not _brace_needs_inner_space($tokens, $open_i, $i)
defined $open_i _is_inline_brace($tokens, $open_i, $pair_for) not _brace_needs_inner_space($tokens, $open_i, $i)
Truth table75%3/4
A and B and not(C)
A= defined $open_iB= _is_inline_brace($tokens, $open_i, $pair_for)C= not _brace_needs_inner_space($tokens, $open_i, $i)
ABCresult
0XX0
10X0
1100
1111
746 defined $open_i
747 and _is_inline_brace( $tokens, $open_i, $pair_for )
748 and ! _brace_needs_inner_space( $tokens, $open_i, $i )
749 ) {
750 10 return 0;
751 }
752 94 return 1;
753 }
754  
755 3149 ▶ if ( $v eq ':' and _is_switch_comparator_colon( $tokens, $i ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq ":" and _is_switch_comparator_colon($tokens, $i)) 2 3147 3149
Condition100%3/3
$v eq ":" and _is_switch_comparator_colon($tokens, $i)
!ll&&!rl&&r
3089582
MC/DC100%2/2
$v eq ":" and _is_switch_comparator_colon($tokens, $i)
$v eq ":" _is_switch_comparator_colon($tokens, $i)
Truth table100%3/3
A and B
A= $v eq ":"B= _is_switch_comparator_colon($tokens, $i)
ABresult
0X0
100
111
756 2 return 1;
757 }
758 3147 ▶ if ( $pv eq ':' and _is_slice_colon( $tokens, $i - 1, $pair_for ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pv eq ":" and _is_slice_colon($tokens, $i - 1, $pair_for)) 7 3140 3147
Condition100%3/3
$pv eq ":" and _is_slice_colon($tokens, $i - 1, $pair_for)
!ll&&!rl&&r
3087537
MC/DC100%2/2
$pv eq ":" and _is_slice_colon($tokens, $i - 1, $pair_for)
$pv eq ":" _is_slice_colon($tokens, $i - 1, $pair_for)
Truth table100%3/3
A and B
A= $pv eq ":"B= _is_slice_colon($tokens, $i - 1, $pair_for)
ABresult
0X0
100
111
759 7 return 0;
760 }
761  
762 # Guarded by is_OP so a string/binary-string literal whose decoded
763 # content happens to equal a punctuation operator (e.g. the literal
764 # string ":" in `text _ ":" _ item`) isn't mistaken for that
765 # operator and tightened against its neighbour.
766 3140 ▶ return 0 if $tok->is_OP and $NO_SPACE_BEFORE{$v} and $v ne ')' and $v ne ']';
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_OP and $NO_SPACE_BEFORE{$v} and $v ne ")" and $v ne "]" 542 2598 3140
Condition100%9/9
$tok->is_OP and $NO_SPACE_BEFORE{$v} and $v ne ")" and $v ne "]"
!ll&&!rl&&r
253761542
$tok->is_OP and $NO_SPACE_BEFORE{$v} and $v ne ")"
!ll&&!rl&&r
2299238603
$tok->is_OP and $NO_SPACE_BEFORE{$v}
!ll&&!rl&&r
1513786841
MC/DC100%4/4
$tok->is_OP and $NO_SPACE_BEFORE{$v} and $v ne ")" and $v ne "]"
$tok->is_OP $NO_SPACE_BEFORE{$v} $v ne ")" $v ne "]"
Truth table100%5/5
A and B and C and D
A= $tok->is_OPB= $NO_SPACE_BEFORE{$v}C= $v ne ")"D= $v ne "]"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
767 2598 ▶ return 0 if $prev->is_OP and $NO_SPACE_AFTER{$pv} and $pv ne '(' and $pv ne '[';
Branch: 1 branch
BranchTrueFalseTotal
if $prev->is_OP and $NO_SPACE_AFTER{$pv} and $pv ne "(" and $pv ne "[" 41 2557 2598
Condition100%9/9
$prev->is_OP and $NO_SPACE_AFTER{$pv} and $pv ne "(" and $pv ne "["
!ll&&!rl&&r
24966141
$prev->is_OP and $NO_SPACE_AFTER{$pv} and $pv ne "("
!ll&&!rl&&r
2261235102
$prev->is_OP and $NO_SPACE_AFTER{$pv}
!ll&&!rl&&r
1267994337
MC/DC100%4/4
$prev->is_OP and $NO_SPACE_AFTER{$pv} and $pv ne "(" and $pv ne "["
$prev->is_OP $NO_SPACE_AFTER{$pv} $pv ne "(" $pv ne "["
Truth table100%5/5
A and B and C and D
A= $prev->is_OPB= $NO_SPACE_AFTER{$pv}C= $pv ne "("D= $pv ne "["
ABCDresult
0XXX0
10XX0
110X0
11100
11111
768  
769 2557 ▶ if ( $v eq '(' or $v eq '[' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq "(" or $v eq "[") 302 2255 2557
Condition100%3/3
$v eq "(" or $v eq "["
l!l&&r!l&&!r
240622255
MC/DC100%2/2
$v eq "(" or $v eq "["
$v eq "(" $v eq "["
Truth table100%3/3
A or B
A= $v eq "("B= $v eq "["
ABresult
1X1
011
000
770 302 ▶ if ( $pv eq ',' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pv eq ",") 7 295 302
771 7 return 1;
772 }
773 295 ▶ if ( _is_binary_op( $tokens, $i - 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_binary_op($tokens, $i - 1)) 30 265 295
774 30 return 1;
775 }
776 265 ▶ if ( $prev->is_KW and $CONTROL_KW{ $prev->value } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev->is_KW and $CONTROL_KW{$prev->value}) 22 243 265
Condition100%3/3
$prev->is_KW and $CONTROL_KW{$prev->value}
!ll&&!rl&&r
2251822
MC/DC100%2/2
$prev->is_KW and $CONTROL_KW{$prev->value}
$prev->is_KW $CONTROL_KW{$prev->value}
Truth table100%3/3
A and B
A= $prev->is_KWB= $CONTROL_KW{$prev->value}
ABresult
0X0
100
111
777 22 return 1;
778 }
779 243 ▶ if ( $v eq '[' and $prev->is_OP and $pv ne '.' and $pv ne ')' and $pv ne ']' and $pv ne '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq "[" and $prev->is_OP and $pv ne "." and $pv ne ")" and $pv ne "]" and $pv ne "}") 6 237 243
Condition80%12/15
$v eq "[" and $prev->is_OP and $pv ne "." and $pv ne ")" and $pv ne "]" and $pv ne "}"
!ll&&!rl&&r
23436
$v eq "[" and $prev->is_OP and $pv ne "." and $pv ne ")" and $pv ne "]"
!ll&&!rl&&r
23409
$v eq "[" and $prev->is_OP and $pv ne "." and $pv ne ")"
!ll&&!rl&&r
23409
$v eq "[" and $prev->is_OP and $pv ne "."
!ll&&!rl&&r
23409
$v eq "[" and $prev->is_OP
!ll&&!rl&&r
210249
MC/DC50%3/6
$v eq "[" and $prev->is_OP and $pv ne "." and $pv ne ")" and $pv ne "]" and $pv ne "}"
$v eq "[" $prev->is_OP $pv ne "." $pv ne ")" $pv ne "]" $pv ne "}"
Truth table57%4/7
A and B and C and D and E and F
A= $v eq "["B= $prev->is_OPC= $pv ne "."D= $pv ne ")"E= $pv ne "]"F= $pv ne "}"
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
780 6 return 1;
781 }
782 237 ▶ if ( $v eq '(' and $prev->is_IDENT and $i >= 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq "(" and $prev->is_IDENT and $i >= 2) 178 59 237
Condition100%6/6
$v eq "(" and $prev->is_IDENT and $i >= 2
!ll&&!rl&&r
581178
$v eq "(" and $prev->is_IDENT
!ll&&!rl&&r
2731179
MC/DC100%3/3
$v eq "(" and $prev->is_IDENT and $i >= 2
$v eq "(" $prev->is_IDENT $i >= 2
Truth table100%4/4
A and B and C
A= $v eq "("B= $prev->is_IDENTC= $i >= 2
ABCresult
0XX0
10X0
1100
1111
783 178 my $before_prev = $tokens->[ $i - 2 ];
784 178 ▶ if ( $before_prev->is_KW('function') or $before_prev->is_KW('method') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before_prev->is_KW("function") or $before_prev->is_KW("method")) 27 151 178
Condition100%3/3
$before_prev->is_KW("function") or $before_prev->is_KW("method")
l!l&&r!l&&!r
189151
MC/DC100%2/2
$before_prev->is_KW("function") or $before_prev->is_KW("method")
$before_prev->is_KW("function") $before_prev->is_KW("method")
Truth table100%3/3
A or B
A= $before_prev->is_KW("function")B= $before_prev->is_KW("method")
ABresult
1X1
011
000
785 27 return 1;
786 }
787 }
788 210 ▶ if ( defined $pair_for->{$i} and ! _paren_needs_inner_space( $tokens, $i, $pair_for->{$i} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pair_for->{$i} and not _paren_needs_inner_space($tokens, $i, $pair_for->{$i})) 114 96 210
Condition100%3/3
defined $pair_for->{$i} and not _paren_needs_inner_space($tokens, $i, $pair_for->{$i})
!ll&&!rl&&r
294114
MC/DC100%2/2
defined $pair_for->{$i} and not _paren_needs_inner_space($tokens, $i, $pair_for->{$i})
defined $pair_for->{$i} not _paren_needs_inner_space($tokens, $i, $pair_for->{$i})
Truth table100%3/3
A and not(B)
A= defined $pair_for->{$i}B= not _paren_needs_inner_space($tokens, $i, $pair_for->{$i})
ABresult
0X0
100
111
789 114 return 0;
790 }
791 96 ▶ if ( $pv eq ')' or $pv eq ']' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pv eq ")" or $pv eq "]") 0 96 96
Condition33%1/3
$pv eq ")" or $pv eq "]"
l!l&&r!l&&!r
0096
MC/DC0%0/2
$pv eq ")" or $pv eq "]"
$pv eq ")" $pv eq "]"
Truth table33%1/3
A or B
A= $pv eq ")"B= $pv eq "]"
ABresult
1X1
011
000
792 0 return 0;
793 }
794 96 ▶ if ( $pv eq '}' or $pv eq '.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pv eq "}" or $pv eq ".") 0 96 96
Condition33%1/3
$pv eq "}" or $pv eq "."
l!l&&r!l&&!r
0096
MC/DC0%0/2
$pv eq "}" or $pv eq "."
$pv eq "}" $pv eq "."
Truth table33%1/3
A or B
A= $pv eq "}"B= $pv eq "."
ABresult
1X1
011
000
795 0 return 0;
796 }
797 96 return 0;
798 }
799  
800 2255 ▶ if ( $pv eq '(' or $pv eq '[' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pv eq "(" or $pv eq "[") 291 1964 2255
Condition100%3/3
$pv eq "(" or $pv eq "["
l!l&&r!l&&!r
231601964
MC/DC100%2/2
$pv eq "(" or $pv eq "["
$pv eq "(" $pv eq "["
Truth table100%3/3
A or B
A= $pv eq "("B= $pv eq "["
ABresult
1X1
011
000
801 291 my $open_i = $i - 1;
802 291 ▶ if ( defined $pair_for->{$open_i} and ! _paren_needs_inner_space( $tokens, $open_i, $pair_for->{$open_i} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pair_for->{$open_i} and not _paren_needs_inner_space($tokens, $open_i, $pair_for->{$open_i})) 132 159 291
Condition66%2/3
defined $pair_for->{$open_i} and not _paren_needs_inner_space($tokens, $open_i, $pair_for->{$open_i})
!ll&&!rl&&r
0159132
MC/DC50%1/2
defined $pair_for->{$open_i} and not _paren_needs_inner_space($tokens, $open_i, $pair_for->{$open_i})
defined $pair_for->{$open_i} not _paren_needs_inner_space($tokens, $open_i, $pair_for->{$open_i})
Truth table66%2/3
A and not(B)
A= defined $pair_for->{$open_i}B= not _paren_needs_inner_space($tokens, $open_i, $pair_for->{$open_i})
ABresult
0X0
100
111
803 132 return 0;
804 }
805 159 return 1;
806 }
807  
808 1964 ▶ if ( $v eq ')' or $v eq ']' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq ")" or $v eq "]") 242 1722 1964
Condition100%3/3
$v eq ")" or $v eq "]"
l!l&&r!l&&!r
184581722
MC/DC100%2/2
$v eq ")" or $v eq "]"
$v eq ")" $v eq "]"
Truth table100%3/3
A or B
A= $v eq ")"B= $v eq "]"
ABresult
1X1
011
000
809 242 my $open_i = $pair_for->{$i};
810 242 ▶ if ( defined $open_i and ! _paren_needs_inner_space( $tokens, $open_i, $i ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $open_i and not _paren_needs_inner_space($tokens, $open_i, $i)) 76 166 242
Condition100%3/3
defined $open_i and not _paren_needs_inner_space($tokens, $open_i, $i)
!ll&&!rl&&r
116576
MC/DC100%2/2
defined $open_i and not _paren_needs_inner_space($tokens, $open_i, $i)
defined $open_i not _paren_needs_inner_space($tokens, $open_i, $i)
Truth table100%3/3
A and not(B)
A= defined $open_iB= not _paren_needs_inner_space($tokens, $open_i, $i)
ABresult
0X0
100
111
811 76 return 0;
812 }
813 166 return 1;
814 }
815  
816 1722 ▶ if ( $pv eq '⌊' or $pv eq '⌈' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pv eq "\x{230a}" or $pv eq "\x{2308}") 0 1722 1722
Condition33%1/3
$pv eq "\x{230a}" or $pv eq "\x{2308}"
l!l&&r!l&&!r
001722
MC/DC0%0/2
$pv eq "\x{230a}" or $pv eq "\x{2308}"
$pv eq "\x{230a}" $pv eq "\x{2308}"
Truth table33%1/3
A or B
A= $pv eq "\x{230a}"B= $pv eq "\x{2308}"
ABresult
1X1
011
000
817 0 my $open_i = $i - 1;
818 0 ▶ if ( defined $pair_for->{$open_i} and ! _paren_needs_inner_space( $tokens, $open_i, $pair_for->{$open_i} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pair_for->{$open_i} and not _paren_needs_inner_space($tokens, $open_i, $pair_for->{$open_i})) 0 0 0
Condition0%0/3
defined $pair_for->{$open_i} and not _paren_needs_inner_space($tokens, $open_i, $pair_for->{$open_i})
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pair_for->{$open_i} and not _paren_needs_inner_space($tokens, $open_i, $pair_for->{$open_i})
defined $pair_for->{$open_i} not _paren_needs_inner_space($tokens, $open_i, $pair_for->{$open_i})
Truth table0%0/3
A and not(B)
A= defined $pair_for->{$open_i}B= not _paren_needs_inner_space($tokens, $open_i, $pair_for->{$open_i})
ABresult
0X0
100
111
819 0 return 0;
820 }
821 0 return 1;
822 }
823  
824 1722 ▶ if ( $v eq '⌋' or $v eq '⌉' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq "\x{230b}" or $v eq "\x{2309}") 0 1722 1722
Condition33%1/3
$v eq "\x{230b}" or $v eq "\x{2309}"
l!l&&r!l&&!r
001722
MC/DC0%0/2
$v eq "\x{230b}" or $v eq "\x{2309}"
$v eq "\x{230b}" $v eq "\x{2309}"
Truth table33%1/3
A or B
A= $v eq "\x{230b}"B= $v eq "\x{2309}"
ABresult
1X1
011
000
825 0 my $open_i = $pair_for->{$i};
826 0 ▶ if ( defined $open_i and ! _paren_needs_inner_space( $tokens, $open_i, $i ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $open_i and not _paren_needs_inner_space($tokens, $open_i, $i)) 0 0 0
Condition0%0/3
defined $open_i and not _paren_needs_inner_space($tokens, $open_i, $i)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $open_i and not _paren_needs_inner_space($tokens, $open_i, $i)
defined $open_i not _paren_needs_inner_space($tokens, $open_i, $i)
Truth table0%0/3
A and not(B)
A= defined $open_iB= not _paren_needs_inner_space($tokens, $open_i, $i)
ABresult
0X0
100
111
827 0 return 0;
828 }
829 0 return 1;
830 }
831  
832 1722 ▶ if ( _is_binary_op( $tokens, $i ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_binary_op($tokens, $i)) 386 1336 1722
833 386 return 1;
834 }
835 1336 ▶ if ( _is_binary_op( $tokens, $i - 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_binary_op($tokens, $i - 1)) 315 1021 1336
836 315 return 1;
837 }
838  
839 1021 return 1;
840 }
841  
842 114 ▶sub _enclosing_open_index {
Subroutine _enclosing_open_index: called CC=11 SCAR=24.1
843 # Returns the token index of the nearest enclosing unmatched
844 # `(`/`[`/`{` before position $i, or undef at the top level.
845 114 my ( $tokens, $i ) = @_;
846  
847 114 my @stack;
848 114 for my $k ( 0 .. $i - 1 ) {
849 11678 ▶ my $v = defined $tokens->[$k]->value ? $tokens->[$k]->value : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $tokens->[$k]->value ? : 11678 0 11678
850 11678 ▶ if ( $v eq '(' or $v eq '[' or $v eq '{' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v eq '(' or $v eq '[' or $v eq '{') { } 1268 10410 11678
elsif ($v eq ')' or $v eq ']' or $v eq '}') { } 1066 9344 10410
Condition100%6/6
$v eq "(" or $v eq "[" or $v eq "{"
l!l&&r!l&&!r
69257610410
$v eq "(" or $v eq "["
l!l&&r!l&&!r
55813410986
MC/DC100%3/3
$v eq "(" or $v eq "[" or $v eq "{"
$v eq "(" $v eq "[" $v eq "{"
Truth table100%4/4
A or B or C
A= $v eq "("B= $v eq "["C= $v eq "{"
ABCresult
1XX1
01X1
0011
0000
851 1268 push @stack, $k;
852 }
853 ▶ elsif ( $v eq ')' or $v eq ']' or $v eq '}' ) {
Condition100%6/6
$v eq ")" or $v eq "]" or $v eq "}"
l!l&&r!l&&!r
6284389344
$v eq ")" or $v eq "]"
l!l&&r!l&&!r
5161129782
MC/DC100%3/3
$v eq ")" or $v eq "]" or $v eq "}"
$v eq ")" $v eq "]" $v eq "}"
Truth table100%4/4
A or B or C
A= $v eq ")"B= $v eq "]"C= $v eq "}"
ABCresult
1XX1
01X1
0011
0000
854 1066 ▶ pop @stack if @stack;
Branch: 1 branch
BranchTrueFalseTotal
if @stack 1066 0 1066
855 }
856 }
857  
858 114 ▶ return @stack ? $stack[-1] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@stack ? : 114 0 114
859 }
860  
861 60 ▶sub _is_switch_comparator_colon {
Subroutine _is_switch_comparator_colon: called CC=6 SCAR=18.0
862 # The `:` that separates a switch subject expression from its
863 # comparator operator, e.g. `switch ( n mod 4 : = )`, reads better
864 # with a space on both sides, unlike every other use of `:` (case
865 # labels, dict keys, ternaries, slices), which stay tight. Detected
866 # by finding the nearest enclosing unmatched bracket: it must be a
867 # `(` opened directly by the `switch` keyword, not some deeper
868 # bracket (e.g. a slice inside the switch subject).
869 60 my ( $tokens, $i ) = @_;
870 60 ▶ return 0 if !$tokens->[$i]->is_OP(':');
Branch: 1 branch
BranchTrueFalseTotal
unless $tokens->[$i]->is_OP(":") 3 57 60
871  
872 57 my $open_i = _enclosing_open_index( $tokens, $i );
873 57 ▶ return 0 if !defined $open_i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $open_i 0 57 57
874 57 ▶ return 0 if !$tokens->[$open_i]->is_OP('(');
Branch: 1 branch
BranchTrueFalseTotal
unless $tokens->[$open_i]->is_OP("(") 43 14 57
875 14 ▶ return 0 if $open_i == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $open_i == 0 0 14 14
876 14 ▶ return 1 if $tokens->[ $open_i - 1 ]->is_KW('switch');
Branch: 1 branch
BranchTrueFalseTotal
if $$tokens[$open_i - 1]->is_KW("switch") 2 12 14
877  
878 12 return 0;
879 }
880  
881 87 ▶sub _is_simple_slice_inner {
Subroutine _is_simple_slice_inner: called CC=8 SCAR=20.8
882 # True if the tokens between `[` and `]` look like a slice:
883 # zero or more `:`-separated parts, each either empty (an omitted
884 # bound, e.g. `[:2]`) or a single simple token.
885 87 my ( @inner ) = @_;
886  
887 87 my @parts = ( [] );
888 87 for my $tok ( @inner ) {
889 604 ▶ if ( $tok->is_OP(':') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->is_OP(":")) 34 570 604
890 34 push @parts, [];
891 34 next;
892 }
893 570 push @{ $parts[-1] }, $tok;
894 }
895 87 ▶ return 0 if @parts < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @parts < 2 59 28 87
896  
897 28 for my $part ( @parts ) {
898 54 ▶ return 0 if @$part > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$part > 1 2 52 54
899 52 ▶ return 0 if @$part == 1 and !_is_simple_token( $part->[0] );
Branch: 1 branch
BranchTrueFalseTotal
if @$part == 1 and not _is_simple_token($part->[0]) 0 52 52
Condition66%2/3
@$part == 1 and not _is_simple_token($part->[0])
!ll&&!rl&&r
6460
MC/DC0%0/2
@$part == 1 and not _is_simple_token($part->[0])
@$part == 1 not _is_simple_token($part->[0])
Truth table66%2/3
A and not(B)
A= @$part == 1B= not _is_simple_token($part->[0])
ABresult
0X0
100
111
900 }
901  
902 26 return 1;
903 }
904  
905 60 ▶sub _is_slice_colon {
Subroutine _is_slice_colon: called CC=5 SCAR=16.2
906 # A `:` directly inside `[ ... ]` that separates simple slice bounds,
907 # e.g. `text[1:2]`, stays tight on both sides, unlike a dict key's
908 # `:` (`{ a: 1 }`) or the switch comparator's `:`.
909 60 my ( $tokens, $i, $pair_for ) = @_;
910 60 ▶ return 0 if !$tokens->[$i]->is_OP(':');
Branch: 1 branch
BranchTrueFalseTotal
unless $tokens->[$i]->is_OP(":") 3 57 60
911  
912 57 my $open_i = _enclosing_open_index( $tokens, $i );
913 57 ▶ return 0 if !defined $open_i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $open_i 0 57 57
914 57 ▶ return 0 if !$tokens->[$open_i]->is_OP('[');
Branch: 1 branch
BranchTrueFalseTotal
unless $tokens->[$open_i]->is_OP("[") 50 7 57
915 7 my $close_i = $pair_for->{$open_i};
916 7 ▶ return 0 if !defined $close_i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $close_i 0 7 7
917  
918 7 my @inner = @{$tokens}[ $open_i + 1 .. $close_i - 1 ];
919 7 return _is_simple_slice_inner(@inner);
920 }
921  
922 6901 ▶sub _is_module_path_slash {
Subroutine _is_module_path_slash: called CC=28 SCAR=35.3
923 6901 my ( $tokens, $i ) = @_;
924 6901 ▶ return 0 if $i < 0 or $i > $#$tokens;
Branch: 1 branch
BranchTrueFalseTotal
if $i < 0 or $i > $tokens->$#* 0 6901 6901
Condition33%1/3
$i < 0 or $i > $tokens->$#*
l!l&&r!l&&!r
006901
MC/DC0%0/2
$i < 0 or $i > $tokens->$#*
$i < 0 $i > $tokens->$#*
Truth table33%1/3
A or B
A= $i < 0B= $i > $tokens->$#*
ABresult
1X1
011
000
925 6901 my $tok = $tokens->[$i];
926 6901 ▶ return 0 if ! $tok->is_OP or $tok->value ne '/';
Branch: 1 branch
BranchTrueFalseTotal
if not $tok->is_OP or $tok->value ne "/" 6869 32 6901
Condition100%3/3
not $tok->is_OP or $tok->value ne "/"
l!l&&r!l&&!r
3341352832
MC/DC100%2/2
not $tok->is_OP or $tok->value ne "/"
not $tok->is_OP $tok->value ne "/"
Truth table100%3/3
not(A) or B
A= not $tok->is_OPB= $tok->value ne "/"
ABresult
1X1
011
000
927  
928 32 my $stmt_start = 0;
929 32 ▶ for ( my $k = $i - 1; $k >= 0; $k-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k >= 0) 105 19 124
930 105 ▶ my $v = defined $tokens->[$k]->value ? $tokens->[$k]->value : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $tokens->[$k]->value ? : 105 0 105
931 105 ▶ if ( $v eq ';' or $v eq '{' or $v eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq ";" or $v eq "{" or $v eq "}") 13 92 105
Condition66%4/6
$v eq ";" or $v eq "{" or $v eq "}"
l!l&&r!l&&!r
13092
$v eq ";" or $v eq "{"
l!l&&r!l&&!r
13092
MC/DC33%1/3
$v eq ";" or $v eq "{" or $v eq "}"
$v eq ";" $v eq "{" $v eq "}"
Truth table50%2/4
A or B or C
A= $v eq ";"B= $v eq "{"C= $v eq "}"
ABCresult
1XX1
01X1
0011
0000
932 13 $stmt_start = $k + 1;
933 13 last;
934 }
935 }
936  
937 32 my $from_i = -1;
938 32 ▶ for ( my $k = $i - 1; $k >= $stmt_start; $k-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k >= $stmt_start) 92 7 99
939 92 ▶ if ( $tokens->[$k]->is_KW('from') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens->[$k]->is_KW("from")) 25 67 92
940 25 $from_i = $k;
941 25 last;
942 }
943 }
944 32 ▶ return 0 if $from_i < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $from_i < 0 7 25 32
945  
946 25 my $stmt_end = $#$tokens;
947 25 ▶ for ( my $k = $i + 1; $k <= $#$tokens; $k++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k <= $tokens->$#*) 118 0 118
948 118 ▶ my $v = defined $tokens->[$k]->value ? $tokens->[$k]->value : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $tokens->[$k]->value ? : 118 0 118
949 118 ▶ if ( $v eq ';' or $v eq '{' or $v eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq ";" or $v eq "{" or $v eq "}") 25 93 118
Condition66%4/6
$v eq ";" or $v eq "{" or $v eq "}"
l!l&&r!l&&!r
25093
$v eq ";" or $v eq "{"
l!l&&r!l&&!r
25093
MC/DC33%1/3
$v eq ";" or $v eq "{" or $v eq "}"
$v eq ";" $v eq "{" $v eq "}"
Truth table50%2/4
A or B or C
A= $v eq ";"B= $v eq "{"C= $v eq "}"
ABCresult
1XX1
01X1
0011
0000
950 25 $stmt_end = $k - 1;
951 25 last;
952 }
953 }
954  
955 25 my $import_i = -1;
956 25 ▶ for ( my $k = $from_i + 1; $k <= $stmt_end; $k++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k <= $stmt_end) 110 0 110
957 110 ▶ if ( $tokens->[$k]->is_KW('import') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens->[$k]->is_KW("import")) 25 85 110
958 25 $import_i = $k;
959 25 last;
960 }
961 }
962 25 ▶ return 0 if $import_i < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $import_i < 0 0 25 25
963 25 ▶ return 0 if $i <= $from_i or $i >= $import_i;
Branch: 1 branch
BranchTrueFalseTotal
if $i <= $from_i or $i >= $import_i 0 25 25
Condition33%1/3
$i <= $from_i or $i >= $import_i
l!l&&r!l&&!r
0025
MC/DC0%0/2
$i <= $from_i or $i >= $import_i
$i <= $from_i $i >= $import_i
Truth table33%1/3
A or B
A= $i <= $from_iB= $i >= $import_i
ABresult
1X1
011
000
964  
965 25 for my $k ( $from_i + 1 .. $import_i - 1 ) {
966 85 my $t = $tokens->[$k];
967 85 ▶ next if $t->is_IDENT;
Branch: 1 branch
BranchTrueFalseTotal
if $t->is_IDENT 54 31 85
968 31 ▶ next if $t->is_KW('try');
Branch: 1 branch
BranchTrueFalseTotal
if $t->is_KW("try") 2 29 31
969 29 ▶ next if $t->is_OP and $t->value eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if $t->is_OP and $t->value eq "/" 29 0 29
Condition33%1/3
$t->is_OP and $t->value eq "/"
!ll&&!rl&&r
0029
MC/DC0%0/2
$t->is_OP and $t->value eq "/"
$t->is_OP $t->value eq "/"
Truth table33%1/3
A and B
A= $t->is_OPB= $t->value eq "/"
ABresult
0X0
100
111
970 0 return 0;
971 }
972  
973 25 return 1;
974 }
975  
976 3482 ▶sub _display_token_text {
Subroutine _display_token_text: called CC=4 SCAR=13.9
977 3482 my ( $tokens, $i, %opts ) = @_;
978 3482 my $tok = $tokens->[$i];
979 3482 my $raw = _token_text($tok);
980  
981 3482 ▶ return $raw if !$opts{canonical_operators};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"canonical_operators"} 3348 134 3482
982 134 ▶ return $raw if !exists $CANONICAL_OPERATOR_SPELLING{$raw};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $CANONICAL_OPERATOR_SPELLING{$raw} 105 29 134
983 29 ▶ return $raw if !_can_canonicalize_operator( $tokens, $i );
Branch: 1 branch
BranchTrueFalseTotal
unless _can_canonicalize_operator($tokens, $i) 3 26 29
984  
985 26 return $CANONICAL_OPERATOR_SPELLING{$raw};
986 }
987  
988 29 ▶sub _can_canonicalize_operator {
Subroutine _can_canonicalize_operator: called CC=12 SCAR=25.1
989 29 my ( $tokens, $i ) = @_;
990 29 my $tok = $tokens->[$i];
991 29 my $raw = _token_text($tok);
992  
993 29 ▶ return 0 if !$tok->is_OP and !$tok->is_KW;
Branch: 1 branch
BranchTrueFalseTotal
unless $tok->is_OP or $tok->is_KW 0 29 29
Condition66%2/3
$tok->is_OP or $tok->is_KW
l!l&&r!l&&!r
16130
MC/DC0%0/2
$tok->is_OP or $tok->is_KW
$tok->is_OP $tok->is_KW
Truth table66%2/3
A or B
A= $tok->is_OPB= $tok->is_KW
ABresult
1X1
011
000
994 29 ▶ return 0 if _is_module_path_slash( $tokens, $i );
Branch: 1 branch
BranchTrueFalseTotal
if _is_module_path_slash($tokens, $i) 1 28 29
995 28 ▶ return 0 if _is_import_wildcard( $tokens, $i );
Branch: 1 branch
BranchTrueFalseTotal
if _is_import_wildcard($tokens, $i) 1 27 28
996 27 ▶ return 0 if $raw eq 'in' and _is_for_loop_in_keyword( $tokens, $i );
Branch: 1 branch
BranchTrueFalseTotal
if $raw eq "in" and _is_for_loop_in_keyword($tokens, $i) 1 26 27
Condition100%3/3
$raw eq "in" and _is_for_loop_in_keyword($tokens, $i)
!ll&&!rl&&r
2511
MC/DC100%2/2
$raw eq "in" and _is_for_loop_in_keyword($tokens, $i)
$raw eq "in" _is_for_loop_in_keyword($tokens, $i)
Truth table100%3/3
A and B
A= $raw eq "in"B= _is_for_loop_in_keyword($tokens, $i)
ABresult
0X0
100
111
997 26 ▶ return 1 if $raw eq '*=' or $raw eq '/=';
Branch: 1 branch
BranchTrueFalseTotal
if $raw eq "*=" or $raw eq "/=" 2 24 26
Condition100%3/3
$raw eq "*=" or $raw eq "/="
l!l&&r!l&&!r
1124
MC/DC100%2/2
$raw eq "*=" or $raw eq "/="
$raw eq "*=" $raw eq "/="
Truth table100%3/3
A or B
A= $raw eq "*="B= $raw eq "/="
ABresult
1X1
011
000
998 24 ▶ return 1 if _is_chain_op($raw);
Branch: 1 branch
BranchTrueFalseTotal
if _is_chain_op($raw) 2 22 24
999 22 ▶ return 1 if _is_unary_operator( $tokens, $i );
Branch: 1 branch
BranchTrueFalseTotal
if _is_unary_operator($tokens, $i) 0 22 22
1000 22 ▶ return 1 if _is_binary_op( $tokens, $i );
Branch: 1 branch
BranchTrueFalseTotal
if _is_binary_op($tokens, $i) 22 0 22
1001  
1002 0 return 0;
1003 }
1004  
1005 28 ▶sub _is_import_wildcard {
Subroutine _is_import_wildcard: called CC=10 SCAR=23.5
1006 28 my ( $tokens, $i ) = @_;
1007 28 ▶ return 0 if $i < 0 or $i > $#$tokens;
Branch: 1 branch
BranchTrueFalseTotal
if $i < 0 or $i > $tokens->$#* 0 28 28
Condition33%1/3
$i < 0 or $i > $tokens->$#*
l!l&&r!l&&!r
0028
MC/DC0%0/2
$i < 0 or $i > $tokens->$#*
$i < 0 $i > $tokens->$#*
Truth table33%1/3
A or B
A= $i < 0B= $i > $tokens->$#*
ABresult
1X1
011
000
1008 28 ▶ return 0 if !$tokens->[$i]->is_OP('*');
Branch: 1 branch
BranchTrueFalseTotal
unless $tokens->[$i]->is_OP("*") 24 4 28
1009  
1010 4 ▶ for ( my $k = $i - 1; $k >= 0; $k-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k >= 0) 17 1 18
1011 17 ▶ my $v = defined $tokens->[$k]->value ? $tokens->[$k]->value : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $tokens->[$k]->value ? : 17 0 17
1012 17 ▶ return 0 if $v eq ';' or $v eq '{' or $v eq '}';
Branch: 1 branch
BranchTrueFalseTotal
if $v eq ";" or $v eq "{" or $v eq "}" 2 15 17
Condition83%5/6
$v eq ";" or $v eq "{" or $v eq "}"
l!l&&r!l&&!r
1115
$v eq ";" or $v eq "{"
l!l&&r!l&&!r
1016
MC/DC66%2/3
$v eq ";" or $v eq "{" or $v eq "}"
$v eq ";" $v eq "{" $v eq "}"
Truth table75%3/4
A or B or C
A= $v eq ";"B= $v eq "{"C= $v eq "}"
ABCresult
1XX1
01X1
0011
0000
1013 15 ▶ return 1 if $tokens->[$k]->is_KW('import');
Branch: 1 branch
BranchTrueFalseTotal
if $tokens->[$k]->is_KW("import") 1 14 15
1014 }
1015  
1016 1 return 0;
1017 }
1018  
1019 2 ▶sub _is_for_loop_in_keyword {
Subroutine _is_for_loop_in_keyword: called CC=12 SCAR=28.3
1020 2 my ( $tokens, $i ) = @_;
1021 2 ▶ return 0 if $i < 0 or $i > $#$tokens;
Branch: 1 branch
BranchTrueFalseTotal
if $i < 0 or $i > $tokens->$#* 0 2 2
Condition33%1/3
$i < 0 or $i > $tokens->$#*
l!l&&r!l&&!r
002
MC/DC0%0/2
$i < 0 or $i > $tokens->$#*
$i < 0 $i > $tokens->$#*
Truth table33%1/3
A or B
A= $i < 0B= $i > $tokens->$#*
ABresult
1X1
011
000
1022 2 ▶ return 0 if !$tokens->[$i]->is_KW('in');
Branch: 1 branch
BranchTrueFalseTotal
unless $tokens->[$i]->is_KW("in") 0 2 2
1023  
1024 2 my @stack;
1025 2 for my $k ( 0 .. $i - 1 ) {
1026 170 ▶ my $v = defined $tokens->[$k]->value ? $tokens->[$k]->value : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $tokens->[$k]->value ? : 170 0 170
1027 170 ▶ if ( $v eq '(' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq "(") 1 169 170
1028 1 push @stack, $k;
1029 1 next;
1030 }
1031 169 ▶ if ( $v eq ')' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq ")") 0 169 169
1032 0 ▶ pop @stack if @stack;
Branch: 1 branch
BranchTrueFalseTotal
if @stack 0 0 0
1033 }
1034 }
1035 2 ▶ return 0 if !@stack;
Branch: 1 branch
BranchTrueFalseTotal
unless @stack 1 1 2
1036  
1037 1 my $open_i = $stack[-1];
1038 1 ▶ return 0 if $open_i == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $open_i == 0 0 1 1
1039 1 ▶ return 1 if $tokens->[ $open_i - 1 ]->is_KW('for');
Branch: 1 branch
BranchTrueFalseTotal
if $$tokens[$open_i - 1]->is_KW("for") 1 0 1
1040  
1041 0 return 0;
1042 }
1043  
1044 3387 ▶sub _is_binary_op {
Subroutine _is_binary_op: called CC=7 SCAR=19.6
1045 3387 my ( $tokens, $i ) = @_;
1046 3387 ▶ return 0 if $i < 0 or $i > $#$tokens;
Branch: 1 branch
BranchTrueFalseTotal
if $i < 0 or $i > $tokens->$#* 0 3387 3387
Condition33%1/3
$i < 0 or $i > $tokens->$#*
l!l&&r!l&&!r
003387
MC/DC0%0/2
$i < 0 or $i > $tokens->$#*
$i < 0 $i > $tokens->$#*
Truth table33%1/3
A or B
A= $i < 0B= $i > $tokens->$#*
ABresult
1X1
011
000
1047 3387 my $tok = $tokens->[$i];
1048 3387 ▶ return 0 if ! $tok->is_OP and ! $tok->is_KW;
Branch: 1 branch
BranchTrueFalseTotal
unless $tok->is_OP or $tok->is_KW 1263 2124 3387
Condition100%3/3
$tok->is_OP or $tok->is_KW
l!l&&r!l&&!r
14017231263
MC/DC100%2/2
$tok->is_OP or $tok->is_KW
$tok->is_OP $tok->is_KW
Truth table100%3/3
A or B
A= $tok->is_OPB= $tok->is_KW
ABresult
1X1
011
000
1049 2124 my $v = $tok->value;
1050 2124 ▶ return 0 if ! $BINARY_OP{$v};
Branch: 1 branch
BranchTrueFalseTotal
unless $BINARY_OP{$v} 1366 758 2124
1051 758 ▶ return 0 if _is_unary_operator( $tokens, $i );
Branch: 1 branch
BranchTrueFalseTotal
if _is_unary_operator($tokens, $i) 3 755 758
1052  
1053 755 return 1;
1054 }
1055  
1056 18 ▶sub _is_call_spread_operator {
Subroutine _is_call_spread_operator: called CC=10 SCAR=26.2
1057 18 my ( $tokens, $i ) = @_;
1058 18 ▶ return 0 if $i < 0 or $i > $#$tokens;
Branch: 1 branch
BranchTrueFalseTotal
if $i < 0 or $i > $tokens->$#* 0 18 18
Condition33%1/3
$i < 0 or $i > $tokens->$#*
l!l&&r!l&&!r
0018
MC/DC0%0/2
$i < 0 or $i > $tokens->$#*
$i < 0 $i > $tokens->$#*
Truth table33%1/3
A or B
A= $i < 0B= $i > $tokens->$#*
ABresult
1X1
011
000
1059 18 my $tok = $tokens->[$i];
1060 18 ▶ return 0 if ! $tok->is_OP or $tok->value ne '...';
Branch: 1 branch
BranchTrueFalseTotal
if not $tok->is_OP or $tok->value ne "..." 0 18 18
Condition33%1/3
not $tok->is_OP or $tok->value ne "..."
l!l&&r!l&&!r
0018
MC/DC0%0/2
not $tok->is_OP or $tok->value ne "..."
not $tok->is_OP $tok->value ne "..."
Truth table33%1/3
not(A) or B
A= not $tok->is_OPB= $tok->value ne "..."
ABresult
1X1
011
000
1061  
1062 18 ▶ my $prev = $i > 0 ? $tokens->[ $i - 1 ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$i > 0 ? : 18 0 18
1063 18 ▶ return 0 if !$prev;
Branch: 1 branch
BranchTrueFalseTotal
unless $prev 0 18 18
1064 18 ▶ return 1 if $prev->is_OP and ( $prev->value eq '(' or $prev->value eq ',' );
Branch: 1 branch
BranchTrueFalseTotal
if $prev->is_OP and $prev->value eq "(" || $prev->value eq "," 10 8 18
Condition66%4/6
$prev->is_OP and $prev->value eq "(" || $prev->value eq ","
!ll&&!rl&&r
8010
$prev->value eq "(" or $prev->value eq ","
l!l&&r!l&&!r
640
MC/DC33%1/3
$prev->is_OP and $prev->value eq "(" || $prev->value eq ","
$prev->is_OP $prev->value eq "(" $prev->value eq ","
Truth table75%3/4
A and B or C
A= $prev->is_OPB= $prev->value eq "("C= $prev->value eq ","
ABCresult
0XX0
1000
11X1
1011
1065  
1066 8 return 0;
1067 }
1068  
1069 2495 ▶sub _is_unary_operator {
Subroutine _is_unary_operator: called CC=19 SCAR=33.8
1070 2495 my ( $tokens, $i ) = @_;
1071 2495 my $tok = $tokens->[$i];
1072 2495 ▶ return 0 if ! $tok->is_OP and ! $tok->is_KW;
Branch: 1 branch
BranchTrueFalseTotal
unless $tok->is_OP or $tok->is_KW 0 2495 2495
Condition66%2/3
$tok->is_OP or $tok->is_KW
l!l&&r!l&&!r
23861090
MC/DC0%0/2
$tok->is_OP or $tok->is_KW
$tok->is_OP $tok->is_KW
Truth table66%2/3
A or B
A= $tok->is_OPB= $tok->is_KW
ABresult
1X1
011
000
1073 2495 my $v = $tok->value;
1074 2495 ▶ return 0 if ! $UNARY_PREFIX_OP{$v};
Branch: 1 branch
BranchTrueFalseTotal
unless $UNARY_PREFIX_OP{$v} 2354 141 2495
1075  
1076 141 ▶ return 1 if $i == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i == 0 0 141 141
1077 141 my $prev = $tokens->[ $i - 1 ];
1078 141 ▶ if ( $prev->is_OP ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev->is_OP) 19 122 141
1079 19 ▶ my $pv = defined $prev->value ? $prev->value : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $prev->value ? : 19 0 19
1080 19 ▶ return 1 if $pv ne ')'
Branch: 1 branch
BranchTrueFalseTotal
if $pv ne ")" and $pv ne "]" and $pv ne "}" and $pv ne "\x{230b}" and $pv ne "\x{2309}" and $pv ne "\x{bb}" and $pv ne ">>" and $pv ne ">>>" 7 12 19
Condition66%14/21
$pv ne ")" and $pv ne "]" and $pv ne "}" and $pv ne "\x{230b}" and $pv ne "\x{2309}" and $pv ne "\x{bb}" and $pv ne ">>" and $pv ne ">>>"
!ll&&!rl&&r
937
$pv ne ")" and $pv ne "]" and $pv ne "}" and $pv ne "\x{230b}" and $pv ne "\x{2309}" and $pv ne "\x{bb}" and $pv ne ">>"
!ll&&!rl&&r
3610
$pv ne ")" and $pv ne "]" and $pv ne "}" and $pv ne "\x{230b}" and $pv ne "\x{2309}" and $pv ne "\x{bb}"
!ll&&!rl&&r
3016
$pv ne ")" and $pv ne "]" and $pv ne "}" and $pv ne "\x{230b}" and $pv ne "\x{2309}"
!ll&&!rl&&r
3016
$pv ne ")" and $pv ne "]" and $pv ne "}" and $pv ne "\x{230b}"
!ll&&!rl&&r
0316
$pv ne ")" and $pv ne "]" and $pv ne "}"
!ll&&!rl&&r
0019
$pv ne ")" and $pv ne "]"
!ll&&!rl&&r
0019
MC/DC37%3/8
$pv ne ")" and $pv ne "]" and $pv ne "}" and $pv ne "\x{230b}" and $pv ne "\x{2309}" and $pv ne "\x{bb}" and $pv ne ">>" and $pv ne ">>>"
$pv ne ")" $pv ne "]" $pv ne "}" $pv ne "\x{230b}" $pv ne "\x{2309}" $pv ne "\x{bb}" $pv ne ">>" $pv ne ">>>"
Truth table44%4/9
A and B and C and D and E and F and G and H
A= $pv ne ")"B= $pv ne "]"C= $pv ne "}"D= $pv ne "\x{230b}"E= $pv ne "\x{2309}"F= $pv ne "\x{bb}"G= $pv ne ">>"H= $pv ne ">>>"
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
111110XX0
1111110X0
111111100
111111111
1081 and $pv ne ']'
1082 and $pv ne '}'
1083 and $pv ne '⌋'
1084 and $pv ne '⌉'
1085 and $pv ne '»'
1086 and $pv ne '>>'
1087 and $pv ne '>>>';
1088 }
1089 134 ▶ return 1 if $prev->is_KW and $prev->value ne 'true' and $prev->value ne 'false' and $prev->value ne 'null';
Branch: 1 branch
BranchTrueFalseTotal
if $prev->is_KW and $prev->value ne "true" and $prev->value ne "false" and $prev->value ne "null" 0 134 134
Condition33%3/9
$prev->is_KW and $prev->value ne "true" and $prev->value ne "false" and $prev->value ne "null"
!ll&&!rl&&r
13400
$prev->is_KW and $prev->value ne "true" and $prev->value ne "false"
!ll&&!rl&&r
13400
$prev->is_KW and $prev->value ne "true"
!ll&&!rl&&r
13400
MC/DC0%0/4
$prev->is_KW and $prev->value ne "true" and $prev->value ne "false" and $prev->value ne "null"
$prev->is_KW $prev->value ne "true" $prev->value ne "false" $prev->value ne "null"
Truth table20%1/5
A and B and C and D
A= $prev->is_KWB= $prev->value ne "true"C= $prev->value ne "false"D= $prev->value ne "null"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1090  
1091 134 return 0;
1092 }
1093  
1094 3388 ▶sub _is_unary_punct_operator {
Subroutine _is_unary_punct_operator: called CC=6 SCAR=18.7
1095 3388 my ( $tokens, $i ) = @_;
1096 3388 ▶ return 0 if $i < 0 or $i > $#$tokens;
Branch: 1 branch
BranchTrueFalseTotal
if $i < 0 or $i > $tokens->$#* 0 3388 3388
Condition33%1/3
$i < 0 or $i > $tokens->$#*
l!l&&r!l&&!r
003388
MC/DC0%0/2
$i < 0 or $i > $tokens->$#*
$i < 0 $i > $tokens->$#*
Truth table33%1/3
A or B
A= $i < 0B= $i > $tokens->$#*
ABresult
1X1
011
000
1097 3388 my $tok = $tokens->[$i];
1098 3388 ▶ return 0 if ! $tok->is_OP;
Branch: 1 branch
BranchTrueFalseTotal
unless $tok->is_OP 1673 1715 3388
1099 1715 ▶ return 0 if ! _is_unary_operator( $tokens, $i );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_unary_operator($tokens, $i) 1711 4 1715
1100 4 ▶ return $tok->value =~ /[[:alpha:]]/ ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$tok->value =~ /[[:alpha:]]/ ? : 0 4 4
1101 }
1102  
1103 740 ▶sub _paren_needs_inner_space {
Subroutine _paren_needs_inner_space: called CC=10 SCAR=23.0
1104 740 my ( $tokens, $open_i, $close_i ) = @_;
1105 740 ▶ return 0 if $close_i == $open_i + 1;
Branch: 1 branch
BranchTrueFalseTotal
if $close_i == $open_i + 1 99 641 740
1106  
1107 641 my @inner = @{$tokens}[ $open_i + 1 .. $close_i - 1 ];
1108 641 ▶ if ( @inner == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@inner == 1) 203 438 641
1109 203 ▶ return _is_simple_token( $inner[0] ) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
_is_simple_token($inner[0]) ? : 200 3 203
1110 }
1111 438 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (@inner == 2 and $inner[0]->is_OP and $inner[0]->value eq "..." and _is_simple_token($inner[1])) 4 434 438
Condition88%8/9
@inner == 2 and $inner[0]->is_OP and $inner[0]->value eq "..." and _is_simple_token($inner[1])
!ll&&!rl&&r
43404
@inner == 2 and $inner[0]->is_OP and $inner[0]->value eq "..."
!ll&&!rl&&r
42954
@inner == 2 and $inner[0]->is_OP
!ll&&!rl&&r
402279
MC/DC75%3/4
@inner == 2 and $inner[0]->is_OP and $inner[0]->value eq "..." and _is_simple_token($inner[1])
@inner == 2 $inner[0]->is_OP $inner[0]->value eq "..." _is_simple_token($inner[1])
Truth table80%4/5
A and B and C and D
A= @inner == 2B= $inner[0]->is_OPC= $inner[0]->value eq "..."D= _is_simple_token($inner[1])
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1112 @inner == 2
1113 and $inner[0]->is_OP
1114 and $inner[0]->value eq '...'
1115 and _is_simple_token( $inner[1] )
1116 ) {
1117 4 return 0;
1118 }
1119 434 ▶ if ( $tokens->[$open_i]->is_OP('[') and _is_simple_slice_inner(@inner) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens->[$open_i]->is_OP("[") and _is_simple_slice_inner(@inner)) 19 415 434
Condition100%3/3
$tokens->[$open_i]->is_OP("[") and _is_simple_slice_inner(@inner)
!ll&&!rl&&r
3546119
MC/DC100%2/2
$tokens->[$open_i]->is_OP("[") and _is_simple_slice_inner(@inner)
$tokens->[$open_i]->is_OP("[") _is_simple_slice_inner(@inner)
Truth table100%3/3
A and B
A= $tokens->[$open_i]->is_OP("[")B= _is_simple_slice_inner(@inner)
ABresult
0X0
100
111
1120 19 return 0;
1121 }
1122  
1123 415 return 1;
1124 }
1125  
1126 39 ▶sub _brace_needs_inner_space {
Subroutine _brace_needs_inner_space: called CC=14 SCAR=28.4
1127 39 my ( $tokens, $open_i, $close_i ) = @_;
1128 39 ▶ return 0 if $close_i == $open_i + 1;
Branch: 1 branch
BranchTrueFalseTotal
if $close_i == $open_i + 1 0 39 39
1129 39 ▶ my $before = $open_i > 0 ? $tokens->[ $open_i - 1 ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$open_i > 0 ? : 39 0 39
1130 39 ▶ my $before_val = ( $before and defined $before->value ) ? $before->value : '';
Branch: 1 branch
BranchTrueFalseTotal
$before && defined $before->value ? : 39 0 39
Condition33%1/3
$before and defined $before->value
!ll&&!rl&&r
0039
MC/DC0%0/2
$before and defined $before->value
$before defined $before->value
Truth table33%1/3
A and B
A= $beforeB= defined $before->value
ABresult
0X0
100
111
1131 39 my $is_accessor = 0;
1132 39 ▶ if ($before) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before) 39 0 39
1133 39 ▶ $is_accessor = 1 if $before->is_IDENT;
Branch: 1 branch
BranchTrueFalseTotal
if $before->is_IDENT 12 27 39
1134 39 ▶ $is_accessor = 1 if $before->is_OP and ( $before_val eq ')' or $before_val eq ']' or $before_val eq '}' );
Branch: 1 branch
BranchTrueFalseTotal
if $before->is_OP and $before_val eq ")" || $before_val eq "]" || $before_val eq "}" 8 31 39
Condition77%7/9
$before->is_OP and $before_val eq ")" || $before_val eq "]" || $before_val eq "}"
!ll&&!rl&&r
20118
$before_val eq ")" or $before_val eq "]" or $before_val eq "}"
l!l&&r!l&&!r
8011
$before_val eq ")" or $before_val eq "]"
l!l&&r!l&&!r
0811
MC/DC50%2/4
$before->is_OP and $before_val eq ")" || $before_val eq "]" || $before_val eq "}"
$before->is_OP $before_val eq ")" $before_val eq "]" $before_val eq "}"
Truth table60%3/5
A and B or C or D
A= $before->is_OPB= $before_val eq ")"C= $before_val eq "]"D= $before_val eq "}"
ABCDresult
0XXX0
10000
11XX1
101X1
10011
1135 }
1136  
1137 39 my @inner = @{$tokens}[ $open_i + 1 .. $close_i - 1 ];
1138 39 ▶ if ( $is_accessor ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_accessor) 20 19 39
1139 20 ▶ return _is_simple_token( $inner[0] ) ? 0 : 1 if @inner == 1;
Branch: 2 branches
BranchTrueFalseTotal
if @inner == 1 20 0 20
_is_simple_token($inner[0]) ? : 20 0 20
1140 0 return 1;
1141 }
1142  
1143 19 return 1;
1144 }
1145  
1146 273 ▶sub _is_simple_token {
Subroutine _is_simple_token: called CC=10 SCAR=25.6
1147 273 my ( $tok ) = @_;
1148 273 ▶ return 1 if $tok->is_IDENT;
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_IDENT 104 169 273
1149 169 ▶ return 1 if $tok->is_NUMBER;
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_NUMBER 139 30 169
1150 30 ▶ return 1 if $tok->is_BOOL;
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_BOOL 0 30 30
1151 30 ▶ return 1 if $tok->is_NULL;
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_NULL 0 30 30
1152 30 ▶ if ( $tok->is_STRING or $tok->is_type('BINARY_STRING') or $tok->is_type('TEMPLATE') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->is_STRING or $tok->is_type("BINARY_STRING") or $tok->is_type("TEMPLATE")) 30 0 30
Condition33%2/6
$tok->is_STRING or $tok->is_type("BINARY_STRING") or $tok->is_type("TEMPLATE")
l!l&&r!l&&!r
3000
$tok->is_STRING or $tok->is_type("BINARY_STRING")
l!l&&r!l&&!r
3000
MC/DC0%0/3
$tok->is_STRING or $tok->is_type("BINARY_STRING") or $tok->is_type("TEMPLATE")
$tok->is_STRING $tok->is_type("BINARY_STRING") $tok->is_type("TEMPLATE")
Truth table25%1/4
A or B or C
A= $tok->is_STRINGB= $tok->is_type("BINARY_STRING")C= $tok->is_type("TEMPLATE")
ABCresult
1XX1
01X1
0011
0000
1153 30 ▶ my $value = defined $tok->value ? $tok->value : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $tok->value ? : 30 0 30
1154 30 ▶ return length($value) <= 12 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
length $value <= 12 ? : 27 3 30
1155 }
1156  
1157 0 return 0;
1158 }
1159  
1160 2985 ▶sub _needs_auto_semicolon {
Subroutine _needs_auto_semicolon: called CC=33 SCAR=35.0
1161 2985 my ( $tok, $next, $paren_depth, $bracket_depth, $brace_depth, $inline_brace_depth, $just_closed_inline, $angle_depth ) = @_;
1162 2985 ▶ return 0 if $tok->is_OP and ( $tok->value eq ';' or $tok->value eq '{' );
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_OP and $tok->value eq ";" || $tok->value eq "{" 24 2961 2985
Condition83%5/6
$tok->is_OP and $tok->value eq ";" || $tok->value eq "{"
!ll&&!rl&&r
1686127524
$tok->value eq ";" or $tok->value eq "{"
l!l&&r!l&&!r
0241275
MC/DC66%2/3
$tok->is_OP and $tok->value eq ";" || $tok->value eq "{"
$tok->is_OP $tok->value eq ";" $tok->value eq "{"
Truth table75%3/4
A and B or C
A= $tok->is_OPB= $tok->value eq ";"C= $tok->value eq "{"
ABCresult
0XX0
1000
11X1
1011
1163 2961 ▶ return 0 if $tok->is_OP and $tok->value eq '}' and ! $just_closed_inline;
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_OP and $tok->value eq "}" and not $just_closed_inline 5 2956 2961
Condition100%6/6
$tok->is_OP and $tok->value eq "}" and not $just_closed_inline
!ll&&!rl&&r
2926305
$tok->is_OP and $tok->value eq "}"
!ll&&!rl&&r
1686124035
MC/DC100%3/3
$tok->is_OP and $tok->value eq "}" and not $just_closed_inline
$tok->is_OP $tok->value eq "}" not $just_closed_inline
Truth table100%4/4
A and B and not(C)
A= $tok->is_OPB= $tok->value eq "}"C= not $just_closed_inline
ABCresult
0XX0
10X0
1100
1111
1164 2956 ▶ return 0 if $tok->is_OP and $tok->value eq ':';
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_OP and $tok->value eq ":" 57 2899 2956
Condition100%3/3
$tok->is_OP and $tok->value eq ":"
!ll&&!rl&&r
1686121357
MC/DC100%2/2
$tok->is_OP and $tok->value eq ":"
$tok->is_OP $tok->value eq ":"
Truth table100%3/3
A and B
A= $tok->is_OPB= $tok->value eq ":"
ABresult
0X0
100
111
1165 2899 ▶ return 0 if $tok->is_KW('else');
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_KW("else") 6 2893 2899
1166 2893 ▶ if ( $next->is_KW and ( $next->value eq 'if' or $next->value eq 'unless' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next->is_KW and $next->value eq "if" || $next->value eq "unless") 6 2887 2893
Condition100%6/6
$next->is_KW and $next->value eq "if" || $next->value eq "unless"
!ll&&!rl&&r
26911966
$next->value eq "if" or $next->value eq "unless"
l!l&&r!l&&!r
42196
MC/DC100%3/3
$next->is_KW and $next->value eq "if" || $next->value eq "unless"
$next->is_KW $next->value eq "if" $next->value eq "unless"
Truth table100%4/4
A and B or C
A= $next->is_KWB= $next->value eq "if"C= $next->value eq "unless"
ABCresult
0XX0
1000
11X1
1011
1167 6 return 0;
1168 }
1169 2887 ▶ return 0 if $next->is_OP and ( $next->value eq ';' or $next->value eq ')' or $next->value eq ']' or $next->value eq '⌋' or $next->value eq '⌉' or $next->value eq ',' or $next->value eq ':' );
Branch: 1 branch
BranchTrueFalseTotal
if $next->is_OP and $next->value eq ";" || $next->value eq ")" || $next->value eq "]" || $next->value eq "\x{230b}" || $next->value eq "\x{2309}" || $next->value eq "," || $next->value eq ":" 773 2114 2887
Condition100%21/21
$next->is_OP and $next->value eq ";" || $next->value eq ")" || $next->value eq "]" || $next->value eq "\x{230b}" || $next->value eq "\x{2309}" || $next->value eq "," || $next->value eq ":"
!ll&&!rl&&r
1226888773
$next->value eq ";" or $next->value eq ")" or $next->value eq "]" or $next->value eq "\x{230b}" or $next->value eq "\x{2309}" or $next->value eq "," or $next->value eq ":"
l!l&&r!l&&!r
71657888
$next->value eq ";" or $next->value eq ")" or $next->value eq "]" or $next->value eq "\x{230b}" or $next->value eq "\x{2309}" or $next->value eq ","
l!l&&r!l&&!r
489227945
$next->value eq ";" or $next->value eq ")" or $next->value eq "]" or $next->value eq "\x{230b}" or $next->value eq "\x{2309}"
l!l&&r!l&&!r
48721172
$next->value eq ";" or $next->value eq ")" or $next->value eq "]" or $next->value eq "\x{230b}"
l!l&&r!l&&!r
48521174
$next->value eq ";" or $next->value eq ")" or $next->value eq "]"
l!l&&r!l&&!r
436491176
$next->value eq ";" or $next->value eq ")"
l!l&&r!l&&!r
2082281225
MC/DC100%8/8
$next->is_OP and $next->value eq ";" || $next->value eq ")" || $next->value eq "]" || $next->value eq "\x{230b}" || $next->value eq "\x{2309}" || $next->value eq "," || $next->value eq ":"
$next->is_OP $next->value eq ";" $next->value eq ")" $next->value eq "]" $next->value eq "\x{230b}" $next->value eq "\x{2309}" $next->value eq "," $next->value eq ":"
Truth table100%9/9
A and B or C or D or E or F or G or H
A= $next->is_OPB= $next->value eq ";"C= $next->value eq ")"D= $next->value eq "]"E= $next->value eq "\x{230b}"F= $next->value eq "\x{2309}"G= $next->value eq ","H= $next->value eq ":"
ABCDEFGHresult
0XXXXXXX0
100000000
11XXXXXX1
101XXXXX1
1001XXXX1
10001XXX1
100001XX1
1000001X1
100000011
1170 2114 ▶ return 0 if $paren_depth > 0 or $bracket_depth > 0 or ( $angle_depth // 0 ) > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $paren_depth > 0 or $bracket_depth > 0 or ($angle_depth // 0) > 0 701 1413 2114
Condition87%7/8
$paren_depth > 0 or $bracket_depth > 0 or ($angle_depth // 0) > 0
l!l&&r!l&&!r
653481413
$paren_depth > 0 or $bracket_depth > 0
l!l&&r!l&&!r
5501031461
$angle_depth // 0
l!l
14610
MC/DC0%0/3
$paren_depth > 0 or $bracket_depth > 0 or ($angle_depth // 0) > 0
$paren_depth > 0 $bracket_depth > 0 $angle_depth
Truth table75%3/4
A or B or C
A= $paren_depth > 0B= $bracket_depth > 0C= $angle_depth
ABCresult
1XX1
01X1
0011
0000
1171 1413 ▶ return 0 if $inline_brace_depth > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $inline_brace_depth > 0 36 1377 1413
1172 1377 ▶ return 1 if $next->is_OP and $next->value eq '}' and _can_end_statement($tok);
Branch: 1 branch
BranchTrueFalseTotal
if $next->is_OP and $next->value eq "}" and _can_end_statement($tok) 30 1347 1377
Condition83%5/6
$next->is_OP and $next->value eq "}" and _can_end_statement($tok)
!ll&&!rl&&r
1347030
$next->is_OP and $next->value eq "}"
!ll&&!rl&&r
69964830
MC/DC66%2/3
$next->is_OP and $next->value eq "}" and _can_end_statement($tok)
$next->is_OP $next->value eq "}" _can_end_statement($tok)
Truth table75%3/4
A and B and C
A= $next->is_OPB= $next->value eq "}"C= _can_end_statement($tok)
ABCresult
0XX0
10X0
1100
1111
1173 1347 ▶ return 1 if $next->is_KW('else');
Branch: 1 branch
BranchTrueFalseTotal
if $next->is_KW("else") 0 1347 1347
1174 1347 ▶ return 1 if $tok->line < $next->line and _can_end_statement($tok) and _can_start_statement($next);
Branch: 1 branch
BranchTrueFalseTotal
if $tok->line < $next->line and _can_end_statement($tok) and _can_start_statement($next) 81 1266 1347
Condition66%4/6
$tok->line < $next->line and _can_end_statement($tok) and _can_start_statement($next)
!ll&&!rl&&r
1266081
$tok->line < $next->line and _can_end_statement($tok)
!ll&&!rl&&r
1266081
MC/DC33%1/3
$tok->line < $next->line and _can_end_statement($tok) and _can_start_statement($next)
$tok->line < $next->line _can_end_statement($tok) _can_start_statement($next)
Truth table50%2/4
A and B and C
A= $tok->line < $next->lineB= _can_end_statement($tok)C= _can_start_statement($next)
ABCresult
0XX0
10X0
1100
1111
1175  
1176 1266 return 0;
1177 }
1178  
1179 459 ▶sub _is_inline_brace {
Subroutine _is_inline_brace: called CC=49 SCAR=47.2
1180 459 my ( $tokens, $i, $pair_for ) = @_;
1181 459 ▶ return 0 if $i <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i <= 0 0 459 459
1182  
1183 459 ▶ return 0 if $tokens->[$i]{_forced_block};
Branch: 1 branch
BranchTrueFalseTotal
if $tokens->[$i]{"_forced_block"} 156 303 459
1184 303 ▶ return 0 if $tokens->[$i]{_force_sequence};
Branch: 1 branch
BranchTrueFalseTotal
if $tokens->[$i]{"_force_sequence"} 8 295 303
1185  
1186 295 my $pairlist_half = $tokens->[$i]{_pairlist_half};
1187 295 ▶ if ( defined $pairlist_half ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pairlist_half) 16 279 295
1188 # The first half of a split {{ is always inline, so it never
1189 # triggers its own newline/indent; the second half is always
1190 # block-kind, which is what produces the indented pairlist body.
1191 # This is independent of whatever token precedes the pairlist
1192 # (e.g. a spread `...`), unlike the heuristics below.
1193 16 ▶ return 1 if $pairlist_half eq 'open1';
Branch: 1 branch
BranchTrueFalseTotal
if $pairlist_half eq "open1" 6 10 16
1194 10 ▶ return 0 if $pairlist_half eq 'open2';
Branch: 1 branch
BranchTrueFalseTotal
if $pairlist_half eq "open2" 10 0 10
1195 }
1196  
1197 279 my $prev = $tokens->[ $i - 1 ];
1198 279 ▶ my $pv = defined $prev->value ? $prev->value : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $prev->value ? : 279 0 279
1199  
1200 279 ▶ if ( $prev->is_IDENT ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev->is_IDENT) 24 255 279
1201 24 ▶ if ( $i >= 2 and $tokens->[ $i - 2 ]->is_KW ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 2 and $$tokens[$i - 2]->is_KW) 4 20 24
Condition66%2/3
$i >= 2 and $$tokens[$i - 2]->is_KW
!ll&&!rl&&r
0204
MC/DC50%1/2
$i >= 2 and $$tokens[$i - 2]->is_KW
$i >= 2 $$tokens[$i - 2]->is_KW
Truth table66%2/3
A and B
A= $i >= 2B= $$tokens[$i - 2]->is_KW
ABresult
0X0
100
111
1202 4 my $kw = $tokens->[ $i - 2 ]->value;
1203 4 ▶ return 0 if $kw eq 'class' or $kw eq 'trait';
Branch: 1 branch
BranchTrueFalseTotal
if $kw eq "class" or $kw eq "trait" 0 4 4
Condition33%1/3
$kw eq "class" or $kw eq "trait"
l!l&&r!l&&!r
004
MC/DC0%0/2
$kw eq "class" or $kw eq "trait"
$kw eq "class" $kw eq "trait"
Truth table33%1/3
A or B
A= $kw eq "class"B= $kw eq "trait"
ABresult
1X1
011
000
1204 }
1205 24 return 1;
1206 }
1207  
1208 255 ▶ if ( $prev->is_KW ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev->is_KW) 128 127 255
1209 128 my $kw = $prev->value;
1210 128 ▶ return 0 if $CONTROL_KW{$kw}
Branch: 1 branch
BranchTrueFalseTotal
if $CONTROL_KW{$kw} or $kw eq "class" or $kw eq "trait" or $kw eq "else" or $kw eq "try" or $kw eq "do" or $kw eq "await" or $kw eq "spawn" or $kw eq "function" or $kw eq "method" 112 16 128
Condition81%22/27
$CONTROL_KW{$kw} or $kw eq "class" or $kw eq "trait" or $kw eq "else" or $kw eq "try" or $kw eq "do" or $kw eq "await" or $kw eq "spawn" or $kw eq "function" or $kw eq "method"
l!l&&r!l&&!r
112016
$CONTROL_KW{$kw} or $kw eq "class" or $kw eq "trait" or $kw eq "else" or $kw eq "try" or $kw eq "do" or $kw eq "await" or $kw eq "spawn" or $kw eq "function"
l!l&&r!l&&!r
112016
$CONTROL_KW{$kw} or $kw eq "class" or $kw eq "trait" or $kw eq "else" or $kw eq "try" or $kw eq "do" or $kw eq "await" or $kw eq "spawn"
l!l&&r!l&&!r
104816
$CONTROL_KW{$kw} or $kw eq "class" or $kw eq "trait" or $kw eq "else" or $kw eq "try" or $kw eq "do" or $kw eq "await"
l!l&&r!l&&!r
406424
$CONTROL_KW{$kw} or $kw eq "class" or $kw eq "trait" or $kw eq "else" or $kw eq "try" or $kw eq "do"
l!l&&r!l&&!r
32888
$CONTROL_KW{$kw} or $kw eq "class" or $kw eq "trait" or $kw eq "else" or $kw eq "try"
l!l&&r!l&&!r
201296
$CONTROL_KW{$kw} or $kw eq "class" or $kw eq "trait" or $kw eq "else"
l!l&&r!l&&!r
200108
$CONTROL_KW{$kw} or $kw eq "class" or $kw eq "trait"
l!l&&r!l&&!r
200108
$CONTROL_KW{$kw} or $kw eq "class"
l!l&&r!l&&!r
200108
MC/DC50%5/10
$CONTROL_KW{$kw} or $kw eq "class" or $kw eq "trait" or $kw eq "else" or $kw eq "try" or $kw eq "do" or $kw eq "await" or $kw eq "spawn" or $kw eq "function" or $kw eq "method"
$CONTROL_KW{$kw} $kw eq "class" $kw eq "trait" $kw eq "else" $kw eq "try" $kw eq "do" $kw eq "await" $kw eq "spawn" $kw eq "function" $kw eq "method"
Truth table54%6/11
A or B or C or D or E or F or G or H or I or J
A= $CONTROL_KW{$kw}B= $kw eq "class"C= $kw eq "trait"D= $kw eq "else"E= $kw eq "try"F= $kw eq "do"G= $kw eq "await"H= $kw eq "spawn"I= $kw eq "function"J= $kw eq "method"
ABCDEFGHIJresult
1XXXXXXXXX1
01XXXXXXXX1
001XXXXXXX1
0001XXXXXX1
00001XXXXX1
000001XXXX1
0000001XXX1
00000001XX1
000000001X1
00000000011
00000000000
1211 or $kw eq 'class'
1212 or $kw eq 'trait'
1213 or $kw eq 'else'
1214 or $kw eq 'try'
1215 or $kw eq 'do'
1216 or $kw eq 'await'
1217 or $kw eq 'spawn'
1218 or $kw eq 'function'
1219 or $kw eq 'method';
1220 16 return 1;
1221 }
1222  
1223 127 ▶ if ( $prev->is_OP and ( $pv eq ':=' or $pv eq '=' or $pv eq ',' or $pv eq '(' or $pv eq '[' or $pv eq ':' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev->is_OP and $pv eq ":=" || $pv eq "=" || $pv eq "," || $pv eq "(" || $pv eq "[" || $pv eq ":") 25 102 127
Condition83%15/18
$prev->is_OP and $pv eq ":=" || $pv eq "=" || $pv eq "," || $pv eq "(" || $pv eq "[" || $pv eq ":"
!ll&&!rl&&r
010225
$pv eq ":=" or $pv eq "=" or $pv eq "," or $pv eq "(" or $pv eq "[" or $pv eq ":"
l!l&&r!l&&!r
196102
$pv eq ":=" or $pv eq "=" or $pv eq "," or $pv eq "(" or $pv eq "["
l!l&&r!l&&!r
154108
$pv eq ":=" or $pv eq "=" or $pv eq "," or $pv eq "("
l!l&&r!l&&!r
150112
$pv eq ":=" or $pv eq "=" or $pv eq ","
l!l&&r!l&&!r
114112
$pv eq ":=" or $pv eq "="
l!l&&r!l&&!r
110116
MC/DC57%4/7
$prev->is_OP and $pv eq ":=" || $pv eq "=" || $pv eq "," || $pv eq "(" || $pv eq "[" || $pv eq ":"
$prev->is_OP $pv eq ":=" $pv eq "=" $pv eq "," $pv eq "(" $pv eq "[" $pv eq ":"
Truth table62%5/8
A and B or C or D or E or F or G
A= $prev->is_OPB= $pv eq ":="C= $pv eq "="D= $pv eq ","E= $pv eq "("F= $pv eq "["G= $pv eq ":"
ABCDEFGresult
0XXXXXX0
10000000
11XXXXX1
101XXXX1
1001XXX1
10001XX1
100001X1
10000011
1224 25 return 1;
1225 }
1226  
1227 102 ▶ if ( $prev->is_OP and $pv eq ')' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev->is_OP and $pv eq ")") 82 20 102
Condition66%2/3
$prev->is_OP and $pv eq ")"
!ll&&!rl&&r
02082
MC/DC50%1/2
$prev->is_OP and $pv eq ")"
$prev->is_OP $pv eq ")"
Truth table66%2/3
A and B
A= $prev->is_OPB= $pv eq ")"
ABresult
0X0
100
111
1228 82 ▶ my $open_i = defined $pair_for->{ $i - 1 } ? $pair_for->{ $i - 1 } : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $$pair_for{$i - 1} ? : 82 0 82
1229 82 ▶ if ( defined $open_i and $open_i > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $open_i and $open_i > 0) 82 0 82
Condition33%1/3
defined $open_i and $open_i > 0
!ll&&!rl&&r
0082
MC/DC0%0/2
defined $open_i and $open_i > 0
defined $open_i $open_i > 0
Truth table33%1/3
A and B
A= defined $open_iB= $open_i > 0
ABresult
0X0
100
111
1230 82 my $before_open = $tokens->[ $open_i - 1 ];
1231 82 ▶ if ( $before_open->is_KW ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before_open->is_KW) 82 0 82
1232 82 my $kw = $before_open->value;
1233 82 ▶ return 0 if $CONTROL_KW{$kw} or $kw eq 'function' or $kw eq 'method' or $kw eq 'while';
Branch: 1 branch
BranchTrueFalseTotal
if $CONTROL_KW{$kw} or $kw eq "function" or $kw eq "method" or $kw eq "while" 82 0 82
Condition33%3/9
$CONTROL_KW{$kw} or $kw eq "function" or $kw eq "method" or $kw eq "while"
l!l&&r!l&&!r
8200
$CONTROL_KW{$kw} or $kw eq "function" or $kw eq "method"
l!l&&r!l&&!r
8200
$CONTROL_KW{$kw} or $kw eq "function"
l!l&&r!l&&!r
8200
MC/DC0%0/4
$CONTROL_KW{$kw} or $kw eq "function" or $kw eq "method" or $kw eq "while"
$CONTROL_KW{$kw} $kw eq "function" $kw eq "method" $kw eq "while"
Truth table20%1/5
A or B or C or D
A= $CONTROL_KW{$kw}B= $kw eq "function"C= $kw eq "method"D= $kw eq "while"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1234 }
1235 0 ▶ if ( $before_open->is_IDENT and $open_i > 1 and $tokens->[ $open_i - 2 ]->is_KW ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before_open->is_IDENT and $open_i > 1 and $$tokens[$open_i - 2]->is_KW) 0 0 0
Condition0%0/6
$before_open->is_IDENT and $open_i > 1 and $$tokens[$open_i - 2]->is_KW
!ll&&!rl&&r
000
$before_open->is_IDENT and $open_i > 1
!ll&&!rl&&r
000
MC/DC0%0/3
$before_open->is_IDENT and $open_i > 1 and $$tokens[$open_i - 2]->is_KW
$before_open->is_IDENT $open_i > 1 $$tokens[$open_i - 2]->is_KW
Truth table0%0/4
A and B and C
A= $before_open->is_IDENTB= $open_i > 1C= $$tokens[$open_i - 2]->is_KW
ABCresult
0XX0
10X0
1100
1111
1236 0 my $kw = $tokens->[ $open_i - 2 ]->value;
1237 0 ▶ return 0 if $kw eq 'function' or $kw eq 'method';
Branch: 1 branch
BranchTrueFalseTotal
if $kw eq "function" or $kw eq "method" 0 0 0
Condition0%0/3
$kw eq "function" or $kw eq "method"
l!l&&r!l&&!r
000
MC/DC0%0/2
$kw eq "function" or $kw eq "method"
$kw eq "function" $kw eq "method"
Truth table0%0/3
A or B
A= $kw eq "function"B= $kw eq "method"
ABresult
1X1
011
000
1238 }
1239 }
1240 0 return 1;
1241 }
1242  
1243 20 ▶ if ( $prev->is_OP and ( $pv eq ']' or $pv eq '}' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev->is_OP and $pv eq "]" || $pv eq "}") 16 4 20
Condition66%4/6
$prev->is_OP and $pv eq "]" || $pv eq "}"
!ll&&!rl&&r
0416
$pv eq "]" or $pv eq "}"
l!l&&r!l&&!r
1604
MC/DC33%1/3
$prev->is_OP and $pv eq "]" || $pv eq "}"
$prev->is_OP $pv eq "]" $pv eq "}"
Truth table50%2/4
A and B or C
A= $prev->is_OPB= $pv eq "]"C= $pv eq "}"
ABCresult
0XX0
1000
11X1
1011
1244 16 return 1;
1245 }
1246  
1247 4 return 0;
1248 }
1249  
1250 97 ▶sub _is_expression_block_brace {
Subroutine _is_expression_block_brace: called CC=6 SCAR=17.9
1251 97 my ( $tokens, $i ) = @_;
1252 97 ▶ return 0 if $i <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i <= 0 0 97 97
1253  
1254 97 my $prev = $tokens->[ $i - 1 ];
1255 97 ▶ return 0 if !$prev->is_KW;
Branch: 1 branch
BranchTrueFalseTotal
unless $prev->is_KW 69 28 97
1256  
1257 28 my $kw = $prev->value;
1258 28 ▶ return 1 if $kw eq 'await' or $kw eq 'spawn' or $kw eq 'do';
Branch: 1 branch
BranchTrueFalseTotal
if $kw eq "await" or $kw eq "spawn" or $kw eq "do" 20 8 28
Condition100%6/6
$kw eq "await" or $kw eq "spawn" or $kw eq "do"
l!l&&r!l&&!r
1828
$kw eq "await" or $kw eq "spawn"
l!l&&r!l&&!r
16210
MC/DC100%3/3
$kw eq "await" or $kw eq "spawn" or $kw eq "do"
$kw eq "await" $kw eq "spawn" $kw eq "do"
Truth table100%4/4
A or B or C
A= $kw eq "await"B= $kw eq "spawn"C= $kw eq "do"
ABCresult
1XX1
01X1
0011
0000
1259  
1260 8 return 0;
1261 }
1262  
1263 148 ▶sub _can_end_statement {
Subroutine _can_end_statement: called CC=21 SCAR=30.5
1264 148 my ( $tok ) = @_;
1265 148 ▶ return 1 if $tok->is_IDENT or $tok->is_NUMBER or $tok->is_STRING or $tok->is_BOOL or $tok->is_NULL;
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_IDENT or $tok->is_NUMBER or $tok->is_STRING or $tok->is_BOOL or $tok->is_NULL 64 84 148
Condition91%11/12
$tok->is_IDENT or $tok->is_NUMBER or $tok->is_STRING or $tok->is_BOOL or $tok->is_NULL
l!l&&r!l&&!r
64084
$tok->is_IDENT or $tok->is_NUMBER or $tok->is_STRING or $tok->is_BOOL
l!l&&r!l&&!r
60484
$tok->is_IDENT or $tok->is_NUMBER or $tok->is_STRING
l!l&&r!l&&!r
461488
$tok->is_IDENT or $tok->is_NUMBER
l!l&&r!l&&!r
2224102
MC/DC80%4/5
$tok->is_IDENT or $tok->is_NUMBER or $tok->is_STRING or $tok->is_BOOL or $tok->is_NULL
$tok->is_IDENT $tok->is_NUMBER $tok->is_STRING $tok->is_BOOL $tok->is_NULL
Truth table83%5/6
A or B or C or D or E
A= $tok->is_IDENTB= $tok->is_NUMBERC= $tok->is_STRINGD= $tok->is_BOOLE= $tok->is_NULL
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1266 84 ▶ return 1 if $tok->is_type('BINARY_STRING');
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_type("BINARY_STRING") 2 82 84
1267 82 ▶ return 1 if $tok->is_REGEXP or $tok->is_type('TEMPLATE') or $tok->is_EMPTY_SET;
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_REGEXP or $tok->is_type("TEMPLATE") or $tok->is_EMPTY_SET 2 80 82
Condition83%5/6
$tok->is_REGEXP or $tok->is_type("TEMPLATE") or $tok->is_EMPTY_SET
l!l&&r!l&&!r
1180
$tok->is_REGEXP or $tok->is_type("TEMPLATE")
l!l&&r!l&&!r
0181
MC/DC66%2/3
$tok->is_REGEXP or $tok->is_type("TEMPLATE") or $tok->is_EMPTY_SET
$tok->is_REGEXP $tok->is_type("TEMPLATE") $tok->is_EMPTY_SET
Truth table75%3/4
A or B or C
A= $tok->is_REGEXPB= $tok->is_type("TEMPLATE")C= $tok->is_EMPTY_SET
ABCresult
1XX1
01X1
0011
0000
1268 80 ▶ return 1 if $tok->is_OP and (
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_OP and $tok->value eq ")" || $tok->value eq "]" || $tok->value eq "}" || $tok->value eq "\x{230b}" || $tok->value eq "\x{2309}" || $tok->value eq "\x{bb}" || $tok->value eq ">>" || $tok->value eq ">>>" || $tok->value eq "++" || $tok->value eq "--" 60 20 80
Condition96%29/30
$tok->is_OP and $tok->value eq ")" || $tok->value eq "]" || $tok->value eq "}" || $tok->value eq "\x{230b}" || $tok->value eq "\x{2309}" || $tok->value eq "\x{bb}" || $tok->value eq ">>" || $tok->value eq ">>>" || $tok->value eq "++" || $tok->value eq "--"
!ll&&!rl&&r
71360
$tok->value eq ")" or $tok->value eq "]" or $tok->value eq "}" or $tok->value eq "\x{230b}" or $tok->value eq "\x{2309}" or $tok->value eq "\x{bb}" or $tok->value eq ">>" or $tok->value eq ">>>" or $tok->value eq "++" or $tok->value eq "--"
l!l&&r!l&&!r
60013
$tok->value eq ")" or $tok->value eq "]" or $tok->value eq "}" or $tok->value eq "\x{230b}" or $tok->value eq "\x{2309}" or $tok->value eq "\x{bb}" or $tok->value eq ">>" or $tok->value eq ">>>" or $tok->value eq "++"
l!l&&r!l&&!r
59113
$tok->value eq ")" or $tok->value eq "]" or $tok->value eq "}" or $tok->value eq "\x{230b}" or $tok->value eq "\x{2309}" or $tok->value eq "\x{bb}" or $tok->value eq ">>" or $tok->value eq ">>>"
l!l&&r!l&&!r
56314
$tok->value eq ")" or $tok->value eq "]" or $tok->value eq "}" or $tok->value eq "\x{230b}" or $tok->value eq "\x{2309}" or $tok->value eq "\x{bb}" or $tok->value eq ">>"
l!l&&r!l&&!r
47917
$tok->value eq ")" or $tok->value eq "]" or $tok->value eq "}" or $tok->value eq "\x{230b}" or $tok->value eq "\x{2309}" or $tok->value eq "\x{bb}"
l!l&&r!l&&!r
46126
$tok->value eq ")" or $tok->value eq "]" or $tok->value eq "}" or $tok->value eq "\x{230b}" or $tok->value eq "\x{2309}"
l!l&&r!l&&!r
45127
$tok->value eq ")" or $tok->value eq "]" or $tok->value eq "}" or $tok->value eq "\x{230b}"
l!l&&r!l&&!r
44128
$tok->value eq ")" or $tok->value eq "]" or $tok->value eq "}"
l!l&&r!l&&!r
38629
$tok->value eq ")" or $tok->value eq "]"
l!l&&r!l&&!r
30835
MC/DC90%10/11
$tok->is_OP and $tok->value eq ")" || $tok->value eq "]" || $tok->value eq "}" || $tok->value eq "\x{230b}" || $tok->value eq "\x{2309}" || $tok->value eq "\x{bb}" || $tok->value eq ">>" || $tok->value eq ">>>" || $tok->value eq "++" || $tok->value eq "--"
$tok->is_OP $tok->value eq ")" $tok->value eq "]" $tok->value eq "}" $tok->value eq "\x{230b}" $tok->value eq "\x{2309}" $tok->value eq "\x{bb}" $tok->value eq ">>" $tok->value eq ">>>" $tok->value eq "++" $tok->value eq "--"
Truth table91%11/12
A and B or C or D or E or F or G or H or I or J or K
A= $tok->is_OPB= $tok->value eq ")"C= $tok->value eq "]"D= $tok->value eq "}"E= $tok->value eq "\x{230b}"F= $tok->value eq "\x{2309}"G= $tok->value eq "\x{bb}"H= $tok->value eq ">>"I= $tok->value eq ">>>"J= $tok->value eq "++"K= $tok->value eq "--"
ABCDEFGHIJKresult
0XXXXXXXXXX0
100000000000
11XXXXXXXXX1
101XXXXXXXX1
1001XXXXXXX1
10001XXXXXX1
100001XXXXX1
1000001XXXX1
10000001XXX1
100000001XX1
1000000001X1
100000000011
1269 $tok->value eq ')'
1270 or $tok->value eq ']'
1271 or $tok->value eq '}'
1272 or $tok->value eq '⌋'
1273 or $tok->value eq '⌉'
1274 or $tok->value eq '»'
1275 or $tok->value eq '>>'
1276 or $tok->value eq '>>>'
1277 or $tok->value eq '++'
1278 or $tok->value eq '--'
1279 );
1280  
1281 20 return 0;
1282 }
1283  
1284 90 ▶sub _can_start_statement {
Subroutine _can_start_statement: called CC=20 SCAR=42.8
1285 90 my ( $tok ) = @_;
1286 90 ▶ return 1 if $tok->is_IDENT or $tok->is_KW;
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_IDENT or $tok->is_KW 83 7 90
Condition100%3/3
$tok->is_IDENT or $tok->is_KW
l!l&&r!l&&!r
21627
MC/DC100%2/2
$tok->is_IDENT or $tok->is_KW
$tok->is_IDENT $tok->is_KW
Truth table100%3/3
A or B
A= $tok->is_IDENTB= $tok->is_KW
ABresult
1X1
011
000
1287 7 ▶ return 1 if $tok->is_NUMBER or $tok->is_STRING or $tok->is_BOOL or $tok->is_NULL;
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_NUMBER or $tok->is_STRING or $tok->is_BOOL or $tok->is_NULL 0 7 7
Condition33%3/9
$tok->is_NUMBER or $tok->is_STRING or $tok->is_BOOL or $tok->is_NULL
l!l&&r!l&&!r
007
$tok->is_NUMBER or $tok->is_STRING or $tok->is_BOOL
l!l&&r!l&&!r
007
$tok->is_NUMBER or $tok->is_STRING
l!l&&r!l&&!r
007
MC/DC0%0/4
$tok->is_NUMBER or $tok->is_STRING or $tok->is_BOOL or $tok->is_NULL
$tok->is_NUMBER $tok->is_STRING $tok->is_BOOL $tok->is_NULL
Truth table20%1/5
A or B or C or D
A= $tok->is_NUMBERB= $tok->is_STRINGC= $tok->is_BOOLD= $tok->is_NULL
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1288 7 ▶ return 1 if $tok->is_REGEXP or $tok->is_EMPTY_SET;
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_REGEXP or $tok->is_EMPTY_SET 0 7 7
Condition33%1/3
$tok->is_REGEXP or $tok->is_EMPTY_SET
l!l&&r!l&&!r
007
MC/DC0%0/2
$tok->is_REGEXP or $tok->is_EMPTY_SET
$tok->is_REGEXP $tok->is_EMPTY_SET
Truth table33%1/3
A or B
A= $tok->is_REGEXPB= $tok->is_EMPTY_SET
ABresult
1X1
011
000
1289 7 ▶ return 1 if $tok->is_type('BINARY_STRING') or $tok->is_type('TEMPLATE');
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_type("BINARY_STRING") or $tok->is_type("TEMPLATE") 0 7 7
Condition33%1/3
$tok->is_type("BINARY_STRING") or $tok->is_type("TEMPLATE")
l!l&&r!l&&!r
007
MC/DC0%0/2
$tok->is_type("BINARY_STRING") or $tok->is_type("TEMPLATE")
$tok->is_type("BINARY_STRING") $tok->is_type("TEMPLATE")
Truth table33%1/3
A or B
A= $tok->is_type("BINARY_STRING")B= $tok->is_type("TEMPLATE")
ABresult
1X1
011
000
1290 7 ▶ return 1 if $tok->is_OP and (
Branch: 1 branch
BranchTrueFalseTotal
if $tok->is_OP and $tok->value eq "(" || $tok->value eq "[" || $tok->value eq "{" || $tok->value eq "<<" || $tok->value eq "<<<" || $tok->value eq "\x{ab}" || $tok->value eq "\x{230a}" || $tok->value eq "\x{2308}" 0 7 7
Condition33%8/24
$tok->is_OP and $tok->value eq "(" || $tok->value eq "[" || $tok->value eq "{" || $tok->value eq "<<" || $tok->value eq "<<<" || $tok->value eq "\x{ab}" || $tok->value eq "\x{230a}" || $tok->value eq "\x{2308}"
!ll&&!rl&&r
070
$tok->value eq "(" or $tok->value eq "[" or $tok->value eq "{" or $tok->value eq "<<" or $tok->value eq "<<<" or $tok->value eq "\x{ab}" or $tok->value eq "\x{230a}" or $tok->value eq "\x{2308}"
l!l&&r!l&&!r
007
$tok->value eq "(" or $tok->value eq "[" or $tok->value eq "{" or $tok->value eq "<<" or $tok->value eq "<<<" or $tok->value eq "\x{ab}" or $tok->value eq "\x{230a}"
l!l&&r!l&&!r
007
$tok->value eq "(" or $tok->value eq "[" or $tok->value eq "{" or $tok->value eq "<<" or $tok->value eq "<<<" or $tok->value eq "\x{ab}"
l!l&&r!l&&!r
007
$tok->value eq "(" or $tok->value eq "[" or $tok->value eq "{" or $tok->value eq "<<" or $tok->value eq "<<<"
l!l&&r!l&&!r
007
$tok->value eq "(" or $tok->value eq "[" or $tok->value eq "{" or $tok->value eq "<<"
l!l&&r!l&&!r
007
$tok->value eq "(" or $tok->value eq "[" or $tok->value eq "{"
l!l&&r!l&&!r
007
$tok->value eq "(" or $tok->value eq "["
l!l&&r!l&&!r
007
MC/DC0%0/9
$tok->is_OP and $tok->value eq "(" || $tok->value eq "[" || $tok->value eq "{" || $tok->value eq "<<" || $tok->value eq "<<<" || $tok->value eq "\x{ab}" || $tok->value eq "\x{230a}" || $tok->value eq "\x{2308}"
$tok->is_OP $tok->value eq "(" $tok->value eq "[" $tok->value eq "{" $tok->value eq "<<" $tok->value eq "<<<" $tok->value eq "\x{ab}" $tok->value eq "\x{230a}" $tok->value eq "\x{2308}"
Truth table10%1/10
A and B or C or D or E or F or G or H or I
A= $tok->is_OPB= $tok->value eq "("C= $tok->value eq "["D= $tok->value eq "{"E= $tok->value eq "<<"F= $tok->value eq "<<<"G= $tok->value eq "\x{ab}"H= $tok->value eq "\x{230a}"I= $tok->value eq "\x{2308}"
ABCDEFGHIresult
0XXXXXXXX0
1000000000
11XXXXXXX1
101XXXXXX1
1001XXXXX1
10001XXXX1
100001XXX1
1000001XX1
10000001X1
1000000011
1291 $tok->value eq '('
1292 or $tok->value eq '['
1293 or $tok->value eq '{'
1294 or $tok->value eq '<<'
1295 or $tok->value eq '<<<'
1296 or $tok->value eq '«'
1297 or $tok->value eq '⌊'
1298 or $tok->value eq '⌈'
1299 );
1300  
1301 7 return 0;
1302 }
1303  
1304 6993 ▶sub _token_text {
Subroutine _token_text: called CC=17 SCAR=29.3
1305 6993 my ( $tok ) = @_;
1306  
1307 6993 ▶ if ( $tok->is_STRING ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->is_STRING) 346 6647 6993
1308 346 ▶ my $value = defined $tok->value ? $tok->value : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $tok->value ? : 346 0 346
1309 346 return '"' . _escape_literal( $value, '"' ) . '"';
1310 }
1311 6647 ▶ if ( $tok->is_type('BINARY_STRING') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->is_type("BINARY_STRING")) 6 6641 6647
1312 6 ▶ my $value = defined $tok->value ? $tok->value : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $tok->value ? : 6 0 6
1313 6 return "'" . _escape_literal( $value, "'" ) . "'";
1314 }
1315 6641 ▶ if ( $tok->is_BOOL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->is_BOOL) 30 6611 6641
1316 30 ▶ return $tok->value ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$tok->value ? : 10 20 30
1317 }
1318 6611 ▶ if ( $tok->is_NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->is_NULL) 8 6603 6611
1319 8 return 'null';
1320 }
1321 6603 ▶ if ( $tok->is_REGEXP ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->is_REGEXP) 6 6597 6603
1322 6 my $re = $tok->value;
1323 6 ▶ my $flags = $re->{flags} // '';
Condition50%1/2
$re->{"flags"} // ""
l!l
60
MC/DC0%0/1
$re->{"flags"} // ""
$re->{"flags"}
Truth table50%1/2
A
A= $re->{"flags"}
Aresult
11
00
1324 my $pattern = exists $re->{parts}
1325 ? _flatten_interpolated_parts( $re->{parts} )
1326 6 ▶ : ( $re->{pattern} // '' );
Branch: 1 branch
BranchTrueFalseTotal
exists $re->{'parts'} ? : 6 0 6
Condition0%0/2
$re->{"pattern"} // ""
l!l
00
MC/DC0%0/1
$re->{"pattern"} // ""
$re->{"pattern"}
Truth table0%0/2
A
A= $re->{"pattern"}
Aresult
11
00
1327 6 return '/' . $pattern . '/' . $flags;
1328 }
1329 6597 ▶ if ( $tok->is_type('TEMPLATE') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->is_type("TEMPLATE")) 10 6587 6597
1330 10 ▶ my $value = defined $tok->value ? $tok->value : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $tok->value ? : 10 0 10
1331 10 ▶ return '`' . _flatten_interpolated_parts( $value, 1 ) . '`'
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "ARRAY" 10 0 10
1332 if ref $value eq 'ARRAY';
1333 0 return '`' . _escape_literal( $value, '`' ) . '`';
1334 }
1335 6587 ▶ if ( $tok->is_EMPTY_SET ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok->is_EMPTY_SET) 2 6585 6587
1336 2 return '∅';
1337 }
1338  
1339 6585 ▶ return defined $tok->value ? $tok->value : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $tok->value ? : 6585 0 6585
1340 }
1341  
1342 16 ▶sub _flatten_interpolated_parts {
Subroutine _flatten_interpolated_parts: called CC=8 SCAR=21.3
1343 16 my ( $parts, $escape_text ) = @_;
1344  
1345 16 ▶ return '' if ref $parts ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $parts ne "ARRAY" 0 16 16
1346  
1347 16 my $out = '';
1348 16 for my $part ( @$parts ) {
1349 26 ▶ if ( exists $part->{text} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $part->{'text'}) { } 16 10 26
elsif (exists $part->{'expr'}) { } 10 0 10
1350 16 ▶ my $text = $part->{text} // '';
Condition50%1/2
$part->{"text"} // ""
l!l
160
MC/DC0%0/1
$part->{"text"} // ""
$part->{"text"}
Truth table50%1/2
A
A= $part->{"text"}
Aresult
11
00
1351 16 ▶ $text = _escape_literal( $text, '`' ) if $escape_text;
Branch: 1 branch
BranchTrueFalseTotal
if $escape_text 10 6 16
1352 16 $out .= $text;
1353 }
1354 elsif ( exists $part->{expr} ) {
1355 10 ▶ $out .= '${' . ( $part->{expr} // '' ) . '}';
Condition50%1/2
$part->{"expr"} // ""
l!l
100
MC/DC0%0/1
$part->{"expr"} // ""
$part->{"expr"}
Truth table50%1/2
A
A= $part->{"expr"}
Aresult
11
00
1356 }
1357 }
1358  
1359 16 return $out;
1360 }
1361  
1362 362 ▶sub _escape_literal {
Subroutine _escape_literal: called CC=1 SCAR=0.0
1363 362 my ( $value, $quote ) = @_;
1364 362 $value =~ s/\\/\\\\/g;
1365 362 $value =~ s/\Q$quote\E/\\$quote/g;
1366 362 $value =~ s/\n/\\n/g;
1367 362 $value =~ s/\r/\\r/g;
1368 362 $value =~ s/\t/\\t/g;
1369  
1370 362 return $value;
1371 }
1372  
1373 3000 ▶sub _visual_length {
Subroutine _visual_length: called CC=3 SCAR=11.0
1374 3000 my ( $line ) = @_;
1375 3000 my $len = 0;
1376 3000 for my $ch ( split //, $line ) {
1377 61152 ▶ $len += ( $ch eq "\t" ) ? 4 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$ch eq "\t" ? : 1549 59603 61152
1378 }
1379  
1380 3000 return $len;
1381 }
1382  
1383 624 ▶sub _rstrip {
Subroutine _rstrip: called CC=1 SCAR=0.0
1384 624 my ( $value ) = @_;
1385 624 $value =~ s/[ \t]+\z//;
1386  
1387 624 return $value;
1388 }
1389  
1390 38 ▶sub _stash_multiline_comments {
Subroutine _stash_multiline_comments: called CC=1 SCAR=0.0
1391 38 my ( $src, $comment_map ) = @_;
1392 38 my $counter = 0;
1393  
1394 38 $src =~ s{
1395 /\* .*? \*/
1396 }{
1397 2 my $placeholder = '__ZUZU_TIDY_COMMENT_' . $counter . '__';
1398 2 $comment_map->{$placeholder} = $&;
1399 2 $counter++;
1400 2 "\n$placeholder\n";
1401 }egsx;
1402  
1403 38 return $src;
1404 }
1405  
1406 40 ▶sub _restore_multiline_comments {
Subroutine _restore_multiline_comments: called CC=5 SCAR=16.1
1407 40 my ( $src, $comment_map ) = @_;
1408 40 my @lines = split /\n/, $src, -1;
1409 40 my @out;
1410  
1411 40 for my $line ( @lines ) {
1412 664 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^([ \t]*)(__ZUZU_TIDY_COMMENT_\d+__)(?:;)?\z/ and exists $comment_map->{$2}) 2 662 664
Condition66%2/3
$line =~ /^([ \t]*)(__ZUZU_TIDY_COMMENT_\d+__)(?:;)?\z/ and exists $comment_map->{$2}
!ll&&!rl&&r
66202
MC/DC50%1/2
$line =~ /^([ \t]*)(__ZUZU_TIDY_COMMENT_\d+__)(?:;)?\z/ and exists $comment_map->{$2}
$line =~ /^([ \t]*)(__ZUZU_TIDY_COMMENT_\d+__)(?:;)?\z/ exists $comment_map->{$2}
Truth table66%2/3
A and B
A= $line =~ /^([ \t]*)(__ZUZU_TIDY_COMMENT_\d+__)(?:;)?\z/B= exists $comment_map->{$2}
ABresult
0X0
100
111
1413 $line =~ /^([ \t]*)(__ZUZU_TIDY_COMMENT_\d+__)(?:;)?\z/
1414 and exists $comment_map->{$2}
1415 ) {
1416 2 my $indent = $1;
1417 2 my $comment = $comment_map->{$2};
1418 2 my @comment_lines = split /\n/, $comment, -1;
1419 2 for my $comment_line ( @comment_lines ) {
1420 3 push @out, $indent . $comment_line;
1421 }
1422 2 next;
1423 }
1424  
1425 662 push @out, $line;
1426 }
1427  
1428 40 return join "\n", @out;
1429 }
1430  
1431 40 ▶sub _strip_multiline_comments_for_parse {
Subroutine _strip_multiline_comments_for_parse: called CC=1 SCAR=0.0
1432 40 my ( $src ) = @_;
1433 40 $src =~ s{/\* .*? \*/}{}gsx;
1434  
1435 40 return $src;
1436 }
1437  
1438 40 ▶sub _apply_vertical_spacing_rules {
Subroutine _apply_vertical_spacing_rules: called CC=47 SCAR=38.6
1439 40 my ( $src ) = @_;
1440 40 my @lines = split /\n/, $src, -1;
1441 40 ▶ pop @lines if @lines and $lines[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
if @lines and $lines[-1] eq "" 40 0 40
Condition33%1/3
@lines and $lines[-1] eq ""
!ll&&!rl&&r
0040
MC/DC0%0/2
@lines and $lines[-1] eq ""
@lines $lines[-1] eq ""
Truth table33%1/3
A and B
A= @linesB= $lines[-1] eq ""
ABresult
0X0
100
111
1442 40 ▶ return $src if ! @lines;
Branch: 1 branch
BranchTrueFalseTotal
unless @lines 0 40 40
1443  
1444 40 my ( @open_for_line, @close_for_line );
1445 40 my @stack;
1446 40 my $paren_bracket_depth = 0;
1447  
1448 40 for my $i ( 0 .. $#lines ) {
1449 625 my $trimmed = $lines[$i];
1450 625 $trimmed =~ s/^\s+//;
1451 625 $trimmed =~ s/\s+\z//;
1452  
1453 # Track paren/bracket nesting across lines (approximate: doesn't
1454 # account for parens inside string literals) so a brace opened
1455 # while still inside an unclosed `(`/`[` -- e.g. a callback body
1456 # passed as a call argument -- can be told apart from a real
1457 # top-level statement block below.
1458 625 my $opens = () = $trimmed =~ /[(\[]/g;
1459 625 my $closes = () = $trimmed =~ /[)\]]/g;
1460  
1461 625 ▶ if ( $trimmed =~ /\{\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trimmed =~ /\{\z/) 97 528 625
1462 97 my $kind = 'block';
1463 97 ▶ if ( $trimmed =~ /^(function|method)\b/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($trimmed =~ /^(function|method)\b/) { } 22 75 97
elsif ($trimmed =~ /^(if|else|while|for|try|catch|switch|unless)\b/) { } 28 47 75
1464 22 $kind = $1;
1465 }
1466 elsif ( $trimmed =~ /^(if|else|while|for|try|catch|switch|unless)\b/ ) {
1467 28 $kind = 'statement_block';
1468 }
1469 97 ▶ push @stack, {
Branch: 1 branch
BranchTrueFalseTotal
$paren_bracket_depth + $opens - $closes > 0 ? : 16 81 97
1470 kind => $kind,
1471 start => $i,
1472 is_call_argument => ( $paren_bracket_depth + $opens - $closes > 0 ) ? 1 : 0,
1473 };
1474 97 $open_for_line[$i] = $stack[-1];
1475 }
1476  
1477 625 $paren_bracket_depth += $opens - $closes;
1478  
1479 625 ▶ if ( $trimmed =~ /^\}/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trimmed =~ /^\}/) 97 528 625
1480 97 ▶ next if ! @stack;
Branch: 1 branch
BranchTrueFalseTotal
unless @stack 0 97 97
1481 97 my $block = pop @stack;
1482 97 $block->{end} = $i;
1483 97 $close_for_line[$i] = $block;
1484 }
1485 }
1486  
1487 40 my %blank_before;
1488 my %blank_after;
1489  
1490 40 for my $i ( 0 .. $#lines ) {
1491 625 my $open_block = $open_for_line[$i];
1492 625 ▶ if ($open_block) {
Branch: 1 branch
BranchTrueFalseTotal
if ($open_block) 97 528 625
1493 97 my $kind = $open_block->{kind};
1494 97 ▶ if ( ( $kind eq 'function' or $kind eq 'method' ) and ! $open_block->{is_call_argument} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "function" || $kind eq "method" and not $open_block->{"is_call_argument"}) 19 78 97
Condition100%6/6
$kind eq "function" || $kind eq "method" and not $open_block->{"is_call_argument"}
!ll&&!rl&&r
75319
$kind eq "function" or $kind eq "method"
l!l&&r!l&&!r
15775
MC/DC100%3/3
$kind eq "function" || $kind eq "method" and not $open_block->{"is_call_argument"}
$kind eq "function" $kind eq "method" not $open_block->{"is_call_argument"}
Truth table80%4/5
A or B and not(C)
A= $kind eq "function"B= $kind eq "method"C= not $open_block->{"is_call_argument"}
ABCresult
00X0
1X00
0100
1X11
0111
1495 19 $blank_before{$i} = 1;
1496 }
1497 }
1498  
1499 625 my $close_block = $close_for_line[$i];
1500 625 ▶ if ($close_block) {
Branch: 1 branch
BranchTrueFalseTotal
if ($close_block) 97 528 625
1501 97 my $kind = $close_block->{kind};
1502 97 my $len = $close_block->{end} - $close_block->{start} + 1;
1503 97 ▶ if ( ( $kind eq 'function' or $kind eq 'method' ) and ! $close_block->{is_call_argument} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "function" || $kind eq "method" and not $close_block->{"is_call_argument"}) 19 78 97
Condition100%6/6
$kind eq "function" || $kind eq "method" and not $close_block->{"is_call_argument"}
!ll&&!rl&&r
75319
$kind eq "function" or $kind eq "method"
l!l&&r!l&&!r
15775
MC/DC100%3/3
$kind eq "function" || $kind eq "method" and not $close_block->{"is_call_argument"}
$kind eq "function" $kind eq "method" not $close_block->{"is_call_argument"}
Truth table80%4/5
A or B and not(C)
A= $kind eq "function"B= $kind eq "method"C= not $close_block->{"is_call_argument"}
ABCresult
00X0
1X00
0100
1X11
0111
1504 19 my $next_nonblank = _next_nonblank_line( \@lines, $i + 1 );
1505 19 ▶ if ( defined $next_nonblank and $lines[$next_nonblank] !~ /^\s*\}/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $next_nonblank and not $lines[$next_nonblank] =~ /^\s*\}/) 12 7 19
Condition100%3/3
defined $next_nonblank and not $lines[$next_nonblank] =~ /^\s*\}/
!ll&&!rl&&r
3412
MC/DC100%2/2
defined $next_nonblank and not $lines[$next_nonblank] =~ /^\s*\}/
defined $next_nonblank not $lines[$next_nonblank] =~ /^\s*\}/
Truth table100%3/3
A and not(B)
A= defined $next_nonblankB= not $lines[$next_nonblank] =~ /^\s*\}/
ABresult
0X0
100
111
1506 12 $blank_after{$i} = 1;
1507 }
1508 }
1509 97 ▶ if ( $len >= 5 and ! $close_block->{is_call_argument} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len >= 5 and not $close_block->{"is_call_argument"}) 31 66 97
Condition100%3/3
$len >= 5 and not $close_block->{"is_call_argument"}
!ll&&!rl&&r
65131
MC/DC100%2/2
$len >= 5 and not $close_block->{"is_call_argument"}
$len >= 5 not $close_block->{"is_call_argument"}
Truth table100%3/3
A and not(B)
A= $len >= 5B= not $close_block->{"is_call_argument"}
ABresult
0X0
100
111
1510 31 $blank_before{ $close_block->{start} } = 1;
1511 31 my $next_nonblank = _next_nonblank_line( \@lines, $i + 1 );
1512 31 ▶ my $cuddles = defined $next_nonblank
Condition100%3/3
defined $next_nonblank && $lines[$next_nonblank] =~ /^\s*(?:catch|else)\b/
!ll&&!rl&&r
6214
MC/DC100%2/2
defined $next_nonblank && $lines[$next_nonblank] =~ /^\s*(?:catch|else)\b/
defined $next_nonblank $lines[$next_nonblank] =~ /^\s*(?:catch|else)\b/
Truth table100%3/3
A && B
A= defined $next_nonblankB= $lines[$next_nonblank] =~ /^\s*(?:catch|else)\b/
ABresult
0X0
100
111
1513 && $lines[$next_nonblank] =~ /^\s*(?:catch|else)\b/;
1514 31 ▶ $blank_after{$i} = 1 if ! $cuddles;
Branch: 1 branch
BranchTrueFalseTotal
unless $cuddles 27 4 31
1515 }
1516 }
1517  
1518 625 ▶ if ( $lines[$i] =~ /^\s*\/\*/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lines[$i] =~ m[^\s*/\*]) 2 623 625
1519 2 ▶ my $is_multiline = $lines[$i] !~ /\*\/\s*\z/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!($lines[$i] =~ m[\*/\s*\z]) ? : 1 1 2
1520 2 ▶ $blank_before{$i} = 1 if $is_multiline;
Branch: 1 branch
BranchTrueFalseTotal
if $is_multiline 1 1 2
1521 }
1522 }
1523  
1524 40 for my $i ( 0 .. $#lines ) {
1525 625 my $trimmed = $lines[$i];
1526 625 $trimmed =~ s/^\s+//;
1527 625 $trimmed =~ s/\s+\z//;
1528 625 ▶ next if $trimmed !~ /^return\b/;
Branch: 1 branch
BranchTrueFalseTotal
unless $trimmed =~ /^return\b/ 595 30 625
1529  
1530 30 my $next_nonblank = _next_nonblank_line( \@lines, $i + 1 );
1531 30 ▶ next if ! defined $next_nonblank;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next_nonblank 0 30 30
1532 30 ▶ next if $lines[$next_nonblank] !~ /^\s*\}/;
Branch: 1 branch
BranchTrueFalseTotal
unless $lines[$next_nonblank] =~ /^\s*\}/ 2 28 30
1533  
1534 28 my $closing_block = $close_for_line[$next_nonblank];
1535 28 ▶ next if ! $closing_block;
Branch: 1 branch
BranchTrueFalseTotal
unless $closing_block 0 28 28
1536 next if $closing_block->{kind} ne 'function'
1537 28 ▶ and $closing_block->{kind} ne 'method';
Branch: 1 branch
BranchTrueFalseTotal
if $closing_block->{"kind"} ne "function" and $closing_block->{"kind"} ne "method" 10 18 28
Condition100%3/3
$closing_block->{"kind"} ne "function" and $closing_block->{"kind"} ne "method"
!ll&&!rl&&r
12610
MC/DC100%2/2
$closing_block->{"kind"} ne "function" and $closing_block->{"kind"} ne "method"
$closing_block->{"kind"} ne "function" $closing_block->{"kind"} ne "method"
Truth table100%3/3
A and B
A= $closing_block->{"kind"} ne "function"B= $closing_block->{"kind"} ne "method"
ABresult
0X0
100
111
1538 18 my $function_lines = $closing_block->{end} - $closing_block->{start} - 1;
1539 18 ▶ next if $function_lines <= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $function_lines <= 2 12 6 18
1540 6 $blank_before{$i} = 1;
1541 }
1542  
1543 40 my @out;
1544 40 for my $i ( 0 .. $#lines ) {
1545 625 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($blank_before{$i} and @out and $out[-1] =~ /\S/) 27 598 625
Condition100%6/6
$blank_before{$i} and @out and $out[-1] =~ /\S/
!ll&&!rl&&r
5841427
$blank_before{$i} and @out
!ll&&!rl&&r
575941
MC/DC100%3/3
$blank_before{$i} and @out and $out[-1] =~ /\S/
$blank_before{$i} @out $out[-1] =~ /\S/
Truth table100%4/4
A and B and C
A= $blank_before{$i}B= @outC= $out[-1] =~ /\S/
ABCresult
0XX0
10X0
1100
1111
1546 $blank_before{$i}
1547 and @out
1548 and $out[-1] =~ /\S/
1549 ) {
1550 27 push @out, '';
1551 }
1552  
1553 625 push @out, $lines[$i];
1554  
1555 625 ▶ if ( $blank_after{$i} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($blank_after{$i}) 35 590 625
1556 35 my $next_nonblank = _next_nonblank_line( \@lines, $i + 1 );
1557 35 ▶ if ( defined $next_nonblank ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $next_nonblank) 29 6 35
1558 29 ▶ push @out, '' if $out[-1] =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $out[-1] =~ /\S/ 29 0 29
1559 }
1560 }
1561 }
1562  
1563 40 my @collapsed;
1564 40 my $previous_blank = 0;
1565 40 for my $line ( @out ) {
1566 681 ▶ if ( $line !~ /\S/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ /\S/) 56 625 681
1567 56 ▶ next if $previous_blank;
Branch: 1 branch
BranchTrueFalseTotal
if $previous_blank 0 56 56
1568 56 $previous_blank = 1;
1569 56 push @collapsed, '';
1570 56 next;
1571 }
1572 625 $previous_blank = 0;
1573 625 push @collapsed, $line;
1574 }
1575  
1576 40 return join( "\n", @collapsed ) . "\n";
1577 }
1578  
1579 115 ▶sub _next_nonblank_line {
Subroutine _next_nonblank_line: called CC=3 SCAR=11.1
1580 115 my ( $lines, $start ) = @_;
1581 115 for my $i ( $start .. $#$lines ) {
1582 100 ▶ return $i if $lines->[$i] =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $lines->[$i] =~ /\S/ 100 0 100
1583 }
1584  
1585 15 return undef;
1586 }
1587  
1588 26 ▶sub _find_matching_sequence_close {
Subroutine _find_matching_sequence_close: called CC=6 SCAR=18.3
1589 # Depth-aware search for the close delimiter matching the open
1590 # delimiter already consumed at the start of $after_open. Unlike a
1591 # plain textual scan for the first occurrence of $close, this tracks
1592 # nesting so an inner occurrence of the same bracket type (e.g. the
1593 # index brackets in `async_lambdas[0]` nested inside an outer `[ ... ]`
1594 # array literal) is not mistaken for the outer literal's close.
1595 26 my ( $lines, $start_i, $after_open, $open, $close ) = @_;
1596 26 my $depth = 1;
1597  
1598 26 for my $j ( $start_i .. $#$lines ) {
1599 29 ▶ my $text = $j == $start_i ? $after_open : $lines->[$j];
Branch: 1 branch
BranchTrueFalseTotal
$j == $start_i ? : 26 3 29
1600 29 ▶ while ( $text =~ /(\Q$open\E|\Q$close\E)/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /(\Q$open\E|\Q$close\E)/g) 26 3 29
1601 26 ▶ if ( $1 eq $open ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq $open) { } 0 26 26
1602 0 $depth++;
1603 }
1604 else {
1605 26 $depth--;
1606 26 ▶ if ( $depth == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth == 0) 26 0 26
1607 26 my $end = pos($text);
1608 26 my $before = substr( $text, 0, $end - length($1) );
1609 26 my $after = substr( $text, $end );
1610 26 return ( $j, $before, $after );
1611 }
1612 }
1613 }
1614 }
1615  
1616 0 return ();
1617 }
1618  
1619 3 ▶sub _split_top_level_commas {
Subroutine _split_top_level_commas: called CC=23 SCAR=44.9
1620 # Splits already-joined inner sequence content on commas, but only at
1621 # bracket depth 0 -- a comma inside a nested array/call/set/etc item
1622 # (e.g. reconstructing a sequence whose items are themselves bracketed
1623 # sub-expressions) must stay with that item rather than being treated
1624 # as another top-level separator.
1625 3 my ( $text ) = @_;
1626 3 my @parts;
1627 3 my $depth = 0;
1628 3 my $current = '';
1629 3 my $pos = 0;
1630 3 my $len = length $text;
1631  
1632 3 ▶ while ( $pos < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < $len) 498 3 501
1633 498 my $three = substr( $text, $pos, 3 );
1634 498 ▶ if ( $three eq '<<<' or $three eq '>>>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($three eq "<<<" or $three eq ">>>") 0 498 498
Condition33%1/3
$three eq "<<<" or $three eq ">>>"
l!l&&r!l&&!r
00498
MC/DC0%0/2
$three eq "<<<" or $three eq ">>>"
$three eq "<<<" $three eq ">>>"
Truth table33%1/3
A or B
A= $three eq "<<<"B= $three eq ">>>"
ABresult
1X1
011
000
1635 0 ▶ $depth += $three eq '<<<' ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$three eq '<<<' ? : 0 0 0
1636 0 $current .= $three;
1637 0 $pos += 3;
1638 0 next;
1639 }
1640 498 my $two = substr( $text, $pos, 2 );
1641 498 ▶ if ( $two eq '<<' or $two eq '>>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($two eq "<<" or $two eq ">>") 0 498 498
Condition33%1/3
$two eq "<<" or $two eq ">>"
l!l&&r!l&&!r
00498
MC/DC0%0/2
$two eq "<<" or $two eq ">>"
$two eq "<<" $two eq ">>"
Truth table33%1/3
A or B
A= $two eq "<<"B= $two eq ">>"
ABresult
1X1
011
000
1642 0 ▶ $depth += $two eq '<<' ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$two eq '<<' ? : 0 0 0
1643 0 $current .= $two;
1644 0 $pos += 2;
1645 0 next;
1646 }
1647 498 my $ch = substr( $text, $pos, 1 );
1648 498 ▶ if ( $ch eq '(' or $ch eq '[' or $ch eq '{' or $ch eq '«' or $ch eq '⌊' or $ch eq '⌈' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ch eq '(' or $ch eq '[' or $ch eq '{' or $ch eq "\253" or $ch eq "\x{230a}" or $ch eq "\x{2308}") { } 0 498 498
elsif ($ch eq ')' or $ch eq ']' or $ch eq '}' or $ch eq "\273" or $ch eq "\x{230b}" or $ch eq "\x{2309}") { } 0 498 498
elsif ($ch eq ',' and $depth == 0) { } 9 978 987
Condition33%5/15
$ch eq "(" or $ch eq "[" or $ch eq "{" or $ch eq "\x{ab}" or $ch eq "\x{230a}" or $ch eq "\x{2308}"
l!l&&r!l&&!r
00498
$ch eq "(" or $ch eq "[" or $ch eq "{" or $ch eq "\x{ab}" or $ch eq "\x{230a}"
l!l&&r!l&&!r
00498
$ch eq "(" or $ch eq "[" or $ch eq "{" or $ch eq "\x{ab}"
l!l&&r!l&&!r
00498
$ch eq "(" or $ch eq "[" or $ch eq "{"
l!l&&r!l&&!r
00498
$ch eq "(" or $ch eq "["
l!l&&r!l&&!r
00498
MC/DC0%0/6
$ch eq "(" or $ch eq "[" or $ch eq "{" or $ch eq "\x{ab}" or $ch eq "\x{230a}" or $ch eq "\x{2308}"
$ch eq "(" $ch eq "[" $ch eq "{" $ch eq "\x{ab}" $ch eq "\x{230a}" $ch eq "\x{2308}"
Truth table14%1/7
A or B or C or D or E or F
A= $ch eq "("B= $ch eq "["C= $ch eq "{"D= $ch eq "\x{ab}"E= $ch eq "\x{230a}"F= $ch eq "\x{2308}"
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
1649 0 $depth++;
1650 }
1651 ▶ elsif ( $ch eq ')' or $ch eq ']' or $ch eq '}' or $ch eq '»' or $ch eq '⌋' or $ch eq '⌉' ) {
Condition33%5/15
$ch eq ")" or $ch eq "]" or $ch eq "}" or $ch eq "\x{bb}" or $ch eq "\x{230b}" or $ch eq "\x{2309}"
l!l&&r!l&&!r
00498
$ch eq ")" or $ch eq "]" or $ch eq "}" or $ch eq "\x{bb}" or $ch eq "\x{230b}"
l!l&&r!l&&!r
00498
$ch eq ")" or $ch eq "]" or $ch eq "}" or $ch eq "\x{bb}"
l!l&&r!l&&!r
00498
$ch eq ")" or $ch eq "]" or $ch eq "}"
l!l&&r!l&&!r
00498
$ch eq ")" or $ch eq "]"
l!l&&r!l&&!r
00498
MC/DC0%0/6
$ch eq ")" or $ch eq "]" or $ch eq "}" or $ch eq "\x{bb}" or $ch eq "\x{230b}" or $ch eq "\x{2309}"
$ch eq ")" $ch eq "]" $ch eq "}" $ch eq "\x{bb}" $ch eq "\x{230b}" $ch eq "\x{2309}"
Truth table14%1/7
A or B or C or D or E or F
A= $ch eq ")"B= $ch eq "]"C= $ch eq "}"D= $ch eq "\x{bb}"E= $ch eq "\x{230b}"F= $ch eq "\x{2309}"
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
1652 0 $depth--;
1653 }
1654 ▶ elsif ( $ch eq ',' and $depth == 0 ) {
Condition66%2/3
$ch eq "," and $depth == 0
!ll&&!rl&&r
48909
MC/DC50%1/2
$ch eq "," and $depth == 0
$ch eq "," $depth == 0
Truth table66%2/3
A and B
A= $ch eq ","B= $depth == 0
ABresult
0X0
100
111
1655 9 push @parts, $current;
1656 9 $current = '';
1657 9 $pos++;
1658 9 next;
1659 }
1660 489 $current .= $ch;
1661 489 $pos++;
1662 }
1663 3 ▶ push @parts, $current if $current ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $current ne "" 3 0 3
1664  
1665 3 return @parts;
1666 }
1667  
1668 40 ▶sub _normalize_split_sequence_literals {
Subroutine _normalize_split_sequence_literals: called CC=14 SCAR=26.8
1669 40 my ( $src ) = @_;
1670 40 my @lines = split /\n/, $src, -1;
1671 40 my @out;
1672  
1673 40 my %close_for = (
1674 '[' => ']',
1675 '<<' => '>>',
1676 '<<<' => '>>>',
1677 '«' => '»',
1678 );
1679  
1680 40 ▶ for ( my $i = 0; $i <= $#lines; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#lines) 717 40 757
1681 717 my $line = $lines[$i];
1682 717 my ( $prefix, $open, $after_open ) = $line =~ /^(.*?(?::=|[\(\[,])\s*)(<<<|<<|«|\[)(.*)\z/;
1683 717 ▶ if ( ! defined $open or $after_open !~ /\S/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $open and $after_open =~ /\S/) 691 26 717
Condition100%3/3
defined $open and $after_open =~ /\S/
!ll&&!rl&&r
6791226
MC/DC100%2/2
defined $open and $after_open =~ /\S/
defined $open $after_open =~ /\S/
Truth table100%3/3
A and B
A= defined $openB= $after_open =~ /\S/
ABresult
0X0
100
111
1684 # Nothing after the open delimiter on this line means it was
1685 # already split (e.g. by the trailing-comma-forces-multi-line
1686 # mechanism in _tidy_code_chunk); reprocessing it would flatten
1687 # the already-correct nested structure onto fewer lines.
1688 691 push @out, $line;
1689 691 next;
1690 }
1691  
1692 26 my $close = $close_for{$open};
1693 26 my ( $j, $before_close, $after_close )
1694 = _find_matching_sequence_close( \@lines, $i, $after_open, $open, $close );
1695 26 ▶ if ( ! defined $j ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $j) 0 26 26
1696 0 push @out, $line;
1697 0 next;
1698 }
1699 26 ▶ if ( $j == $i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j == $i) 23 3 26
1700 23 push @out, $line;
1701 23 next;
1702 }
1703  
1704 3 my @inner_chunks = ( $after_open );
1705 3 ▶ push @inner_chunks, @lines[ $i + 1 .. $j - 1 ] if $j > $i + 1;
Branch: 1 branch
BranchTrueFalseTotal
if $j > $i + 1 0 3 3
1706 3 push @inner_chunks, $before_close;
1707  
1708 my $inner_joined = join ' ', map {
1709 3 ▶ my $t = $_ // '';
Condition50%1/2
$_ // ""
l!l
60
MC/DC0%0/1
$_ // ""
$_
Truth table50%1/2
A
A= $_
Aresult
11
00
1710 6 $t =~ s/^\s+//;
1711 6 $t =~ s/\s+\z//;
1712 6 $t;
1713 } @inner_chunks;
1714 12 my @parts = grep { $_ ne '' } map {
1715 3 my $p = $_;
1716 12 $p =~ s/^\s+//;
1717 12 $p =~ s/\s+\z//;
1718 12 $p;
1719 } _split_top_level_commas($inner_joined);
1720 3 ▶ if ( ! @parts ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@parts) 0 3 3
1721 0 push @out, $line;
1722 0 next;
1723 }
1724  
1725 3 my ( $base_indent ) = $line =~ /^(\s*)/;
1726 3 my $inner_indent = $base_indent . "\t";
1727 3 push @out, $prefix . $open;
1728 3 for my $part ( @parts ) {
1729 12 push @out, $inner_indent . $part . ',';
1730 }
1731 3 ▶ my $tail = defined $after_close ? $after_close : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $after_close ? : 3 0 3
1732 3 $tail =~ s/^\s+//;
1733 3 my $extra_skip = 0;
1734 3 ▶ if ( $tail eq '' and $j + 1 <= $#lines and $lines[ $j + 1 ] =~ /^\s*;\s*\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tail eq "" and $j + 1 <= $#lines and $lines[$j + 1] =~ /^\s*;\s*\z/) 1 2 3
Condition66%4/6
$tail eq "" and $j + 1 <= $#lines and $lines[$j + 1] =~ /^\s*;\s*\z/
!ll&&!rl&&r
201
$tail eq "" and $j + 1 <= $#lines
!ll&&!rl&&r
201
MC/DC33%1/3
$tail eq "" and $j + 1 <= $#lines and $lines[$j + 1] =~ /^\s*;\s*\z/
$tail eq "" $j + 1 <= $#lines $lines[$j + 1] =~ /^\s*;\s*\z/
Truth table50%2/4
A and B and C
A= $tail eq ""B= $j + 1 <= $#linesC= $lines[$j + 1] =~ /^\s*;\s*\z/
ABCresult
0XX0
10X0
1100
1111
1735 1 $tail = ';';
1736 1 $extra_skip = 1;
1737 }
1738 3 push @out, $base_indent . $close . $tail;
1739 3 $i = $j + $extra_skip;
1740 }
1741  
1742 40 return join "\n", @out;
1743 }
1744  
1745 =pod
1746  
1747 =head1 NAME
1748  
1749 Zuzu::Tidy - format ZuzuScript source with consistent style
1750  
1751 =head1 SYNOPSIS
1752  
1753 use Zuzu::Tidy;
1754  
1755 my $tidied = Zuzu::Tidy->tidy( $source, filename => 'main.zzs' );
1756 my $canonical = Zuzu::Tidy->tidy(
1757 $source,
1758 filename => 'main.zzs',
1759 canonical_operators => 1,
1760 );
1761  
1762 =head1 DESCRIPTION
1763  
1764 C<Zuzu::Tidy> rewrites ZuzuScript text into a consistent house style.
1765 It tokenizes with C<Zuzu::Lexer> and validates syntax with C<Zuzu::Parser>
1766 before rewriting. Pod sections are passed through unchanged.
1767  
1768 The tidier applies indentation, brace placement, operator spacing,
1769 parenthesis/bracket spacing, and adds trailing statement semicolons when
1770 needed.
1771  
1772 =head1 METHODS
1773  
1774 =head2 tidy
1775  
1776 Returns tidied source text as a single UTF-8 string.
1777  
1778 Pass C<canonical_operators =E<gt> 1> to rewrite non-canonical operator
1779 spellings such as C<*> and C<< |> >> to canonical forms such as C<×> and
1780 C<▷>. This option is disabled by default.
1781  
1782 =head1 SEE ALSO
1783  
1784 L<Zuzu::Lexer>, L<Zuzu::Parser>, L<Zuzu::Tidy::CLI>.
1785  
1786 =head1 COPYRIGHT AND LICENCE
1787  
1788 B<< Zuzu::Tidy >> is copyright Toby Inkster.
1789  
1790 It is free software; you may redistribute it and/or modify it under
1791 the terms of either the Artistic License 1.0 or the GNU General Public
1792 License version 2.
1793  
1794 =cut
1795  
1796 5 1;
« blib/lib/Zuzu/Module/Archive.pm ↑ Summary blib/lib/Zuzu/Module/Math/BigNum.pm »