lib/ChordPro/Output/ChordPro.pm

filter: Statementstmt 64.3% 249 / 387 Branchbran 53.3% 145 / 272 Conditioncond 34.7% 16 / 46 MC/DCmcdc 18.5% 5 / 27 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 7 totaltotal 57.0% 430 / 754 CC 174 SCAR 73.8
CC
174
Cov
58%
generate_song
2254.8
define
34.6
gridline
22.5
CRAP 1601.0
« lib/ChordPro/lib/SVGPDF/Parser.pm ↑ Summary lib/ChordPro/Song.pm »
1 #! perl
2  
3 package main;
4  
5 5 our $options;
6 5 our $config;
7  
8 package ChordPro::Output::ChordPro;
9  
10 5 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use feature qw( signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶no warnings "experimental::signatures";
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 5 ▶use ChordPro::Output::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use ChordPro::Utils qw( fq qquote demarkup is_true is_ttrue );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use Ref::Util qw( is_arrayref );
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 5 my $re_meta;
21  
22 23 ▶sub generate_songbook ( $self, $sb ) {
Subroutine generate_songbook: called CC=5 SCAR=16.1
Pod undocumented
23  
24 # Skip empty songbooks.
25 23 ▶ return [] unless eval { $sb->{songs}->[0]->{body} };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $sb->{"songs"}[0]{"body"} } } 0 23 23
26  
27 # Build regex for the known metadata items.
28 $re_meta = join( '|',
29 23 map { quotemeta }
30 "title", "subtitle",
31 "artist", "composer", "lyricist", "arranger",
32 "album", "copyright", "year",
33 "key", "time", "tempo", "capo", "duration" );
34 23 $re_meta = qr/^($re_meta)$/;
35  
36 23 my @book;
37  
38 23 foreach my $song ( @{$sb->{songs}} ) {
39 26 ▶ if ( @book ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@book) 3 23 26
40 3 ▶ push(@book, "") if $options->{'backend-option'}->{tidy};
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"backend-option"}{"tidy"} 0 3 3
41 3 push(@book, "{new_song}");
42 }
43 26 push(@book, @{generate_song($song)});
44 }
45  
46 23 push( @book, "");
47 23 \@book;
48 }
49  
50 5 my $lyrics_only = 0;
51 5 my $variant = 'cho';
52 5 my $rechorus;
53  
54 26 ▶sub upd_config () {
Subroutine upd_config: called CC=1 SCAR=0.0
Pod undocumented
55 26 $rechorus = $::config->{chordpro}->{chorus}->{recall};
56 26 $lyrics_only = 2 * $::config->{settings}->{'lyrics-only'};
57 }
58  
59 26 ▶sub generate_song ( $s ) {
Subroutine generate_song: called CC=133 SCAR=77.2
Pod undocumented
60  
61 26 my $tidy = $options->{'backend-option'}->{tidy};
62 26 ▶ my $structured = ( $options->{'backend-option'}->{structure} // '' ) eq 'structured';
Condition50%1/2
$main::options->{"backend-option"}{"structure"} // ""
l!l
026
MC/DC0%0/1
$main::options->{"backend-option"}{"structure"} // ""
$main::options->{"backend-option"}{"structure"}
Truth table50%1/2
A
A= $main::options->{"backend-option"}{"structure"}
Aresult
11
00
63 # $s->structurize if ++$structured;
64 26 ▶ $variant = $options->{'backend-option'}->{variant} || 'cho';
Condition50%1/2
$main::options->{'backend-option'}{'variant'} || 'cho'
l!l
026
MC/DC0%0/1
$main::options->{'backend-option'}{'variant'} || 'cho'
$main::options->{'backend-option'}{'variant'}
Truth table50%1/2
A
A= $main::options->{'backend-option'}{'variant'}
Aresult
11
00
65 26 my $seq = $options->{'backend-option'}->{seq};
66 26 my $expand = $options->{'backend-option'}->{expand};
67 26 my $msp = $variant eq "msp";
68 26 my $movable = ChordPro::Chords::Parser->get_parser($s->{system})->movable;
69 26 upd_config();
70  
71 26 my @s;
72 my %imgs;
73  
74 26 ▶ if ( $s->{preamble} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"preamble"}) 0 26 26
75 0 @s = @{ $s->{preamble} };
76 }
77  
78 push(@s, "{title: " . fq($s->{meta}->{title}->[0]) . "}")
79 26 ▶ if defined $s->{meta}->{title};
Branch: 1 branch
BranchTrueFalseTotal
if defined $s->{"meta"}{"title"} 26 0 26
80 26 ▶ if ( defined $s->{subtitle} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s->{"subtitle"}) 6 20 26
81 6 push(@s, map { +"{subtitle: ".fq($_)."}" } @{$s->{subtitle}});
82 }
83  
84 26 ▶ if ( $s->{meta} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"meta"}) 26 0 26
85 26 ▶ if ( $msp ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msp) 0 26 26
86 0 ▶ $s->{meta}->{source} //= [ "Lead Sheet" ];
Condition0%0/2
$s->{"meta"}{"source"} //= ["Lead Sheet"]
l!l
00
MC/DC0%0/1
$s->{"meta"}{"source"} //= ["Lead Sheet"]
$s->{"meta"}{"source"}
Truth table0%0/2
A
A= $s->{"meta"}{"source"}
Aresult
11
00
87 0 ▶ $s->{meta}->{custom2} //= [ $seq ] if defined $seq;
Branch: 1 branch
BranchTrueFalseTotal
if defined $seq 0 0 0
Condition0%0/2
$s->{"meta"}{"custom2"} //= [$seq]
l!l
00
MC/DC0%0/1
$s->{"meta"}{"custom2"} //= [$seq]
$s->{"meta"}{"custom2"}
Truth table0%0/2
A
A= $s->{"meta"}{"custom2"}
Aresult
11
00
88 }
89 # Known ones 'as is'.
90 26 my %used;
91 26 foreach my $k ( sort keys %{ $s->{meta} } ) {
92 197 ▶ next if $k =~ /^(?:title|subtitle|key)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^(?:title|subtitle|key)$/u 40 157 197
93 157 ▶ if ( $k =~ $re_meta ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /$re_meta/u) 3 154 157
94 3 $used{$k}++;
95 3 push( @s, map { +"{$k: ".fq($_)."}" } @{ $s->{meta}->{$k} } );
96 }
97 }
98 # Unknowns with meta prefix.
99 26 foreach my $k ( sort keys %{ $s->{meta} } ) {
100 197 ▶ next if $used{$k};
Branch: 1 branch
BranchTrueFalseTotal
if $used{$k} 3 194 197
101 194 ▶ next if $k =~ /^(?:title|subtitle|songindex|key.*|chords|numchords)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^(?:title|subtitle|songindex|key.*|chords|numchords)$/u 134 60 194
102 60 ▶ next if $k =~ /^_/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^_/u 34 26 60
103 26 ▶ next if $k =~ /\./;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /\./u 0 26 26
104 26 ▶ next if $k =~ /^bookmark/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^bookmark/u 26 0 26
105 0 push( @s, map { +"{meta: $k ".fq($_)."}" } @{ $s->{meta}->{$k} } );
106 }
107 }
108  
109 26 ▶ if ( $s->{settings} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"settings"}) 26 0 26
110 26 foreach ( sort keys %{ $s->{settings} } ) {
111 16 ▶ if ( $_ eq "diagrams" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_ eq 'diagrams') { } 3 13 16
elsif ($_ eq 'diagrampos') { } 1 12 13
112 3 ▶ next if $s->{settings}->{diagrampos};
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"settings"}{"diagrampos"} 1 2 3
113 2 my $v = $s->{settings}->{$_};
114 2 ▶ if ( is_ttrue($v) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_ttrue($v)) { } 0 2 2
elsif (is_true($v)) { } 0 2 2
115 0 $v = "on";
116 }
117 elsif ( is_true($v) ) {
118 }
119 else {
120 2 $v = "off";
121 }
122 2 push(@s, "{diagrams: $v}");
123 }
124 elsif ( $_ eq "diagrampos" ) {
125 1 my $v = $s->{settings}->{$_};
126 1 push(@s, "{diagrams: $v}");
127 }
128 else {
129 12 push(@s, "{$_: " . $s->{settings}->{$_} . "}");
130 }
131 }
132 }
133  
134 26 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 26 26
135  
136 # Move a trailing list of chords to the beginning, so the chords
137 # are defined when the song is parsed.
138 26 ▶ if ( @{ $s->{body} } && $s->{body}->[-1]->{type} eq "diagrams"
Branch: 1 branch
BranchTrueFalseTotal
if (@{$s->{"body"};} and $s->{"body"}[-1]{"type"} eq "diagrams" and $s->{"body"}[-1]{"origin"} ne "__CLI__") 0 26 26
Condition33%2/6
@{$s->{"body"};} and $s->{"body"}[-1]{"type"} eq "diagrams" and $s->{"body"}[-1]{"origin"} ne "__CLI__"
!ll&&!rl&&r
2600
@{$s->{"body"};} and $s->{"body"}[-1]{"type"} eq "diagrams"
!ll&&!rl&&r
0260
MC/DC0%0/3
@{$s->{"body"};} and $s->{"body"}[-1]{"type"} eq "diagrams" and $s->{"body"}[-1]{"origin"} ne "__CLI__"
@{$s->{"body"};} $s->{"body"}[-1]{"type"} eq "diagrams" $s->{"body"}[-1]{"origin"} ne "__CLI__"
Truth table25%1/4
A and B and C
A= @{$s->{"body"};}B= $s->{"body"}[-1]{"type"} eq "diagrams"C= $s->{"body"}[-1]{"origin"} ne "__CLI__"
ABCresult
0XX0
10X0
1100
1111
139 && $s->{body}->[-1]->{origin} ne "__CLI__"
140 ) {
141 0 unshift( @{ $s->{body} }, pop( @{ $s->{body} } ) );
142 }
143  
144 26 ▶ if ( $s->{define} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"define"}) 9 17 26
145 9 foreach my $info ( @{ $s->{define} } ) {
146 27 push( @s, define($info) );
147 }
148 9 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 9 9
149 }
150  
151 26 ▶ if ( $s->{spreadimage} && $variant eq "msp" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"spreadimage"} and $variant eq "msp") 0 26 26
Condition33%1/3
$s->{"spreadimage"} and $variant eq "msp"
!ll&&!rl&&r
2600
MC/DC0%0/2
$s->{"spreadimage"} and $variant eq "msp"
$s->{"spreadimage"} $variant eq "msp"
Truth table33%1/3
A and B
A= $s->{"spreadimage"}B= $variant eq "msp"
ABresult
0X0
100
111
152 0 my $a = $s->{assets}->{$s->{spreadimage}->{id}};
153 0 ▶ if ( $a->{delegate} =~ /^abc$/i && !$a->{uri} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->{"delegate"} =~ /^abc$/iu and not $a->{"uri"}) 0 0 0
Condition0%0/3
$a->{"delegate"} =~ /^abc$/iu and not $a->{"uri"}
!ll&&!rl&&r
000
MC/DC0%0/2
$a->{"delegate"} =~ /^abc$/iu and not $a->{"uri"}
$a->{"delegate"} =~ /^abc$/iu not $a->{"uri"}
Truth table0%0/3
A and not(B)
A= $a->{"delegate"} =~ /^abc$/iuB= not $a->{"uri"}
ABresult
0X0
100
111
154 push( @s, "{start_of_" . lc($a->{delegate}) . "}",
155 0 @{$a->{data}},
156 0 "{end_of_" . lc($a->{delegate}) . "}" );
157 }
158 }
159  
160 26 my $ctx = "";
161  
162 26 my @elts = @{$s->{body}};
163 26 ▶ while ( @elts ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@elts) 318 26 344
164 318 my $elt = shift(@elts);
165  
166 318 ▶ if ( $elt->{context} ne $ctx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"context"} ne $ctx) 30 288 318
167 30 ▶ push(@s, "{end_of_$ctx}") if $ctx;
Branch: 1 branch
BranchTrueFalseTotal
if $ctx 12 18 30
168 30 $ctx = $elt->{context};
169 30 ▶ if ( $ctx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx) 18 12 30
170  
171 18 my $t = "{start_of_$ctx";
172  
173 18 ▶ if ( $elt->{type} eq "set" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "set") 4 14 18
174 4 ▶ if ( $elt->{name} eq "gridparams" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($elt->{'name'} eq 'gridparams') { } 2 2 4
elsif ($elt->{'name'} eq 'label') { } 2 0 2
175 2 my @gridparams = @{ $elt->{value} };
176 2 $t .= ": ";
177 2 ▶ $t .= $gridparams[2] . "+" if $gridparams[2];
Branch: 1 branch
BranchTrueFalseTotal
if $gridparams[2] 0 2 2
178 2 $t .= $gridparams[0];
179 2 ▶ $t .= "x" . $gridparams[1] if $gridparams[1];
Branch: 1 branch
BranchTrueFalseTotal
if $gridparams[1] 2 0 2
180 2 ▶ $t .= "+" . $gridparams[3] if $gridparams[3];
Branch: 1 branch
BranchTrueFalseTotal
if $gridparams[3] 2 0 2
181 2 ▶ if ( $gridparams[4] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gridparams[4]) 0 2 2
182 0 my $tag = $gridparams[4];
183 0 ▶ $t .= " " . $tag if $tag ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $tag ne "" 0 0 0
184 }
185 }
186 elsif ( $elt->{name} eq "label" ) {
187 2 my $tag = $elt->{value};
188 2 ▶ if ( $variant eq "msp" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($variant eq 'msp') { } 0 2 2
189 0 $tag =~ s/\s+/ /g;
190 0 ▶ $t .= ": " . $tag if $tag ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $tag ne "" 0 0 0
191 }
192 else {
193 2 $tag =~ s/\n/\\n/g;
194 2 ▶ $t .= " label=\"" . $tag . "\"" if $tag ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $tag ne "" 2 0 2
195 }
196 }
197  
198 }
199 18 $t .= "}";
200 18 push( @s, $t );
201  
202 18 ▶ if ( $ctx =~ /^abc$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ctx =~ /^abc$/u) { } 0 18 18
elsif ($ctx =~ /^textblock$/u) { } 0 18 18
203 0 ▶ if ( $elt->{id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{'id'}) { } 0 0 0
204 0 push( @s, @{$s->{assets}->{$elt->{id}}->{data}} );
205 0 next;
206 }
207 else {
208 0 pop(@s);
209 0 $ctx = '';
210 0 next;
211 }
212 }
213 elsif ( $ctx =~ /^textblock$/ ) {
214 0 push( @s, @{$s->{assets}->{$elt->{id}}->{data}} );
215 0 next;
216 }
217 }
218 }
219  
220 318 ▶ if ( $elt->{type} eq "empty" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "empty") 61 257 318
221 61 ▶ push(@s, "***SHOULD NOT HAPPEN***"), next
Branch: 1 branch
BranchTrueFalseTotal
if $structured 0 61 61
222 if $structured;
223 61 push( @s, "" );
224 61 next;
225 }
226  
227 257 ▶ if ( $elt->{type} eq "colb" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "colb") 3 254 257
228 3 ▶ next if $msp;
Branch: 1 branch
BranchTrueFalseTotal
if $msp 0 3 3
229 3 push(@s, "{column_break}");
230 3 next;
231 }
232  
233 254 ▶ if ( $elt->{type} eq "newpage" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "newpage") 3 251 254
234 3 ▶ next if $msp;
Branch: 1 branch
BranchTrueFalseTotal
if $msp 0 3 3
235 3 push(@s, "{new_page}");
236 3 next;
237 }
238  
239 251 ▶ if ( $elt->{type} eq "songline" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "songline") 119 132 251
240 119 push(@s, songline( $s, $elt ));
241 119 next;
242 }
243  
244 132 ▶ if ( $elt->{type} eq "tabline" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "tabline") 24 108 132
245 24 push(@s, $elt->{text} );
246 24 next;
247 }
248  
249 108 ▶ if ( $elt->{type} eq "gridline" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "gridline") 4 104 108
250 4 push(@s, gridline( $s, $elt ));
251 4 next;
252 }
253  
254 104 ▶ if ( $elt->{type} eq "verse" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "verse") 0 104 104
255 0 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 0 0
256 0 foreach my $e ( @{$elt->{body}} ) {
257 0 ▶ if ( $e->{type} eq "empty" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"type"} eq "empty") 0 0 0
258 0 ▶ push(@s, "***SHOULD NOT HAPPEN***"), next
Branch: 1 branch
BranchTrueFalseTotal
if $structured 0 0 0
259 if $structured;
260 }
261 0 ▶ if ( $e->{type} eq "song" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"type"} eq "song") 0 0 0
262 0 push(@s, songline( $s, $e ));
263 0 next;
264 }
265 }
266 0 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 0 0
267 0 next;
268 }
269  
270 104 ▶ if ( $elt->{type} eq "chorus" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "chorus") 0 104 104
271 0 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 0 0
272 0 push(@s, "{start_of_chorus*}");
273 0 foreach my $e ( @{$elt->{body}} ) {
274 0 ▶ if ( $e->{type} eq "empty" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"type"} eq "empty") 0 0 0
275 0 push(@s, "");
276 0 next;
277 }
278 0 ▶ if ( $e->{type} eq "songline" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"type"} eq "songline") 0 0 0
279 0 push(@s, songline( $s, $e ));
280 0 next;
281 }
282 }
283 0 push(@s, "{end_of_chorus*}");
284 0 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 0 0
285 0 next;
286 }
287  
288 104 ▶ if ( $elt->{type} eq "rechorus" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "rechorus") 0 104 104
289 0 ▶ if ( $msp ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($msp) { } 0 0 0
elsif ($rechorus->{'quote'}) { } 0 0 0
elsif ($rechorus->{'type'} and $rechorus->{'tag'}) { } 0 0 0
290 0 push( @s, "{chorus}" );
291 }
292 elsif ( $rechorus->{quote} ) {
293 0 unshift( @elts, @{ $elt->{chorus} } );
294 }
295 ▶ elsif ( $rechorus->{type} && $rechorus->{tag} ) {
Condition0%0/3
$rechorus->{"type"} and $rechorus->{"tag"}
!ll&&!rl&&r
000
MC/DC0%0/2
$rechorus->{"type"} and $rechorus->{"tag"}
$rechorus->{"type"} $rechorus->{"tag"}
Truth table0%0/3
A and B
A= $rechorus->{"type"}B= $rechorus->{"tag"}
ABresult
0X0
100
111
296 0 push( @s, "{".$rechorus->{type}.": ".$rechorus->{tag}."}" );
297 }
298 else {
299 0 push( @s, "{chorus}" );
300 }
301 0 next;
302 }
303  
304 104 ▶ if ( $elt->{type} eq "tab" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "tab") 0 104 104
305 0 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 0 0
306 0 push(@s, "{start_of_tab}");
307 0 push(@s, @{$elt->{body}});
308 0 push(@s, "{end_of_tab}");
309 0 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 0 0
310 0 next;
311 }
312  
313 104 ▶ if ( $elt->{type} =~ /^comment(?:_italic|_box)?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} =~ /^comment(?:_italic|_box)?$/u) 25 79 104
314 25 my $type = $elt->{type};
315 25 ▶ my $text = $expand ? $elt->{text} : $elt->{orig};
Branch: 1 branch
BranchTrueFalseTotal
$expand ? : 10 15 25
316 25 ▶ if ( $msp ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msp) 0 25 25
317 0 ▶ $type = $type eq 'comment'
Branch: 2 branches
BranchTrueFalseTotal
$type eq 'comment' ? : 0 0 0
$type eq 'comment_italic' ? : 0 0 0
318 ? 'highlight'
319 : $type eq 'comment_italic'
320 ? 'comment'
321 : $type;
322 }
323 # Flatten chords/phrases.
324 25 ▶ if ( $elt->{chords} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"chords"}) 0 25 25
325 0 $text = "";
326 0 for ( 0..$#{ $elt->{chords} } ) {
327 $text .= "[" . fq(chord( $s, $elt->{chords}->[$_])) . "]"
328 0 ▶ if $elt->{chords}->[$_] ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $elt->{"chords"}[$_] ne "" 0 0 0
329 0 $text .= $elt->{phrases}->[$_];
330 }
331 }
332 25 ▶ $text = fmt_subst( $s, $text ) if $msp;
Branch: 1 branch
BranchTrueFalseTotal
if $msp 0 25 25
333 25 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 25 25
334 25 push(@s, "{$type: ".fq($text)."}");
335 25 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 25 25
336 25 next;
337 }
338  
339 79 ▶ if ( $elt->{type} eq "image" && !$msp ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "image" and not $msp) 0 79 79
Condition33%1/3
$elt->{"type"} eq "image" and not $msp
!ll&&!rl&&r
7900
MC/DC0%0/2
$elt->{"type"} eq "image" and not $msp
$elt->{"type"} eq "image" not $msp
Truth table33%1/3
A and not(B)
A= $elt->{"type"} eq "image"B= not $msp
ABresult
0X0
100
111
340 0 my $uri = $s->{assets}->{$elt->{id}}->{uri};
341 0 ▶ if ( $msp && $uri !~ /^id=/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msp and not $uri =~ /^id=/u) 0 0 0
Condition0%0/3
$msp and not $uri =~ /^id=/u
!ll&&!rl&&r
000
MC/DC0%0/2
$msp and not $uri =~ /^id=/u
$msp not $uri =~ /^id=/u
Truth table0%0/3
A and not(B)
A= $mspB= not $uri =~ /^id=/u
ABresult
0X0
100
111
342 0 ▶ $imgs{$uri} //= keys(%imgs);
Condition0%0/2
$imgs{$uri} //= keys %imgs
l!l
00
MC/DC0%0/1
$imgs{$uri} //= keys %imgs
$imgs{$uri}
Truth table0%0/2
A
A= $imgs{$uri}
Aresult
11
00
343 0 $uri = sprintf("id=img%02d", $imgs{$uri});
344 }
345 0 my @args = ( "image:", qquote($uri) );
346 0 ▶ while ( my($k,$v) = each( %{ $elt->{opts} } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$elt{"opts"};}) 0 0 0
347 0 ▶ $v = join( ",",@$v ) if is_arrayref($v);
Branch: 1 branch
BranchTrueFalseTotal
if is_arrayref($v) 0 0 0
348 0 push( @args, "$k=$v" );
349 }
350 0 foreach ( @args ) {
351 0 ▶ next unless /\s/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\s/u 0 0 0
352 0 $_ = '"' . $_ . '"';
353 }
354 0 push( @s, "{@args}" );
355 0 next;
356 }
357  
358 79 ▶ if ( $elt->{type} eq "diagrams" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "diagrams") 2 77 79
359 2 for ( @{$elt->{chords}} ) {
360 2 push( @s, define( $s->{chordsinfo}->{$_}, 1 ) );
361 }
362 }
363  
364 79 ▶ if ( $elt->{type} eq "set" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "set") 30 49 79
365 30 ▶ if ( $elt->{name} eq "lyrics-only" ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($elt->{'name'} eq 'lyrics-only') { } 0 30 30
elsif ($elt->{'name'} eq 'transpose') { } 0 30 30
elsif ($elt->{'name'} =~ /^(chordpro\..+)/u) { } 0 30 30
366 $lyrics_only = $elt->{value}
367 0 ▶ unless $lyrics_only > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $lyrics_only > 1 0 0 0
368 }
369 elsif ( $elt->{name} eq "transpose" ) {
370 }
371 # Arbitrary config values.
372 elsif ( $elt->{name} =~ /^(chordpro\..+)/ ) {
373 0 my @k = split( /[.]/, $1 );
374 0 my $cc = {};
375 0 my $c = \$cc;
376 0 foreach ( @k ) {
377 0 $c = \($$c->{$_});
378 }
379 0 $$c = $elt->{value};
380 0 $config->augment($cc);
381 0 upd_config();
382 }
383 30 next;
384 }
385  
386 49 ▶ if ( $elt->{type} eq "control" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "control") 0 49 49
387 0 ▶ if ( $elt->{name} =~ /^(\w+)-(size|color|font)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"name"} =~ /^(\w+)-(size|color|font)/u) 0 0 0
388 0 my $t = "{$1$2: " . $elt->{value} . "}";
389 0 ▶ push( @s, $t ) unless $t =~ s/^\{\Kchorus/text/r eq $s[-1];
Branch: 1 branch
BranchTrueFalseTotal
unless $t =~ s/^\{\Kchorus/text/ru eq $s[-1] 0 0 0
390 }
391 0 next;
392 }
393  
394 49 ▶ if ( $elt->{type} eq "meta" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "meta") 8 41 49
395 8 ▶ if ( $elt->{key} eq "key" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"key"} eq "key") 8 0 8
396 8 ▶ next if $movable;
Branch: 1 branch
BranchTrueFalseTotal
if $movable 0 8 8
397 8 push( @s, "{key: " . $elt->{value}->[-1] . "}" );
398 }
399 8 next;
400 }
401  
402 41 ▶ if ( $elt->{type} eq "ignore" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "ignore") 39 2 41
403 39 push( @s, $elt->{text} );
404 39 next;
405 }
406  
407 }
408  
409 26 ▶ push(@s, "{end_of_$ctx}") if $ctx;
Branch: 1 branch
BranchTrueFalseTotal
if $ctx 6 20 26
410  
411 26 my $did = 0;
412 26 ▶ if ( $s->{chords} && @{ $s->{chords}->{chords} } && $variant ne 'msp' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"chords"} and @{$s->{"chords"}{"chords"};} and $variant ne "msp") 23 3 26
Condition83%5/6
$s->{"chords"} and @{$s->{"chords"}{"chords"};} and $variant ne "msp"
!ll&&!rl&&r
3023
$s->{"chords"} and @{$s->{"chords"}{"chords"};}
!ll&&!rl&&r
2123
MC/DC66%2/3
$s->{"chords"} and @{$s->{"chords"}{"chords"};} and $variant ne "msp"
$s->{"chords"} @{$s->{"chords"}{"chords"};} $variant ne "msp"
Truth table75%3/4
A and B and C
A= $s->{"chords"}B= @{$s->{"chords"}{"chords"};}C= $variant ne "msp"
ABCresult
0XX0
10X0
1100
1111
413 23 for ( @{ $s->{chords}->{chords} } ) {
414 70 ▶ last unless $s->{chordsinfo}->{$_}->parser->has_diagrams;
Branch: 1 branch
BranchTrueFalseTotal
unless $s->{"chordsinfo"}{$_}->parser->has_diagrams 4 66 70
415 66 ▶ push( @s, "" ) unless $did++;
Branch: 1 branch
BranchTrueFalseTotal
unless $did++ 19 47 66
416 66 push( @s, define( $s->{chordsinfo}->{$_}, 1 ) );
417 }
418 }
419  
420 # Process image assets.
421 0 foreach ( sort { $imgs{$a} <=> $imgs{$b} } keys %imgs ) {
422 0 my $url = $_;
423 0 my $id = $imgs{$url};
424 0 my $type = "jpg";
425 0 ▶ $type = lc($1) if $url =~ /\.(\w+)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $url =~ /\.(\w+)$/u 0 0 0
426 0 require MIME::Base64;
427 0 require Image::Info;
428  
429 # Slurp the image.
430 0 my $data = fs_blob($url);
431 0 ▶ unless ( defined $data ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data) 0 0 0
432 0 warn("$url: $!\n");
433 0 next;
434 }
435  
436 # Get info.
437 0 my $info = Image::Info::image_info(\$data);
438 0 ▶ if ( $info->{error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"error"}) 0 0 0
439 0 do_warn($info->{error});
440 0 next;
441 }
442  
443 # Write in-line data.
444 push( @s,
445 sprintf( "##image: id=img%02d" .
446 " src=%s type=%s width=%d height=%d enc=base64",
447 $id, $url, $info->{file_ext},
448 0 $info->{width}, $info->{height} ) );
449 0 $data = MIME::Base64::encode($data, '');
450 0 my $i = 0;
451 # Note: 76 is the standard chunk size for base64 data.
452 0 ▶ while ( $i < length($data) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $data) 0 0 0
453 0 push( @s, "# ".substr($data, $i, 76) );
454 0 $i += 76;
455 }
456 }
457  
458 26 \@s;
459 }
460  
461 119 ▶sub songline ( $song, $elt ) {
Subroutine songline: called CC=4 SCAR=13.9
Pod undocumented
462  
463 119 ▶ if ( $lyrics_only || !exists($elt->{chords}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lyrics_only or not exists $elt->{"chords"}) 40 79 119
Condition100%3/3
$lyrics_only or not exists $elt->{"chords"}
l!l&&r!l&&!r
241679
MC/DC100%2/2
$lyrics_only or not exists $elt->{"chords"}
$lyrics_only not exists $elt->{"chords"}
Truth table100%3/3
A or not(B)
A= $lyrics_onlyB= not exists $elt->{"chords"}
ABresult
1X1
011
000
464 40 return fq(join( "", @{ $elt->{phrases} } ));
465 }
466  
467 79 my $line = "";
468 79 foreach my $c ( 0..$#{$elt->{chords}} ) {
469 226 $line .= "[" . fq(chord( $song, $elt->{chords}->[$c])) . "]" . fq($elt->{phrases}->[$c]);
470 }
471 79 $line =~ s/^\[\]//;
472 79 $line;
473 }
474  
475 4 ▶sub gridline ( $song, $elt ) {
Subroutine gridline: called CC=10 SCAR=31.1
Pod undocumented
476  
477 4 my $line = "";
478  
479 4 ▶ if ( $elt->{margin} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"margin"}) 0 4 4
480 0 $line .= fq( $elt->{margin}->{text} );
481 }
482  
483 4 for ( @{ $elt->{tokens} } ) {
484 44 ▶ $line .= " " if $line;
Branch: 1 branch
BranchTrueFalseTotal
if $line 40 4 44
485 44 ▶ if ( $_->{class} eq "chord" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{'class'} eq 'chord') { } 10 34 44
486 10 $line .= chord( $song, $_->{chord} );
487 }
488 else {
489 34 $line .= $_->{symbol};
490 34 ▶ $line .= $_->{volta} if $_->{volta};
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"volta"} 0 34 34
491 }
492 }
493  
494 4 ▶ if ( $elt->{comment} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"comment"}) 0 4 4
495 0 ▶ $line .= " " if $line;
Branch: 1 branch
BranchTrueFalseTotal
if $line 0 0 0
496 0 my $res = "";
497 0 my $t = $elt->{comment};
498 0 ▶ if ( $t->{chords} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{'chords'}) { } 0 0 0
499 0 for ( 0..$#{ $t->{chords} } ) {
500 0 $res .= "[" . fq(chord( $song, $t->{chords}->[$_])) . "]" . fq($t->{phrases}->[$_]);
501 }
502 }
503 else {
504 0 $res .= fq($t->{text});
505 }
506 0 $res =~ s/^\[\]//;
507 0 $line .= $res;
508 }
509  
510 4 $line;
511 }
512  
513 236 ▶sub chord ( $s, $c ) {
Subroutine chord: called CC=4 SCAR=13.9
Pod undocumented
514 236 ▶ return "" unless length($c);
Branch: 1 branch
BranchTrueFalseTotal
unless length $c 60 176 236
515 176 local $c->info->{display} = undef;
516 176 local $c->info->{format} = undef;
517 176 my $t = $c->chord_display;
518 176 ▶ if ( $variant ne 'msp' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($variant ne "msp") 176 0 176
519 176 $t = demarkup($t);
520 }
521 176 ▶ return "*$t" if $c->info->is_annotation;
Branch: 1 branch
BranchTrueFalseTotal
if $c->info->is_annotation 2 174 176
522 174 return $t;
523 }
524  
525 95 ▶sub define ( $info, $is_diag = 0 ) {
Subroutine define: called CC=23 SCAR=35.4
Pod undocumented
526  
527 95 ▶ my $t = $is_diag ? "#{chord: " : "{define: ";
Branch: 1 branch
BranchTrueFalseTotal
$is_diag ? : 68 27 95
528 95 $t .= $info->{name};
529 95 ▶ unless ( $is_diag ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_diag) 27 68 95
530 27 ▶ if ( $info->{copyall} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($info->{'copyall'}) { } 0 27 27
elsif ($info->{'copy'}) { } 0 27 27
531 0 $t .= " copyall " . qquote($info->{copyall});
532 }
533 elsif ( $info->{copy} ) {
534 0 $t .= " copy " . qquote($info->{copy});
535 }
536 27 for ( qw( display ) ) {
537 27 ▶ next unless defined $info->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $info->{$_} 25 2 27
538 2 $t .= " $_ " . qquote($info->{$_}->name );
539 }
540 27 for ( qw( format ) ) {
541 27 ▶ next unless defined $info->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $info->{$_} 18 9 27
542 9 my $x = qquote($info->{$_}, 1 );
543 9 $x =~ s/\%\{/\\%{/g;
544 9 $t .= " $_ $x";
545 }
546 }
547  
548 95 ▶ if ( $::config->{instrument}->{type} eq "keyboard" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{'instrument'}{'type'} eq 'keyboard') { } 0 95 95
549 $t .= " keys " .
550 0 join(" ", @{$info->{keys}})
551 0 ▶ if $info->{keys} && @{$info->{keys}};
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"keys"} and @{$info->{"keys"};} 0 0 0
Condition0%0/3
$info->{"keys"} and @{$info->{"keys"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$info->{"keys"} and @{$info->{"keys"};}
$info->{"keys"} @{$info->{"keys"};}
Truth table0%0/3
A and B
A= $info->{"keys"}B= @{$info->{"keys"};}
ABresult
0X0
100
111
552 }
553 else {
554 95 $t .= " base-fret " . $info->{base};
555 $t .= " frets " .
556 570 ▶ join(" ", map { $_ < 0 ? "N" : $_ } @{$info->{frets}})
Branch: 1 branch
BranchTrueFalseTotal
$_ < 0 ? : 81 489 570
557 95 ▶ if $info->{frets};
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"frets"} 95 0 95
558 $t .= " fingers " .
559 432 ▶ join(" ", map { $_ < 0 ? "N" : $_ } @{$info->{fingers}})
Branch: 1 branch
BranchTrueFalseTotal
$_ < 0 ? : 0 432 432
560 95 ▶ if $info->{fingers} && @{$info->{fingers}};
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"fingers"} and @{$info->{"fingers"};} 72 23 95
Condition66%2/3
$info->{"fingers"} and @{$info->{"fingers"};}
!ll&&!rl&&r
23072
MC/DC50%1/2
$info->{"fingers"} and @{$info->{"fingers"};}
$info->{"fingers"} @{$info->{"fingers"};}
Truth table66%2/3
A and B
A= $info->{"fingers"}B= @{$info->{"fingers"};}
ABresult
0X0
100
111
561 }
562 95 ▶ unless ( $is_diag ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_diag) 27 68 95
563 27 for ( qw( diagram ) ) {
564 27 ▶ next unless defined $info->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $info->{$_} 24 3 27
565 3 my $v = $info->{$_};
566 3 ▶ if ( is_true($v) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_true($v)) { } 0 3 3
567 0 ▶ if ( is_ttrue($v) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_ttrue($v)) 0 0 0
568 0 next;
569 }
570 }
571 else {
572 3 $v = "off";
573 }
574 3 $t .= " $_ $v";
575 }
576 }
577  
578 95 return $t . "}";
579 }
580  
581 5 1;
« lib/ChordPro/lib/SVGPDF/Parser.pm ↑ Summary lib/ChordPro/Song.pm »