lib/ChordPro/Song.pm

filter: Statementstmt 71.8% 1102 / 1534 Branchbran 56.1% 595 / 1060 Conditioncond 51.5% 299 / 580 MC/DCmcdc 24.8% 85 / 342 Subroutinesub 97.1% 69 / 71 Podpod 0.0% 0 / 44 totaltotal 59.2% 2150 / 3631 CC 767 SCAR 73.4
CC
767
Cov
63%
parse_song
5200.9
directive
844.2
decompose_grid
642.4
CRAP 1543.2
« lib/ChordPro/Output/ChordPro.pm ↑ Summary lib/ChordPro/Delegate/TextBlock.pm »
1 #!/usr/bin/perl
2  
3 92 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package main;
6  
7 92 our $options;
8 92 our $config;
9  
10 package ChordPro::Song;
11  
12 92 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 92 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 92 ▶use ChordPro;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 92 ▶use ChordPro::Files;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 92 ▶use ChordPro::Paths;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 92 ▶use ChordPro::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 92 ▶use ChordPro::Chords;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 92 ▶use ChordPro::Chords::Appearance;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 92 ▶use ChordPro::Chords::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 92 ▶use ChordPro::Chords::Transpose;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 92 ▶use ChordPro::Output::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 92 ▶use ChordPro::Symbols qw( is_strum );
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 92 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 92 ▶use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
28 92 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 92 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 92 ▶use Text::ParseWords qw(quotewords);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 92 ▶use Ref::Util qw( is_arrayref is_hashref );
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 92 my $backend; # backend tag
34  
35 # Parser context.
36 92 my $def_context = "";
37 92 my $in_context = $def_context;
38 92 my $skip_context = 0;
39 92 my $grid_arg; # also used for grilles?
40 my $grid_cells; # also used for grilles?
41 92 my $grid_type = 0; # 0 = chords, 1,2 = strums
42 92 my @grille;
43  
44 # Transposition.
45 # We have the following transpositions:
46 # - outer, from cli or settings
47 # - capo (if decapo this is just another transpose)
48 # - inner, from transpose directives
49 # outer and inner control the print
50 # outer, inner and capo control the sound.
51 # Transpositions are applied in the order inner, capo, outer.
52 92 our $xpose; # accumulated {transpose} directives.
53 # This is the composite of {transpose} directives and CLI transpose.
54 92 my $capo;
55  
56 # Used chords, in order of appearance.
57 # Note that the key is not a chord.
58 my @used_chords;
59  
60 # Chorus lines, if any.
61 92 my @chorus;
62 92 my $chorus_xpose = 0; # xpose_base when chorus was defined
63  
64 # Memorized chords.
65 92 my $cctag; # current cc name
66 my %memchords; # all sections
67 92 my $memchords; # current section
68 92 my $memcrdinx; # chords tally
69 92 my $memorizing; # if memorizing (a.o.t. recalling)
70  
71 # Keep track of unknown chords, to avoid dup warnings.
72 92 my %warned_chords;
73  
74 92 our $re_chords; # for chords
75 92 my $propitems_re = propitems_re();
76 92 my $intervals; # number of note intervals
77 my @labels; # labels used
78  
79 # Normally, transposition and subtitutions are handled by the parser.
80 92 my $decapo;
81 92 my $no_transpose; # NYI
82 92 my $xcmov; # transcode to movable system
83 92 my $no_substitute;
84  
85 # Stack for properties like textsize.
86 92 my %propstack;
87  
88 92 my $diag; # for diagnostics
89 92 my @diag; # keep track of includes
90 92 my $lineinfo; # keep lineinfo
91 92 my $assetid = "001"; # for assets
92  
93 # Constructor.
94  
95 250 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod undocumented
96 250 my ( $pkg, $opts ) = @_;
97  
98 # use Tie::Trace qw(watch); watch( $xpose, pkg => 'Song' );
99  
100 250 ▶ my $filesource = $opts->{filesource} || $opts->{_filesource};
Condition66%2/3
$opts->{'filesource'} || $opts->{'_filesource'}
l!l&&r!l&&!r
02473
MC/DC50%1/2
$opts->{'filesource'} || $opts->{'_filesource'}
$opts->{'filesource'} $opts->{'_filesource'}
Truth table66%2/3
A || B
A= $opts->{'filesource'}B= $opts->{'_filesource'}
ABresult
1X1
011
000
101  
102 250 $grid_arg = [ 4, 4, 1, 1, "" ]; # 1+4x4+1
103 250 $in_context = $def_context;
104 250 @used_chords = ();
105 250 %warned_chords = ();
106 250 %memchords = ();
107 250 %propstack = ();
108 250 ChordPro::Chords::reset_song_chords();
109 250 @labels = ();
110 250 @chorus = ();
111 250 $capo = undef;
112 250 $xpose = parse_transpose(0);
113 250 $xcmov = undef;
114 250 upd_config();
115  
116 250 ▶ $diag->{format} = $opts->{diagformat} // $config->{diagnostics}->{format};
Condition33%1/3
$opts->{"diagformat"} // $main::config->{"diagnostics"}{"format"}
l!l&&r!l&&!r
02500
MC/DC0%0/2
$opts->{"diagformat"} // $main::config->{"diagnostics"}{"format"}
$opts->{"diagformat"} $main::config->{"diagnostics"}{"format"}
Truth table33%1/3
A // B
A= $opts->{"diagformat"}B= $main::config->{"diagnostics"}{"format"}
ABresult
1X1
011
000
117 250 $diag->{file} = $filesource;
118 250 $diag->{line} = 0;
119 250 $diag->{orig} = "(at start of song)";
120  
121 bless { chordsinfo => {},
122 meta => {},
123 generate => $opts->{generate},
124 250 structure => "linear",
125 } => $pkg;
126 }
127  
128 508 ▶sub upd_config {
Subroutine upd_config: called CC=1 SCAR=0.0
Pod undocumented
129 # These cannot be changed on the fly.
130 508 $decapo = $config->{settings}->{decapo};
131 508 $lineinfo = $config->{settings}->{lineinfo};
132 508 $intervals = @{ $config->{notes}->{sharp} };
133 }
134  
135 235 ▶sub is_gridstrum($) {
Subroutine is_gridstrum: called CC=2 SCAR=7.6
Pod undocumented
136 235 ▶ $_[0] == 1 || $_[0] == 2;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] == 1 or $_[0] == 2 0 235 235
137 }
138  
139 # Fetch a value for key $k from hash $h, with possible specialisation
140 # for the current backend.
141 1294 ▶sub beo {
Subroutine beo: called CC=6 SCAR=18.0
Pod undocumented
142 1294 my ( $h, $k ) = @_;
143 1294 ▶ if ( exists( $h->{$backend} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $h->{$backend} and exists $h->{$backend}{$k} and defined $h->{$backend}{$k}) 149 1145 1294
Condition83%5/6
exists $h->{$backend} and exists $h->{$backend}{$k} and defined $h->{$backend}{$k}
!ll&&!rl&&r
11450149
exists $h->{$backend} and exists $h->{$backend}{$k}
!ll&&!rl&&r
107273149
MC/DC66%2/3
exists $h->{$backend} and exists $h->{$backend}{$k} and defined $h->{$backend}{$k}
exists $h->{$backend} exists $h->{$backend}{$k} defined $h->{$backend}{$k}
Truth table75%3/4
A and B and C
A= exists $h->{$backend}B= exists $h->{$backend}{$k}C= defined $h->{$backend}{$k}
ABCresult
0XX0
10X0
1100
1111
144 && exists( $h->{$backend}->{$k} )
145 && defined( $h->{$backend}->{$k} ) ) {
146 149 return $h->{$backend}->{$k};
147 }
148 1145 ▶ return '' unless exists($h->{$k}) && defined($h->{$k});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $h->{$k} and defined $h->{$k} 6 1139 1145
Condition66%2/3
exists $h->{$k} and defined $h->{$k}
!ll&&!rl&&r
601139
MC/DC50%1/2
exists $h->{$k} and defined $h->{$k}
exists $h->{$k} defined $h->{$k}
Truth table66%2/3
A and B
A= exists $h->{$k}B= defined $h->{$k}
ABresult
0X0
100
111
149 1139 return $h->{$k};
150 }
151  
152 247 ▶sub parse_song {
Subroutine parse_song: called CC=212 SCAR=85.6
Pod undocumented
153 247 my ( $self, $lines, $linecnt, $meta, $defs ) = @_;
154 247 ▶ die("OOPS! Wrong meta") unless ref($meta) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $meta eq "HASH" 0 247 247
155  
156 247 local $config = dclone($config);
157  
158 247 ▶ $backend = lc( $self->{generate} // "None" );
Condition100%2/2
$self->{"generate"} // "None"
l!l
140107
MC/DC100%1/1
$self->{"generate"} // "None"
$self->{"generate"}
Truth table100%2/2
A
A= $self->{"generate"}
Aresult
11
00
159  
160 247 ▶ warn("Processing song ", $diag->{file}, "...\n") if $options->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"verbose"} 0 247 247
161  
162 247 my @configs;
163  
164 247 ▶ while ( $lines->[0] =~ /^##config:\s*(.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lines->[0] =~ /^##config:\s*(.*)/) 0 247 247
165 0 my $cf = "";
166 0 shift(@$lines);
167 0 $$linecnt++;
168  
169 0 my $cfginc;
170  
171 0 ▶ if ( $1 eq "json" || $1 eq "-" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq 'json' or $1 eq '-') { } 0 0 0
Condition0%0/3
$1 eq "json" or $1 eq "-"
l!l&&r!l&&!r
000
MC/DC0%0/2
$1 eq "json" or $1 eq "-"
$1 eq "json" $1 eq "-"
Truth table0%0/3
A or B
A= $1 eq "json"B= $1 eq "-"
ABresult
1X1
011
000
172 0 ▶ while ( @$lines ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$lines) 0 0 0
173 0 ▶ if ( $lines->[0] =~ /^# (.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lines->[0] =~ /^# (.*)/) { } 0 0 0
174 0 $cf .= $1 . "\n";
175 0 shift(@$lines);
176 0 $$linecnt++;
177 }
178 else {
179 0 last;
180 }
181 }
182 }
183 else {
184 0 $cf = "include: [ $1 ]";
185 0 $cfginc++;
186 }
187  
188 0 ▶ if ( $cf ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cf) 0 0 0
189 0 my $prename = "__PRECFG__";
190 0 my $precfg = ChordPro::Config->new( json_load( $cf, $prename ) );
191 0 $precfg->precheck($prename);
192 0 push( @configs, $precfg->prep_configs($prename) );
193 0 ▶ pop( @configs ) if $cfginc;
Branch: 1 branch
BranchTrueFalseTotal
if $cfginc 0 0 0
194 }
195 }
196  
197 # Load song-specific config, if any.
198 247 ▶ if ( !$options->{nosongconfig} && $diag->{file} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $main::options->{"nosongconfig"} and $diag->{"file"}) 107 140 247
Condition66%2/3
not $main::options->{"nosongconfig"} and $diag->{"file"}
!ll&&!rl&&r
1400107
MC/DC50%1/2
not $main::options->{"nosongconfig"} and $diag->{"file"}
not $main::options->{"nosongconfig"} $diag->{"file"}
Truth table66%2/3
not(A) and B
A= not $main::options->{"nosongconfig"}B= $diag->{"file"}
ABresult
0X0
100
111
199 107 ▶ if ( $options->{verbose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::options->{"verbose"}) 0 107 107
200 0 ChordPro::Chords::set_parser( $config->{notes}->{system} );
201 0 my $this = ChordPro::Chords::get_parser();
202 0 ▶ $this = defined($this) ? $this->{system} : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $this ? : 0 0 0
203 0 print STDERR ("Parsers at start of ", $diag->{file}, ":");
204 print STDERR ( $this eq $_ ? " *" : " ", "$_")
205 0 ▶ for keys %{ ChordPro::Chords::Parser->parsers };
Branch: 1 branch
BranchTrueFalseTotal
$this eq $_ ? : 0 0 0
206 0 print STDERR ("\n");
207 }
208 107 ▶ if ( $meta && $meta->{__config} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta and $meta->{'__config'}) { } 0 107 107
Condition33%1/3
$meta and $meta->{"__config"}
!ll&&!rl&&r
01070
MC/DC0%0/2
$meta and $meta->{"__config"}
$meta $meta->{"__config"}
Truth table33%1/3
A and B
A= $metaB= $meta->{"__config"}
ABresult
0X0
100
111
209 0 my $cf = delete($meta->{__config})->[0];
210 0 ▶ warn("Config[song]: $cf\n") if $options->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"verbose"} 0 0 0
211 0 my $have = ChordPro::Config::get_config( CP->findcfg($cf) );
212 0 ▶ die("Missing config: $cf\n") unless $have;
Branch: 1 branch
BranchTrueFalseTotal
unless $have 0 0 0
213 0 push( @configs, $have->prep_configs($cf) );
214 }
215 else {
216 107 for ( "prp", "json" ) {
217 214 ( my $cf = $diag->{file} ) =~ s/\.\w+$/.$_/;
218 214 ▶ $cf .= ".$_" if $cf eq $diag->{file};
Branch: 1 branch
BranchTrueFalseTotal
if $cf eq $diag->{"file"} 158 56 214
219 214 ▶ next unless fs_test( s => $cf );
Branch: 1 branch
BranchTrueFalseTotal
unless fs_test("s", $cf) 214 0 214
220 0 ▶ warn("Config[song]: $cf\n") if $options->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"verbose"} 0 0 0
221 0 my $have = ChordPro::Config::get_config($cf);
222 0 push( @configs, $have->prep_configs($cf) );
223 0 last;
224 }
225 }
226 }
227 247 my $tuncheck = join("|",@{$config->{tuning}});
228 247 foreach my $have ( @configs ) {
229 0 ▶ warn("Config[song*]: ", $have->{_src}, "\n") if $options->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"verbose"} 0 0 0
230 0 my $chords = $have->{chords};
231 0 $config->augment($have);
232 0 ▶ if ( $tuncheck ne join("|",@{$config->{tuning}}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tuncheck ne join("|", @{$main::config->{"tuning"};})) 0 0 0
233 0 my $res =
234 ChordPro::Chords::set_tuning($config);
235 0 ▶ warn( "Invalid tuning in config: ", $res, "\n" ) if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
236 }
237 0 ChordPro::Chords::reset_parser();
238 0 ChordPro::Chords::Parser->reset_parsers;
239 0 ▶ if ( $chords ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chords) 0 0 0
240 0 my $c = $chords;
241 0 ▶ if ( @$c && $c->[0] eq "append" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$c and $c->[0] eq "append") 0 0 0
Condition0%0/3
@$c and $c->[0] eq "append"
!ll&&!rl&&r
000
MC/DC0%0/2
@$c and $c->[0] eq "append"
@$c $c->[0] eq "append"
Truth table0%0/3
A and B
A= @$cB= $c->[0] eq "append"
ABresult
0X0
100
111
242 0 shift(@$c);
243 }
244 0 foreach ( @$c ) {
245 0 my $res =
246 ChordPro::Chords::add_config_chord($_);
247 warn( "Invalid chord in config: ",
248 0 ▶ $_->{name}, ": ", $res, "\n" ) if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
249 }
250 }
251 0 ▶ if ( $options->{verbose} > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::options->{"verbose"} > 1) 0 0 0
252 0 ▶ warn( "Processed ", scalar(@$chords), " chord entries\n")
Branch: 1 branch
BranchTrueFalseTotal
if $chords 0 0 0
253 if $chords;
254 0 warn( "Totals: ",
255 ChordPro::Chords::chord_stats(), "\n" );
256 }
257 0 if ( 0 && $options->{verbose} ) {
258 my $this = ChordPro::Chords::get_parser()->{system};
259 print STDERR ("Parsers after local config:");
260 print STDERR ( $this eq $_ ? " *" : " ", "$_")
261 for keys %{ ChordPro::Chords::Parser->parsers };
262 print STDERR ("\n");
263 }
264 }
265  
266 247 $config->unlock;
267 247 ▶ if ( my $a = $config->{parser}->{altbrackets} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $a = $main::config->{"parser"}{"altbrackets"}) 0 247 247
268 0 ▶ die("Config error: parser.altbrackets must be a 2-character string\n")
Branch: 1 branch
BranchTrueFalseTotal
unless length $a == 2 0 0 0
269 unless length($a) == 2;
270 }
271  
272 247 ▶ if ( %$defs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$defs) 0 247 247
273 0 prpadd2cfg( $config, %$defs );
274 }
275  
276 247 for ( qw( transcode decapo lyrics-only ) ) {
277 741 ▶ next unless defined $options->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $main::options->{$_} 729 12 741
278 12 $config->{settings}->{$_} = $options->{$_};
279 }
280 # Catch common error.
281 247 ▶ unless ( UNIVERSAL::isa( $config->{instrument}, 'HASH' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($main::config->{"instrument"}, "HASH")) 0 247 247
282 0 ▶ $config->{instrument} //= "guitar";
Condition0%0/2
$main::config->{"instrument"} //= "guitar"
l!l
00
MC/DC0%0/1
$main::config->{"instrument"} //= "guitar"
$main::config->{"instrument"}
Truth table0%0/2
A
A= $main::config->{"instrument"}
Aresult
11
00
283 $config->{instrument} =
284 { type => $config->{instrument},
285 0 description => ucfirst $config->{instrument} };
286 do_warn( "Missing or invalid instrument - set to ",
287 0 $config->{instrument}->{type}, "\n" );
288 }
289  
290 # Remove inactive delegates.
291 247 ▶ while ( my ($k,$v) = each %{ $config->{delegates} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$main::config{"delegates"};}) 1235 247 1482
292 1235 ▶ delete( $config->{delegates}->{$k} )
Branch: 1 branch
BranchTrueFalseTotal
if not $v or (beo($v, "type") // "none") eq "none" 345 890 1235
Condition60%3/5
not $v or (beo($v, "type") // "none") eq "none"
l!l&&r!l&&!r
0345890
beo($v, "type") // "none"
l!l
12350
MC/DC0%0/2
not $v or (beo($v, "type") // "none") eq "none"
not $v beo($v, "type")
Truth table33%1/3
not(A) or B
A= not $vB= beo($v, "type")
ABresult
1X1
011
000
293 if !$v || (beo( $v, 'type')//'none') eq 'none';
294 }
295  
296 # Handle transpose (needs parsing unless cli).
297 247 ▶ if ( ref($config->{settings}->{transpose}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $main::config->{'settings'}{'transpose'}) { } 9 238 247
298 # From CLI; already parsed.
299 }
300 else {
301 238 my $t = parse_transpose( $config->{settings}->{transpose} );
302 die("Config error: invalid transpose value \"" .
303 238 ▶ $config->{settings}->{transpose} . "\"\n" ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 238 238
304 238 $config->{settings}->{transpose} = $t;
305 }
306  
307 # Enforce key transpose semantics unless otherwise specified.
308 247 ▶ if ( $config->{settings}->{'transpose-sf-key'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{"settings"}{"transpose-sf-key"}) 0 247 247
309 0 for ( $config->{settings}->{transpose} ) {
310 0 ▶ if ( $_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_) { } 0 0 0
311 0 ▶ $_ = parse_transpose( $_ . "k" ) unless $_->forced;
Branch: 1 branch
BranchTrueFalseTotal
unless $_->forced 0 0 0
312 }
313 else {
314 0 $_ = parse_transpose("0k");
315 }
316 }
317 }
318  
319 # And lock the config.
320 247 $config->lock;
321  
322 247 for ( keys %{ $config->{meta} } ) {
323 247 ▶ $meta->{$_} //= [];
Condition50%1/2
$meta->{$_} //= []
l!l
2470
MC/DC0%0/1
$meta->{$_} //= []
$meta->{$_}
Truth table50%1/2
A
A= $meta->{$_}
Aresult
11
00
324 247 my $v = $config->{meta}->{$_};
325 247 ▶ $v = [ $v ] unless is_arrayref($v);
Branch: 1 branch
BranchTrueFalseTotal
unless is_arrayref($v) 247 0 247
326 247 ▶ if ( is_arrayref($meta->{$_}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_arrayref($meta->{$_})) { } 0 247 247
327 0 push( @{ $meta->{$_} }, @$v );
328 }
329 else {
330 247 $meta->{$_} = $v;
331 }
332 }
333  
334 247 $xpose = parse_transpose(0);
335 247 $no_transpose = $options->{'no-transpose'};
336 247 $no_substitute = $options->{'no-substitute'};
337 247 my $fragment = $options->{fragment};
338 247 my $target = $config->{settings}->{transcode};
339 247 ▶ if ( $target ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target) { } 2 245 247
340 2 ▶ unless ( ChordPro::Chords::Parser->have_parser($target) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("ChordPro::Chords::Parser"->have_parser($target)) 2 0 2
341 2 ▶ if ( my $file = CP->findres("config/notes/$target.json") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = CP()->findres("config/notes/$target.json")) 2 0 2
342 2 for ( ChordPro::Config::get_config($file) ) {
343 2 my $new = $config->hmerge($_);
344 2 local $config = $new;
345 2 ChordPro::Chords::Parser->new($new);
346 }
347 }
348 }
349 2 ▶ unless ( ChordPro::Chords::Parser->have_parser($target) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("ChordPro::Chords::Parser"->have_parser($target)) 0 2 2
350 0 die("No transcoder for ", $target, "\n");
351 }
352 2 ▶ warn("Got transcoder for $target\n") if $::options->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"verbose"} 0 2 2
353 2 ChordPro::Chords::set_parser($target);
354 2 my $p = ChordPro::Chords::get_parser;
355 2 $xcmov = $p->movable;
356 2 ▶ if ( $target ne $p->{system} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target ne $p->{"system"}) 0 2 2
357 0 ::dump(ChordPro::Chords::Parser->parsers);
358 warn("OOPS parser mixup, $target <> ",
359 ChordPro::Chords::get_parser->{system})
360 0 }
361 2 ChordPro::Chords::set_parser($self->{system});
362 }
363 else {
364 245 $target = $self->{system};
365 }
366  
367 247 upd_config();
368 247 $self->{source} = { file => $diag->{file}, line => 1 + $$linecnt };
369 247 ▶ $self->{system} = $target // $config->{notes}->{system};
Condition66%2/3
$target // $main::config->{"notes"}{"system"}
l!l&&r!l&&!r
22450
MC/DC0%0/2
$target // $main::config->{"notes"}{"system"}
$target $main::config->{"notes"}{"system"}
Truth table66%2/3
A // B
A= $targetB= $main::config->{"notes"}{"system"}
ABresult
1X1
011
000
370 247 $self->{config} = $config;
371 247 ▶ $self->{meta} = $meta if $meta;
Branch: 1 branch
BranchTrueFalseTotal
if $meta 247 0 247
372 247 $self->{chordsinfo} = {};
373 247 ▶ $target //= $self->{system};
Condition66%2/3
$target //= $self->{"system"}
l!l&&r!l&&!r
22450
MC/DC0%0/2
$target //= $self->{"system"}
$target $self->{"system"}
Truth table66%2/3
A //= B
A= $targetB= $self->{"system"}
ABresult
1X1
011
000
374  
375 # Preprocessor.
376 247 my $prep = make_preprocessor( $config->{parser}->{preprocess} );
377  
378 # Pre-fill meta data, if any. TODO? ALREADY DONE?
379 247 ▶ if ( $options->{meta} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::options->{"meta"}) 0 247 247
380 0 ▶ while ( my ($k, $v ) = each( %{ $options->{meta} } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$main::options{"meta"};}) 0 0 0
381 0 $self->{meta}->{$k} = [ $v ];
382 }
383 }
384 $self->{meta}->{"chordpro.songsource"} = $diag->{file}
385 247 ▶ unless $::running_under_test;
Branch: 1 branch
BranchTrueFalseTotal
unless $main::running_under_test 12 235 247
386  
387 # Build regexp to split out chords.
388 247 ▶ if ( $config->{settings}->{memorize} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{'settings'}{'memorize'}) { } 3 244 247
389 3 $re_chords = qr/(\[.*?\]|\^)/;
390 }
391 else {
392 244 $re_chords = qr/(\[.*?\])/;
393 }
394  
395 247 my $skipcnt = 0;
396 247 ▶ while ( @$lines ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$lines) 2381 192 2573
397 2381 ▶ if ( $skipcnt ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skipcnt) { } 0 2381 2381
398 0 $skipcnt--;
399 }
400 else {
401 2381 $diag->{line} = ++$$linecnt;
402 }
403  
404 2381 $_ = shift(@$lines);
405 2381 ▶ while ( /\\\Z/ && @$lines ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\\\Z/ and @$lines) 0 2381 2381
Condition33%1/3
/\\\Z/ and @$lines
!ll&&!rl&&r
238100
MC/DC0%0/2
/\\\Z/ and @$lines
/\\\Z/ @$lines
Truth table33%1/3
A and B
A= /\\\Z/B= @$lines
ABresult
0X0
100
111
406 0 chop;
407 0 my $cont = shift(@$lines);
408 0 $$linecnt++;
409 0 $cont =~ s/^\s+//;
410 0 $_ .= $cont;
411 }
412  
413 # Uncomment this to allow \uDXXX\uDYYY (surrogate) escapes.
414 s/ \\u(d[89ab][[:xdigit:]]{2})\\u(d[cdef][[:xdigit:]]{2})
415 0 / pack('U*', 0x10000 + (hex($1) - 0xD800) * 0x400 + (hex($2) - 0xDC00) )
416 2381 /igex;
417  
418 # Uncomment this to allow \uXXXX escapes.
419 0 s/\\u([0-9a-f]{4})/chr(hex("0x$1"))/ige;
420 # Uncomment this to allow \u{XX...} escapes.
421 0 s/\\u\{([0-9a-f]+)\}/chr(hex("0x$1"))/ige;
422  
423 2381 $diag->{orig} = $_;
424 # Get rid of TABs.
425 2381 s/\t/ /g;
426  
427 2381 ▶ if ( $config->{debug}->{echo} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{"debug"}{"echo"}) 0 2381 2381
428 0 warn(sprintf("==[%3d]=> %s\n", $diag->{line}, $diag->{orig} ) );
429 }
430  
431 2381 for my $pp ( "all", "env-$in_context" ) {
432 next if $pp eq "env-$in_context"
433 && /^\s*\{(\w+)\}\s*$/
434 4762 ▶ && $self->parse_directive($1)->{name} eq "end_of_$in_context";
Branch: 1 branch
BranchTrueFalseTotal
if $pp eq "env-$in_context" and /^\s*\{(\w+)\}\s*$/ and $self->parse_directive($1)->{"name"} eq "end_of_$in_context" 97 4665 4762
Condition100%6/6
$pp eq "env-$in_context" and /^\s*\{(\w+)\}\s*$/ and $self->parse_directive($1)->{"name"} eq "end_of_$in_context"
!ll&&!rl&&r
437628997
$pp eq "env-$in_context" and /^\s*\{(\w+)\}\s*$/
!ll&&!rl&&r
23811995386
MC/DC100%3/3
$pp eq "env-$in_context" and /^\s*\{(\w+)\}\s*$/ and $self->parse_directive($1)->{"name"} eq "end_of_$in_context"
$pp eq "env-$in_context" /^\s*\{(\w+)\}\s*$/ $self->parse_directive($1)->{"name"} eq "end_of_$in_context"
Truth table100%4/4
A and B and C
A= $pp eq "env-$in_context"B= /^\s*\{(\w+)\}\s*$/C= $self->parse_directive($1)->{"name"} eq "end_of_$in_context"
ABCresult
0XX0
10X0
1100
1111
435 4665 ▶ if ( $prep->{$pp} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prep->{$pp}) 0 4665 4665
436 0 ▶ $config->{debug}->{pp} && warn("PRE: ", $_, "\n");
Branch: 1 branch
BranchTrueFalseTotal
$main::config->{"debug"}{"pp"} and warn("PRE: ", $_, "\n") 0 0 0
437 0 $prep->{$pp}->($_);
438 0 ▶ $config->{debug}->{pp} && warn("POST: ", $_, "\n");
Branch: 1 branch
BranchTrueFalseTotal
$main::config->{"debug"}{"pp"} and warn("POST: ", $_, "\n") 0 0 0
439 0 ▶ if ( /\n/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\n/) 0 0 0
440 0 my @a = split( /\n/, $_ );
441 0 $_ = shift(@a);
442 0 unshift( @$lines, @a );
443 0 $skipcnt += @a;
444 }
445 }
446 }
447  
448 2381 ▶ if ( $skip_context ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip_context) 4 2377 2381
449 4 ▶ if ( /^\s*\{(\w+)\}\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*\{(\w+)\}\s*$/) 2 2 4
450 2 my $dir = $self->parse_directive($1);
451 2 ▶ if ( $dir->{name} eq "end_of_$in_context" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir->{"name"} eq "end_of_$in_context") 2 0 2
452 2 $in_context = $def_context;
453 2 $skip_context = 0;
454 }
455 }
456 4 next;
457 }
458  
459 2377 ▶ if ( /^\s*\{((?:new_song|ns)\b.*)\}\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*\{((?:new_song|ns)\b.*)\}\s*$/) 115 2262 2377
460 115 ▶ if ( $self->{body} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"body"}) 55 60 115
461 55 unshift( @$lines, $_ );
462 55 $$linecnt--;
463 55 last;
464 }
465 60 my $dir = $self->parse_directive($1);
466 60 ▶ next unless my $kv = parse_kv($dir->{arg}//"");
Branch: 1 branch
BranchTrueFalseTotal
unless my $kv = parse_kv($dir->{"arg"} // "") 0 60 60
Condition50%1/2
$dir->{"arg"} // ""
l!l
600
MC/DC0%0/1
$dir->{"arg"} // ""
$dir->{"arg"}
Truth table50%1/2
A
A= $dir->{"arg"}
Aresult
11
00
467 60 ▶ if ( defined $kv->{toc} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $kv->{"toc"}) 0 60 60
468 0 $self->{meta}->{_TOC} = [ $kv->{toc} ];
469 }
470 60 ▶ if ( $kv->{forceifempty} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kv->{"forceifempty"}) 0 60 60
471 0 push( @{ $self->{body} },
472 { type => "set",
473 name => "forceifempty",
474 0 value => $kv->{forceifempty} } );
475 }
476 60 next;
477 }
478  
479 2262 ▶ if ( /^#/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^#/) 57 2205 2262
480  
481 # Handle assets.
482 57 my $kw = "";
483 57 my $kv = {};
484 57 ▶ if ( /^##(image|asset|include)(?:-(.+))?:\s+(.*)/i
Branch: 1 branch
BranchTrueFalseTotal
if (/^##(image|asset|include)(?:-(.+))?:\s+(.*)/i and $self->selected($2)) 3 54 57
Condition66%2/3
/^##(image|asset|include)(?:-(.+))?:\s+(.*)/i and $self->selected($2)
!ll&&!rl&&r
5403
MC/DC50%1/2
/^##(image|asset|include)(?:-(.+))?:\s+(.*)/i and $self->selected($2)
/^##(image|asset|include)(?:-(.+))?:\s+(.*)/i $self->selected($2)
Truth table66%2/3
A and B
A= /^##(image|asset|include)(?:-(.+))?:\s+(.*)/iB= $self->selected($2)
ABresult
0X0
100
111
485 && $self->selected($2) ) {
486 3 $kw = lc($1);
487 3 $kv = parse_kv($3);
488 }
489  
490 57 ▶ if ( $kw eq "image" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "image") 2 55 57
491 2 my $id = $kv->{id};
492 2 ▶ unless ( $id ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id) 0 2 2
493 0 do_warn("Missing id for image asset\n");
494 0 next;
495 }
496  
497 # In-line image asset.
498 2 require MIME::Base64;
499 2 require Image::Info;
500  
501 # Read the image.
502 2 my $data = '';
503 2 ▶ while ( @$lines && $lines->[0] =~ /^# (.+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$lines and $lines->[0] =~ /^# (.+)/) 9 2 11
Condition100%3/3
@$lines and $lines->[0] =~ /^# (.+)/
!ll&&!rl&&r
119
MC/DC100%2/2
@$lines and $lines->[0] =~ /^# (.+)/
@$lines $lines->[0] =~ /^# (.+)/
Truth table100%3/3
A and B
A= @$linesB= $lines->[0] =~ /^# (.+)/
ABresult
0X0
100
111
504 9 $data .= MIME::Base64::decode($1);
505 9 shift(@$lines);
506 }
507  
508 # Get info.
509 2 my $info = Image::Info::image_info(\$data);
510 2 ▶ if ( $info->{error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"error"}) 0 2 2
511 0 do_warn($info->{error});
512 0 next;
513 }
514  
515 # Store in assets.
516 2 ▶ $self->{assets} //= {};
Condition100%2/2
$self->{"assets"} //= {}
l!l
11
MC/DC100%1/1
$self->{"assets"} //= {}
$self->{"assets"}
Truth table100%2/2
A
A= $self->{"assets"}
Aresult
11
00
517 $self->{assets}->{$id} =
518 { type => "image",
519 data => $data,
520 subtype => $info->{file_ext},
521 width => $info->{width},
522 height => $info->{height},
523 2 opts => $kv,
524 };
525  
526 2 ▶ if ( $config->{debug}->{images} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{"debug"}{"images"}) 0 2 2
527 warn( "asset[$id] type=image/$info->{file_ext} ",
528 length($data), " bytes, ",
529 "width=$info->{width}, height=$info->{height}",
530 0 ▶ $kv->{persist} ? ", persist" : "",
Branch: 1 branch
BranchTrueFalseTotal
$kv->{'persist'} ? : 0 0 0
531 "\n");
532 }
533 2 next;
534 }
535  
536 55 ▶ if ( $kw eq "asset" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "asset") 1 54 55
537 1 my $id = $kv->{id};
538 1 my $type = $kv->{type};
539 1 ▶ unless ( $id ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id) 0 1 1
540 0 do_warn("Missing id for asset\n");
541 0 next;
542 }
543 1 ▶ unless ( $type ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type) 0 1 1
544 0 do_warn("Missing type for asset\n");
545 0 next;
546 }
547 1 ▶ unless ( exists $config->{delegates}->{$type} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $main::config->{"delegates"}{$type}) 0 1 1
548 0 do_warn("Unhandled type for asset: $type\n");
549 0 next;
550 }
551  
552 # Read the data.
553 1 my @data;
554 1 ▶ while ( @$lines && $lines->[0] =~ /^# (.+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$lines and $lines->[0] =~ /^# (.+)/) 3 1 4
Condition66%2/3
@$lines and $lines->[0] =~ /^# (.+)/
!ll&&!rl&&r
103
MC/DC50%1/2
@$lines and $lines->[0] =~ /^# (.+)/
@$lines $lines->[0] =~ /^# (.+)/
Truth table66%2/3
A and B
A= @$linesB= $lines->[0] =~ /^# (.+)/
ABresult
0X0
100
111
555 3 push( @data, $1 );
556 3 shift(@$lines);
557 }
558  
559 # Store in assets.
560 1 ▶ $self->{assets} //= {};
Condition50%1/2
$self->{"assets"} //= {}
l!l
10
MC/DC0%0/1
$self->{"assets"} //= {}
$self->{"assets"}
Truth table50%1/2
A
A= $self->{"assets"}
Aresult
11
00
561 $self->{assets}->{$id} =
562 { data => \@data,
563 type => "image",
564 subtype => $type,
565 module => beo( $config->{delegates}->{$type}, 'module' ),
566 1 handler => beo( $config->{delegates}->{$type}, 'handler' ),
567 opts => $kv,
568 };
569 1 ▶ if ( $config->{debug}->{images} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{"debug"}{"images"}) 0 1 1
570 warn("asset[$id] type=image/$type ",
571 scalar(@data), " lines",
572 0 ▶ $kv->{persist} ? ", persist" : "",
Branch: 1 branch
BranchTrueFalseTotal
$kv->{'persist'} ? : 0 0 0
573 "\n");
574 }
575 1 next;
576 }
577  
578 54 ▶ if ( $kw eq "include" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "include") 0 54 54
579 0 ▶ if ( $kv->{end} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kv->{'end'}) { } 0 0 0
580 0 $diag = pop( @diag );
581 0 $$linecnt = $diag->{line};
582 }
583 else {
584 0 my $uri = $kv->{src};
585 0 ▶ if ( $uri && CP->is_here($uri) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri and CP()->is_here($uri)) 0 0 0
Condition0%0/3
$uri and CP()->is_here($uri)
!ll&&!rl&&r
000
MC/DC0%0/2
$uri and CP()->is_here($uri)
$uri CP()->is_here($uri)
Truth table0%0/3
A and B
A= $uriB= CP()->is_here($uri)
ABresult
0X0
100
111
586 0 my $found = CP->siblingres( $diag->{file}, $uri, class => "include" );
587 0 ▶ if ( $found ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) { } 0 0 0
588 0 $uri = $found;
589 }
590 else {
591 0 do_warn("Missing include for \"$uri\"");
592 0 $uri = undef;
593 }
594 }
595 0 ▶ if ( $uri ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri) 0 0 0
596 0 unshift( @$lines, @{fs_load($uri)}, "##include: end=1" );
597 0 push( @diag, { %$diag } );
598 0 $diag->{file} = $uri;
599 0 $diag->{line} = $$linecnt = 0;
600 0 $diag->{orig} = "(including $uri)";
601 }
602 }
603 0 next;
604 }
605  
606 # Currently the ChordPro backend is the only one that
607 # cares about comment lines.
608 # Collect pre-title stuff separately.
609 next unless exists($config->{$backend})
610 54 ▶ && beo( $config->{$backend}, 'comments') eq "retain";
Branch: 1 branch
BranchTrueFalseTotal
unless exists $main::config->{$backend} and beo($main::config->{$backend}, "comments") eq "retain" 15 39 54
Condition100%3/3
exists $main::config->{$backend} and beo($main::config->{$backend}, "comments") eq "retain"
!ll&&!rl&&r
9639
MC/DC100%2/2
exists $main::config->{$backend} and beo($main::config->{$backend}, "comments") eq "retain"
exists $main::config->{$backend} beo($main::config->{$backend}, "comments") eq "retain"
Truth table100%3/3
A and B
A= exists $main::config->{$backend}B= beo($main::config->{$backend}, "comments") eq "retain"
ABresult
0X0
100
111
611  
612 39 ▶ if ( exists $self->{title} || $fragment ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'title'} or $fragment) { } 39 0 39
Condition33%1/3
exists $self->{"title"} or $fragment
l!l&&r!l&&!r
3900
MC/DC0%0/2
exists $self->{"title"} or $fragment
exists $self->{"title"} $fragment
Truth table33%1/3
A or B
A= exists $self->{"title"}B= $fragment
ABresult
1X1
011
000
613 39 $self->add( type => "ignore", text => $_ );
614 }
615 else {
616 0 push( @{ $self->{preamble} }, $_ );
617 }
618 39 next;
619 }
620  
621 # Tab content goes literally.
622 2205 ▶ if ( $in_context eq "tab" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_context eq "tab") 64 2141 2205
623 64 ▶ unless ( /^\s*\{(?:end_of_tab|eot)\}\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/^\s*\{(?:end_of_tab|eot)\}\s*$/) 49 15 64
624 49 $self->add( type => "tabline", text => $_ );
625 49 next;
626 }
627 }
628  
629 2156 ▶ if ( exists $config->{delegates}->{$in_context} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $main::config->{"delegates"}{$in_context}) 11 2145 2156
630 # 'open' indicates open.
631 11 ▶ if ( /^\s*\{(?:end_of_\Q$in_context\E)\}\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*\{(?:end_of_\Q$in_context\E)\}\s*$/) { } 2 9 11
632 2 delete $self->{body}->[-1]->{open};
633 2 $grid_type = 0;
634 # A subsequent {start_of_XXX} will open a new item
635  
636 2 my $d = $config->{delegates}->{$in_context};
637 2 ▶ if ( beo( $d, 'type' ) eq "image" ) {
Branch: 2 branches
BranchTrueFalseTotal
if (beo($d, 'type') eq 'image') { } 2 0 2
elsif (beo($d, 'type') eq 'filter') { } 0 0 0
638 2 local $_;
639 2 my $a = pop( @{ $self->{body} } );
640 2 my $id = $a->{id};
641 2 my $opts = {};
642 2 ▶ unless ( $id ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id) 2 0 2
643 2 my $pkg = 'ChordPro::Delegate::' . $a->{delegate};
644 2 ▶ eval "require $pkg" || warn($@);
Branch: 1 branch
BranchTrueFalseTotal
eval "require $pkg" or warn($@) 2 0 2
645 2 ▶ if ( my $c = $pkg->can("options") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $pkg->can("options")) 2 0 2
646 2 $opts = $c->($a->{data});
647 2 $id = $opts->{id};
648 }
649 }
650 2 $opts = $a->{opts} = { %$opts, %{$a->{opts}} };
651 2 ▶ unless ( is_true($opts->{omit}) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_true($opts->{"omit"})) 2 0 2
652 2 ▶ if ( $opts->{align} && $opts->{x} && $opts->{x} =~ /\%$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"align"} and $opts->{"x"} and $opts->{"x"} =~ /\%$/) 0 2 2
Condition33%2/6
$opts->{"align"} and $opts->{"x"} and $opts->{"x"} =~ /\%$/
!ll&&!rl&&r
200
$opts->{"align"} and $opts->{"x"}
!ll&&!rl&&r
200
MC/DC0%0/3
$opts->{"align"} and $opts->{"x"} and $opts->{"x"} =~ /\%$/
$opts->{"align"} $opts->{"x"} $opts->{"x"} =~ /\%$/
Truth table25%1/4
A and B and C
A= $opts->{"align"}B= $opts->{"x"}C= $opts->{"x"} =~ /\%$/
ABCresult
0XX0
10X0
1100
1111
653 0 do_warn( "Useless combination of x percentage with align (align ignored)" );
654 0 delete $opts->{align};
655 }
656  
657 2 my $def = !!$id;
658 2 ▶ $id //= "_Image".$assetid++;
Condition100%2/2
$id //= '_Image' . $assetid++
l!l
11
MC/DC100%1/1
$id //= '_Image' . $assetid++
$id
Truth table100%2/2
A
A= $id
Aresult
11
00
659  
660 2 ▶ if ( defined $opts->{spread} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{"spread"}) 0 2 2
661 0 $def++;
662 0 ▶ if ( exists $self->{spreadimage} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'spreadimage'}) { } 0 0 0
663 0 do_warn("Skipping superfluous spread image");
664 }
665 else {
666 $self->{spreadimage} =
667 0 { id => $id, space => $opts->{spread} };
668 warn("Got spread image $id with space=$opts->{spread}\n")
669 0 ▶ if $config->{debug}->{images};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"images"} 0 0 0
670 }
671 }
672  
673 # Move to assets.
674 2 $self->{assets}->{$id} = $a;
675 2 ▶ if ( $def ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($def) { } 1 1 2
676 1 my $label = delete $a->{label};
677 1 ▶ do_warn("Label \"$label\" ignored on non-displaying $in_context section\n")
Branch: 1 branch
BranchTrueFalseTotal
if $label 0 1 1
678 if $label;
679 }
680 else {
681 1 my $label = delete $opts->{label};
682 1 ▶ $self->add( type => "set",
Branch: 1 branch
BranchTrueFalseTotal
if $label and $label ne "" 0 1 1
Condition33%1/3
$label and $label ne ""
!ll&&!rl&&r
100
MC/DC0%0/2
$label and $label ne ""
$label $label ne ""
Truth table33%1/3
A and B
A= $labelB= $label ne ""
ABresult
0X0
100
111
683 name => "label",
684 value => $label )
685 if $label && $label ne "";
686 1 $self->add( type => "image",
687 opts => $opts,
688 id => $id );
689 1 ▶ if ( $opts->{label} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"label"}) 0 1 1
690 push( @labels, $opts->{label} )
691 unless $in_context eq "chorus"
692 0 ▶ && !$config->{settings}->{choruslabels};
Branch: 1 branch
BranchTrueFalseTotal
unless $in_context eq "chorus" and not $main::config->{"settings"}{"choruslabels"} 0 0 0
Condition0%0/3
$in_context eq "chorus" and not $main::config->{"settings"}{"choruslabels"}
!ll&&!rl&&r
000
MC/DC0%0/2
$in_context eq "chorus" and not $main::config->{"settings"}{"choruslabels"}
$in_context eq "chorus" not $main::config->{"settings"}{"choruslabels"}
Truth table0%0/3
A and not(B)
A= $in_context eq "chorus"B= not $main::config->{"settings"}{"choruslabels"}
ABresult
0X0
100
111
693 }
694 }
695 }
696 }
697 elsif ( beo( $d, 'type' ) eq "filter" ) {
698 0 local $_;
699 0 my $a = pop( @{ $self->{body} } );
700 0 my $pkg = 'ChordPro::Delegate::' . $a->{delegate};
701 0 ▶ eval "require $pkg" || warn($@);
Branch: 1 branch
BranchTrueFalseTotal
eval "require $pkg" or warn($@) 0 0 0
702 0 my $c = $pkg->can( $a->{handler} );
703 0 my $res = $c->( $c, elt => $a );
704 0 my @lines = @{$res->{data}};
705 0 $skipcnt += @lines;
706 0 unshift( @$lines, @lines );
707 0 $in_context = $def_context;
708 # Prevent context set.
709 0 next;
710 }
711 }
712 else {
713 # Add to an open item.
714 9 ▶ if ( $self->{body} && @{ $self->{body} }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'body'} and @{$self->{'body'};} and $self->{'body'}[-1]{'context'} eq $in_context and $self->{'body'}[-1]{'open'}) { } 9 0 9
Condition33%3/9
$self->{"body"} and @{$self->{"body"};} and $self->{"body"}[-1]{"context"} eq $in_context and $self->{"body"}[-1]{"open"}
!ll&&!rl&&r
009
$self->{"body"} and @{$self->{"body"};} and $self->{"body"}[-1]{"context"} eq $in_context
!ll&&!rl&&r
009
$self->{"body"} and @{$self->{"body"};}
!ll&&!rl&&r
009
MC/DC0%0/4
$self->{"body"} and @{$self->{"body"};} and $self->{"body"}[-1]{"context"} eq $in_context and $self->{"body"}[-1]{"open"}
$self->{"body"} @{$self->{"body"};} $self->{"body"}[-1]{"context"} eq $in_context $self->{"body"}[-1]{"open"}
Truth table20%1/5
A and B and C and D
A= $self->{"body"}B= @{$self->{"body"};}C= $self->{"body"}[-1]{"context"} eq $in_contextD= $self->{"body"}[-1]{"open"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
715 && $self->{body}->[-1]->{context} eq $in_context
716 && $self->{body}->[-1]->{open} ) {
717 9 push( @{$self->{body}->[-1]->{data}},
718 fmt_subst( $self, $_ ) );
719 }
720  
721 # Else start new item.
722 else {
723 0 croak("Reopening delegate");
724 }
725 9 next;
726 }
727 }
728  
729 # For now, directives should go on their own lines.
730 2147 ▶ if ( /^\s*\{(.*)\}\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*\{(.*)\}\s*$/) 1270 877 2147
731 1270 my $dir = $1;
732 1270 ▶ if ( $prep->{directive} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prep->{"directive"}) 0 1270 1270
733 0 ▶ $config->{debug}->{pp} && warn("PRE: ", $_, "\n");
Branch: 1 branch
BranchTrueFalseTotal
$main::config->{"debug"}{"pp"} and warn("PRE: ", $_, "\n") 0 0 0
734 0 $prep->{directive}->($dir);
735 0 ▶ $config->{debug}->{pp} && warn("POST: {", $dir, "}\n");
Branch: 1 branch
BranchTrueFalseTotal
$main::config->{"debug"}{"pp"} and warn("POST: {", $dir, "}\n") 0 0 0
736 }
737 1270 ▶ $self->add( type => "ignore",
Branch: 1 branch
BranchTrueFalseTotal
unless $self->directive($dir) 2 1268 1270
738 text => $_ )
739 unless $self->directive($dir);
740 1270 next;
741 }
742  
743 877 ▶ if ( /\S/ && !$fragment && !exists $self->{title} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\S/ and not $fragment and not exists $self->{"title"}) 0 877 877
Condition66%4/6
/\S/ and not $fragment and not exists $self->{"title"}
!ll&&!rl&&r
3075700
/\S/ and not $fragment
!ll&&!rl&&r
3070570
MC/DC0%0/3
/\S/ and not $fragment and not exists $self->{"title"}
/\S/ not $fragment not exists $self->{"title"}
Truth table50%2/4
A and not(B) and not(C)
A= /\S/B= not $fragmentC= not exists $self->{"title"}
ABCresult
0XX0
10X0
1100
1111
744 0 do_warn("Missing {title} -- prepare for surprising results");
745 0 unshift( @$lines, "{title:$_}");
746 0 $skipcnt++;
747 0 next;
748 }
749  
750 877 ▶ if ( $in_context eq "tab" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_context eq "tab") 0 877 877
751 0 $self->add( type => "tabline", text => $_ );
752 0 warn("OOPS");
753 0 next;
754 }
755  
756 877 ▶ if ( $in_context eq "grid" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_context eq "grid") 39 838 877
757 39 $self->add( type => "gridline", $self->decompose_grid($_) );
758 39 next;
759 }
760 838 ▶ if ( $in_context eq "grille" && @grille ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_context eq "grille" and @grille) 0 838 838
Condition33%1/3
$in_context eq "grille" and @grille
!ll&&!rl&&r
83800
MC/DC0%0/2
$in_context eq "grille" and @grille
$in_context eq "grille" @grille
Truth table33%1/3
A and B
A= $in_context eq "grille"B= @grille
ABresult
0X0
100
111
761 push( @grille, { line => $diag->{line},
762 0 $self->decompose_grid($_) } );
763 0 next;
764 }
765  
766 838 ▶ if ( /\S/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (/\S/) { } 531 307 838
elsif (exists $self->{'title'} or $fragment) { } 307 0 307
767 531 ▶ if ( $prep->{songline} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prep->{"songline"}) 0 531 531
768 0 ▶ $config->{debug}->{pp} && warn("PRE: ", $_, "\n");
Branch: 1 branch
BranchTrueFalseTotal
$main::config->{"debug"}{"pp"} and warn("PRE: ", $_, "\n") 0 0 0
769 0 $prep->{songline}->($_);
770 0 ▶ $config->{debug}->{pp} && warn("POST: ", $_, "\n");
Branch: 1 branch
BranchTrueFalseTotal
$main::config->{"debug"}{"pp"} and warn("POST: ", $_, "\n") 0 0 0
771 }
772 531 ▶ if ( $config->{settings}->{flowtext}
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{'settings'}{'flowtext'} and @{$self->{'body'} // [];}) { } 0 531 531
Condition33%1/3
$main::config->{"settings"}{"flowtext"} and @{$self->{"body"} // [];}
!ll&&!rl&&r
53100
MC/DC0%0/2
$main::config->{"settings"}{"flowtext"} and @{$self->{"body"} // [];}
$main::config->{"settings"}{"flowtext"} @{$self->{"body"} // [];}
Truth table33%1/3
A and B
A= $main::config->{"settings"}{"flowtext"}B= @{$self->{"body"} // [];}
ABresult
0X0
100
111
773 0 ▶ && @{ $self->{body}//[] } ) {
Condition0%0/2
$self->{"body"} // []
l!l
00
MC/DC0%0/1
$self->{"body"} // []
$self->{"body"}
Truth table0%0/2
A
A= $self->{"body"}
Aresult
11
00
774 0 my $prev = $self->{body}->[-1];
775 0 my $this = { $self->decompose($_) };
776 0 ▶ if ( $prev->{type} eq "songline"
Branch: 1 branch
BranchTrueFalseTotal
if ($prev->{'type'} eq 'songline' and not $prev->{'chords'} and not $this->{'chords'}) { } 0 0 0
Condition0%0/6
$prev->{"type"} eq "songline" and not $prev->{"chords"} and not $this->{"chords"}
!ll&&!rl&&r
000
$prev->{"type"} eq "songline" and not $prev->{"chords"}
!ll&&!rl&&r
000
MC/DC0%0/3
$prev->{"type"} eq "songline" and not $prev->{"chords"} and not $this->{"chords"}
$prev->{"type"} eq "songline" not $prev->{"chords"} not $this->{"chords"}
Truth table0%0/4
A and not(B) and not(C)
A= $prev->{"type"} eq "songline"B= not $prev->{"chords"}C= not $this->{"chords"}
ABCresult
0XX0
10X0
1100
1111
777 && !$prev->{chords}
778 && !$this->{chords} ) {
779 0 $prev->{phrases}->[0] .= " " . $this->{phrases}->[0];
780 }
781 else {
782 0 $self->add( type => "songline", %$this );
783 }
784 }
785 else {
786 531 $self->add( type => "songline", $self->decompose($_) );
787 }
788 }
789 ▶ elsif ( exists $self->{title} || $fragment ) {
Condition33%1/3
exists $self->{"title"} or $fragment
l!l&&r!l&&!r
30700
MC/DC0%0/2
exists $self->{"title"} or $fragment
exists $self->{"title"} $fragment
Truth table33%1/3
A or B
A= exists $self->{"title"}B= $fragment
ABresult
1X1
011
000
790 307 $self->add( type => "empty" );
791 }
792 else {
793 # Collect pre-title stuff separately.
794 0 push( @{ $self->{preamble} }, $_ );
795 }
796 }
797 247 ▶ do_warn("Unterminated context in song: $in_context")
Branch: 1 branch
BranchTrueFalseTotal
if $in_context 0 247 247
798 if $in_context;
799  
800 247 ▶ warn("Processed song...\n") if $options->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"verbose"} 0 247 247
801 247 $diag->{format} = "\"%f\": %m";
802  
803 ::dump($self->{assets}, as => "Assets, Pass 1")
804 247 ▶ if $config->{debug}->{assets} & 1;
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"assets"} & 1 0 247 247
805 247 ▶ $self->dump(0) if $config->{debug}->{song} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"song"} > 1 0 247 247
806 247 ▶ ::dump($self->{body}) if $config->{debug}->{ops};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"ops"} 0 247 247
807  
808 247 ▶ if ( @labels ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@labels) 1 246 247
809 1 $self->{labels} = [ @labels ];
810 }
811  
812 # Suppress chords that the user considers 'easy'.
813 247 my %suppress;
814 247 my $xc = $config->{settings}->{transcode};
815 247 for ( @{ $config->{diagrams}->{suppress} } ) {
816 0 my $info = ChordPro::Chords::known_chord($_);
817 0 ▶ warn("Unknown chord \"$_\" in suppress list\n"), next
Branch: 1 branch
BranchTrueFalseTotal
unless $info 0 0 0
818 unless $info;
819 # Note we do transcode, but we do not transpose.
820 0 ▶ if ( $xc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xc) 0 0 0
821 0 $info = $info->transcode($xc);
822 }
823 0 $suppress{$info->name} = $info->{origin} ne "song";
824 }
825 # Suppress chords that the user don't want.
826 247 ▶ while ( my ($k,$v) = each %{ $self->{chordsinfo} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"chordsinfo"};}) 469 247 716
827 469 ▶ $suppress{$k} = 1 if !is_true($v->{diagram}//1);
Branch: 1 branch
BranchTrueFalseTotal
unless is_true($v->{"diagram"} // 1) 2 467 469
Condition100%2/2
$v->{"diagram"} // 1
l!l
2467
MC/DC100%1/1
$v->{"diagram"} // 1
$v->{"diagram"}
Truth table100%2/2
A
A= $v->{"diagram"}
Aresult
11
00
828 }
829 247 ▶ @used_chords = map { $suppress{$_} ? () : $_ } @used_chords;
Branch: 1 branch
BranchTrueFalseTotal
$suppress{$_} ? : 2 963 965
830  
831 247 my $diagrams;
832 247 ▶ if ( exists($self->{settings}->{diagrams} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'settings'}{'diagrams'}) { } 6 241 247
833 6 $diagrams = $self->{settings}->{diagrams};
834 6 ▶ $diagrams &&= $config->{diagrams}->{show} || "all";
Condition80%4/5
$diagrams &&= $main::config->{"diagrams"}{"show"} || "all"
!ll&&!rl&&r
402
$main::config->{'diagrams'}{'show'} || 'all'
l!l
11
MC/DC50%1/2
$diagrams &&= $main::config->{"diagrams"}{"show"} || "all"
$diagrams $main::config->{'diagrams'}{'show'}
Truth table66%2/3
A &&= B
A= $diagramsB= $main::config->{'diagrams'}{'show'}
ABresult
0X0
100
111
835 }
836 else {
837 241 $diagrams = $config->{diagrams}->{show};
838 }
839  
840 247 ▶ if ( $diagrams =~ /^(user|all)$/
Branch: 1 branch
BranchTrueFalseTotal
if ($diagrams =~ /^(user|all)$/ and not "ChordPro::Chords::Parser"->get_parser($target, 1)->has_diagrams) 0 247 247
Condition66%2/3
$diagrams =~ /^(user|all)$/ and not "ChordPro::Chords::Parser"->get_parser($target, 1)->has_diagrams
!ll&&!rl&&r
841630
MC/DC0%0/2
$diagrams =~ /^(user|all)$/ and not "ChordPro::Chords::Parser"->get_parser($target, 1)->has_diagrams
$diagrams =~ /^(user|all)$/ not "ChordPro::Chords::Parser"->get_parser($target, 1)->has_diagrams
Truth table66%2/3
A and not(B)
A= $diagrams =~ /^(user|all)$/B= not "ChordPro::Chords::Parser"->get_parser($target, 1)->has_diagrams
ABresult
0X0
100
111
841 && !ChordPro::Chords::Parser->get_parser($target,1)->has_diagrams ) {
842 do_warn( "Chord diagrams suppressed for " .
843 0 ▶ ucfirst($target) . " chords" ) unless $options->{silent};
Branch: 1 branch
BranchTrueFalseTotal
unless $main::options->{"silent"} 0 0 0
844 0 $diagrams = "none";
845 }
846  
847 247 ▶ if ( $diagrams eq "user" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diagrams eq 'user') { } 0 247 247
848  
849 0 ▶ if ( $self->{define} && @{$self->{define}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'define'} and @{$self->{'define'};}) { } 0 0 0
Condition0%0/3
$self->{"define"} and @{$self->{"define"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"define"} and @{$self->{"define"};}
$self->{"define"} @{$self->{"define"};}
Truth table0%0/3
A and B
A= $self->{"define"}B= @{$self->{"define"};}
ABresult
0X0
100
111
850 0 my %h = map { demarkup($_) => 1 } @used_chords;
851 @used_chords =
852 0 ▶ map { $h{$_->{name}} ? $_->{name} : () } @{$self->{define}};
Branch: 1 branch
BranchTrueFalseTotal
$h{$_->{'name'}} ? : 0 0 0
853 }
854 else {
855 0 @used_chords = ();
856 }
857 }
858 else {
859 247 my %h;
860 963 ▶ @used_chords = map { $h{$_}++ ? () : $_ }
Branch: 1 branch
BranchTrueFalseTotal
$h{$_}++ ? : 630 333 963
861 247 map { demarkup($_) } @used_chords;
862 }
863  
864 247 ▶ if ( $config->{diagrams}->{sorted} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{"diagrams"}{"sorted"}) 1 246 247
865 7 ▶ sub byname { ChordPro::Chords::chordcompare($a,$b) }
Subroutine byname: called CC=1 SCAR=0.0
Pod undocumented
866 1 @used_chords = sort byname @used_chords;
867 }
868  
869 # For headings, footers, table of contents, ...
870 247 ▶ $self->{meta}->{chords} //= [ @used_chords ];
Condition50%1/2
$self->{"meta"}{"chords"} //= [@used_chords]
l!l
0247
MC/DC0%0/1
$self->{"meta"}{"chords"} //= [@used_chords]
$self->{"meta"}{"chords"}
Truth table50%1/2
A
A= $self->{"meta"}{"chords"}
Aresult
11
00
871 247 $self->{meta}->{numchords} = [ scalar(@{$self->{meta}->{chords}}) ];
872  
873 247 ▶ if ( %memchords ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%memchords) { } 49 198 247
874 49 ▶ ::dump(\%memchords, as => "cc (atend)") if $config->{debug}->{chords};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"chords"} 0 49 49
875 }
876 else {
877 # Avoid clutter.
878 198 delete $self->{meta}->{cc};
879 }
880  
881 247 ▶ if ( $config->{settings}->{strict} && !$self->{meta}->{key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{"settings"}{"strict"} and not $self->{"meta"}{"key"}) 0 247 247
Condition33%1/3
$main::config->{"settings"}{"strict"} and not $self->{"meta"}{"key"}
!ll&&!rl&&r
24700
MC/DC0%0/2
$main::config->{"settings"}{"strict"} and not $self->{"meta"}{"key"}
$main::config->{"settings"}{"strict"} not $self->{"meta"}{"key"}
Truth table33%1/3
A and not(B)
A= $main::config->{"settings"}{"strict"}B= not $self->{"meta"}{"key"}
ABresult
0X0
100
111
882 0 do_warn( "Song is missing {key} directive" );
883 }
884  
885  
886 247 ▶ if ( $diagrams =~ /^(user|all)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diagrams =~ /^(user|all)$/) 163 84 247
887 $self->{chords} =
888 163 { type => "diagrams",
889 origin => "song",
890 show => $diagrams,
891 chords => [ @used_chords ],
892 };
893  
894 163 ▶ if ( %warned_chords ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%warned_chords) 0 163 163
895 0 my @a = sort ChordPro::Chords::chordcompare
896 keys(%warned_chords);
897 0 my $l;
898 0 ▶ if ( @a > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a > 1) { } 0 0 0
899 0 my $a = pop(@a);
900 0 $l = '"' . join('", "', @a) . '" and "' . $a . '"';
901 }
902 else {
903 0 $l = '"' . $a[0] . '"';
904 }
905 0 do_warn( "No chord diagram defined for $l (skipped)\n" );
906 }
907 }
908  
909 247 ▶ $self->dump(0) if $config->{debug}->{song} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"song"} > 0 0 247 247
910 247 ▶ $self->dump(2) if $config->{debug}->{song} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"song"} < 0 0 247 247
911 247 ▶ $self->dump(1) if $config->{debug}->{songfull};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"songfull"} 0 247 247
912  
913 247 return $self;
914 }
915  
916 1520 ▶sub add {
Subroutine add: called CC=6 SCAR=18.3
Pod undocumented
917 1520 my $self = shift;
918 1520 ▶ return if $skip_context;
Branch: 1 branch
BranchTrueFalseTotal
if $skip_context 0 1520 1520
919 1520 my %args = @_;
920  
921 # Later... Needs adjusting many tests.
922 # $args{np} //= 1 if $args{type} =~ /empty|ignore|meta|set/;
923  
924 1520 ▶ $args{line} ||= $diag->{line} if $lineinfo;
Branch: 1 branch
BranchTrueFalseTotal
if $lineinfo 1155 365 1520
Condition33%1/3
$args{"line"} ||= $diag->{"line"}
l!l&&r!l&&!r
011550
MC/DC0%0/2
$args{"line"} ||= $diag->{"line"}
$args{"line"} $diag->{"line"}
Truth table33%1/3
A ||= B
A= $args{"line"}B= $diag->{"line"}
ABresult
1X1
011
000
925 1520 ▶ $args{context} ||= $in_context;
Condition66%2/3
$args{"context"} ||= $in_context
l!l&&r!l&&!r
03241196
MC/DC50%1/2
$args{"context"} ||= $in_context
$args{"context"} $in_context
Truth table66%2/3
A ||= B
A= $args{"context"}B= $in_context
ABresult
1X1
011
000
926  
927 1520 push( @{$self->{body}}, \%args );
928 1520 ▶ if ( $in_context eq "chorus" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_context eq "chorus") 110 1410 1520
929 110 push( @chorus, { context => $in_context, %args } );
930 110 $chorus_xpose = $xpose;
931 }
932 }
933  
934 # Parses a chord and adds it to the song.
935 # It understands markup, parenthesized chords and annotations.
936 # Returns the chord Appearance.
937 1009 ▶sub chord {
Subroutine chord: called CC=22 SCAR=33.8
Pod undocumented
938 1009 my ( $self, $orig ) = @_;
939 1009 ▶ Carp::confess unless length($orig);
Branch: 1 branch
BranchTrueFalseTotal
unless length $orig 0 1009 1009
940  
941 # Intercept annotations.
942 1009 ▶ if ( $orig =~ /^\*(.+)/ || $orig =~ /^(\||\s+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($orig =~ /^\*(.+)/ or $orig =~ /^(\||\s+)$/) 3 1006 1009
Condition66%2/3
$orig =~ /^\*(.+)/ or $orig =~ /^(\||\s+)$/
l!l&&r!l&&!r
301006
MC/DC50%1/2
$orig =~ /^\*(.+)/ or $orig =~ /^(\||\s+)$/
$orig =~ /^\*(.+)/ $orig =~ /^(\||\s+)$/
Truth table66%2/3
A or B
A= $orig =~ /^\*(.+)/B= $orig =~ /^(\||\s+)$/
ABresult
1X1
011
000
943 3 my $i = ChordPro::Chord::Annotation->new
944 ( { name => $orig, text => $1 } );
945 return
946 3 ChordPro::Chords::Appearance->new
947 ( key => $self->add_chord($i), info => $i, orig => $orig );
948 }
949  
950 # Check for markup.
951 1006 my $markup = $orig;
952 1006 my $c = demarkup($orig);
953 1006 ▶ if ( $markup eq $c ) { # no markup
Branch: 1 branch
BranchTrueFalseTotal
if ($markup eq $c) 999 7 1006
954 999 undef $markup;
955 }
956  
957 # Special treatment for parenthesized chords.
958 1006 $c =~ s/^\((.*)\)$/$1/;
959 1006 ▶ do_warn("Double parens in chord: \"$orig\"")
Branch: 1 branch
BranchTrueFalseTotal
if $c =~ s/^\((.*)\)$/$1/ 0 1006 1006
960 if $c =~ s/^\((.*)\)$/$1/;
961  
962 # We have a 'bare' chord now. Parse it.
963 1006 my $info = $self->parse_chord($c);
964 1006 ▶ unless ( defined $info ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $info) 8 998 1006
965 # Warning was given.
966 # Make annotation.
967 8 my $i = ChordPro::Chord::Annotation->new
968 ( { name => $orig, text => $orig } );
969 return
970 8 ChordPro::Chords::Appearance->new
971 ( key => $self->add_chord($i), info => $i, orig => $orig );
972 }
973  
974 998 my $ap = ChordPro::Chords::Appearance->new( orig => $orig );
975  
976 # Handle markup, if any.
977 998 ▶ if ( $markup ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($markup) { } 7 991 998
elsif ((my $m = $orig) =~ s/\Q$c\E/%{formatted}/) { } 991 0 991
978 7 ▶ if ( $markup =~ s/\>\Q$c\E\</>%{formatted}</
Branch: 1 branch
BranchTrueFalseTotal
if ($markup =~ s/\>\Q$c\E\</>%{formatted}</ or $markup =~ s/\>\(\Q$c\E\)\</>(%{formatted})</) { } 6 1 7
Condition100%3/3
$markup =~ s/\>\Q$c\E\</>%{formatted}</ or $markup =~ s/\>\(\Q$c\E\)\</>(%{formatted})</
l!l&&r!l&&!r
421
MC/DC100%2/2
$markup =~ s/\>\Q$c\E\</>%{formatted}</ or $markup =~ s/\>\(\Q$c\E\)\</>(%{formatted})</
$markup =~ s/\>\Q$c\E\</>%{formatted}</ $markup =~ s/\>\(\Q$c\E\)\</>(%{formatted})</
Truth table100%3/3
A or B
A= $markup =~ s/\>\Q$c\E\</>%{formatted}</B= $markup =~ s/\>\(\Q$c\E\)\</>(%{formatted})</
ABresult
1X1
011
000
979 ||
980 $markup =~ s/\>\(\Q$c\E\)\</>(%{formatted})</ ) {
981 }
982 else {
983 1 do_warn("Invalid markup in chord: \"$markup\"\n");
984 }
985 7 $ap->format = $markup;
986 }
987 elsif ( (my $m = $orig) =~ s/\Q$c\E/%{formatted}/ ) {
988 991 ▶ $ap->format = $m unless $m eq "%{formatted}";
Branch: 1 branch
BranchTrueFalseTotal
unless $m eq "%{formatted}" 5 986 991
989 }
990  
991 # After parsing, the chord can be changed by transpose/code.
992 # info->name is the new key.
993 998 $ap->key = $self->add_chord( $info, $c = $info->name );
994 998 $ap->info = $info;
995  
996 998 ▶ unless ( $info->is_nc || $info->is_note ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($info->is_nc or $info->is_note) 984 14 998
Condition100%3/3
$info->is_nc or $info->is_note
l!l&&r!l&&!r
86984
MC/DC100%2/2
$info->is_nc or $info->is_note
$info->is_nc $info->is_note
Truth table100%3/3
A or B
A= $info->is_ncB= $info->is_note
ABresult
1X1
011
000
997 # if ( $info->is_keyboard ) {
998 984 ▶ if ( $::config->{instrument}->{type} eq "keyboard" ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($main::config->{'instrument'}{'type'} eq 'keyboard') { } 0 984 984
elsif ($info->{'origin'}) { } 784 200 984
elsif ($main::running_under_test) { } 200 0 200
elsif (not $info->is_rootless || $info->has_diagram || !$info->parser->has_diagrams) { } 0 0 0
999 0 push( @used_chords, $c );
1000 }
1001 elsif ( $info->{origin} ) {
1002 # Include if we have diagram info.
1003 784 ▶ push( @used_chords, $c ) if $info->has_diagram;
Branch: 1 branch
BranchTrueFalseTotal
if $info->has_diagram 784 0 784
1004 }
1005 elsif ( $::running_under_test ) {
1006 # Tests run without config and chords, so pretend.
1007 200 push( @used_chords, $c );
1008 }
1009 ▶ elsif ( ! ( $info->is_rootless
Condition0%0/6
$info->is_rootless || $info->has_diagram || !$info->parser->has_diagrams
l!l&&r!l&&!r
000
$info->is_rootless or $info->has_diagram
l!l&&r!l&&!r
000
MC/DC0%0/3
$info->is_rootless || $info->has_diagram || !$info->parser->has_diagrams
$info->is_rootless $info->has_diagram !$info->parser->has_diagrams
Truth table0%0/4
A or B || not(C)
A= $info->is_rootlessB= $info->has_diagramC= !$info->parser->has_diagrams
ABCresult
1XX1
01X1
0011
0000
1010 || $info->has_diagram
1011 || !$info->parser->has_diagrams
1012 ) ) {
1013 do_warn("Unknown chord: $c")
1014 0 ▶ unless $warned_chords{$c}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $warned_chords{$c}++ 0 0 0
1015 }
1016 }
1017  
1018 998 return $ap;
1019 }
1020  
1021 665 ▶sub decompose {
Subroutine decompose: called CC=27 SCAR=33.9
Pod undocumented
1022 665 my ($self, $orig) = @_;
1023 665 my $line = fmt_subst( $self, $orig );
1024 665 ▶ undef $orig if $orig eq $line;
Branch: 1 branch
BranchTrueFalseTotal
if $orig eq $line 664 1 665
1025 665 $line =~ s/\s+$//;
1026 665 my @a = split( $re_chords, $line, -1);
1027 665 ▶ if ( @a <= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a <= 1) 297 368 665
1028 # For the exceptional case you need brackets [] in your lyrics
1029 # or annotations.
1030 297 ▶ if ( my $a = $config->{parser}->{altbrackets} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $a = $main::config->{"parser"}{"altbrackets"}) 0 297 297
1031 0 eval "\$line =~ tr/$a/[]/";
1032 }
1033 297 ▶ return ( phrases => [ $line ],
Branch: 1 branch
BranchTrueFalseTotal
$orig ? : 0 297 297
1034 $orig ? ( orig => $orig ) : (),
1035 );
1036 }
1037  
1038 # For the exceptional case you need brackets [] in your lyrics
1039 # or annotations.
1040 368 ▶ if ( my $a = $config->{parser}->{altbrackets} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $a = $main::config->{"parser"}{"altbrackets"}) 0 368 368
1041 0 @a = map { eval "tr/$a/[]/r" } @a;
1042 }
1043  
1044 368 my $dummy;
1045 368 ▶ shift(@a) if $a[0] eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $a[0] eq "" 135 233 368
1046 368 ▶ unshift(@a, '[]'), $dummy++ if $a[0] !~ $re_chords;
Branch: 1 branch
BranchTrueFalseTotal
unless $a[0] =~ /$ChordPro::Song::re_chords/ 233 135 368
1047  
1048 368 my @phrases;
1049 my @chords;
1050 368 ▶ while ( @a ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 1102 368 1470
1051 1102 my $chord = shift(@a);
1052 1102 push(@phrases, shift(@a));
1053  
1054 # Normal chords.
1055 1102 ▶ if ( $chord =~ s/^\[(.*)\]$/$1/ && $chord ne "^" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($chord =~ s/^\[(.*)\]$/$1/ and $chord ne '^') { } 1058 44 1102
elsif ($memchords and $in_context and not $chord =~ /^\*/) { } 37 7 44
Condition100%3/3
$chord =~ s/^\[(.*)\]$/$1/ and $chord ne "^"
!ll&&!rl&&r
10341058
MC/DC100%2/2
$chord =~ s/^\[(.*)\]$/$1/ and $chord ne "^"
$chord =~ s/^\[(.*)\]$/$1/ $chord ne "^"
Truth table100%3/3
A and B
A= $chord =~ s/^\[(.*)\]$/$1/B= $chord ne "^"
ABresult
0X0
100
111
1056 1058 ▶ push(@chords, $chord eq "" ? "" : $self->chord($chord));
Branch: 1 branch
BranchTrueFalseTotal
$chord eq '' ? : 233 825 1058
1057 1058 ▶ if ( $memchords && !$dummy && $chord !~ /^\*/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($memchords and not $dummy and not $chord =~ /^\*/) 222 836 1058
Condition83%5/6
$memchords and not $dummy and not $chord =~ /^\*/
!ll&&!rl&&r
8360222
$memchords and not $dummy
!ll&&!rl&&r
75284222
MC/DC66%2/3
$memchords and not $dummy and not $chord =~ /^\*/
$memchords not $dummy not $chord =~ /^\*/
Truth table75%3/4
A and not(B) and not(C)
A= $memchordsB= not $dummyC= not $chord =~ /^\*/
ABCresult
0XX0
10X0
1100
1111
1058 222 ▶ if ( $memcrdinx == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($memcrdinx == 0) 35 187 222
1059 35 $memorizing++;
1060 }
1061 222 ▶ if ( $memorizing ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($memorizing) 220 2 222
1062 220 ▶ push( @$memchords, $chord eq "" ? "" : $chord );
Branch: 1 branch
BranchTrueFalseTotal
$chord eq '' ? : 0 220 220
1063 warn("Chord memorized for $in_context\[$memcrdinx]: ",
1064 $memchords->[-1], "\n")
1065 220 ▶ if $config->{debug}->{chords};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"chords"} 0 220 220
1066 }
1067 222 $memcrdinx++;
1068 }
1069 }
1070  
1071 # Recall memorized chords.
1072 ▶ elsif ( $memchords && $in_context && $chord !~ /^\*/ ) {
Condition66%4/6
$memchords and $in_context and not $chord =~ /^\*/
!ll&&!rl&&r
7037
$memchords and $in_context
!ll&&!rl&&r
7037
MC/DC33%1/3
$memchords and $in_context and not $chord =~ /^\*/
$memchords $in_context not $chord =~ /^\*/
Truth table50%2/4
A and B and not(C)
A= $memchordsB= $in_contextC= not $chord =~ /^\*/
ABCresult
0XX0
10X0
1100
1111
1073 37 ▶ if ( $memcrdinx == 0 && @$memchords == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($memcrdinx == 0 and @$memchords == 0) { } 1 36 37
elsif ($memcrdinx >= @$memchords) { } 0 36 36
Condition100%3/3
$memcrdinx == 0 and @$memchords == 0
!ll&&!rl&&r
2971
MC/DC100%2/2
$memcrdinx == 0 and @$memchords == 0
$memcrdinx == 0 @$memchords == 0
Truth table100%3/3
A and B
A= $memcrdinx == 0B= @$memchords == 0
ABresult
0X0
100
111
1074 1 do_warn("No chords memorized for $in_context");
1075 1 push( @chords, $self->chord($chord) );
1076 1 undef $memchords;
1077 }
1078 elsif ( $memcrdinx >= @$memchords ) {
1079 0 do_warn("Not enough chords memorized for $in_context");
1080 0 push( @chords, $self->chord($chord) );
1081 }
1082 else {
1083 warn("Chord recall $in_context\[$memcrdinx]: ", $memchords->[$memcrdinx], "\n")
1084 36 ▶ if $config->{debug}->{chords};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"chords"} 0 36 36
1085 36 push( @chords, $self->chord($memchords->[$memcrdinx]) );
1086 }
1087 37 $memcrdinx++;
1088 }
1089  
1090 # Not memorizing.
1091 else {
1092 # do_warn("No chords memorized for $in_context");
1093 7 push( @chords, $self->chord($chord) );
1094 }
1095 1102 $dummy = 0;
1096 }
1097  
1098 368 ▶ return ( phrases => \@phrases,
Branch: 1 branch
BranchTrueFalseTotal
$orig ? : 1 367 368
1099 chords => \@chords,
1100 $orig ? ( orig => $orig ) : (),
1101 );
1102 }
1103  
1104 134 ▶sub cdecompose {
Subroutine cdecompose: called CC=3 SCAR=11.0
Pod undocumented
1105 134 my ( $self, $line ) = @_;
1106 134 ▶ $line = fmt_subst( $self, $line ) unless $no_substitute;
Branch: 1 branch
BranchTrueFalseTotal
unless $no_substitute 134 0 134
1107 134 my %res = $self->decompose($line);
1108 134 ▶ return ( text => $line ) unless $res{chords};
Branch: 1 branch
BranchTrueFalseTotal
unless $res{"chords"} 120 14 134
1109 14 return %res;
1110 }
1111  
1112 39 ▶sub decompose_grid {
Subroutine decompose_grid: called CC=57 SCAR=64.7
Pod undocumented
1113 39 my ($self, $orig) = @_;
1114 39 my $line = fmt_subst( $self, $orig );
1115 39 ▶ undef $orig if $orig eq $line;
Branch: 1 branch
BranchTrueFalseTotal
if $orig eq $line 39 0 39
1116 39 $line =~ s/^\s+//;
1117 39 $line =~ s/\s+$//;
1118 39 ▶ return ( tokens => [] ) if $line eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "" 0 39 39
1119 39 local $re_chords = qr/(\[.*?\])/;
1120 39 my $memchords = $memchords;
1121  
1122 39 my %res;
1123 39 ▶ if ( $line !~ /\|/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $line =~ /\|/) { } 0 39 39
1124 0 $res{margin} = { $self->cdecompose($line), orig => $line };
1125 0 $line = "";
1126 }
1127 else {
1128 39 ▶ if ( $line =~ /(.*\|\S*)\s([^\|]*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /(.*\|\S*)\s([^\|]*)$/) 0 39 39
1129 0 $line = $1;
1130 0 $res{comment} = { $self->cdecompose($2), orig => $2 };
1131 0 ▶ do_warn( "No margin cell for trailing comment" )
Branch: 1 branch
BranchTrueFalseTotal
unless $in_context eq "grille" or $grid_cells->[2] 0 0 0
Condition0%0/3
$in_context eq "grille" or $grid_cells->[2]
l!l&&r!l&&!r
000
MC/DC0%0/2
$in_context eq "grille" or $grid_cells->[2]
$in_context eq "grille" $grid_cells->[2]
Truth table0%0/3
A or B
A= $in_context eq "grille"B= $grid_cells->[2]
ABresult
1X1
011
000
1132 unless $in_context eq "grille" || $grid_cells->[2];
1133 }
1134 39 ▶ if ( $line =~ /^([^|]+?)\s*(\|.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^([^|]+?)\s*(\|.*)/) 0 39 39
1135 0 $line = $2;
1136 0 $res{margin} = { $self->cdecompose($1), orig => $1 };
1137 0 ▶ do_warn( "No cell for margin text" )
Branch: 1 branch
BranchTrueFalseTotal
unless $in_context eq "grille" or $grid_cells->[1] 0 0 0
Condition0%0/3
$in_context eq "grille" or $grid_cells->[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$in_context eq "grille" or $grid_cells->[1]
$in_context eq "grille" $grid_cells->[1]
Truth table0%0/3
A or B
A= $in_context eq "grille"B= $grid_cells->[1]
ABresult
1X1
011
000
1138 unless $in_context eq "grille" || $grid_cells->[1];
1139 }
1140 }
1141  
1142 39 my @tokens;
1143 39 my @t = split( ' ', $line );
1144  
1145 # Unfortunately, <span xxx> gets split too.
1146 39 ▶ while ( @t ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@t) 663 39 702
1147 663 $_ = shift(@t);
1148 663 push( @tokens, $_ );
1149 663 ▶ if ( /\<span$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\<span$/) 0 663 663
1150 0 ▶ while ( @t ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@t) 0 0 0
1151 0 $_ = shift(@t);
1152 0 $tokens[-1] .= " " . $_;
1153 0 ▶ last if /\<\/span>/
Branch: 1 branch
BranchTrueFalseTotal
if m[\</span>] and not m[\</span>.*?\<span] 0 0 0
Condition0%0/3
m[\</span>] and not m[\</span>.*?\<span]
!ll&&!rl&&r
000
MC/DC0%0/2
m[\</span>] and not m[\</span>.*?\<span]
m[\</span>] not m[\</span>.*?\<span]
Truth table0%0/3
A and not(B)
A= m[\</span>]B= not m[\</span>.*?\<span]
ABresult
0X0
100
111
1154 && ! /\<\/span>.*?\<span/;
1155 }
1156 }
1157 }
1158 39 my $nbt = 0; # non-bar tokens
1159 39 my $p0; # this bar chords
1160 my $p1; # prev chords (for % and %% repeat)
1161 39 my $p2; # pprev chords (for %% repeat)
1162 39 my $si = 0; # start index
1163  
1164 39 $grid_type = 0;
1165 39 ▶ if ( @tokens && uc($tokens[0]) =~ /^\|.*S/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens and uc($tokens[0]) =~ /^\|.*S/i) 0 39 39
Condition33%1/3
@tokens and uc($tokens[0]) =~ /^\|.*S/i
!ll&&!rl&&r
0390
MC/DC0%0/2
@tokens and uc($tokens[0]) =~ /^\|.*S/i
@tokens uc($tokens[0]) =~ /^\|.*S/i
Truth table33%1/3
A and B
A= @tokensB= uc($tokens[0]) =~ /^\|.*S/i
ABresult
0X0
100
111
1166 0 $grid_type = 1 + (chop($tokens[0]) eq "S"); # strum line
1167 0 $memchords = 0;
1168 }
1169  
1170 118 ▶ my $chord = sub {
Subroutine __ANON__: called CC=3 SCAR=14.2
1171 118 my $c = shift;
1172 118 ▶ if ( is_gridstrum($grid_type) && is_strum($c) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&is_gridstrum($grid_type) and is_strum($c)) { } 0 118 118
Condition33%1/3
&is_gridstrum($grid_type) and is_strum($c)
!ll&&!rl&&r
11800
MC/DC0%0/2
&is_gridstrum($grid_type) and is_strum($c)
&is_gridstrum($grid_type) is_strum($c)
Truth table33%1/3
A and B
A= &is_gridstrum($grid_type)B= is_strum($c)
ABresult
0X0
100
111
1173 0 my $i = ChordPro::Chord::Strum->new( { name => $c } );
1174 0 ChordPro::Chords::Appearance->new
1175 ( key => $self->add_chord($i), info => $i );
1176 }
1177 else {
1178 118 $self->chord($c);
1179 }
1180 39 };
1181  
1182 39 foreach ( @tokens ) {
1183 663 ▶ if ( $_ eq "|:" || $_ eq "{" ) {
Branch: 11 branches
BranchTrueFalseTotal
if ($_ eq '|:' or $_ eq '{') { } 0 663 663
elsif (/^(:?\|)(\d+)(>?)$/) { } 0 663 663
elsif ($_ eq ':|' or $_ eq '}') { } 0 663 663
elsif ($_ eq ':|:' or $_ eq '}{') { } 0 663 663
elsif ($_ eq '|') { } 149 514 663
elsif ($_ eq '||') { } 2 512 514
elsif ($_ eq '|.') { } 0 512 512
elsif ($_ eq '%') { } 0 512 512
elsif ($_ eq '%%') { } 0 512 512
elsif ($_ eq '/') { } 0 512 512
elsif ($_ eq '.') { } 395 117 512
Condition33%1/3
$_ eq "|:" or $_ eq "{"
l!l&&r!l&&!r
00663
MC/DC0%0/2
$_ eq "|:" or $_ eq "{"
$_ eq "|:" $_ eq "{"
Truth table33%1/3
A or B
A= $_ eq "|:"B= $_ eq "{"
ABresult
1X1
011
000
1184 0 $_ = { symbol => $_, class => "bar" };
1185 0 ▶ $si = @$memchords if $memchords;
Branch: 1 branch
BranchTrueFalseTotal
if $memchords 0 0 0
1186 }
1187 elsif ( /^(:?\|)(\d+)(>?)$/ ) {
1188 0 $_ = { symbol => $1, volta => $2, class => "bar" };
1189 0 ▶ $_->{align} = 1 if $3;
Branch: 1 branch
BranchTrueFalseTotal
if $3 0 0 0
1190 }
1191 ▶ elsif ( $_ eq ":|" || $_ eq "}" ) {
Condition33%1/3
$_ eq ":|" or $_ eq "}"
l!l&&r!l&&!r
00663
MC/DC0%0/2
$_ eq ":|" or $_ eq "}"
$_ eq ":|" $_ eq "}"
Truth table33%1/3
A or B
A= $_ eq ":|"B= $_ eq "}"
ABresult
1X1
011
000
1192 0 $_ = { symbol => $_, class => "bar" };
1193 0 ▶ if ( $memchords ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($memchords) 0 0 0
1194 0 push( @$memchords, @$memchords[ $si .. $#{$memchords} ] );
1195 }
1196 }
1197 ▶ elsif ( $_ eq ":|:" || $_ eq "}{" ) {
Condition33%1/3
$_ eq ":|:" or $_ eq "}{"
l!l&&r!l&&!r
00663
MC/DC0%0/2
$_ eq ":|:" or $_ eq "}{"
$_ eq ":|:" $_ eq "}{"
Truth table33%1/3
A or B
A= $_ eq ":|:"B= $_ eq "}{"
ABresult
1X1
011
000
1198 0 $_ = { symbol => $_, class => "bar" };
1199 0 ▶ if ( $memchords ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($memchords) 0 0 0
1200 0 push( @$memchords, @$memchords[ $si .. $#{$memchords} ] );
1201 0 $si = @$memchords;
1202 }
1203 }
1204 elsif ( $_ eq "|" ) {
1205 149 $_ = { symbol => $_, class => "bar" };
1206 }
1207 elsif ( $_ eq "||" ) {
1208 2 $_ = { symbol => $_, class => "bar" };
1209 }
1210 elsif ( $_ eq "|." ) {
1211 0 $_ = { symbol => $_, class => "bar" };
1212 }
1213 elsif ( $_ eq "%" ) {
1214 0 $_ = { symbol => $_, class => "repeat1" };
1215 0 ▶ if ( $memchords && $p1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($memchords and $p1) 0 0 0
Condition0%0/3
$memchords and $p1
!ll&&!rl&&r
000
MC/DC0%0/2
$memchords and $p1
$memchords $p1
Truth table0%0/3
A and B
A= $memchordsB= $p1
ABresult
0X0
100
111
1216 0 push( @$memchords, @$p1 );
1217 0 ▶ if ( $config->{debug}->{chords} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{"debug"}{"chords"}) 0 0 0
1218 warn("Chord memorized for $cctag\[$memcrdinx]: ",
1219 $_, "\n"), $memcrdinx++
1220 0 for @$p1;
1221 }
1222 }
1223 }
1224 elsif ( $_ eq '%%' ) {
1225 0 $_ = { symbol => $_, class => "repeat2" };
1226 0 ▶ if ( $memchords && $p1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($memchords and $p1) 0 0 0
Condition0%0/3
$memchords and $p1
!ll&&!rl&&r
000
MC/DC0%0/2
$memchords and $p1
$memchords $p1
Truth table0%0/3
A and B
A= $memchordsB= $p1
ABresult
0X0
100
111
1227 0 ▶ push( @$memchords, @$p2 ) if $p2;
Branch: 1 branch
BranchTrueFalseTotal
if $p2 0 0 0
1228 0 push( @$memchords, @$p1 );
1229 0 ▶ if ( $config->{debug}->{chords} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{"debug"}{"chords"}) 0 0 0
1230 warn("Chord memorized for $cctag\[$memcrdinx]: ",
1231 $_, "\n"), $memcrdinx++
1232 0 for @$p2, @$p1;
1233 }
1234 }
1235 }
1236 elsif ( $_ eq "/" ) {
1237 0 $_ = { symbol => $_, class => "slash" };
1238 }
1239 elsif ( $_ eq "." ) {
1240 395 $_ = { symbol => $_, class => "space" };
1241 395 $nbt++;
1242 }
1243 else {
1244 # Multiple chords in a cell?
1245 117 my @a = split( /~/, $_, -1 );
1246 117 ▶ if ( @a == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a == 1) { } 116 1 117
1247 # Normal case, single chord.
1248 116 $_ = { chord => $chord->($_), class => "chord" };
1249 }
1250 else {
1251 # Multiple chords.
1252 $_ = { chords =>
1253 1 ▶ [ map { ( $_ eq '.' || $_ eq '' )
Branch: 2 branches
BranchTrueFalseTotal
$_ eq '.' || $_ eq '' ? : 0 2 2
$_ eq '/' ? : 0 2 2
Condition33%1/3
$_ eq "." or $_ eq ""
l!l&&r!l&&!r
002
MC/DC0%0/2
$_ eq "." or $_ eq ""
$_ eq "." $_ eq ""
Truth table33%1/3
A or B
A= $_ eq "."B= $_ eq ""
ABresult
1X1
011
000
1254 ? ''
1255 : $_ eq "/"
1256 ? "/"
1257 : $chord->($_) } @a ],
1258 class => "chords" };
1259 }
1260 117 ▶ if ( $memchords && !is_gridstrum($grid_type) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($memchords and not &is_gridstrum($grid_type)) 117 0 117
Condition33%1/3
$memchords and not &is_gridstrum($grid_type)
!ll&&!rl&&r
00117
MC/DC0%0/2
$memchords and not &is_gridstrum($grid_type)
$memchords not &is_gridstrum($grid_type)
Truth table33%1/3
A and not(B)
A= $memchordsB= not &is_gridstrum($grid_type)
ABresult
0X0
100
111
1261 117 @a = grep { !m;^[/.]?$; } @a;
1262 117 push( @$memchords, @a );
1263 117 push( @$p0, @a );
1264 117 ▶ if ( $config->{debug}->{chords} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{"debug"}{"chords"}) 0 117 117
1265 warn("Chord memorized for $cctag\[$memcrdinx]: ",
1266 $_, "\n"), $memcrdinx++
1267 0 for @a;
1268 }
1269 }
1270 117 $nbt++;
1271 }
1272 663 ▶ if ( $_->{class} eq "bar" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"class"} eq "bar") 151 512 663
1273 151 $p2 = $p1; $p1 = $p0; undef $p0;
1274 }
1275 }
1276 39 ▶ if ( $nbt > $grid_cells->[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nbt > $grid_cells->[0]) 0 39 39
1277 0 do_warn( "Too few cells for grid content" );
1278 }
1279 39 ▶ return ( tokens => \@tokens,
Branch: 2 branches
BranchTrueFalseTotal
$grid_type == 1 ? : 0 39 39
$grid_type == 2 ? : 0 39 39
1280 $grid_type == 1 ? ( type => "strumline" ) : (),
1281 $grid_type == 2 ? ( type => "strumline", subtype => "cellbars" ) : (),
1282 %res );
1283 }
1284  
1285 ################ Parsing directives ################
1286  
1287 92 my %directives = (
1288 chord => \&define_chord,
1289 chorus => \&dir_chorus,
1290 column_break => \&dir_column_break,
1291 columns => \&dir_columns,
1292 comment => \&dir_comment,
1293 comment_box => \&dir_comment,
1294 comment_italic => \&dir_comment,
1295 define => \&define_chord,
1296 diagrams => \&dir_diagrams,
1297 end_of_bridge => undef,
1298 end_of_chorus => undef,
1299 end_of_grid => undef,
1300 end_of_grille => undef,
1301 end_of_tab => undef,
1302 end_of_verse => undef,
1303 grid => \&dir_grid,
1304 highlight => \&dir_comment,
1305 image => \&dir_image,
1306 meta => \&dir_meta,
1307 new_page => \&dir_new_page,
1308 new_physical_page => \&dir_new_page,
1309 new_song => \&dir_new_song,
1310 no_grid => \&dir_no_grid,
1311 pagesize => \&dir_papersize,
1312 pagetype => \&dir_papersize,
1313 start_of_bridge => undef,
1314 start_of_chorus => undef,
1315 start_of_grid => undef,
1316 start_of_grille => undef,
1317 start_of_tab => undef,
1318 start_of_verse => undef,
1319 subtitle => \&dir_subtitle,
1320 title => \&dir_title,
1321 titles => \&dir_titles,
1322 transpose => \&dir_transpose,
1323 );
1324 # NOTE: Flex: start_of_... end_of_... x_...
1325  
1326 92 my %abbrevs = (
1327 c => "comment",
1328 cb => "comment_box",
1329 cf => "chordfont",
1330 ci => "comment_italic",
1331 col => "columns",
1332 colb => "column_break",
1333 cs => "chordsize",
1334 eob => "end_of_bridge",
1335 eoc => "end_of_chorus",
1336 eog => "end_of_grid",
1337 eot => "end_of_tab",
1338 eov => "end_of_verse",
1339 g => "diagrams",
1340 ng => "no_grid",
1341 np => "new_page",
1342 npp => "new_physical_page",
1343 ns => "new_song",
1344 sob => "start_of_bridge",
1345 soc => "start_of_chorus",
1346 sog => "start_of_grid",
1347 sot => "start_of_tab",
1348 sov => "start_of_verse",
1349 st => "subtitle",
1350 t => "title",
1351 tf => "textfont",
1352 ts => "textsize",
1353 );
1354  
1355 # Use by: runtimeinfo.
1356 14 ▶sub _directives { \%directives }
Subroutine _directives: called CC=1 SCAR=0.0
1357 14 ▶sub _directive_abbrevs { \%abbrevs }
Subroutine _directive_abbrevs: called CC=1 SCAR=0.0
1358  
1359 92 my $dirpat;
1360  
1361 1936 ▶sub parse_directive {
Subroutine parse_directive: called CC=15 SCAR=28.6
Pod undocumented
1362 1936 my ( $self, $d ) = @_;
1363  
1364 # Pattern for all recognized directives.
1365 1936 ▶ unless ( $dirpat ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dirpat) 66 1870 1936
1366 $dirpat =
1367 '(?:' .
1368 join( '|', keys(%directives),
1369 66 @{$config->{metadata}->{keys}},
1370 keys(%abbrevs),
1371 '(?:start|end)_of_\w+',
1372 "(?:$propitems_re".
1373 '(?:font|size|colou?r))',
1374 ) . ')';
1375 66 $dirpat = qr/$dirpat/;
1376 }
1377  
1378 # $d is the complete directive line, without leading/trailing { }.
1379 1936 ▶ if ( $options->{reference} and $d =~ s/^\s*:[: ]*//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::options->{"reference"} and $d =~ s/^\s*:[: ]*//) 0 1936 1936
Condition33%1/3
$main::options->{"reference"} and $d =~ s/^\s*:[: ]*//
!ll&&!rl&&r
193600
MC/DC0%0/2
$main::options->{"reference"} and $d =~ s/^\s*:[: ]*//
$main::options->{"reference"} $d =~ s/^\s*:[: ]*//
Truth table33%1/3
A and B
A= $main::options->{"reference"}B= $d =~ s/^\s*:[: ]*//
ABresult
0X0
100
111
1380 0 do_warn("Incorrect start of directive (':' not allowed at start)");
1381 }
1382 1936 $d =~ s/^[: ]+//;
1383 1936 $d =~ s/\s+$//;
1384 1936 my $dir = lc($d);
1385 1936 my $arg = "";
1386 1936 ▶ if ( $d =~ /^(.*?)([: ])\s*(.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d =~ /^(.*?)([: ])\s*(.*)/) 1175 761 1936
1387 1175 ( $dir, $arg ) = ( lc($1), $3 );
1388 1175 ▶ if ( $options->{reference} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::options->{"reference"}) 0 1175 1175
1389 0 ▶ do_warn("Directive name must be followed by a ':'")
Branch: 1 branch
BranchTrueFalseTotal
unless $2 eq ":" 0 0 0
1390 unless $2 eq ":";
1391 }
1392 }
1393 1936 $dir =~ s/[: ]+$//;
1394 # $dir is the lowcase directive name.
1395 # $arg is the rest, if any.
1396  
1397 # Check for xxx-yyy selectors.
1398 1936 ▶ if ( $dir =~ /^($dirpat)-(.+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir =~ /^($dirpat)-(.+)$/) { } 229 1707 1936
1399 229 ▶ $dir = $abbrevs{$1} // $1;
Condition66%2/3
$abbrevs{$1} // $1
l!l&&r!l&&!r
501790
MC/DC0%0/2
$abbrevs{$1} // $1
$abbrevs{$1} $1
Truth table66%2/3
A // B
A= $abbrevs{$1}B= $1
ABresult
1X1
011
000
1400 229 ▶ unless ( $self->selected($2) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->selected($2)) 113 116 229
1401 113 ▶ if ( $dir =~ /^start_of_/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir =~ /^start_of_/) { } 11 102 113
1402 11 return { name => $dir, arg => $arg, omit => 2 };
1403 }
1404 else {
1405 102 return { name => $dir, arg => $arg, omit => 1 };
1406 }
1407 }
1408 }
1409 else {
1410 1707 ▶ $dir = $abbrevs{$dir} // $dir;
Condition66%2/3
$abbrevs{$dir} // $dir
l!l&&r!l&&!r
38113260
MC/DC0%0/2
$abbrevs{$dir} // $dir
$abbrevs{$dir} $dir
Truth table66%2/3
A // B
A= $abbrevs{$dir}B= $dir
ABresult
1X1
011
000
1411 }
1412  
1413 1823 ▶ if ( $dir =~ /^start_of_(.*)/
Branch: 1 branch
BranchTrueFalseTotal
if ($dir =~ /^start_of_(.*)/ and exists $main::config->{"delegates"}{$1} and beo($main::config->{"delegates"}{$1}, "type") eq "omit") 0 1823 1823
Condition83%5/6
$dir =~ /^start_of_(.*)/ and exists $main::config->{"delegates"}{$1} and beo($main::config->{"delegates"}{$1}, "type") eq "omit"
!ll&&!rl&&r
181940
$dir =~ /^start_of_(.*)/ and exists $main::config->{"delegates"}{$1}
!ll&&!rl&&r
16501694
MC/DC0%0/3
$dir =~ /^start_of_(.*)/ and exists $main::config->{"delegates"}{$1} and beo($main::config->{"delegates"}{$1}, "type") eq "omit"
$dir =~ /^start_of_(.*)/ exists $main::config->{"delegates"}{$1} beo($main::config->{"delegates"}{$1}, "type") eq "omit"
Truth table75%3/4
A and B and C
A= $dir =~ /^start_of_(.*)/B= exists $main::config->{"delegates"}{$1}C= beo($main::config->{"delegates"}{$1}, "type") eq "omit"
ABCresult
0XX0
10X0
1100
1111
1414 && exists $config->{delegates}->{$1}
1415 && beo( $config->{delegates}->{$1}, 'type' ) eq 'omit' ) {
1416 0 return { name => $dir, arg => $arg, omit => 2 };
1417 }
1418  
1419 1823 return { name => $dir, arg => $arg, omit => 0 }
1420 }
1421  
1422 # Process a selector.
1423 232 ▶sub selected {
Subroutine selected: called CC=6 SCAR=18.0
Pod undocumented
1424 232 my ( $self, $sel ) = @_;
1425 232 ▶ return 1 unless defined $sel;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sel 3 229 232
1426 229 my $negate = $sel =~ s/\!$//;
1427 $sel = ( $sel eq lc($config->{instrument}->{type}) )
1428 ||
1429 ( $sel eq lc($config->{user}->{name})
1430 ||
1431 229 ▶ ( $self->{meta}->{lc $sel} && is_true($self->{meta}->{lc $sel}->[0]) )
Condition77%7/9
$sel eq lc $main::config->{'instrument'}{'type'} || ($sel eq lc $main::config->{'user'}{'name'} || $self->{'meta'}{lc $sel} && is_true($self->{'meta'}{lc $sel}[0]))
l!l&&r!l&&!r
5109115
$sel eq lc $main::config->{"user"}{"name"} or $self->{"meta"}{lc $sel} and is_true($self->{"meta"}{lc $sel}[0])
l!l&&r!l&&!r
0109115
$self->{"meta"}{lc $sel} and is_true($self->{"meta"}{lc $sel}[0])
!ll&&!rl&&r
1150109
MC/DC50%2/4
$sel eq lc $main::config->{'instrument'}{'type'} || ($sel eq lc $main::config->{'user'}{'name'} || $self->{'meta'}{lc $sel} && is_true($self->{'meta'}{lc $sel}[0]))
$sel eq lc $main::config->{'instrument'}{'type'} $sel eq lc $main::config->{"user"}{"name"} $self->{"meta"}{lc $sel} is_true($self->{"meta"}{lc $sel}[0])
Truth table60%3/5
A || B or C and D
A= $sel eq lc $main::config->{'instrument'}{'type'}B= $sel eq lc $main::config->{"user"}{"name"}C= $self->{"meta"}{lc $sel}D= is_true($self->{"meta"}{lc $sel}[0])
ABCDresult
1XXX1
01XX1
00111
000X0
00100
1432 );
1433 229 ▶ $sel = !$sel if $negate;
Branch: 1 branch
BranchTrueFalseTotal
if $negate 6 223 229
1434 229 return $sel;
1435 }
1436  
1437 1270 ▶sub directive {
Subroutine directive: called CC=82 SCAR=67.4
Pod undocumented
1438 1270 my ( $self, $d ) = @_;
1439  
1440 1270 my $dd = $self->parse_directive($d);
1441 1270 ▶ return 1 if $dd->{omit} == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $dd->{"omit"} == 1 2 1268 1270
1442  
1443 1268 my $dir = $dd->{name};
1444 1268 my $arg = $dd->{arg};
1445 1268 ▶ if ( $arg ne "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg ne "") 994 274 1268
1446 994 $arg = fmt_subst( $self, $arg );
1447 994 ▶ if ( $arg !~ /\S/ ) { # expansion yields empty
Branch: 1 branch
BranchTrueFalseTotal
unless ($arg =~ /\S/) 0 994 994
1448 0 ▶ if ( $dir =~ /^start_of_/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir =~ /^start_of_/) { } 0 0 0
1449 0 $dd->{omit} = 2;
1450 }
1451 else {
1452 0 return 1;
1453 }
1454 }
1455 }
1456  
1457 1268 ▶ if ( $directives{$dir} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($directives{$dir}) 741 527 1268
1458 741 return $directives{$dir}->( $self, $dir, $arg, $dd->{arg} );
1459 }
1460  
1461 # Context flags.
1462  
1463 527 ▶ if ( $dir =~ /^start_of_(\w+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir =~ /^start_of_(\w+)$/) 97 430 527
1464 97 ▶ do_warn("Already in " . ucfirst($in_context) . " context\n")
Branch: 1 branch
BranchTrueFalseTotal
if $in_context 0 97 97
1465 if $in_context;
1466 97 $in_context = $1;
1467 97 ▶ if ( $dd->{omit} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dd->{"omit"}) 2 95 97
1468 2 $skip_context = 1;
1469 # warn("Skipping context: $in_context\n");
1470 2 return 1;
1471 }
1472 95 ▶ @chorus = (), $chorus_xpose = parse_transpose(0)
Branch: 1 branch
BranchTrueFalseTotal
if $in_context eq "chorus" 29 66 95
1473 if $in_context eq "chorus";
1474 95 undef $cctag;
1475  
1476 95 ▶ if ( $in_context eq "grid"
Branch: 3 branches
BranchTrueFalseTotal
if ($in_context eq 'grid' or $in_context eq 'grille' and not exists $main::config->{'delegates'}{$in_context}) { } 26 69 95
elsif (exists $main::config->{'delegates'}{$in_context}) { } 2 67 69
elsif ($arg ne '') { } 2 65 67
Condition50%3/6
$in_context eq "grid" or $in_context eq "grille" and not exists $main::config->{"delegates"}{$in_context}
l!l&&r!l&&!r
26069
$in_context eq "grille" and not exists $main::config->{"delegates"}{$in_context}
!ll&&!rl&&r
6900
MC/DC33%1/3
$in_context eq "grid" or $in_context eq "grille" and not exists $main::config->{"delegates"}{$in_context}
$in_context eq "grid" $in_context eq "grille" not exists $main::config->{"delegates"}{$in_context}
Truth table50%2/4
A or B and not(C)
A= $in_context eq "grid"B= $in_context eq "grille"C= not exists $main::config->{"delegates"}{$in_context}
ABCresult
1XX1
0111
00X0
0100
1477 || ( $in_context eq "grille" && !exists $config->{delegates}->{$in_context} ) ) {
1478 26 $cctag = $in_context;
1479 26 my $kv = parse_kv( $arg, "shape" );
1480 26 ▶ my $shape = $kv->{shape} // "";
Condition50%1/2
$kv->{"shape"} // ""
l!l
260
MC/DC0%0/1
$kv->{"shape"} // ""
$kv->{"shape"}
Truth table50%1/2
A
A= $kv->{"shape"}
Aresult
11
00
1481 26 ▶ if ( $in_context eq "grille" ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($in_context eq 'grille') { } 0 26 26
elsif ($shape eq '') { } 4 22 26
elsif ($shape =~ /^ (?: (\d+) \+)? (\d+) (?: x (\d+) )? (?:\+ (\d+) )? (?:[:\s+] (.*)? )? $/x) { } 22 0 22
elsif ($shape ne '') { } 0 0 0
1482 }
1483 elsif ( $shape eq "" ) {
1484 4 $self->add( type => "set",
1485 name => "gridparams",
1486 value => [ @$grid_arg[0..3] ] );
1487 }
1488 elsif ( $shape =~ m/^
1489 (?: (\d+) \+)?
1490 (\d+) (?: x (\d+) )?
1491 (?:\+ (\d+) )?
1492 (?:[:\s+] (.*)? )? $/x ) {
1493 22 ▶ do_warn("Invalid grid params: $shape (must be non-zero)"), return
Branch: 1 branch
BranchTrueFalseTotal
unless $2 0 22 22
1494 unless $2;
1495 22 ▶ $grid_arg = [ $2, $3//1, $1//0, $4//0 ];
Condition83%5/6
$3 // 1
l!l
220
$1 // 0
l!l
319
$4 // 0
l!l
319
MC/DC0%0/1
$3 // 1
$3
MC/DC100%1/1
$1 // 0
$1
MC/DC100%1/1
$4 // 0
$4
Truth table50%1/2
A
A= $3
Aresult
11
00
Truth table100%2/2
A
A= $1
Aresult
11
00
Truth table100%2/2
A
A= $4
Aresult
11
00
1496 22 ▶ push( @$grid_arg, $5 ) if defined $5;
Branch: 1 branch
BranchTrueFalseTotal
if defined $5 0 22 22
1497 22 $self->add( type => "set",
1498 name => "gridparams",
1499 value => [ @$grid_arg ] );
1500 22 ▶ push( @labels, $5 ) if defined($5);
Branch: 1 branch
BranchTrueFalseTotal
if defined $5 0 22 22
1501 }
1502 elsif ( $shape ne "" ) {
1503 0 $self->add( type => "set",
1504 name => "gridparams",
1505 value => [ @$grid_arg[0..3], $shape ] );
1506 0 push( @labels, $shape );
1507 }
1508 26 ▶ if ( ($kv->{label}//"") ne "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($kv->{"label"} // "") ne "") 0 26 26
Condition50%1/2
$kv->{"label"} // ""
l!l
026
MC/DC0%0/1
$kv->{"label"} // ""
$kv->{"label"}
Truth table50%1/2
A
A= $kv->{"label"}
Aresult
11
00
1509 $self->add( type => "set",
1510 name => "label",
1511 0 value => $kv->{label} );
1512 0 push( @labels, $kv->{label} );
1513 }
1514  
1515 # Grid sections always memorize unless "cc=".
1516 26 ▶ if ( ($kv->{cc}//="grid") ne "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($kv->{"cc"} //= "grid") ne "") 26 0 26
Condition50%1/2
$kv->{"cc"} //= "grid"
l!l
026
MC/DC0%0/1
$kv->{"cc"} //= "grid"
$kv->{"cc"}
Truth table50%1/2
A
A= $kv->{"cc"}
Aresult
11
00
1517 26 $cctag = $kv->{cc};
1518 26 ▶ $memchords = $memchords{$cctag} //= [];
Condition100%2/2
$memchords{$cctag} //= []
l!l
1313
MC/DC100%1/1
$memchords{$cctag} //= []
$memchords{$cctag}
Truth table100%2/2
A
A= $memchords{$cctag}
Aresult
11
00
1519 26 $memcrdinx = 0;
1520 26 $memorizing = 1;
1521 }
1522 26 $grid_cells = [ $grid_arg->[0] * $grid_arg->[1],
1523 $grid_arg->[2], $grid_arg->[3] ];
1524  
1525 26 ▶ @grille = ( $kv ) if $in_context eq "grille";
Branch: 1 branch
BranchTrueFalseTotal
if $in_context eq "grille" 0 26 26
1526 26 return 1;
1527 }
1528 elsif ( exists $config->{delegates}->{$in_context} ) {
1529 2 my $d = $config->{delegates}->{$in_context};
1530 2 my %opts;
1531 2 my $xp = transpose_print();
1532 2 ▶ if ( $xp->xp ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xp->xp) 0 2 2
1533 0 $opts{transpose} = $xp;
1534 }
1535 2 my $kv = parse_kv( $arg, "label" );
1536 2 ▶ delete $kv->{label} if ($kv->{label}//"") eq "";
Branch: 1 branch
BranchTrueFalseTotal
if ($kv->{"label"} // "") eq "" 2 0 2
Condition50%1/2
$kv->{"label"} // ""
l!l
20
MC/DC0%0/1
$kv->{"label"} // ""
$kv->{"label"}
Truth table50%1/2
A
A= $kv->{"label"}
Aresult
11
00
1537 $self->add( type => beo( $d, 'type' ),
1538 subtype => "delegate",
1539 delegate => beo( $d, 'module' ),
1540 handler => beo( $d, 'handler' ),
1541 data => [ ],
1542 opts => { %opts, %$kv },
1543 2 ▶ exists($kv->{id}) ? ( id => $kv->{id} ) : (),
Branch: 1 branch
BranchTrueFalseTotal
exists $kv->{'id'} ? : 0 2 2
1544 open => 1 );
1545 2 ▶ push( @labels, $kv->{label} ) if exists $kv->{label};
Branch: 1 branch
BranchTrueFalseTotal
if exists $kv->{"label"} 0 2 2
1546 }
1547 elsif ( $arg ne "" ) {
1548 2 my $kv = parse_kv( $arg, "label" );
1549 2 my $label = delete $kv->{label};
1550 2 my $chords = delete $kv->{cc};
1551 2 ▶ if ( %$kv ) {
Branch: 2 branches
BranchTrueFalseTotal
if (%$kv) { } 0 2 2
elsif ($label) { } 2 0 2
1552 # Assume a mistake.
1553 0 do_warn("Garbage in start_of_$in_context: $arg (ignored)\n");
1554 }
1555 elsif ( $label ) {
1556 2 $self->add( type => "set",
1557 name => "label",
1558 value => $label );
1559 push( @labels, $label)
1560 unless $in_context eq "chorus"
1561 2 ▶ && !$config->{settings}->{choruslabels};
Branch: 1 branch
BranchTrueFalseTotal
unless $in_context eq "chorus" and not $main::config->{"settings"}{"choruslabels"} 2 0 2
Condition33%1/3
$in_context eq "chorus" and not $main::config->{"settings"}{"choruslabels"}
!ll&&!rl&&r
200
MC/DC0%0/2
$in_context eq "chorus" and not $main::config->{"settings"}{"choruslabels"}
$in_context eq "chorus" not $main::config->{"settings"}{"choruslabels"}
Truth table33%1/3
A and not(B)
A= $in_context eq "chorus"B= not $main::config->{"settings"}{"choruslabels"}
ABresult
0X0
100
111
1562 }
1563 2 ▶ if ( $chords ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chords) 0 2 2
1564 0 $chords =~ s/^\s*(.*)\s*/$1/;
1565 0 $cctag = $in_context;
1566 # Do we have a name? Chords? Both?
1567 # name:C D E
1568 # :C D E
1569 # :
1570 0 ▶ if ( $chords =~ /^(\w*):(.*)/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($chords =~ /^(\w*):(.*)/) { } 0 0 0
elsif ($chords =~ /\s/) { } 0 0 0
elsif ($chords =~ /^\w+$/) { } 0 0 0
1571 # Name, possibly empty.
1572 0 ▶ $cctag = $1 if length($1);
Branch: 1 branch
BranchTrueFalseTotal
if length $1 0 0 0
1573 # Chords, possibly empty.
1574 0 $chords = $2;
1575 }
1576 # C D E
1577 elsif ( $chords =~ /\s/ ) {
1578 # Whitespace separated chords.
1579 }
1580 # name
1581 elsif ( $chords =~ /^\w+$/ ) {
1582 0 $cctag = $chords;
1583 0 $chords = "";
1584 }
1585 # ???
1586 else {
1587 0 ▶ warn("Unrecognized cc value: \"$chords\"\n")
Branch: 1 branch
BranchTrueFalseTotal
if $chords 0 0 0
1588 if $chords;
1589 0 $chords = "";
1590 }
1591 0 ▶ if ( $chords ne "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chords ne "") 0 0 0
1592 0 $memchords = [ split( ' ', $chords ) ];
1593 0 $memchords{$cctag} = $memchords;
1594 0 $memcrdinx = 0;
1595 0 $memorizing = 0;
1596 0 ▶ if ( $config->{debug}->{chords} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{"debug"}{"chords"}) 0 0 0
1597 0 my $i = 0;
1598 warn("Chord memorized for $cctag\[$i]: ",
1599 $_, "\n"), $i++
1600 0 for @$memchords;
1601 }
1602 0 return 1;
1603 }
1604 }
1605 }
1606  
1607 # Enabling this always would allow [^] to recall anyway.
1608 # Feature?
1609 69 if ( 1 || $config->{settings}->{memorize} ) {
1610 69 ▶ $memchords = ($memchords{$cctag//$in_context} //= []);
Condition60%3/5
$memchords{$cctag // $in_context} //= []
l!l
1950
$cctag // $in_context
l!l&&r!l&&!r
0690
MC/DC100%1/1
$memchords{$cctag // $in_context} //= []
$memchords{$cctag // $in_context}
MC/DC0%0/2
$cctag // $in_context
$cctag $in_context
Truth table100%2/2
A
A= $memchords{$cctag // $in_context}
Aresult
11
00
Truth table33%1/3
A // B
A= $cctagB= $in_context
ABresult
1X1
011
000
1611 69 $memcrdinx = 0;
1612 69 $memorizing = 0;
1613 }
1614 69 return 1;
1615 }
1616  
1617 430 ▶ if ( $dir =~ /^end_of_(\w+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir =~ /^end_of_(\w+)$/) 95 335 430
1618 95 ▶ do_warn("Not in " . ucfirst($1) . " context\n")
Branch: 1 branch
BranchTrueFalseTotal
unless $in_context eq $1 0 95 95
1619 unless $in_context eq $1;
1620 95 $grid_type = 0;
1621 95 ▶ if ( $in_context eq "grille" && @grille > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_context eq 'grille' and @grille > 1) { } 0 95 95
Condition33%1/3
$in_context eq "grille" and @grille > 1
!ll&&!rl&&r
9500
MC/DC0%0/2
$in_context eq "grille" and @grille > 1
$in_context eq "grille" @grille > 1
Truth table33%1/3
A and B
A= $in_context eq "grille"B= @grille > 1
ABresult
0X0
100
111
1622 0 my $opts = shift(@grille);
1623 0 my $id = $opts->{id};
1624 0 ▶ unless ( is_true($opts->{omit}) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_true($opts->{"omit"})) 0 0 0
1625 0 ▶ if ( $opts->{align} && $opts->{x} && $opts->{x} =~ /\%$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"align"} and $opts->{"x"} and $opts->{"x"} =~ /\%$/) 0 0 0
Condition0%0/6
$opts->{"align"} and $opts->{"x"} and $opts->{"x"} =~ /\%$/
!ll&&!rl&&r
000
$opts->{"align"} and $opts->{"x"}
!ll&&!rl&&r
000
MC/DC0%0/3
$opts->{"align"} and $opts->{"x"} and $opts->{"x"} =~ /\%$/
$opts->{"align"} $opts->{"x"} $opts->{"x"} =~ /\%$/
Truth table0%0/4
A and B and C
A= $opts->{"align"}B= $opts->{"x"}C= $opts->{"x"} =~ /\%$/
ABCresult
0XX0
10X0
1100
1111
1626 0 do_warn( "Useless combination of x percentage with align (align ignored)" );
1627 0 delete $opts->{align};
1628 }
1629  
1630 0 my $def = !!$id;
1631 0 ▶ $id //= "_Image".$assetid++;
Condition0%0/2
$id //= '_Image' . $assetid++
l!l
00
MC/DC0%0/1
$id //= '_Image' . $assetid++
$id
Truth table0%0/2
A
A= $id
Aresult
11
00
1632  
1633 0 ▶ if ( defined $opts->{spread} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{"spread"}) 0 0 0
1634 0 $def++;
1635 0 ▶ if ( exists $self->{spreadimage} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'spreadimage'}) { } 0 0 0
1636 0 do_warn("Skipping superfluous spread image");
1637 }
1638 else {
1639 $self->{spreadimage} =
1640 0 { id => $id, space => $opts->{spread} };
1641 warn("Got spread image $id with space=$opts->{spread}\n")
1642 0 ▶ if $config->{debug}->{images};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"images"} 0 0 0
1643 }
1644 }
1645  
1646 # Move to assets.
1647 $self->{assets}->{$id} =
1648 { type => "image",
1649 subtype => "delegate",
1650 delegate => "Grille",
1651 handler => "grille2xo",
1652 opts => $opts,
1653 line => $grille[0]{line},
1654 0 data => \@grille,
1655 context => $in_context,
1656 };
1657 0 ▶ if ( $def ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($def) { } 0 0 0
1658 0 my $label = delete $a->{label};
1659 0 ▶ do_warn("Label \"$label\" ignored on non-displaying $in_context section\n")
Branch: 1 branch
BranchTrueFalseTotal
if $label 0 0 0
1660 if $label;
1661 }
1662 else {
1663 0 my $label = delete $opts->{label};
1664 0 ▶ $self->add( type => "set",
Branch: 1 branch
BranchTrueFalseTotal
if $label and $label ne "" 0 0 0
Condition0%0/3
$label and $label ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
$label and $label ne ""
$label $label ne ""
Truth table0%0/3
A and B
A= $labelB= $label ne ""
ABresult
0X0
100
111
1665 name => "label",
1666 value => $label )
1667 if $label && $label ne "";
1668 0 $self->add( type => "image",
1669 opts => $opts,
1670 id => $id );
1671 0 ▶ if ( $opts->{label} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"label"}) 0 0 0
1672 push( @labels, $opts->{label} )
1673 unless $in_context eq "chorus"
1674 0 ▶ && !$config->{settings}->{choruslabels};
Branch: 1 branch
BranchTrueFalseTotal
unless $in_context eq "chorus" and not $main::config->{"settings"}{"choruslabels"} 0 0 0
Condition0%0/3
$in_context eq "chorus" and not $main::config->{"settings"}{"choruslabels"}
!ll&&!rl&&r
000
MC/DC0%0/2
$in_context eq "chorus" and not $main::config->{"settings"}{"choruslabels"}
$in_context eq "chorus" not $main::config->{"settings"}{"choruslabels"}
Truth table0%0/3
A and not(B)
A= $in_context eq "chorus"B= not $main::config->{"settings"}{"choruslabels"}
ABresult
0X0
100
111
1675 }
1676 }
1677 }
1678 }
1679 else {
1680 95 $self->add( type => "set",
1681 name => "context",
1682 value => $def_context );
1683 }
1684 95 $in_context = $def_context;
1685 95 undef $memchords;
1686 95 return 1;
1687 }
1688  
1689 # Metadata extensions (legacy). Should use meta instead.
1690 # Only accept the list from config.
1691 335 ▶ if ( any { $_ eq $dir } @{ $config->{metadata}->{keys} } ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $_ eq $dir; } , @{$$main::config{"metadata"}{"keys"};})) 251 84 335
1692 251 return $self->dir_meta( "meta", "$dir $arg" );
1693 }
1694  
1695 # Formatting. {chordsize XX} and such.
1696 84 ▶ if ( $dir =~ m/ ^( $propitems_re )
Branch: 1 branch
BranchTrueFalseTotal
if ($dir =~ / ^( $propitems_re ) ( font | size | colou?r ) $/x) 72 12 84
1697 ( font | size | colou?r )
1698 $/x ) {
1699 72 my $item = $1;
1700 72 my $prop = $2;
1701  
1702 72 $self->propset( $item, $prop, $arg );
1703  
1704 # Derived props.
1705 72 ▶ $self->propset( "chorus", $prop, $arg ) if $item eq "text";
Branch: 1 branch
BranchTrueFalseTotal
if $item eq "text" 15 57 72
1706  
1707 # ::dump( { %propstack, line => $diag->{line} } );
1708 72 return 1;
1709 }
1710 # More private hacks.
1711 12 ▶ if ( !$options->{reference} && $d =~ /^([-+])([-\w.]+)$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $main::options->{"reference"} and $d =~ /^([-+])([-\w.]+)$/i) 0 12 12
Condition33%1/3
not $main::options->{"reference"} and $d =~ /^([-+])([-\w.]+)$/i
!ll&&!rl&&r
0120
MC/DC0%0/2
not $main::options->{"reference"} and $d =~ /^([-+])([-\w.]+)$/i
not $main::options->{"reference"} $d =~ /^([-+])([-\w.]+)$/i
Truth table33%1/3
not(A) and B
A= not $main::options->{"reference"}B= $d =~ /^([-+])([-\w.]+)$/i
ABresult
0X0
100
111
1712 0 ▶ if ( $2 eq "dumpmeta" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 eq "dumpmeta") 0 0 0
1713 0 warn(::dump($self->{meta}));
1714 }
1715 0 ▶ $self->add( type => "set",
Branch: 1 branch
BranchTrueFalseTotal
$1 eq '+' ? : 0 0 0
1716 name => $2,
1717 value => $1 eq "+" ? 1 : 0,
1718 );
1719 0 return 1;
1720 }
1721  
1722 12 ▶ if ( !$options->{reference} && $dir =~ /^\+([-\w.]+(?:\.[<>])?)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $main::options->{"reference"} and $dir =~ /^\+([-\w.]+(?:\.[<>])?)$/) 11 1 12
Condition66%2/3
not $main::options->{"reference"} and $dir =~ /^\+([-\w.]+(?:\.[<>])?)$/
!ll&&!rl&&r
0111
MC/DC50%1/2
not $main::options->{"reference"} and $dir =~ /^\+([-\w.]+(?:\.[<>])?)$/
not $main::options->{"reference"} $dir =~ /^\+([-\w.]+(?:\.[<>])?)$/
Truth table66%2/3
not(A) and B
A= not $main::options->{"reference"}B= $dir =~ /^\+([-\w.]+(?:\.[<>])?)$/
ABresult
0X0
100
111
1723 11 $self->add( type => "set",
1724 name => $1,
1725 value => $arg,
1726 );
1727  
1728 11 $config->unlock;
1729 11 prpadd2cfg( $config, $1 => $arg );
1730 11 $config->lock;
1731  
1732 11 upd_config();
1733  
1734 11 return 1;
1735 }
1736  
1737 # Warn about unknowns, unless they are x_... form.
1738 do_warn("Unknown directive: $d\n")
1739 1 ▶ if $config->{settings}->{strict} && $d !~ /^x_/;
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"settings"}{"strict"} and not $d =~ /^x_/ 0 1 1
Condition33%1/3
$main::config->{"settings"}{"strict"} and not $d =~ /^x_/
!ll&&!rl&&r
100
MC/DC0%0/2
$main::config->{"settings"}{"strict"} and not $d =~ /^x_/
$main::config->{"settings"}{"strict"} not $d =~ /^x_/
Truth table33%1/3
A and not(B)
A= $main::config->{"settings"}{"strict"}B= not $d =~ /^x_/
ABresult
0X0
100
111
1740 1 return;
1741 }
1742  
1743 31 ▶sub dir_chorus {
Subroutine dir_chorus: called CC=19 SCAR=36.3
Pod undocumented
1744 31 my ( $self, $dir, $arg ) = @_;
1745  
1746 31 ▶ if ( $in_context ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_context) 0 31 31
1747 0 do_warn("{chorus} encountered while in $in_context context -- ignored\n");
1748 0 return 1;
1749 }
1750  
1751 # Clone the chorus so we can modify the label, if required.
1752 31 ▶ my $chorus = @chorus ? dclone(\@chorus) : [];
Branch: 1 branch
BranchTrueFalseTotal
@chorus ? : 29 2 31
1753  
1754 31 ▶ if ( @$chorus && $arg && $arg ne "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$chorus and $arg and $arg ne "") 0 31 31
Condition50%3/6
@$chorus and $arg and $arg ne ""
!ll&&!rl&&r
3100
@$chorus and $arg
!ll&&!rl&&r
2290
MC/DC0%0/3
@$chorus and $arg and $arg ne ""
@$chorus $arg $arg ne ""
Truth table50%2/4
A and B and C
A= @$chorusB= $argC= $arg ne ""
ABCresult
0XX0
10X0
1100
1111
1755 0 my $kv = parse_kv( $arg, "label" );
1756 0 my $label = $kv->{label};
1757 0 ▶ if ( $chorus->[0]->{type} eq "set" && $chorus->[0]->{name} eq "label" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($chorus->[0]{'type'} eq 'set' and $chorus->[0]{'name'} eq 'label') { } 0 0 0
elsif (defined $label) { } 0 0 0
Condition0%0/3
$chorus->[0]{"type"} eq "set" and $chorus->[0]{"name"} eq "label"
!ll&&!rl&&r
000
MC/DC0%0/2
$chorus->[0]{"type"} eq "set" and $chorus->[0]{"name"} eq "label"
$chorus->[0]{"type"} eq "set" $chorus->[0]{"name"} eq "label"
Truth table0%0/3
A and B
A= $chorus->[0]{"type"} eq "set"B= $chorus->[0]{"name"} eq "label"
ABresult
0X0
100
111
1758 0 $chorus->[0]->{value} = $label;
1759 }
1760 elsif ( defined $label ) {
1761 0 unshift( @$chorus,
1762 { type => "set",
1763 name => "label",
1764 value => $label,
1765 context => "chorus",
1766 } );
1767 }
1768 push( @labels, $label )
1769 0 ▶ if $config->{settings}->{choruslabels};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"settings"}{"choruslabels"} 0 0 0
1770 }
1771  
1772 31 ▶ if ( $chorus_xpose ne $xpose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chorus_xpose ne $ChordPro::Song::xpose) 17 14 31
1773 # The chorus has already been transposed with chorus_xpose.
1774 17 my $xp = do {
1775 17 local $xpose = $chorus_xpose;
1776 17 transpose_print()->invert;
1777 };
1778 17 my $t = transpose_print();
1779 17 $xp += $t;
1780 17 $xp->dir = $t->dir;
1781 warn("XPOSE: chorus ", $chorus_xpose->_data_printer,
1782 " (", $xpose->_data_printer, ")",
1783 " ", $xp->_data_printer,
1784 17 ▶ "\n") if $config->{debug}->{xpose};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"xpose"} 0 17 17
1785 17 for ( @$chorus ) {
1786 32 ▶ if ( $_->{type} eq "songline" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"type"} eq "songline") 16 16 32
1787 16 for ( @{ $_->{chords} } ) {
1788 61 ▶ next if $_ eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "" 15 46 61
1789 46 my $info = $self->{chordsinfo}->{$_->key};
1790 46 ▶ next if $info->is_annotation;
Branch: 1 branch
BranchTrueFalseTotal
if $info->is_annotation 0 46 46
1791 46 ▶ $info = $info->transpose($xp) if $xp;
Branch: 1 branch
BranchTrueFalseTotal
if $xp 46 0 46
1792 46 $info = $info->new($info);
1793 46 $_ = ChordPro::Chords::Appearance->new
1794 ( key => $self->add_chord($info),
1795 info => $info,
1796 maybe format => $_->format
1797 );
1798 }
1799 }
1800 }
1801 }
1802  
1803 31 ▶ $self->add( type => "rechorus",
Branch: 1 branch
BranchTrueFalseTotal
@$chorus ? : 29 2 31
1804 @$chorus
1805 ? ( "chorus" => $chorus )
1806 : (),
1807 );
1808 31 return 1;
1809 }
1810  
1811 #### Directive handlers ####
1812  
1813 # Song settings.
1814  
1815 # Breaks.
1816  
1817 15 ▶sub dir_column_break {
Subroutine dir_column_break: called CC=1 SCAR=0.0
Pod undocumented
1818 15 my ( $self, $dir, $arg ) = @_;
1819 15 $self->add( type => "colb" );
1820 15 return 1;
1821 }
1822  
1823 40 ▶sub dir_new_page {
Subroutine dir_new_page: called CC=1 SCAR=0.0
Pod undocumented
1824 40 my ( $self, $dir, $arg ) = @_;
1825 40 $self->add( type => "newpage" );
1826 40 return 1;
1827 }
1828  
1829 0 ▶sub dir_new_song {
Subroutine dir_new_song: not called CC=1 SCAR=6.9
Pod undocumented
1830 0 my ( $self, $dir, $arg ) = @_;
1831 0 die("FATAL - cannot start a new song now\n");
1832 }
1833  
1834 # Comments. Strictly speaking they do not belong here.
1835  
1836 134 ▶sub dir_comment {
Subroutine dir_comment: called CC=4 SCAR=14.0
Pod undocumented
1837 134 my ( $self, $dir, $arg, $orig ) = @_;
1838 134 ▶ $dir = "comment" if $dir eq "highlight";
Branch: 1 branch
BranchTrueFalseTotal
if $dir eq "highlight" 3 131 134
1839 134 my %res = $self->cdecompose($arg);
1840 134 $res{orig} = $orig;
1841 $self->add( type => $dir, %res )
1842 134 ▶ unless exists($res{text}) && $res{text} =~ /^[ \t]*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless exists $res{"text"} and $res{"text"} =~ /^[ \t]*$/ 134 0 134
Condition66%2/3
exists $res{"text"} and $res{"text"} =~ /^[ \t]*$/
!ll&&!rl&&r
141200
MC/DC0%0/2
exists $res{"text"} and $res{"text"} =~ /^[ \t]*$/
exists $res{"text"} $res{"text"} =~ /^[ \t]*$/
Truth table66%2/3
A and B
A= exists $res{"text"}B= $res{"text"} =~ /^[ \t]*$/
ABresult
0X0
100
111
1843 134 return 1;
1844 }
1845  
1846 7 ▶sub dir_image {
Subroutine dir_image: called CC=77 SCAR=64.6
Pod undocumented
1847 7 my ( $self, $dir, $arg ) = @_;
1848 7 ▶ return 1 if $::running_under_test && !$arg;
Branch: 1 branch
BranchTrueFalseTotal
if $main::running_under_test and not $arg 1 6 7
Condition66%2/3
$main::running_under_test and not $arg
!ll&&!rl&&r
061
MC/DC50%1/2
$main::running_under_test and not $arg
$main::running_under_test not $arg
Truth table66%2/3
A and not(B)
A= $main::running_under_testB= not $arg
ABresult
0X0
100
111
1849 92 ▶ use Text::ParseWords qw(quotewords);
Subroutine BEGIN: called CC=1 SCAR=0.0
1850 6 my @words = quotewords( '\s+', 1, $arg );
1851 6 my $res;
1852 # Imply src= if word 0 is not kv.
1853 6 ▶ if ( @words && $words[0] !~ /\w+=/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@words and not $words[0] =~ /\w+=/) { } 2 4 6
Condition66%2/3
@words and not $words[0] =~ /\w+=/
!ll&&!rl&&r
042
MC/DC50%1/2
@words and not $words[0] =~ /\w+=/
@words not $words[0] =~ /\w+=/
Truth table66%2/3
A and not(B)
A= @wordsB= not $words[0] =~ /\w+=/
ABresult
0X0
100
111
1854 2 $words[0] = "src=" . $words[0];
1855 2 $res = parse_kv( \@words );
1856 }
1857 else {
1858 4 $res = parse_kv( \@words, "src" );
1859 }
1860  
1861 6 my $uri;
1862 my $id;
1863 6 my $chord;
1864 6 my $type;
1865 6 my %opts;
1866  
1867 6 ▶ while ( my($k,$v) = each(%$res) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$res) 20 6 26
1868 20 ▶ if ( $k =~ /^(title)$/i && $v ne "" ) {
Branch: 15 branches
BranchTrueFalseTotal
if ($k =~ /^(title)$/i and $v ne '') { } 1 19 20
elsif ($k =~ /^(border|spread|center|persist|omit)$/i and $v =~ /^(\d+)$/) { } 4 15 19
elsif ($k =~ /^(width|height)$/i and $v =~ /^(\d+(?:\.\d+)?\%?)$/) { } 2 13 15
elsif ($k =~ /^(x|y)$/i and $v =~ /^(?:base[+-])?([-+]?\d+(?:\.\d+)?\%?)$/) { } 2 11 13
elsif ($k =~ /^(scale)$/ and $v =~ /^(\d+(?:\.\d+)?)(%)?(?:,(\d+(?:\.\d+)?)(%)?)?$/) { } 3 8 11
elsif ($k =~ /^(center|border|spread|persist|omit)$/i) { } 0 8 8
elsif ($k =~ /^(src|uri)$/i and $v ne '') { } 2 6 8
elsif ($k =~ /^(id)$/i and $v ne '') { } 4 2 6
elsif ($k =~ /^(chord)$/i and $v ne '') { } 0 2 2
elsif ($k =~ /^(type)$/i and $v ne '') { } 0 2 2
elsif ($k =~ /^(label|href)$/i and $v ne '') { } 0 2 2
elsif ($k =~ /^(anchor)$/i and $v =~ /^(paper|page|allpages|column|float|line)$/) { } 2 0 2
elsif ($k =~ /^(align)$/i and $v =~ /^(center|left|right)$/) { } 0 0 0
elsif ($k =~ /^(bordertrbl)$/i and $v =~ /^[trbl]*$/) { } 0 0 0
elsif ($uri) { } 0 0 0
Condition66%2/3
$k =~ /^(title)$/i and $v ne ""
!ll&&!rl&&r
1901
MC/DC50%1/2
$k =~ /^(title)$/i and $v ne ""
$k =~ /^(title)$/i $v ne ""
Truth table66%2/3
A and B
A= $k =~ /^(title)$/iB= $v ne ""
ABresult
0X0
100
111
1869 1 $opts{lc($k)} = $v;
1870 }
1871 ▶ elsif ( $k =~ /^(border|spread|center|persist|omit)$/i
Condition66%2/3
$k =~ /^(border|spread|center|persist|omit)$/i and $v =~ /^(\d+)$/
!ll&&!rl&&r
1504
MC/DC50%1/2
$k =~ /^(border|spread|center|persist|omit)$/i and $v =~ /^(\d+)$/
$k =~ /^(border|spread|center|persist|omit)$/i $v =~ /^(\d+)$/
Truth table66%2/3
A and B
A= $k =~ /^(border|spread|center|persist|omit)$/iB= $v =~ /^(\d+)$/
ABresult
0X0
100
111
1872 && $v =~ /^(\d+)$/ ) {
1873 4 ▶ if ( $k eq "center" && $v ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq 'center' and $v) { } 1 3 4
Condition66%2/3
$k eq "center" and $v
!ll&&!rl&&r
301
MC/DC50%1/2
$k eq "center" and $v
$k eq "center" $v
Truth table66%2/3
A and B
A= $k eq "center"B= $v
ABresult
0X0
100
111
1874 1 $opts{align} = $k;
1875 }
1876 else {
1877 3 $opts{lc($k)} = $v;
1878 }
1879 }
1880 ▶ elsif ( $k =~ /^(width|height)$/i
Condition66%2/3
$k =~ /^(width|height)$/i and $v =~ /^(\d+(?:\.\d+)?\%?)$/
!ll&&!rl&&r
1302
MC/DC50%1/2
$k =~ /^(width|height)$/i and $v =~ /^(\d+(?:\.\d+)?\%?)$/
$k =~ /^(width|height)$/i $v =~ /^(\d+(?:\.\d+)?\%?)$/
Truth table66%2/3
A and B
A= $k =~ /^(width|height)$/iB= $v =~ /^(\d+(?:\.\d+)?\%?)$/
ABresult
0X0
100
111
1881 && $v =~ /^(\d+(?:\.\d+)?\%?)$/ ) {
1882 2 $opts{lc($k)} = $v;
1883 }
1884 ▶ elsif ( $k =~ /^(x|y)$/i
Condition66%2/3
$k =~ /^(x|y)$/i and $v =~ /^(?:base[+-])?([-+]?\d+(?:\.\d+)?\%?)$/
!ll&&!rl&&r
1102
MC/DC50%1/2
$k =~ /^(x|y)$/i and $v =~ /^(?:base[+-])?([-+]?\d+(?:\.\d+)?\%?)$/
$k =~ /^(x|y)$/i $v =~ /^(?:base[+-])?([-+]?\d+(?:\.\d+)?\%?)$/
Truth table66%2/3
A and B
A= $k =~ /^(x|y)$/iB= $v =~ /^(?:base[+-])?([-+]?\d+(?:\.\d+)?\%?)$/
ABresult
0X0
100
111
1885 && $v =~ /^(?:base[+-])?([-+]?\d+(?:\.\d+)?\%?)$/ ) {
1886 2 $opts{lc($k)} = $v;
1887 }
1888 ▶ elsif ( $k =~ /^(scale)$/
Condition66%2/3
$k =~ /^(scale)$/ and $v =~ /^(\d+(?:\.\d+)?)(%)?(?:,(\d+(?:\.\d+)?)(%)?)?$/
!ll&&!rl&&r
803
MC/DC50%1/2
$k =~ /^(scale)$/ and $v =~ /^(\d+(?:\.\d+)?)(%)?(?:,(\d+(?:\.\d+)?)(%)?)?$/
$k =~ /^(scale)$/ $v =~ /^(\d+(?:\.\d+)?)(%)?(?:,(\d+(?:\.\d+)?)(%)?)?$/
Truth table66%2/3
A and B
A= $k =~ /^(scale)$/B= $v =~ /^(\d+(?:\.\d+)?)(%)?(?:,(\d+(?:\.\d+)?)(%)?)?$/
ABresult
0X0
100
111
1889 && $v =~ /^(\d+(?:\.\d+)?)(%)?(?:,(\d+(?:\.\d+)?)(%)?)?$/ ) {
1890 3 ▶ $opts{lc($k)} = [ $2 ? $1/100 : $1 ];
Branch: 1 branch
BranchTrueFalseTotal
$2 ? : 0 3 3
1891 3 ▶ $opts{lc($k)}->[1] = $3 ? $4 ? $3/100 : $3 : $opts{lc($k)}->[0];
Branch: 2 branches
BranchTrueFalseTotal
$3 ? : 0 3 3
$4 ? : 0 0 0
1892 }
1893 elsif ( $k =~ /^(center|border|spread|persist|omit)$/i ) {
1894 0 ▶ if ( $k eq "center" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq 'center') { } 0 0 0
1895 0 $opts{align} = $k;
1896 }
1897 else {
1898 0 $opts{lc($k)} = $v;
1899 }
1900 }
1901 ▶ elsif ( $k =~ /^(src|uri)$/i && $v ne "" ) {
Condition66%2/3
$k =~ /^(src|uri)$/i and $v ne ""
!ll&&!rl&&r
602
MC/DC50%1/2
$k =~ /^(src|uri)$/i and $v ne ""
$k =~ /^(src|uri)$/i $v ne ""
Truth table66%2/3
A and B
A= $k =~ /^(src|uri)$/iB= $v ne ""
ABresult
0X0
100
111
1902 2 $uri = $v;
1903 }
1904 ▶ elsif ( $k =~ /^(id)$/i && $v ne "" ) {
Condition66%2/3
$k =~ /^(id)$/i and $v ne ""
!ll&&!rl&&r
204
MC/DC50%1/2
$k =~ /^(id)$/i and $v ne ""
$k =~ /^(id)$/i $v ne ""
Truth table66%2/3
A and B
A= $k =~ /^(id)$/iB= $v ne ""
ABresult
0X0
100
111
1905 4 $id = $v;
1906 }
1907 ▶ elsif ( $k =~ /^(chord)$/i && $v ne "" ) {
Condition33%1/3
$k =~ /^(chord)$/i and $v ne ""
!ll&&!rl&&r
200
MC/DC0%0/2
$k =~ /^(chord)$/i and $v ne ""
$k =~ /^(chord)$/i $v ne ""
Truth table33%1/3
A and B
A= $k =~ /^(chord)$/iB= $v ne ""
ABresult
0X0
100
111
1908 0 $chord = $v;
1909 }
1910 ▶ elsif ( $k =~ /^(type)$/i && $v ne "" ) {
Condition33%1/3
$k =~ /^(type)$/i and $v ne ""
!ll&&!rl&&r
200
MC/DC0%0/2
$k =~ /^(type)$/i and $v ne ""
$k =~ /^(type)$/i $v ne ""
Truth table33%1/3
A and B
A= $k =~ /^(type)$/iB= $v ne ""
ABresult
0X0
100
111
1911 0 $opts{type} = $v;
1912 }
1913 ▶ elsif ( $k =~ /^(label|href)$/i && $v ne "" ) {
Condition33%1/3
$k =~ /^(label|href)$/i and $v ne ""
!ll&&!rl&&r
200
MC/DC0%0/2
$k =~ /^(label|href)$/i and $v ne ""
$k =~ /^(label|href)$/i $v ne ""
Truth table33%1/3
A and B
A= $k =~ /^(label|href)$/iB= $v ne ""
ABresult
0X0
100
111
1914 0 $opts{lc($k)} = $v;
1915 }
1916 ▶ elsif ( $k =~ /^(anchor)$/i
Condition33%1/3
$k =~ /^(anchor)$/i and $v =~ /^(paper|page|allpages|column|float|line)$/
!ll&&!rl&&r
002
MC/DC0%0/2
$k =~ /^(anchor)$/i and $v =~ /^(paper|page|allpages|column|float|line)$/
$k =~ /^(anchor)$/i $v =~ /^(paper|page|allpages|column|float|line)$/
Truth table33%1/3
A and B
A= $k =~ /^(anchor)$/iB= $v =~ /^(paper|page|allpages|column|float|line)$/
ABresult
0X0
100
111
1917 && $v =~ /^(paper|page|allpages|column|float|line)$/ ) {
1918 2 $opts{lc($k)} = lc($v);
1919 }
1920 ▶ elsif ( $k =~ /^(align)$/i
Condition0%0/3
$k =~ /^(align)$/i and $v =~ /^(center|left|right)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$k =~ /^(align)$/i and $v =~ /^(center|left|right)$/
$k =~ /^(align)$/i $v =~ /^(center|left|right)$/
Truth table0%0/3
A and B
A= $k =~ /^(align)$/iB= $v =~ /^(center|left|right)$/
ABresult
0X0
100
111
1921 && $v =~ /^(center|left|right)$/ ) {
1922 0 $opts{lc($k)} = lc($v);
1923 }
1924 ▶ elsif ( $k =~ /^(bordertrbl)$/i
Condition0%0/3
$k =~ /^(bordertrbl)$/i and $v =~ /^[trbl]*$/
!ll&&!rl&&r
000
MC/DC0%0/2
$k =~ /^(bordertrbl)$/i and $v =~ /^[trbl]*$/
$k =~ /^(bordertrbl)$/i $v =~ /^[trbl]*$/
Truth table0%0/3
A and B
A= $k =~ /^(bordertrbl)$/iB= $v =~ /^[trbl]*$/
ABresult
0X0
100
111
1925 && $v =~ /^[trbl]*$/ ) {
1926 0 $opts{lc($k)} = lc($v);
1927 }
1928 elsif ( $uri ) {
1929 0 do_warn( "Unknown image attribute: $k\n" );
1930 0 next;
1931 }
1932 # Assume just an image file uri.
1933 else {
1934 0 $uri = $k;
1935 }
1936 }
1937  
1938 6 ▶ return if is_true($opts{omit});
Branch: 1 branch
BranchTrueFalseTotal
if is_true($opts{"omit"}) 0 6 6
1939  
1940 6 ▶ unless ( $uri || $id || $chord ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($uri or $id or $chord) 0 6 6
Condition50%3/6
$uri or $id or $chord
l!l&&r!l&&!r
600
$uri or $id
l!l&&r!l&&!r
240
MC/DC0%0/3
$uri or $id or $chord
$uri $id $chord
Truth table50%2/4
A or B or C
A= $uriB= $idC= $chord
ABCresult
1XX1
01X1
0011
0000
1941 0 do_warn( "Missing image source\n" );
1942 0 return;
1943 }
1944 6 ▶ if ( $opts{align} && $opts{x} && $opts{x} =~ /\%$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"align"} and $opts{"x"} and $opts{"x"} =~ /\%$/) 0 6 6
Condition50%3/6
$opts{"align"} and $opts{"x"} and $opts{"x"} =~ /\%$/
!ll&&!rl&&r
600
$opts{"align"} and $opts{"x"}
!ll&&!rl&&r
510
MC/DC0%0/3
$opts{"align"} and $opts{"x"} and $opts{"x"} =~ /\%$/
$opts{"align"} $opts{"x"} $opts{"x"} =~ /\%$/
Truth table50%2/4
A and B and C
A= $opts{"align"}B= $opts{"x"}C= $opts{"x"} =~ /\%$/
ABCresult
0XX0
10X0
1100
1111
1945 0 do_warn( "Useless combination of x percentage with align (align ignored)" );
1946 0 delete $opts{align};
1947 }
1948  
1949 # If the image uri does not have a directory, look it up
1950 # next to the song, and then in the images folder of the
1951 # resources.
1952 6 ▶ if ( $uri ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri) 2 4 6
1953 2 ▶ if ( CP->is_here($uri) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (CP()->is_here($uri)) { } 2 0 2
elsif (not $uri =~ m[^(data:|\w+://)]) { } 0 0 0
1954 my $found = CP->siblingres( $diag->{file}, $uri, class => "images" )
1955 2 ▶ || CP->siblingres( $diag->{file}, $uri, class => "icons" );
Condition33%1/3
CP()->siblingres($diag->{'file'}, $uri, 'class', 'images') || CP()->siblingres($diag->{'file'}, $uri, 'class', 'icons')
l!l&&r!l&&!r
200
MC/DC0%0/2
CP()->siblingres($diag->{'file'}, $uri, 'class', 'images') || CP()->siblingres($diag->{'file'}, $uri, 'class', 'icons')
CP()->siblingres($diag->{'file'}, $uri, 'class', 'images') CP()->siblingres($diag->{'file'}, $uri, 'class', 'icons')
Truth table33%1/3
A || B
A= CP()->siblingres($diag->{'file'}, $uri, 'class', 'images')B= CP()->siblingres($diag->{'file'}, $uri, 'class', 'icons')
ABresult
1X1
011
000
1956 2 ▶ if ( $found ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) { } 2 0 2
1957 2 $uri = $found;
1958 }
1959 else {
1960 0 do_warn("Missing image for \"$uri\"");
1961 0 return;
1962 }
1963 }
1964 # Do not affect URIs and base64 data strings.
1965 elsif ( $uri !~ /^(data:|\w+:\/\/)/ ) {
1966 0 $uri = expand_tilde($uri);
1967 }
1968 }
1969  
1970 6 ▶ if ( $chord ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chord) 0 6 6
1971 0 ▶ if ( $chord =~ /^\[(.*)\]$/ ) { # transposable
Branch: 1 branch
BranchTrueFalseTotal
if ($chord =~ /^\[(.*)\]$/) 0 0 0
1972 0 my $info = $self->parse_chord($1);
1973 0 ▶ $chord = $info->{name} if $info;
Branch: 1 branch
BranchTrueFalseTotal
if $info 0 0 0
1974 }
1975 0 $uri = "chord:$chord";
1976 }
1977  
1978 6 ▶ my $aid = $id || "_Image".$assetid++;
Condition100%2/2
$id || '_Image' . $assetid++
l!l
42
MC/DC100%1/1
$id || '_Image' . $assetid++
$id
Truth table100%2/2
A
A= $id
Aresult
11
00
1979  
1980 6 ▶ if ( defined $opts{spread} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"spread"}) 0 6 6
1981 0 ▶ if ( exists $self->{spreadimage} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'spreadimage'}) { } 0 0 0
1982 0 do_warn("Skipping superfluous spread image");
1983 }
1984 else {
1985 $self->{spreadimage} =
1986 0 { id => $aid, space => $opts{spread} };
1987 warn("Got spread image $aid with $opts{spread} space\n")
1988 0 ▶ if $config->{debug}->{images};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"images"} 0 0 0
1989 }
1990 }
1991  
1992 # Store as asset.
1993 6 ▶ if ( $uri ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri) 2 4 6
1994 2 my $opts;
1995 2 for ( qw( type persist href ) ) {
1996 6 ▶ $opts->{$_} = $opts{$_} if defined $opts{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{$_} 0 6 6
1997 6 delete $opts{$_};
1998 }
1999 2 for ( qw( spread ) ) {
2000 2 ▶ $opts->{$_} = $opts{$_} if defined $opts{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{$_} 0 2 2
2001 }
2002  
2003 2 ▶ if ( $id && %opts ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id and %opts) 0 2 2
Condition33%1/3
$id and %opts
!ll&&!rl&&r
200
MC/DC0%0/2
$id and %opts
$id %opts
Truth table33%1/3
A and B
A= $idB= %opts
ABresult
0X0
100
111
2004 0 do_warn("Asset definition \"$id\" does not take attributes",
2005 " (" . join(" ",sort keys %opts) . ")");
2006 0 return;
2007 }
2008  
2009 2 ▶ $self->{assets} //= {};
Condition50%1/2
$self->{"assets"} //= {}
l!l
02
MC/DC0%0/1
$self->{"assets"} //= {}
$self->{"assets"}
Truth table50%1/2
A
A= $self->{"assets"}
Aresult
11
00
2010 2 my $a;
2011 2 ▶ if ( $uri =~ /\.(\w+)$/ && exists $config->{delegates}->{$1} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri =~ /\.(\w+)$/ and exists $main::config->{'delegates'}{$1}) { } 0 2 2
Condition33%1/3
$uri =~ /\.(\w+)$/ and exists $main::config->{"delegates"}{$1}
!ll&&!rl&&r
020
MC/DC0%0/2
$uri =~ /\.(\w+)$/ and exists $main::config->{"delegates"}{$1}
$uri =~ /\.(\w+)$/ exists $main::config->{"delegates"}{$1}
Truth table33%1/3
A and B
A= $uri =~ /\.(\w+)$/B= exists $main::config->{"delegates"}{$1}
ABresult
0X0
100
111
2012 0 my $d = $config->{delegates}->{$1};
2013 0 $a = { type => "image",
2014 subtype => "delegate",
2015 delegate => beo( $d, 'module' ),
2016 handler => beo( $d, 'handler' ),
2017 uri => $uri,
2018 };
2019 }
2020 else {
2021 2 $a = { type => "image",
2022 uri => $uri,
2023 };
2024 }
2025 2 ▶ $a->{opts} = $opts if $opts;
Branch: 1 branch
BranchTrueFalseTotal
if $opts 0 2 2
2026 2 $self->{assets}->{$aid} = $a;
2027  
2028 2 ▶ if ( $config->{debug}->{images} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{"debug"}{"images"}) 0 2 2
2029 warn("asset[$aid] type=image uri=$uri",
2030 $a->{subtype} ? " subtype=$a->{subtype}" : (),
2031 $a->{delegate} ? " delegate=$a->{delegate}" : (),
2032 0 ▶ $opts->{persist} ? " persist" : (),
Branch: 3 branches
BranchTrueFalseTotal
$a->{'subtype'} ? : 0 0 0
$a->{'delegate'} ? : 0 0 0
$opts->{'persist'} ? : 0 0 0
2033 "\n");
2034 }
2035 2 ▶ return if $id || defined $opts{spread}; # defining only
Branch: 1 branch
BranchTrueFalseTotal
if $id or defined $opts{"spread"} 0 2 2
Condition33%1/3
$id or defined $opts{"spread"}
l!l&&r!l&&!r
002
MC/DC0%0/2
$id or defined $opts{"spread"}
$id defined $opts{"spread"}
Truth table33%1/3
A or B
A= $idB= defined $opts{"spread"}
ABresult
1X1
011
000
2036 }
2037  
2038 6 ▶ if ( $opts{label} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"label"}) 0 6 6
2039 $self->add( type => "set",
2040 name => "label",
2041 value => $opts{label},
2042 0 context => "image" );
2043 0 push( @labels, $opts{label} );
2044 }
2045  
2046 6 $self->add( type => "image",
2047 id => $aid,
2048 opts => \%opts );
2049 6 return 1;
2050 }
2051  
2052 252 ▶sub dir_title {
Subroutine dir_title: called CC=1 SCAR=0.0
Pod undocumented
2053 252 my ( $self, $dir, $arg ) = @_;
2054 252 $self->{title} = $arg;
2055 252 push( @{ $self->{meta}->{title} }, $arg );
2056 252 return 1;
2057 }
2058  
2059 51 ▶sub dir_subtitle {
Subroutine dir_subtitle: called CC=1 SCAR=0.0
Pod undocumented
2060 51 my ( $self, $dir, $arg ) = @_;
2061 51 push( @{ $self->{subtitle} }, $arg );
2062 51 push( @{ $self->{meta}->{subtitle} }, $arg );
2063 51 return 1;
2064 }
2065  
2066 # Metadata.
2067  
2068 290 ▶sub dir_meta {
Subroutine dir_meta: called CC=35 SCAR=39.5
Pod undocumented
2069 290 my ( $self, $dir, $arg ) = @_;
2070  
2071 290 ▶ if ( $arg =~ /([^ :]+)[ :]+(.*)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /([^ :]+)[ :]+(.*)/) { } 290 0 290
2072 290 my $key = lc $1;
2073 290 my @vals = ( $2 );
2074 290 ▶ if ( $config->{metadata}->{autosplit} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{'metadata'}{'autosplit'}) { } 283 7 290
2075 283 @vals = map { s/s\+$//; $_ }
2076 283 split( quotemeta($config->{metadata}->{separator}), $vals[0] );
2077 }
2078 else {
2079 7 ▶ pop(@vals) if $vals[0] eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $vals[0] eq "" 0 7 7
2080 }
2081 290 my $m = $self->{meta};
2082  
2083 # User and instrument cannot be set here.
2084 290 ▶ if ( $key eq "user" || $key eq "instrument" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "user" or $key eq "instrument") 0 290 290
Condition33%1/3
$key eq "user" or $key eq "instrument"
l!l&&r!l&&!r
00290
MC/DC0%0/2
$key eq "user" or $key eq "instrument"
$key eq "user" $key eq "instrument"
Truth table33%1/3
A or B
A= $key eq "user"B= $key eq "instrument"
ABresult
1X1
011
000
2085 0 do_warn("\"$key\" can be set from config only.\n");
2086 0 return 1;
2087 }
2088  
2089 290 for my $val ( @vals ) {
2090  
2091 290 ▶ if ( $key eq "key" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "key") 96 194 290
2092 96 $val =~ s/[\[\]]//g;
2093  
2094 # We do not want the key to be transposed!
2095 96 my @save = ( $xpose, $capo );
2096 96 ( $xpose, $capo ) = ( parse_transpose(0), 0 );
2097 96 my $info = do {
2098 96 local( $config->{settings}->{transpose} ) = parse_transpose(0);
2099 # When transcoding to nash/roman, parse_chord will
2100 # complain about a missing key. Fake one.
2101 96 local( $self->{meta}->{key} ) = [ '_dummy_' ];
2102 96 local( $self->{chordsinfo}->{_dummy_} ) = { root_ord => 0 };
2103 96 $self->parse_chord($val);
2104 };
2105 96 ( $xpose, $capo ) = @save;;
2106 96 ▶ do_warn("Invalid key: \"$val\"\n"), next
Branch: 1 branch
BranchTrueFalseTotal
unless $info and $info->is_key 0 96 96
Condition33%1/3
$info and $info->is_key
!ll&&!rl&&r
0096
MC/DC0%0/2
$info and $info->is_key
$info $info->is_key
Truth table33%1/3
A and B
A= $infoB= $info->is_key
ABresult
0X0
100
111
2107 unless $info && $info->is_key;
2108  
2109 96 my $name = $info->name;
2110 96 my $act = $name;
2111 $info->{key} = $name
2112 96 ▶ unless $config->{settings}->{'enharmonic-transpose'};
Branch: 1 branch
BranchTrueFalseTotal
unless $main::config->{"settings"}{"enharmonic-transpose"} 0 96 96
2113  
2114 96 my $m = $self->{meta};
2115 96 push( @{ $m->{key} }, $info->keyname );
2116 96 push( @{ $m->{_key} }, $info->name );
2117 96 ▶ if ( $xpose || $capo || $config->{settings}->{transpose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ChordPro::Song::xpose or $capo or $main::config->{'settings'}{'transpose'}) { } 15 81 96
Condition66%4/6
$ChordPro::Song::xpose or $capo or $main::config->{"settings"}{"transpose"}
l!l&&r!l&&!r
6090
$ChordPro::Song::xpose or $capo
l!l&&r!l&&!r
6090
MC/DC0%0/3
$ChordPro::Song::xpose or $capo or $main::config->{"settings"}{"transpose"}
$ChordPro::Song::xpose $capo $main::config->{"settings"}{"transpose"}
Truth table25%1/4
A or B or C
A= $ChordPro::Song::xposeB= $capoC= $main::config->{"settings"}{"transpose"}
ABCresult
1XX1
01X1
0011
0000
2118 15 my $key = $name;
2119 15 my $xpk = $self->{chordsinfo}->{$key};
2120 15 ▶ if ( $xpk ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xpk) { } 15 0 15
2121 15 my $info_p = $xpk->transpose( transpose_print() );
2122 15 my $info_s = $xpk->transpose( transpose_sound() );
2123 15 ▶ $self->{chordsinfo}->{$info_p->name} //= $info_p;
Condition66%2/3
$self->{"chordsinfo"}{$info_p->name} //= $info_p
l!l&&r!l&&!r
690
MC/DC0%0/2
$self->{"chordsinfo"}{$info_p->name} //= $info_p
$self->{"chordsinfo"}{$info_p->name} $info_p
Truth table66%2/3
A //= B
A= $self->{"chordsinfo"}{$info_p->name}B= $info_p
ABresult
1X1
011
000
2124 15 ▶ $self->{chordsinfo}->{$info_s->name} //= $info_s;
Condition33%1/3
$self->{"chordsinfo"}{$info_s->name} //= $info_s
l!l&&r!l&&!r
1500
MC/DC0%0/2
$self->{"chordsinfo"}{$info_s->name} //= $info_s
$self->{"chordsinfo"}{$info_s->name} $info_s
Truth table33%1/3
A //= B
A= $self->{"chordsinfo"}{$info_s->name}B= $info_s
ABresult
1X1
011
000
2125 15 $m->{key_print} = [ $info_p->keyname ];
2126 15 $m->{key_sound} = [ $info_s->keyname ];
2127 15 $xpose->set_key($info_p);
2128 15 transpose_debug( "key($val)", $m );
2129 }
2130 else {
2131 0 warn("WHOAH! Key \"$key\" not found in chordsinfo");
2132 }
2133 }
2134 else {
2135 81 $m->{key_print} = $m->{key_sound} = [ $m->{key}->[-1] ];
2136 81 $xpose->set_key($info);
2137 81 transpose_debug( "key($val)", $m );
2138 }
2139 $self->add( type => "meta",
2140 96 key => "key", value => $m->{key_print} );
2141 96 return 1;
2142 }
2143  
2144  
2145 194 ▶ if ( $key eq "capo" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($key eq 'capo') { } 17 177 194
elsif ($key eq 'duration' and $val) { } 9 335 344
2146 do_warn("Multiple capo settings may yield surprising results.")
2147 17 ▶ if exists $m->{capo};
Branch: 1 branch
BranchTrueFalseTotal
if exists $m->{"capo"} 1 16 17
2148  
2149 17 ▶ if ( $val && $decapo ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val and $decapo) 4 13 17
Condition100%3/3
$val and $decapo
!ll&&!rl&&r
1124
MC/DC100%2/2
$val and $decapo
$val $decapo
Truth table100%3/3
A and B
A= $valB= $decapo
ABresult
0X0
100
111
2150 warn( "XPOSE: capo($val) -> transpose (decapo)\n" )
2151 4 ▶ if $config->{debug}->{xpose};;
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"xpose"} 0 4 4
2152 4 return $self->dir_transpose( "transpose", $val );
2153 }
2154  
2155 13 ▶ return 1 unless $val;
Branch: 1 branch
BranchTrueFalseTotal
unless $val 1 12 13
2156 12 $capo = $val;
2157 12 my $m = $self->{meta};
2158 12 ▶ if ( $m->{key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->{"key"}) 12 0 12
2159 12 my $key = $m->{_key}->[-1];
2160 12 my $xpk = $self->{chordsinfo}->{$key};
2161 12 ▶ if ( $xpk ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xpk) { } 12 0 12
2162 12 my $info = $xpk->transpose( transpose_sound() );
2163 12 ▶ $self->{chordsinfo}->{$info->name} //= $info;
Condition33%1/3
$self->{"chordsinfo"}{$info->name} //= $info
l!l&&r!l&&!r
0120
MC/DC0%0/2
$self->{"chordsinfo"}{$info->name} //= $info
$self->{"chordsinfo"}{$info->name} $info
Truth table33%1/3
A //= B
A= $self->{"chordsinfo"}{$info->name}B= $info
ABresult
1X1
011
000
2164 12 $m->{key_sound} = [ $info->keyname ];
2165 12 transpose_debug( "capo($val)", $m );;
2166 }
2167 else {
2168 0 warn("WHOAH! Key \"$key\" not found in chordsinfo");
2169 }
2170 }
2171 }
2172 ▶ elsif ( $key eq "duration" && $val ) {
Condition100%3/3
$key eq "duration" and $val
!ll&&!rl&&r
16719
MC/DC100%2/2
$key eq "duration" and $val
$key eq "duration" $val
Truth table100%3/3
A and B
A= $key eq "duration"B= $val
ABresult
0X0
100
111
2173 9 $val = duration($val);
2174 }
2175  
2176 189 ▶ if ( $config->{metadata}->{strict}
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{"metadata"}{"strict"} and not &any(sub { $_ eq $key; } , @{$$main::config{"metadata"}{"keys"};})) 0 189 189
Condition33%1/3
$main::config->{"metadata"}{"strict"} and not &any(sub { $_ eq $key; } , @{$$main::config{"metadata"}{"keys"};})
!ll&&!rl&&r
01890
MC/DC0%0/2
$main::config->{"metadata"}{"strict"} and not &any(sub { $_ eq $key; } , @{$$main::config{"metadata"}{"keys"};})
$main::config->{"metadata"}{"strict"} not &any(sub { $_ eq $key; } , @{$$main::config{"metadata"}{"keys"};})
Truth table33%1/3
A and not(B)
A= $main::config->{"metadata"}{"strict"}B= not &any(sub { $_ eq $key; } , @{$$main::config{"metadata"}{"keys"};})
ABresult
0X0
100
111
2177 189 ▶ && ! any { $_ eq $key } @{ $config->{metadata}->{keys} } ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
2178 # Unknown, and strict.
2179 do_warn("Unknown metadata item: $key")
2180 0 ▶ if $config->{settings}->{strict};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"settings"}{"strict"} 0 0 0
2181 0 return;
2182 }
2183  
2184 189 ▶ if ( defined $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 189 0 189
2185 $self->{meta}->{$key} = [ $self->{meta}->{$key} ]
2186 189 ▶ if $self->{meta}->{$key} && !is_arrayref($self->{meta}->{$key});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"meta"}{$key} and not is_arrayref($self->{"meta"}{$key}) 0 189 189
Condition66%2/3
$self->{"meta"}{$key} and not is_arrayref($self->{"meta"}{$key})
!ll&&!rl&&r
165240
MC/DC0%0/2
$self->{"meta"}{$key} and not is_arrayref($self->{"meta"}{$key})
$self->{"meta"}{$key} not is_arrayref($self->{"meta"}{$key})
Truth table66%2/3
A and not(B)
A= $self->{"meta"}{$key}B= not is_arrayref($self->{"meta"}{$key})
ABresult
0X0
100
111
2187 189 push( @{ $self->{meta}->{$key} }, $val );
2188 }
2189 }
2190 }
2191 else {
2192 do_warn("Incomplete meta directive: $dir $arg\n")
2193 0 ▶ if $config->{settings}->{strict};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"settings"}{"strict"} 0 0 0
2194 0 return;
2195 }
2196 189 return 1;
2197 }
2198  
2199 # Song / Global settings.
2200  
2201 23 ▶sub dir_titles {
Subroutine dir_titles: called CC=3 SCAR=11.8
Pod undocumented
2202 23 my ( $self, $dir, $arg ) = @_;
2203  
2204 23 ▶ unless ( $arg =~ /^(left|right|center|centre)$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($arg =~ /^(left|right|center|centre)$/i) 0 23 23
2205 0 do_warn("Invalid argument for titles directive: $arg\n");
2206 0 return 1;
2207 }
2208 23 ▶ $self->{settings}->{titles} = lc($1) eq "centre" ? "center" : lc($1);
Branch: 1 branch
BranchTrueFalseTotal
lc $1 eq 'centre' ? : 1 22 23
2209 23 return 1;
2210 }
2211  
2212 20 ▶sub dir_columns {
Subroutine dir_columns: called CC=4 SCAR=17.3
Pod undocumented
2213 20 my ( $self, $dir, $arg ) = @_;
2214  
2215 20 ▶ unless ( $arg =~ /^(\d+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($arg =~ /^(\d+)$/) 0 20 20
2216 0 do_warn("Invalid argument for columns directive: $arg (should be a number)\n");
2217 0 return 1;
2218 }
2219 # If there a column specifications in the config, retain them
2220 # if the number of columns match.
2221 20 ▶ unless( ref($config->{settings}->{columns}) eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $main::config->{"settings"}{"columns"} eq "ARRAY" and $arg == @{$main::config->{"settings"}{"columns"};}) 20 0 20
Condition33%1/3
ref $main::config->{"settings"}{"columns"} eq "ARRAY" and $arg == @{$main::config->{"settings"}{"columns"};}
!ll&&!rl&&r
2000
MC/DC0%0/2
ref $main::config->{"settings"}{"columns"} eq "ARRAY" and $arg == @{$main::config->{"settings"}{"columns"};}
ref $main::config->{"settings"}{"columns"} eq "ARRAY" $arg == @{$main::config->{"settings"}{"columns"};}
Truth table33%1/3
A and B
A= ref $main::config->{"settings"}{"columns"} eq "ARRAY"B= $arg == @{$main::config->{"settings"}{"columns"};}
ABresult
0X0
100
111
2222 0 && $arg == @{$config->{settings}->{columns}}
2223 ) {
2224 20 $self->{settings}->{columns} = $arg;
2225 }
2226 20 return 1;
2227 }
2228  
2229 4 ▶sub dir_papersize {
Subroutine dir_papersize: called CC=1 SCAR=0.0
Pod undocumented
2230 4 my ( $self, $dir, $arg ) = @_;
2231 4 $self->{settings}->{papersize} = $arg;
2232 4 return 1;
2233 }
2234  
2235 3 ▶sub dir_diagrams { # AKA grid
Subroutine dir_diagrams: called CC=3 SCAR=11.2
Pod undocumented
2236 3 my ( $self, $dir, $arg ) = @_;
2237  
2238 3 ▶ if ( $arg ne "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg ne '') { } 3 0 3
2239 3 $self->{settings}->{diagrams} = !!is_true($arg);
2240 3 ▶ $self->{settings}->{diagrampos} = lc($arg)
Branch: 1 branch
BranchTrueFalseTotal
if $arg =~ /^(right|bottom|top|below)$/i 1 2 3
2241 if $arg =~ /^(right|bottom|top|below)$/i;
2242 }
2243 else {
2244 0 $self->{settings}->{diagrams} = 1;
2245 }
2246 3 return 1;
2247 }
2248  
2249 2 ▶sub dir_grid {
Subroutine dir_grid: called CC=1 SCAR=0.0
Pod undocumented
2250 2 my ( $self, $dir, $arg ) = @_;
2251 2 $self->{settings}->{diagrams} = 1;
2252 2 return 1;
2253 }
2254  
2255 5 ▶sub dir_no_grid {
Subroutine dir_no_grid: called CC=1 SCAR=0.0
Pod undocumented
2256 5 my ( $self, $dir, $arg ) = @_;
2257 5 $self->{settings}->{diagrams} = 0;
2258 5 return 1;
2259 }
2260  
2261 59 ▶sub dir_transpose {
Subroutine dir_transpose: called CC=15 SCAR=28.3
Pod undocumented
2262 59 my ( $self, $dir, $arg ) = @_;
2263  
2264 59 ▶ $propstack{transpose} //= [];
Condition100%2/2
$propstack{"transpose"} //= []
l!l
3326
MC/DC100%1/1
$propstack{"transpose"} //= []
$propstack{"transpose"}
Truth table100%2/2
A
A= $propstack{"transpose"}
Aresult
11
00
2265  
2266 59 my %a = ( type => "control",
2267 name => "transpose",
2268 previous => $xpose,
2269 );
2270  
2271 59 ▶ if ( $arg =~ /\S/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /\S/) { } 38 21 59
2272 38 ▶ my $t = parse_transpose($arg) //
Condition33%1/3
parse_transpose($arg) // do_warn(qq[Invalid transpose: "$arg" (ignored)])
l!l&&r!l&&!r
3800
MC/DC0%0/2
parse_transpose($arg) // do_warn(qq[Invalid transpose: "$arg" (ignored)])
parse_transpose($arg) do_warn(qq[Invalid transpose: "$arg" (ignored)])
Truth table33%1/3
A // B
A= parse_transpose($arg)B= do_warn(qq[Invalid transpose: "$arg" (ignored)])
ABresult
1X1
011
000
2273 do_warn("Invalid transpose: \"$arg\" (ignored)");
2274 38 ▶ return unless $t;
Branch: 1 branch
BranchTrueFalseTotal
unless $t 1 37 38
2275 37 push( @{ $propstack{transpose} }, $xpose );
2276 37 $xpose += $t;
2277  
2278 37 my $m = $self->{meta};
2279 37 ▶ if ( $m->{key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->{"key"}) 26 11 37
2280 26 my $key = $m->{_key}->[-1];
2281 26 my $xpk = $self->{chordsinfo}->{$key};
2282 26 ▶ if ( $xpk ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xpk) { } 26 0 26
2283 26 my $info_p = $xpk->transpose( transpose_print() );
2284 26 my $info_s = $xpk->transpose( transpose_sound() );
2285 26 ▶ $self->{chordsinfo}->{$info_p->name} //= $info_p;
Condition33%1/3
$self->{"chordsinfo"}{$info_p->name} //= $info_p
l!l&&r!l&&!r
0260
MC/DC0%0/2
$self->{"chordsinfo"}{$info_p->name} //= $info_p
$self->{"chordsinfo"}{$info_p->name} $info_p
Truth table33%1/3
A //= B
A= $self->{"chordsinfo"}{$info_p->name}B= $info_p
ABresult
1X1
011
000
2286 26 ▶ $self->{chordsinfo}->{$info_s->name} //= $info_s;
Condition66%2/3
$self->{"chordsinfo"}{$info_s->name} //= $info_s
l!l&&r!l&&!r
2420
MC/DC0%0/2
$self->{"chordsinfo"}{$info_s->name} //= $info_s
$self->{"chordsinfo"}{$info_s->name} $info_s
Truth table66%2/3
A //= B
A= $self->{"chordsinfo"}{$info_s->name}B= $info_s
ABresult
1X1
011
000
2287 26 $m->{key_print} = [ $info_p->keyname ];
2288 26 $m->{key_sound} = [ $info_s->keyname ];
2289 26 $xpose->set_key($info_p);
2290 26 transpose_debug( "xp($arg)", $m );
2291 }
2292 else {
2293 0 warn("WHOAH! Key \"$key\" not found in chordsinfo");
2294 }
2295 }
2296 }
2297 else {
2298 21 my $m = $self->{meta};
2299 21 ▶ if ( @{ $propstack{transpose} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$propstack{'transpose'};}) { } 21 0 21
2300 21 $xpose = pop( @{ $propstack{transpose} } );
2301 }
2302 else {
2303 0 $xpose = parse_transpose(0);
2304 }
2305  
2306 21 ▶ if ( $m->{key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->{"key"}) 15 6 21
2307 15 my $key = $m->{_key}->[-1];
2308 15 my $xpk = $self->{chordsinfo}->{$key};
2309 15 ▶ if ( $xpk ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xpk) { } 15 0 15
2310 15 my $info_p = $xpk->transpose( transpose_print() );
2311 15 my $info_s = $xpk->transpose( transpose_sound() );
2312 15 ▶ $self->{chordsinfo}->{$info_p->name} //= $info_p;
Condition33%1/3
$self->{"chordsinfo"}{$info_p->name} //= $info_p
l!l&&r!l&&!r
1500
MC/DC0%0/2
$self->{"chordsinfo"}{$info_p->name} //= $info_p
$self->{"chordsinfo"}{$info_p->name} $info_p
Truth table33%1/3
A //= B
A= $self->{"chordsinfo"}{$info_p->name}B= $info_p
ABresult
1X1
011
000
2313 15 ▶ $self->{chordsinfo}->{$info_s->name} //= $info_s;
Condition33%1/3
$self->{"chordsinfo"}{$info_s->name} //= $info_s
l!l&&r!l&&!r
1500
MC/DC0%0/2
$self->{"chordsinfo"}{$info_s->name} //= $info_s
$self->{"chordsinfo"}{$info_s->name} $info_s
Truth table33%1/3
A //= B
A= $self->{"chordsinfo"}{$info_s->name}B= $info_s
ABresult
1X1
011
000
2314 15 $m->{key_print} = [ $info_p->keyname ];
2315 15 $m->{key_sound} = [ $info_s->keyname ];
2316 15 $xpose->set_key($info_p);
2317 15 transpose_debug( "xp($arg)", $m );
2318 }
2319 else {
2320 0 warn("WHOAH! Key \"$key\" not found in chordsinfo");
2321 }
2322 }
2323 }
2324  
2325 58 ▶ $self->add( %a, value => $xpose )
Branch: 1 branch
BranchTrueFalseTotal
if $no_transpose 0 58 58
2326 if $no_transpose;
2327 58 return 1;
2328 }
2329  
2330 #### End of directive handlers ####
2331  
2332 1405 ▶sub transpose_sound {
Subroutine transpose_sound: called CC=7 SCAR=24.9
Pod undocumented
2333 1405 my ( $only_print ) = @_;
2334  
2335 my $xp =
2336 # Use current.
2337 $xpose
2338 # Apply capo.
2339 + ( $only_print ? 0 : $capo//0 )
2340 # Apply global (cli, config) transpose.
2341 1405 ▶ + $config->{settings}->{transpose};
Branch: 1 branch
BranchTrueFalseTotal
$only_print ? : 1337 68 1405
Condition100%2/2
$capo // 0
l!l
1652
MC/DC100%1/1
$capo // 0
$capo
Truth table100%2/2
A
A= $capo
Aresult
11
00
2342  
2343 warn( "XPOSE: ",
2344 "base = ", $xpose->_data_printer, " ",
2345 ($only_print || !$capo) ? "" : "capo = $capo ",
2346 "outer = ", $config->{settings}->{transpose}->_data_printer, " ",
2347 $only_print ? "print = " : "sound = ", $xp->_data_printer,
2348 1405 ▶ "\n") if $config->{debug}->{xpose};
Branch: 3 branches
BranchTrueFalseTotal
if $main::config->{"debug"}{"xpose"} 0 1405 1405
$only_print || !$capo ? : 0 0 0
$only_print ? : 0 0 0
Condition0%0/3
$only_print or not $capo
l!l&&r!l&&!r
000
MC/DC0%0/2
$only_print or not $capo
$only_print not $capo
Truth table0%0/3
A or not(B)
A= $only_printB= not $capo
ABresult
1X1
011
000
2349  
2350 1405 return $xp;
2351 }
2352  
2353 1337 ▶sub transpose_print {
Subroutine transpose_print: called CC=1 SCAR=0.0
Pod undocumented
2354 1337 transpose_sound(1);
2355 }
2356  
2357 149 ▶sub transpose_debug {
Subroutine transpose_debug: called CC=4 SCAR=25.0
Pod undocumented
2358 149 ▶ return unless $config->{debug}->{xpose};
Branch: 1 branch
BranchTrueFalseTotal
unless $main::config->{"debug"}{"xpose"} 149 0 149
2359 0 my ( $tag, $m ) = @_;
2360 0 my $xp = transpose_print();
2361 warn( "XPOSE: $tag, ",
2362 "key = ", $m->{key}->[-1], ", ",
2363 "print = ", $m->{key_print}->[0], ", ",
2364 "sound = ", $m->{key_sound}->[0],
2365 " [ ", join( " ", $config->{settings}->{transpose},
2366 0 ▶ $xpose, $capo//0,
Branch: 1 branch
BranchTrueFalseTotal
$xp->key ? : 0 0 0
Condition0%0/2
$capo // 0
l!l
00
MC/DC0%0/1
$capo // 0
$capo
Truth table0%0/2
A
A= $capo
Aresult
11
00
2367 $xp->key ? "\@" . $xp->key->keyname : () ),
2368 " ]\n" );
2369 }
2370  
2371 87 ▶sub propset {
Subroutine propset: called CC=17 SCAR=33.2
Pod undocumented
2372 87 my ( $self, $item, $prop, $value ) = @_;
2373 87 ▶ $prop = "color" if $prop eq "colour";
Branch: 1 branch
BranchTrueFalseTotal
if $prop eq "colour" 23 64 87
2374 87 my $name = "$item-$prop";
2375 87 ▶ $propstack{$name} //= [];
Condition100%2/2
$propstack{$name} //= []
l!l
2562
MC/DC100%1/1
$propstack{$name} //= []
$propstack{$name}
Truth table100%2/2
A
A= $propstack{$name}
Aresult
11
00
2376  
2377 87 ▶ if ( $value eq "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value eq "") 2 85 87
2378 2 my @toadd;
2379 # Pop current value from stack.
2380 2 ▶ if ( @{ $propstack{$name} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$propstack{$name};}) { } 2 0 2
2381 2 my $old = pop( @{ $propstack{$name} } );
2382 # A trailing number after a font directive means there
2383 # was also a size saved. Pop it.
2384 2 ▶ if ( $prop eq "font" && $old =~ /\s(\d+(?:\.\d+)?)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prop eq "font" and $old =~ /\s(\d+(?:\.\d+)?)$/) 0 2 2
Condition33%1/3
$prop eq "font" and $old =~ /\s(\d+(?:\.\d+)?)$/
!ll&&!rl&&r
200
MC/DC0%0/2
$prop eq "font" and $old =~ /\s(\d+(?:\.\d+)?)$/
$prop eq "font" $old =~ /\s(\d+(?:\.\d+)?)$/
Truth table33%1/3
A and B
A= $prop eq "font"B= $old =~ /\s(\d+(?:\.\d+)?)$/
ABresult
0X0
100
111
2385 0 pop( @{ $propstack{"$item-size"} } );
2386 # Resetting the size must follow the font reset.
2387 push( @toadd, type => "control",
2388 name => "$item-size",
2389 value =>
2390 0 @{ $propstack{"$item-size"} }
2391 0 ▶ ? $propstack{"$item-size"}->[-1]
Branch: 1 branch
BranchTrueFalseTotal
@{$propstack{"$item-size"};} ? : 0 0 0
2392 : undef );
2393 }
2394 }
2395 else {
2396 0 do_warn("No saved value for property $item$prop\n" )
2397 }
2398 # Use new current value, if any.
2399 2 ▶ if ( @{ $propstack{$name} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$propstack{$name};}) { } 2 0 2
2400 2 $value = $propstack{$name}->[-1]
2401 }
2402 else {
2403 0 $value = undef;
2404 }
2405 2 $self->add( type => "control",
2406 name => $name,
2407 value => $value );
2408 2 ▶ $self->add( @toadd ) if @toadd;
Branch: 1 branch
BranchTrueFalseTotal
if @toadd 0 2 2
2409 2 return 1;
2410 }
2411  
2412 85 ▶ if ( $prop eq "size" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prop eq "size") 24 61 85
2413 24 ▶ unless ( $value =~ /^\d+(?:\.\d+)?\%?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value =~ /^\d+(?:\.\d+)?\%?$/) 0 24 24
2414 0 do_warn("Illegal value \"$value\" for $item$prop\n");
2415 0 return 1;
2416 }
2417 }
2418 85 ▶ if ( $prop eq "color" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prop eq "color") 37 48 85
2419 37 my $v;
2420 37 ▶ unless ( $v = get_color($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v = get_color($value)) 0 37 37
2421 0 do_warn("Illegal value \"$value\" for $item$prop\n");
2422 0 return 1;
2423 }
2424 37 $value = $v;
2425 }
2426 85 ▶ $value = $prop eq "font" ? $value : lc($value);
Branch: 1 branch
BranchTrueFalseTotal
$prop eq 'font' ? : 24 61 85
2427 85 $self->add( type => "control",
2428 name => $name,
2429 value => $value );
2430 85 push( @{ $propstack{$name} }, $value );
2431  
2432 # A trailing number after a font directive is an implicit size
2433 # directive.
2434 85 ▶ if ( $prop eq 'font' && $value =~ /\s(\d+(?:\.\d+)?)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prop eq "font" and $value =~ /\s(\d+(?:\.\d+)?)$/) 0 85 85
Condition66%2/3
$prop eq "font" and $value =~ /\s(\d+(?:\.\d+)?)$/
!ll&&!rl&&r
61240
MC/DC0%0/2
$prop eq "font" and $value =~ /\s(\d+(?:\.\d+)?)$/
$prop eq "font" $value =~ /\s(\d+(?:\.\d+)?)$/
Truth table66%2/3
A and B
A= $prop eq "font"B= $value =~ /\s(\d+(?:\.\d+)?)$/
ABresult
0X0
100
111
2435 0 $self->add( type => "control",
2436 name => "$item-size",
2437 value => $1 );
2438 0 push( @{ $propstack{"$item-size"} }, $1 );
2439 }
2440 }
2441  
2442 1064 ▶sub add_chord {
Subroutine add_chord: called CC=3 SCAR=11.0
Pod undocumented
2443 1064 my ( $self, $info, $new_id ) = @_;
2444  
2445 1064 ▶ if ( $new_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_id) { } 1007 57 1064
2446 1007 ▶ if ( $new_id eq "1" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_id eq 1) 11 996 1007
2447 11 state $id = "ch0000";
2448 11 $new_id = " $id";
2449 11 $id++;
2450 }
2451 }
2452 else {
2453 57 $new_id = $info->name;
2454 }
2455 1064 $self->{chordsinfo}->{$new_id} = $info->new($info);
2456  
2457 1064 return $new_id;
2458 }
2459  
2460 72 ▶sub define_chord {
Subroutine define_chord: called CC=72 SCAR=51.2
Pod undocumented
2461 72 my ( $self, $dir, $args ) = @_;
2462  
2463 # Split the arguments and keep a copy for error messages.
2464 # Note that quotewords returns an empty result if it gets confused,
2465 # so fall back to the ancient split method if so.
2466 72 $args =~ s/^\s+//;
2467 72 $args =~ s/\s+$//;
2468 72 my @a = quotewords( '[: ]+', 0, $args );
2469 72 ▶ @a = split( /[: ]+/, $args ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 2 70 72
2470  
2471 72 my @orig = @a;
2472 72 my $show = $dir eq "chord";
2473 72 my $fail = 0;
2474 72 my $name = shift(@a);
2475 72 my $strings = $config->diagram_strings;
2476  
2477 # Process the options.
2478 72 my %kv = ( name => $name );
2479 72 ▶ while ( @a ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 162 72 234
2480 162 my $a = shift(@a);
2481  
2482 # Copy existing definition.
2483 162 ▶ if ( $a eq "copy" || $a eq "copyall" ) {
Branch: 8 branches
BranchTrueFalseTotal
if ($a eq 'copy' or $a eq 'copyall') { } 11 151 162
elsif ($a eq 'display' and @a) { } 2 149 151
elsif ($a eq 'format' and @a) { } 9 140 149
elsif ($a eq 'base-fret') { } 46 94 140
elsif ($a eq 'frets') { } 57 37 94
elsif ($a eq 'fingers') { } 16 21 37
elsif ($a eq 'keys') { } 8 13 21
elsif ($a eq 'diagram' and @a > 0) { } 13 0 13
Condition66%2/3
$a eq "copy" or $a eq "copyall"
l!l&&r!l&&!r
110151
MC/DC50%1/2
$a eq "copy" or $a eq "copyall"
$a eq "copy" $a eq "copyall"
Truth table66%2/3
A or B
A= $a eq "copy"B= $a eq "copyall"
ABresult
1X1
011
000
2484 11 ▶ if ( my $i = ChordPro::Chords::known_chord($a[0]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $i = ChordPro::Chords::known_chord($a[0])) { } 11 0 11
2485 11 $kv{$a} = $a[0];
2486 11 $kv{orig} = $i;
2487 11 shift(@a);
2488 }
2489 else {
2490 0 do_warn("Unknown chord to copy: $a[0]\n");
2491 0 $fail++;
2492 0 last;
2493 }
2494 }
2495  
2496 # display
2497 ▶ elsif ( $a eq "display" && @a ) {
Condition66%2/3
$a eq "display" and @a
!ll&&!rl&&r
14902
MC/DC50%1/2
$a eq "display" and @a
$a eq "display" @a
Truth table66%2/3
A and B
A= $a eq "display"B= @a
ABresult
0X0
100
111
2498 2 $kv{display} = demarkup($a[0]);
2499 do_warn( "\"display\" should not contain markup, use \"format\"" )
2500 2 ▶ unless $kv{display} eq shift(@a);
Branch: 1 branch
BranchTrueFalseTotal
unless $kv{"display"} eq shift @a 0 2 2
2501 2 $kv{display} = $self->parse_chord($kv{display},1);
2502 2 ▶ delete $kv{display} unless defined $kv{display};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $kv{"display"} 0 2 2
2503 }
2504  
2505 # format
2506 ▶ elsif ( $a eq "format" && @a ) {
Condition66%2/3
$a eq "format" and @a
!ll&&!rl&&r
14009
MC/DC50%1/2
$a eq "format" and @a
$a eq "format" @a
Truth table66%2/3
A and B
A= $a eq "format"B= @a
ABresult
0X0
100
111
2507 9 $kv{format} = shift(@a);
2508 }
2509  
2510 # base-fret N
2511 elsif ( $a eq "base-fret" ) {
2512 46 ▶ if ( $a[0] =~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a[0] =~ /^\d+$/) { } 46 0 46
2513 46 $kv{base} = shift(@a);
2514 }
2515 else {
2516 0 do_warn("Invalid base-fret value: $a[0]\n");
2517 0 $fail++;
2518 0 last;
2519 }
2520 }
2521 # frets N N ... N
2522 elsif ( $a eq "frets" ) {
2523 57 my @f;
2524 57 ▶ while ( @a && $a[0] =~ /^(?:-?[0-9]+|[-xXN])$/ && @f < $strings ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] =~ /^(?:-?[0-9]+|[-xXN])$/ and @f < $strings) 342 57 399
Condition83%5/6
@a and $a[0] =~ /^(?:-?[0-9]+|[-xXN])$/ and @f < $strings
!ll&&!rl&&r
570342
@a and $a[0] =~ /^(?:-?[0-9]+|[-xXN])$/
!ll&&!rl&&r
3918342
MC/DC66%2/3
@a and $a[0] =~ /^(?:-?[0-9]+|[-xXN])$/ and @f < $strings
@a $a[0] =~ /^(?:-?[0-9]+|[-xXN])$/ @f < $strings
Truth table75%3/4
A and B and C
A= @aB= $a[0] =~ /^(?:-?[0-9]+|[-xXN])$/C= @f < $strings
ABCresult
0XX0
10X0
1100
1111
2525 342 push( @f, shift(@a) );
2526 }
2527 57 ▶ if ( @f == $strings ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@f == $strings) { } 57 0 57
2528 57 ▶ $kv{frets} = [ map { $_ =~ /^\d+/ ? $_ : -1 } @f ];
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /^\d+/ ? : 302 40 342
2529 }
2530 else {
2531 0 do_warn("Incorrect number of fret positions (" .
2532 scalar(@f) . ", should be $strings)\n");
2533 0 $fail++;
2534 0 last;
2535 }
2536 }
2537  
2538 # fingers N N ... N
2539 elsif ( $a eq "fingers" ) {
2540 16 my @f;
2541 # It is tempting to limit the fingers to 1..5 ...
2542 16 ▶ while ( @a && @f < $strings ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a and @f < $strings) 96 16 112
Condition100%3/3
@a and @f < $strings
!ll&&!rl&&r
8896
MC/DC100%2/2
@a and @f < $strings
@a @f < $strings
Truth table100%3/3
A and B
A= @aB= @f < $strings
ABresult
0X0
100
111
2543 96 local $_ = shift(@a);
2544 96 ▶ if ( /^[0-9]+$/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^[0-9]+$/) { } 90 6 96
elsif (/^[A-MO-WYZ]$/) { } 0 6 6
elsif (/^[-xNX]$/) { } 6 0 6
2545 90 push( @f, 0 + $_ );
2546 }
2547 elsif ( /^[A-MO-WYZ]$/ ) {
2548 0 push( @f, $_ );
2549 }
2550 elsif ( /^[-xNX]$/ ) {
2551 6 push( @f, -1 );
2552 }
2553 else {
2554 0 unshift( @a, $_ );
2555 0 last;
2556 }
2557 }
2558 16 ▶ if ( @f == $strings ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@f == $strings) { } 16 0 16
2559 16 $kv{fingers} = \@f;
2560 }
2561 else {
2562 0 do_warn("Incorrect number of finger settings (" .
2563 scalar(@f) . ", should be $strings)\n");
2564 0 $fail++;
2565 0 last;
2566 }
2567 }
2568  
2569 # keys N N ... N
2570 elsif ( $a eq "keys" ) {
2571 8 my @f;
2572 8 ▶ while ( @a && $a[0] =~ /^[0-9]+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a and $a[0] =~ /^[0-9]+$/) 24 8 32
Condition100%3/3
@a and $a[0] =~ /^[0-9]+$/
!ll&&!rl&&r
1724
MC/DC100%2/2
@a and $a[0] =~ /^[0-9]+$/
@a $a[0] =~ /^[0-9]+$/
Truth table100%3/3
A and B
A= @aB= $a[0] =~ /^[0-9]+$/
ABresult
0X0
100
111
2573 24 push( @f, shift(@a) );
2574 }
2575 8 ▶ if ( @f ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@f) { } 8 0 8
2576 8 $kv{keys} = \@f;
2577 }
2578 else {
2579 0 do_warn("Invalid or missing keys\n");
2580 0 $fail++;
2581 0 last;
2582 }
2583 }
2584  
2585 ▶ elsif ( $a eq "diagram" && @a > 0 ) {
Condition33%1/3
$a eq "diagram" and @a > 0
!ll&&!rl&&r
0013
MC/DC0%0/2
$a eq "diagram" and @a > 0
$a eq "diagram" @a > 0
Truth table33%1/3
A and B
A= $a eq "diagram"B= @a > 0
ABresult
0X0
100
111
2586 13 ▶ if ( $show && !is_true($a[0]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($show and not is_true($a[0])) 0 13 13
Condition33%1/3
$show and not is_true($a[0])
!ll&&!rl&&r
1300
MC/DC0%0/2
$show and not is_true($a[0])
$show not is_true($a[0])
Truth table33%1/3
A and not(B)
A= $showB= not is_true($a[0])
ABresult
0X0
100
111
2587 0 do_warn("Useless diagram suppression");
2588 0 next;
2589 }
2590 13 $kv{diagram} = shift(@a);
2591 }
2592  
2593 # Wrong...
2594 else {
2595 # Insert a marker to show how far we got.
2596 0 splice( @orig, @orig-@a, 0, "<<<" );
2597 0 splice( @orig, @orig-@a-2, 0, ">>>" );
2598 0 do_warn("Invalid chord definition: @orig\n");
2599 0 $fail++;
2600 0 last;
2601 }
2602 }
2603  
2604 72 ▶ return 1 if $fail;
Branch: 1 branch
BranchTrueFalseTotal
if $fail 0 72 72
2605 # All options are verified and stored in %kv;
2606  
2607 72 my $fixed = 1; # not transposable
2608 72 ▶ if ( $name =~ /^\[(.*)\]$/ ) { # transposable
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^\[(.*)\]$/) 0 72 72
2609 0 ▶ if ( %kv > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%kv > 1) 0 0 0
2610 0 ▶ use DDP; p %kv;
Subroutine BEGIN: called CC=1 SCAR=0.2
2611 0 do_warn("Transposable chord $name does not allow attributes");
2612 0 %kv = ();
2613 }
2614 0 $name = $1;
2615 0 $fixed = 0;
2616 }
2617  
2618 # Result structure.
2619 72 my $res = { name => $name };
2620  
2621 # Try to find info.
2622 72 my $info = $self->parse_chord( $name, $fixed );
2623 72 ▶ if ( $info ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info) { } 71 1 72
2624 # Copy the chord info.
2625 $res->{$_} //= $info->{$_} // ''
2626 71 ▶ for qw( parser root qual ext bass
Condition75%3/4
$res->{$_} //= $info->{$_} // ""
l!l
0923
$info->{$_} // ""
l!l
764159
MC/DC0%0/1
$res->{$_} //= $info->{$_} // ""
$res->{$_}
Truth table50%1/2
A
A= $res->{$_}
Aresult
11
00
2627 root_canon qual_canon ext_canon bass_canon
2628 root_ord root_mod bass_ord bass_mod
2629 );
2630 71 ▶ if ( $show ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($show) 9 62 71
2631 $res->{$_} //= $info->{$_}
2632 9 ▶ for qw( base frets fingers keys );
Condition66%2/3
$res->{$_} //= $info->{$_}
l!l&&r!l&&!r
01620
MC/DC50%1/2
$res->{$_} //= $info->{$_}
$res->{$_} $info->{$_}
Truth table66%2/3
A //= B
A= $res->{$_}B= $info->{$_}
ABresult
1X1
011
000
2633 }
2634 }
2635 else {
2636 1 $res->{parser} = ChordPro::Chords::get_parser();
2637 }
2638  
2639 # Copy existing definition.
2640 72 ▶ for ( $kv{copyall} // $kv{copy} ) {
Condition66%2/3
$kv{"copyall"} // $kv{"copy"}
l!l&&r!l&&!r
01161
MC/DC50%1/2
$kv{"copyall"} // $kv{"copy"}
$kv{"copyall"} $kv{"copy"}
Truth table66%2/3
A // B
A= $kv{"copyall"}B= $kv{"copy"}
ABresult
1X1
011
000
2641 72 ▶ next unless defined;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 61 11 72
2642 11 $res->{copy} = $_;
2643 11 my $orig = $res->{orig} = $kv{orig};
2644 $res->{$_} //= $orig->{$_}
2645 11 ▶ for qw( base frets fingers keys );
Condition33%1/3
$res->{$_} //= $orig->{$_}
l!l&&r!l&&!r
0440
MC/DC0%0/2
$res->{$_} //= $orig->{$_}
$res->{$_} $orig->{$_}
Truth table33%1/3
A //= B
A= $res->{$_}B= $orig->{$_}
ABresult
1X1
011
000
2646 11 ▶ if ( $kv{copyall} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kv{"copyall"}) 0 11 11
2647 $res->{$_} //= $orig->{$_}
2648 0 ▶ for qw( display format );
Condition0%0/3
$res->{$_} //= $orig->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$res->{$_} //= $orig->{$_}
$res->{$_} $orig->{$_}
Truth table0%0/3
A //= B
A= $res->{$_}B= $orig->{$_}
ABresult
1X1
011
000
2649 }
2650 }
2651 72 for ( qw( display format ) ) {
2652 144 ▶ $res->{$_} = $kv{$_} if defined $kv{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $kv{$_} 11 133 144
2653 }
2654  
2655 # If we've got diagram visibility, remove it if true.
2656 72 ▶ if ( defined $kv{diagram} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $kv{"diagram"}) 13 59 72
2657 13 for ( my $v = $kv{diagram} ) {
2658 13 ▶ if ( is_true($v) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_true($v)) { } 7 6 13
2659 7 ▶ if ( is_ttrue($v) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_ttrue($v)) 6 1 7
2660 6 next;
2661 }
2662 }
2663 else {
2664 6 $v = 0;
2665 }
2666 7 $res->{diagram} = $v;
2667 }
2668 }
2669  
2670 # Copy rest of options.
2671 72 for ( qw( base frets fingers keys display format ) ) {
2672 432 ▶ next unless defined $kv{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $kv{$_} 294 138 432
2673 138 $res->{$_} = $kv{$_};
2674 }
2675  
2676 # At this time, $res is still just a hash. Time to make a chord.
2677 72 ▶ $res->{base} ||= 1;
Condition100%2/2
$res->{"base"} ||= 1
l!l
6111
MC/DC100%1/1
$res->{"base"} ||= 1
$res->{"base"}
Truth table100%2/2
A
A= $res->{"base"}
Aresult
11
00
2678 72 ▶ $res = ChordPro::Chord::Common->new
Branch: 1 branch
BranchTrueFalseTotal
$show ? : 9 63 72
2679 ( { %$res, origin => $show ? "inline" : "song" } );
2680 72 ▶ $res->{parser} //= ChordPro::Chords::get_parser();
Condition33%1/3
$res->{"parser"} //= ChordPro::Chords::get_parser()
l!l&&r!l&&!r
7200
MC/DC0%0/2
$res->{"parser"} //= ChordPro::Chords::get_parser()
$res->{"parser"} ChordPro::Chords::get_parser()
Truth table33%1/3
A //= B
A= $res->{"parser"}B= ChordPro::Chords::get_parser()
ABresult
1X1
011
000
2681  
2682 72 ▶ if ( $show) {
Branch: 1 branch
BranchTrueFalseTotal
if ($show) 9 63 72
2683 9 my $ci = $res->clone;
2684 9 my $chidx = $self->add_chord( $ci, 1 );
2685 # Combine consecutive entries.
2686 9 ▶ if ( defined($self->{body})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'body'} and $self->{'body'}[-1]{'type'} eq 'diagrams') { } 2 7 9
Condition66%2/3
defined $self->{"body"} and $self->{"body"}[-1]{"type"} eq "diagrams"
!ll&&!rl&&r
072
MC/DC50%1/2
defined $self->{"body"} and $self->{"body"}[-1]{"type"} eq "diagrams"
defined $self->{"body"} $self->{"body"}[-1]{"type"} eq "diagrams"
Truth table66%2/3
A and B
A= defined $self->{"body"}B= $self->{"body"}[-1]{"type"} eq "diagrams"
ABresult
0X0
100
111
2687 && $self->{body}->[-1]->{type} eq "diagrams" ) {
2688 2 push( @{ $self->{body}->[-1]->{chords} }, $chidx );
2689 }
2690 else {
2691 7 $self->add( type => "diagrams",
2692 show => "user",
2693 origin => "chord",
2694 chords => [ $chidx ] );
2695 }
2696 9 return 1;
2697 }
2698  
2699 63 my $def = {};
2700 63 for ( qw( name base frets fingers keys display format diagram ) ) {
2701 504 ▶ next unless defined $res->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res->{$_} 256 248 504
2702 248 $def->{$_} = $res->{$_};
2703 }
2704 63 push( @{$self->{define}}, $def );
2705 63 my $ret = ChordPro::Chords::add_song_chord($res);
2706 63 ▶ if ( $ret ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret) 0 63 63
2707 0 do_warn("Invalid chord: ", $res->{name}, ": ", $ret, "\n");
2708 0 return 1;
2709 }
2710 63 $info = ChordPro::Chords::known_chord($res->{name});
2711 63 ▶ croak("We just entered it?? ", $res->{name}) unless $info;
Branch: 1 branch
BranchTrueFalseTotal
unless $info 0 63 63
2712  
2713 63 ▶ $info->dump if $config->{debug}->{x1};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"x1"} 0 63 63
2714  
2715 63 return 1;
2716 }
2717  
2718 9 ▶sub duration {
Subroutine duration: called CC=4 SCAR=14.5
Pod undocumented
2719 9 my ( $dur ) = @_;
2720  
2721 9 ▶ if ( $dur =~ /(?:(?:(\d+):)?(\d+):)?(\d+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dur =~ /(?:(?:(\d+):)?(\d+):)?(\d+)/) 9 0 9
2722 9 ▶ $dur = $3 + ( $2 ? 60 * $2 :0 ) + ( $1 ? 3600 * $1 : 0 );
Branch: 2 branches
BranchTrueFalseTotal
$2 ? : 0 9 9
$1 ? : 0 9 9
2723 }
2724 9 my $res = sprintf( "%d:%02d:%02d",
2725 int( $dur / 3600 ),
2726 int( ( $dur % 3600 ) / 60 ),
2727 $dur % 60 );
2728 9 $res =~ s/^[0:]+//;
2729 9 return $res;
2730 }
2731  
2732 37 ▶sub get_color {
Subroutine get_color: called CC=1 SCAR=0.0
Pod undocumented
2733 37 $_[0];
2734 }
2735  
2736 23 ▶sub _diag {
Subroutine _diag: called CC=2 SCAR=6.9
2737 23 my ( $self, %d ) = @_;
2738 23 $diag->{$_} = $d{$_} for keys(%d);
2739 }
2740  
2741 4 ▶sub msg {
Subroutine msg: called CC=1 SCAR=0.0
Pod undocumented
2742 4 my $m = join("", @_);
2743 4 $m =~ s/\n+$//;
2744 4 my $t = $diag->{format};
2745 4 $t =~ s/\\n/\n/g;
2746 4 $t =~ s/\\t/\t/g;
2747 4 $t =~ s/\%f/$diag->{file}/g;
2748 4 $t =~ s/\%n/$diag->{line}/g;
2749 4 $t =~ s/\%l/$diag->{orig}/g;
2750 4 $t =~ s/\%m/$m/g;
2751 4 $t;
2752 }
2753  
2754 4 ▶sub do_warn {
Subroutine do_warn: called CC=1 SCAR=0.0
Pod undocumented
2755 4 warn(msg(@_)."\n");
2756 4 undef;
2757 }
2758  
2759 # Parse a chord.
2760 # Handles transpose/transcode.
2761 # Returns the chord object.
2762 # No parens or annotations, please.
2763 1245 ▶sub parse_chord {
Subroutine parse_chord: called CC=70 SCAR=54.5
Pod undocumented
2764 1245 my ( $self, $chord, $def ) = @_;
2765  
2766 1245 my $debug = $config->{debug}->{chords};
2767  
2768 1245 ▶ if ( $chord =~ /^\[(.*)\]$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chord =~ /^\[(.*)\]$/) 0 1245 1245
2769 0 $chord = $1;
2770 0 $def = 0;
2771 }
2772  
2773 1245 ▶ warn("Parsing chord: \"$chord\"\n") if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1245 1245
2774 1245 my $info;
2775  
2776 1245 my $xp = transpose_print();
2777 1245 ▶ $xp = 0 unless $xp->xp || $xp->forced;
Branch: 1 branch
BranchTrueFalseTotal
unless $xp->xp or $xp->forced 1094 151 1245
Condition66%2/3
$xp->xp or $xp->forced
l!l&&r!l&&!r
15101094
MC/DC50%1/2
$xp->xp or $xp->forced
$xp->xp $xp->forced
Truth table66%2/3
A or B
A= $xp->xpB= $xp->forced
ABresult
1X1
011
000
2778  
2779 1245 my $xc = $config->{settings}->{transcode};
2780 1245 my $unk;
2781  
2782 # When called from {define} ignore xc/xp.
2783 1245 ▶ ( $xc, $xp ) = ( '', 0 ) if $def;
Branch: 1 branch
BranchTrueFalseTotal
if $def 74 1171 1245
2784  
2785 1245 $info = ChordPro::Chords::known_chord($chord);
2786 1245 ▶ if ( $info ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info) { } 907 338 1245
2787 warn( "Parsing chord: \"$chord\" found \"",
2788 907 ▶ $info->name, "\" in ", $info->{_via}, "\n" ) if $debug > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $debug > 1 0 907 907
2789 #### This return triggered issue #580. Exclude format/display.
2790 return ChordPro::Chord::NC->new( { name => $info->name } )
2791 if $info->is_nc
2792 907 ▶ && !( $info->{display} || $info->{format} );
Branch: 1 branch
BranchTrueFalseTotal
if $info->is_nc and not $info->{"display"} || $info->{"format"} 7 900 907
Condition50%3/6
$info->is_nc and not $info->{"display"} || $info->{"format"}
!ll&&!rl&&r
90007
$info->{'display'} || $info->{'format'}
l!l&&r!l&&!r
007
MC/DC33%1/3
$info->is_nc and not $info->{"display"} || $info->{"format"}
$info->is_nc $info->{'display'} $info->{'format'}
Truth table50%2/4
A and not(B || C)
A= $info->is_ncB= $info->{'display'}C= $info->{'format'}
ABCresult
0XX0
11X0
1010
1001
2793 900 ▶ $info->dump if $debug > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $debug > 2 0 900 900
2794 }
2795 else {
2796 338 $info = ChordPro::Chords::parse_chord($chord);
2797 warn( "Parsing chord: \"$chord\" parsed ok [",
2798 $info->{system},
2799 338 ▶ "]\n" ) if $info && $debug > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $info and $debug > 1 0 338 338
Condition66%2/3
$info and $debug > 1
!ll&&!rl&&r
303080
MC/DC0%0/2
$info and $debug > 1
$info $debug > 1
Truth table66%2/3
A and B
A= $infoB= $debug > 1
ABresult
0X0
100
111
2800 }
2801 1238 $unk = !defined $info;
2802  
2803 1238 ▶ if ( ( $def || $xp || $xc )
Branch: 1 branch
BranchTrueFalseTotal
if ($def || $xp || $xc and not $info && $info->is_xpxc) 22 1216 1238
Condition91%11/12
$def || $xp || $xc and not $info && $info->is_xpxc
!ll&&!rl&&r
99522122
$def or $xp or $xc
l!l&&r!l&&!r
22320995
$def or $xp
l!l&&r!l&&!r
74131151
$info && $info->is_xpxc
!ll&&!rl&&r
220221
MC/DC40%2/5
$def || $xp || $xc and not $info && $info->is_xpxc
$def $xp $xc $info $info->is_xpxc
Truth table40%4/10
A or B or C and not(D && E)
A= $defB= $xpC= $xcD= $infoE= $info->is_xpxc
ABCDEresult
000XX0
1XX110
01X110
001110
1XX0X1
1XX101
01X0X1
01X101
0010X1
001101
2804 &&
2805 ! ($info && $info->is_xpxc ) ) {
2806 22 local $::config->{settings}->{chordnames} = "relaxed";
2807 22 $info = ChordPro::Chords::parse_chord($chord);
2808 }
2809  
2810 1238 ▶ unless ( ( $info && $info->is_xpxc )
Branch: 1 branch
BranchTrueFalseTotal
unless ($info and $info->is_xpxc or $def and not $xc || $xp) 8 1230 1238
Condition66%8/12
$info and $info->is_xpxc or $def and not $xc || $xp
l!l&&r!l&&!r
122918
$info and $info->is_xpxc
!ll&&!rl&&r
901229
$def and not $xc || $xp
!ll&&!rl&&r
801
$xc || $xp
l!l&&r!l&&!r
001
MC/DC40%2/5
$info and $info->is_xpxc or $def and not $xc || $xp
$info $info->is_xpxc $def $xc $xp
Truth table33%3/9
A and B or C and not(D || E)
A= $infoB= $info->is_xpxcC= $defD= $xcE= $xp
ABCDEresult
11XXX1
0X1001
101001
0X0XX0
0X11X0
0X1010
100XX0
1011X0
101010
2811 ||
2812 ( $def && !( $xc || $xp ) ) ) {
2813 do_warn( "Cannot parse",
2814 $xp ? "/transpose" : "",
2815 $xc ? "/transcode" : "",
2816 " chord \"$chord\"\n" )
2817 8 ▶ if $xp || $xc || $config->{debug}->{chords};
Branch: 3 branches
BranchTrueFalseTotal
if $xp or $xc or $main::config->{"debug"}{"chords"} 0 8 8
$xp ? : 0 0 0
$xc ? : 0 0 0
Condition33%2/6
$xp or $xc or $main::config->{"debug"}{"chords"}
l!l&&r!l&&!r
008
$xp or $xc
l!l&&r!l&&!r
008
MC/DC0%0/3
$xp or $xc or $main::config->{"debug"}{"chords"}
$xp $xc $main::config->{"debug"}{"chords"}
Truth table25%1/4
A or B or C
A= $xpB= $xcC= $main::config->{"debug"}{"chords"}
ABCresult
1XX1
01X1
0011
0000
2818 }
2819  
2820 1238 ▶ if ( $xp && $info
Branch: 1 branch
BranchTrueFalseTotal
if ($xp and $info and not $xc && ($xc eq "nashville" || $xc eq "roman")) 149 1089 1238
Condition41%5/12
$xp and $info and not $xc && ($xc eq "nashville" || $xc eq "roman")
!ll&&!rl&&r
10890149
$xp and $info
!ll&&!rl&&r
10890149
$xc && ($xc eq 'nashville' || $xc eq 'roman')
!ll&&!rl&&r
14900
$xc eq "nashville" or $xc eq "roman"
l!l&&r!l&&!r
000
MC/DC20%1/5
$xp and $info and not $xc && ($xc eq "nashville" || $xc eq "roman")
$xp $info $xc $xc eq "nashville" $xc eq "roman"
Truth table33%2/6
A and B and not(C && D or E)
A= $xpB= $infoC= $xcD= $xc eq "nashville"E= $xc eq "roman"
ABCDEresult
0XXXX0
10XXX0
1111X0
111010
110XX1
111001
2821 && !( $xc && ( $xc eq "nashville" || $xc eq "roman" ) ) ) {
2822 # For transpose/transcode, chord must be wellformed.
2823 149 my $i = $info->transpose($xp);
2824 # Prevent self-references.
2825 149 ▶ $i->{xp} = $info unless $i eq $info;
Branch: 1 branch
BranchTrueFalseTotal
unless $i eq $info 149 0 149
2826 149 $info = $i;
2827 warn( "Parsing chord: \"$chord\" transposed $xp (".
2828 $xp->_data_printer.") to \"",
2829 $info->name, "\"",
2830 149 ▶ ( $self->{meta}->{key} ? (" key ".$self->{meta}->{key}->[-1]) : ()),
Branch: 2 branches
BranchTrueFalseTotal
if $debug > 1 0 149 149
$self->{'meta'}{'key'} ? : 0 0 0
2831 "\n" ) if $debug > 1;
2832 }
2833 # else: warning has been given.
2834  
2835 1238 ▶ if ( $info ) { # TODO roman?
Branch: 1 branch
BranchTrueFalseTotal
if ($info) 1229 9 1238
2836 # Look it up now, the name may change by transcode.
2837 1229 ▶ if ( my $i = ChordPro::Chords::known_chord($info) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $i = ChordPro::Chords::known_chord($info)) { } 905 324 1229
elsif ($main::config->{'instrument'}{'type'} eq 'keyboard' and my $k = ChordPro::Chords::get_keys($info)) { } 0 324 324
2838 warn( "Parsing chord: \"$chord\" found ",
2839 $i->name, " for ", $info->name,
2840 905 ▶ " in ", $i->{_via}, "\n" ) if $debug > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $debug > 1 0 905 905
2841 $info = $i->new({ %$i, name => $info->name,
2842 $info->{xp} ? ( xp => $info->{xp} ) : (),
2843 905 ▶ $info->{xc} ? ( xc => $info->{xc} ) : (),
Branch: 2 branches
BranchTrueFalseTotal
$info->{'xp'} ? : 84 821 905
$info->{'xc'} ? : 0 905 905
2844 }) ;
2845 905 $unk = 0;
2846 }
2847 ▶ elsif ( $config->{instrument}->{type} eq 'keyboard'
Condition33%1/3
$main::config->{"instrument"}{"type"} eq "keyboard" and my $k = ChordPro::Chords::get_keys($info)
!ll&&!rl&&r
32400
MC/DC0%0/2
$main::config->{"instrument"}{"type"} eq "keyboard" and my $k = ChordPro::Chords::get_keys($info)
$main::config->{"instrument"}{"type"} eq "keyboard" my $k = ChordPro::Chords::get_keys($info)
Truth table33%1/3
A and B
A= $main::config->{"instrument"}{"type"} eq "keyboard"B= my $k = ChordPro::Chords::get_keys($info)
ABresult
0X0
100
111
2848 && ( my $k = ChordPro::Chords::get_keys($info) ) ) {
2849 0 ▶ warn( "Parsing chord: \"$chord\" \"", $info->name, "\" not found ",
Branch: 1 branch
BranchTrueFalseTotal
if $debug > 1 0 0 0
2850 "but we know what to do\n" ) if $debug > 1;
2851 0 $info = $info->new({ %$info, keys => $k }) ;
2852 0 $unk = 0;
2853 }
2854 else {
2855 324 ▶ warn( "Parsing chord: \"$chord\" \"", $info->name,
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 324 324
2856 "\" not found in song/config chords\n" ) if $debug;
2857 # warn("XX \'", $info->agnostic, "\'\n");
2858 324 $unk = 1;
2859 }
2860 }
2861  
2862 1238 ▶ if ( $xc && $info ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xc and $info) 20 1218 1238
Condition66%2/3
$xc and $info
!ll&&!rl&&r
1218020
MC/DC50%1/2
$xc and $info
$xc $info
Truth table66%2/3
A and B
A= $xcB= $info
ABresult
0X0
100
111
2863 20 my $key_ord;
2864 $key_ord = $self->{chordsinfo}->{$self->{meta}->{key}->[-1]}->{root_ord}
2865 20 ▶ if $self->{meta}->{key};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"meta"}{"key"} 20 0 20
2866 20 ▶ if ( $xcmov && !defined $key_ord ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xcmov and not defined $key_ord) 0 20 20
Condition33%1/3
$xcmov and not defined $key_ord
!ll&&!rl&&r
2000
MC/DC0%0/2
$xcmov and not defined $key_ord
$xcmov not defined $key_ord
Truth table33%1/3
A and not(B)
A= $xcmovB= not defined $key_ord
ABresult
0X0
100
111
2867 0 do_warn("Warning: Transcoding to $xc without key may yield unexpected results\n");
2868 0 undef $xcmov;
2869 }
2870 20 my $i = $info->transcode( $xc, $key_ord );
2871 # Prevent self-references.
2872 20 ▶ $i->{xc} = $info unless $i eq $info;
Branch: 1 branch
BranchTrueFalseTotal
unless $i eq $info 20 0 20
2873 20 $info = $i;
2874 warn( "Parsing chord: \"$chord\" transcoded to ",
2875 $info->name,
2876 " (", $info->{system}, ")",
2877 20 ▶ defined($key_ord) ? " key ".$self->{meta}->{key}->[-1] : "",
Branch: 2 branches
BranchTrueFalseTotal
if $debug > 1 0 20 20
defined $key_ord ? : 0 0 0
2878 "\n" ) if $debug > 1;
2879 20 ▶ if ( my $i = ChordPro::Chords::known_chord($info) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $i = ChordPro::Chords::known_chord($info)) 8 12 20
2880 8 ▶ warn( "Parsing chord: \"$chord\" found \"",
Branch: 1 branch
BranchTrueFalseTotal
if $debug > 1 0 8 8
2881 $info->name, "\" in song/config chords\n" ) if $debug > 1;
2882 8 $unk = 0;
2883 }
2884 }
2885 # else: warning has been given.
2886  
2887 1238 ▶ if ( ! $info ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($info) 9 1229 1238
2888 9 ▶ if ( my $i = ChordPro::Chords::known_chord($chord) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $i = ChordPro::Chords::known_chord($chord)) 0 9 9
2889 0 $info = $i;
2890 warn( "Parsing chord: \"$chord\" found \"",
2891 $chord, "\" in ",
2892 0 ▶ $i->{_via}, "\n" ) if $debug > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $debug > 1 0 0 0
2893 0 $unk = 0;
2894 }
2895 }
2896  
2897 1238 ▶ unless ( $info || $def ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($info or $def) 8 1230 1238
Condition100%3/3
$info or $def
l!l&&r!l&&!r
122918
MC/DC100%2/2
$info or $def
$info $def
Truth table100%3/3
A or B
A= $infoB= $def
ABresult
1X1
011
000
2898 8 ▶ if ( $config->{debug}->{chords} || ! $warned_chords{$chord}++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{"debug"}{"chords"} or not $warned_chords{$chord}++) 1 7 8
Condition66%2/3
$main::config->{"debug"}{"chords"} or not $warned_chords{$chord}++
l!l&&r!l&&!r
017
MC/DC50%1/2
$main::config->{"debug"}{"chords"} or not $warned_chords{$chord}++
$main::config->{"debug"}{"chords"} not $warned_chords{$chord}++
Truth table66%2/3
A or not(B)
A= $main::config->{"debug"}{"chords"}B= not $warned_chords{$chord}++
ABresult
1X1
011
000
2899 1 ▶ warn("Parsing chord: \"$chord\" unknown\n") if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1 1
2900 1 ▶ do_warn( "Unknown chord: \"$chord\"\n" )
Branch: 1 branch
BranchTrueFalseTotal
unless $chord =~ /^n\.?c\.?$/i 1 0 1
2901 unless $chord =~ /^n\.?c\.?$/i;
2902 }
2903 }
2904  
2905 1238 ▶ if ( $info ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info) 1229 9 1238
2906 $info->{key} = $self->{meta}->{key}->[-1]
2907 1229 ▶ unless $config->{settings}->{'enharmonic-transpose'};
Branch: 1 branch
BranchTrueFalseTotal
unless $main::config->{"settings"}{"enharmonic-transpose"} 0 1229 1229
2908 1229 ▶ warn( "Parsing chord: \"$chord\" okay: \"",
Branch: 2 branches
BranchTrueFalseTotal
if $debug > 1 0 1229 1229
$unk ? : 0 0 0
2909 $info->name, "\" \"",
2910 $info->chord_display, "\"",
2911 $unk ? " but unknown" : "",
2912 "\n" ) if $debug > 1;
2913 1229 $self->store_chord($info);
2914 1229 return $info;
2915 }
2916  
2917 9 ▶ warn( "Parsing chord: \"$chord\" not found\n" ) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 9 9
2918 9 return;
2919 }
2920  
2921 1229 ▶sub store_chord {
Subroutine store_chord: called CC=1 SCAR=0.0
Pod undocumented
2922 1229 my ( $self, $info ) = @_;
2923 1229 $self->{chordsinfo}->{$info->name} = $info;
2924 1229 $info->name;
2925 }
2926  
2927 13 ▶sub structurize {
Subroutine structurize: called CC=9 SCAR=22.0
Pod undocumented
2928 13 my ( $self ) = @_;
2929  
2930 13 ▶ return if $self->{structure} eq "structured";
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"structure"} eq "structured" 0 13 13
2931  
2932 13 my @body;
2933 13 my $context = $def_context;
2934  
2935 13 foreach my $item ( @{ $self->{body} } ) {
2936 244 ▶ if ( $item->{type} eq "empty" && $item->{context} eq $def_context ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{"type"} eq "empty" and $item->{"context"} eq $def_context) 56 188 244
Condition66%2/3
$item->{"type"} eq "empty" and $item->{"context"} eq $def_context
!ll&&!rl&&r
188056
MC/DC50%1/2
$item->{"type"} eq "empty" and $item->{"context"} eq $def_context
$item->{"type"} eq "empty" $item->{"context"} eq $def_context
Truth table66%2/3
A and B
A= $item->{"type"} eq "empty"B= $item->{"context"} eq $def_context
ABresult
0X0
100
111
2937 56 $context = $def_context;
2938 56 next;
2939 }
2940 188 ▶ if ( $item->{type} eq "songline" && $item->{context} eq '' ){ # A songline should have a context - non means verse
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{"type"} eq "songline" and $item->{"context"} eq "") 36 152 188
Condition100%3/3
$item->{"type"} eq "songline" and $item->{"context"} eq ""
!ll&&!rl&&r
737936
MC/DC100%2/2
$item->{"type"} eq "songline" and $item->{"context"} eq ""
$item->{"type"} eq "songline" $item->{"context"} eq ""
Truth table100%3/3
A and B
A= $item->{"type"} eq "songline"B= $item->{"context"} eq ""
ABresult
0X0
100
111
2941 36 $item->{context} = 'verse';
2942 }
2943 188 ▶ if ( $context ne $item->{context} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context ne $item->{"context"}) 43 145 188
2944 43 push( @body, { type => $context = $item->{context}, body => [] } );
2945 }
2946 188 ▶ if ( $context ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context) { } 135 53 188
2947 135 push( @{ $body[-1]->{body} }, $item );
2948 }
2949 else {
2950 53 push( @body, $item );
2951 }
2952 }
2953 13 $self->{body} = [ @body ];
2954 13 $self->{structure} = "structured";
2955 }
2956  
2957 0 ▶sub dump {
Subroutine dump: not called CC=5 SCAR=34.0
Pod undocumented
2958 0 my ( $self, $full ) = @_;
2959 0 ▶ $full ||= 0;
Condition0%0/2
$full ||= 0
l!l
00
MC/DC0%0/1
$full ||= 0
$full
Truth table0%0/2
A
A= $full
Aresult
11
00
2960  
2961 0 ▶ if ( $full == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($full == 2) 0 0 0
2962 0 return ::dump($self->{body});
2963 }
2964 0 my $a = dclone($self);
2965 0 $a->{config} = ref(delete($a->{config}));
2966 0 ▶ unless ( $full ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($full) 0 0 0
2967 0 for my $ci ( keys %{$a->{chordsinfo}} ) {
2968 0 $a->{chordsinfo}{$ci} = $a->{chordsinfo}{$ci}->simplify;
2969 }
2970 }
2971 0 ::dump($a);
2972 }
2973  
2974 92 1;
« lib/ChordPro/Output/ChordPro.pm ↑ Summary lib/ChordPro/Delegate/TextBlock.pm »