lib/ChordPro.pm

filter: Statementstmt 63.5% 334 / 526 Branchbran 37.6% 94 / 250 Conditioncond 28.1% 40 / 142 MC/DCmcdc 6.2% 5 / 80 Subroutinesub 69.5% 32 / 46 Podpod 0.0% 0 / 9 totaltotal 47.9% 505 / 1053 CC 207 SCAR 65.1
CC
207
Cov
51%
chordpro
1210.4
app_setup
1051.7
runtimeinfo
49.3
CRAP 669.8
« lib/ChordPro/lib/SVGPDF.pm ↑ Summary lib/ChordPro/lib/SVGPDF/Path.pm »
1 #! perl
2  
3 92 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package ChordPro;
6  
7 92 ▶use ChordPro::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 92 ▶use ChordPro::Files;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 92 ▶use ChordPro::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 92 ▶use ChordPro::Chords;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 92 ▶use ChordPro::Chords::Transpose;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 92 ▶use ChordPro::Output::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # Single line for stupid tools.
15 92 ▶use ChordPro::Version; our $VERSION = $ChordPro::Version::VERSION;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head1 NAME
18  
19 ChordPro - A lyrics and chords formatting program
20  
21 =head1 SYNOPSIS
22  
23 perl -MChordpro -e run -- [ options ] [ file ... ]
24  
25 When the associated B<chordpro> program has been installed correctly:
26  
27 chordpro [ options ] [ file ... ]
28  
29 =head1 DESCRIPTION
30  
31 B<chordpro> will read one or more text files containing the lyrics of
32 one or many songs plus chord information. B<chordpro> will then
33 generate a photo-ready, professional looking, impress-your-friends
34 sheet-music suitable for printing on your nearest printer.
35  
36 Typical ChordPro input:
37  
38 {title: Swing Low Sweet Chariot}
39 {subtitle: Traditional}
40  
41 {start_of_chorus}
42 Swing [D]low, sweet [G]chari[D]ot,
43 Comin' for to carry me [A7]home.
44 Swing [D7]low, sweet [G]chari[D]ot,
45 Comin' for to [A7]carry me [D]home.
46 {end_of_chorus}
47  
48 # Verse
49 I [D]looked over Jordan, and [G]what did I [D]see,
50 Comin' for to carry me [A7]home.
51 A [D]band of angels [G]comin' after [D]me,
52 Comin' for to [A7]carry me [D]home.
53  
54 {c: Chorus}
55  
56 B<chordpro> is a rewrite of the Chordii program.
57  
58 For more information about the ChordPro file format, see
59 L<https://www.chordpro.org>.
60  
61 =cut
62  
63 ################ Common stuff ################
64  
65 92 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 92 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 92 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 92 ▶use Text::ParseWords ();
Subroutine BEGIN: called CC=1 SCAR=0.0
69  
70 ################ The Process ################
71  
72 package main;
73  
74 92 our $options;
75 92 our $config;
76  
77 package ChordPro;
78  
79 92 ▶use ChordPro::Paths;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 92 ▶use Encode qw(decode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82 0 ▶sub xximport {
Subroutine xximport: not called CC=3 SCAR=24.8
Pod undocumented
83 # Add private library.
84 0 my $lib = CP->privlib;
85 0 for ( @INC ) {
86 0 ▶ return if $_ eq $lib;
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $lib 0 0 0
87 }
88 0 unshift( @INC, $lib );
89 }
90  
91 96 ▶sub ::run {
Subroutine run: called CC=6 SCAR=18.2
92 96 binmode(STDERR, ':utf8');
93 96 binmode(STDOUT, ':utf8');
94 96 for ( @ARGV ) {
95 722 ▶ next if ref ne "";
Branch: 1 branch
BranchTrueFalseTotal
if ref $_ ne "" 12 710 722
96 710 $_ = decode_utf8($_);
97 }
98  
99 96 $options = app_setup( "ChordPro", $VERSION );
100 96 ▶ $options->{trace} = 1 if $options->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"debug"} 0 96 96
101 96 ▶ $options->{verbose} = 1 if $options->{trace};
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"trace"} 0 96 96
102 96 ▶ $options->{verbose} = 9 if $options->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"debug"} 0 96 96
103 96 main();
104 }
105  
106 96 ▶sub main {
Subroutine main: called CC=3 SCAR=12.0
Pod undocumented
107 96 my ($opts) = @_;
108 96 ▶ $options = { %$options, %$opts } if $opts;
Branch: 1 branch
BranchTrueFalseTotal
if $opts 0 96 96
109 0 ▶ warn("ChordPro invoked: @{$options->{_argv}}\n") if $options->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"debug"} 0 96 96
110 96 chordpro();
111  
112 }
113  
114 96 ▶sub chordpro {
Subroutine chordpro: called CC=83 SCAR=71.0
Pod undocumented
115  
116 # Establish backend.
117 96 my $of = $options->{output};
118  
119 # Progress callback, if any.
120 progress( callback => $options->{progress_callback}, index => -1 )
121 96 ▶ if $options->{progress_callback};
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"progress_callback"} 0 96 96
122  
123 96 ▶ if ( $options->{'convert-config'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::options->{"convert-config"}) 0 96 96
124 0 ▶ die("\"--convert-config\" requires a single config file name\n")
Branch: 1 branch
BranchTrueFalseTotal
if @ARGV 0 0 0
125 if @ARGV;
126 0 return ChordPro::Config::convert_config( $options->{'convert-config'}, $of );
127 }
128  
129 96 ▶ if ( defined($of) && $of ne "" ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $of and $of ne '') { } 96 0 96
elsif (-t STDOUT) { } 0 0 0
Condition33%1/3
defined $of and $of ne ""
!ll&&!rl&&r
0096
MC/DC0%0/2
defined $of and $of ne ""
defined $of $of ne ""
Truth table33%1/3
A and B
A= defined $ofB= $of ne ""
ABresult
0X0
100
111
130 96 ▶ if ( $of =~ /\.pdf$/i ) {
Branch: 11 branches
BranchTrueFalseTotal
if ($of =~ /\.pdf$/iu) { } 13 83 96
elsif ($of =~ /\.ly$/iu) { } 0 83 83
elsif ($of =~ /\.(tex|ltx)$/iu) { } 0 83 83
elsif ($of =~ /\.cho$/iu) { } 6 77 83
elsif ($of =~ /\.msp$/iu) { } 0 77 77
elsif ($of =~ /\.(crd|txt)$/iu) { } 9 68 77
elsif ($of =~ /\.html?$/iu) { } 3 65 68
elsif ($of =~ /\.mma?$/iu) { } 0 65 65
elsif ($of =~ /\.(md|markdown)$/iu) { } 0 65 65
elsif ($of =~ /\.meta$/iu) { } 0 65 65
elsif ($of =~ /\.(debug)$/iu) { } 0 65 65
131 13 ▶ $options->{generate} ||= "PDF";
Condition50%1/2
$main::options->{"generate"} ||= "PDF"
l!l
013
MC/DC0%0/1
$main::options->{"generate"} ||= "PDF"
$main::options->{"generate"}
Truth table50%1/2
A
A= $main::options->{"generate"}
Aresult
11
00
132 }
133 elsif ( $of =~ /\.ly$/i ) {
134 0 ▶ $options->{generate} ||= "LilyPond";
Condition0%0/2
$main::options->{"generate"} ||= "LilyPond"
l!l
00
MC/DC0%0/1
$main::options->{"generate"} ||= "LilyPond"
$main::options->{"generate"}
Truth table0%0/2
A
A= $main::options->{"generate"}
Aresult
11
00
135 }
136 elsif ( $of =~ /\.(tex|ltx)$/i ) {
137 0 ▶ $options->{generate} ||= "LaTeX";
Condition0%0/2
$main::options->{"generate"} ||= "LaTeX"
l!l
00
MC/DC0%0/1
$main::options->{"generate"} ||= "LaTeX"
$main::options->{"generate"}
Truth table0%0/2
A
A= $main::options->{"generate"}
Aresult
11
00
138 }
139 elsif ( $of =~ /\.cho$/i ) {
140 6 ▶ $options->{generate} ||= "ChordPro";
Condition50%1/2
$main::options->{"generate"} ||= "ChordPro"
l!l
06
MC/DC0%0/1
$main::options->{"generate"} ||= "ChordPro"
$main::options->{"generate"}
Truth table50%1/2
A
A= $main::options->{"generate"}
Aresult
11
00
141 }
142 elsif ( $of =~ /\.msp$/i ) {
143 0 ▶ $options->{generate} ||= "ChordPro";
Condition0%0/2
$main::options->{"generate"} ||= "ChordPro"
l!l
00
MC/DC0%0/1
$main::options->{"generate"} ||= "ChordPro"
$main::options->{"generate"}
Truth table0%0/2
A
A= $main::options->{"generate"}
Aresult
11
00
144 0 $options->{'backend-option'}->{variant} = "msp";
145 }
146 elsif ( $of =~ /\.(crd|txt)$/i ) {
147 9 ▶ $options->{generate} ||= "Text";
Condition50%1/2
$main::options->{"generate"} ||= "Text"
l!l
09
MC/DC0%0/1
$main::options->{"generate"} ||= "Text"
$main::options->{"generate"}
Truth table50%1/2
A
A= $main::options->{"generate"}
Aresult
11
00
148 }
149 elsif ( $of =~ /\.html?$/i ) {
150 3 ▶ $options->{generate} ||= "HTML";
Condition50%1/2
$main::options->{"generate"} ||= "HTML"
l!l
03
MC/DC0%0/1
$main::options->{"generate"} ||= "HTML"
$main::options->{"generate"}
Truth table50%1/2
A
A= $main::options->{"generate"}
Aresult
11
00
151 }
152 elsif ( $of =~ /\.mma?$/i ) {
153 0 ▶ $options->{generate} ||= "MMA";
Condition0%0/2
$main::options->{"generate"} ||= "MMA"
l!l
00
MC/DC0%0/1
$main::options->{"generate"} ||= "MMA"
$main::options->{"generate"}
Truth table0%0/2
A
A= $main::options->{"generate"}
Aresult
11
00
154 }
155 elsif ( $of =~ /\.(md|markdown)$/i ) {
156 0 ▶ $options->{generate} ||= "Markdown";
Condition0%0/2
$main::options->{"generate"} ||= "Markdown"
l!l
00
MC/DC0%0/1
$main::options->{"generate"} ||= "Markdown"
$main::options->{"generate"}
Truth table0%0/2
A
A= $main::options->{"generate"}
Aresult
11
00
157 }
158 elsif ( $of =~ /\.meta$/i ) {
159 0 ▶ $options->{generate} ||= "Meta";
Condition0%0/2
$main::options->{"generate"} ||= "Meta"
l!l
00
MC/DC0%0/1
$main::options->{"generate"} ||= "Meta"
$main::options->{"generate"}
Truth table0%0/2
A
A= $main::options->{"generate"}
Aresult
11
00
160 }
161 elsif ( $of =~ /\.(debug)$/i ) {
162 0 ▶ $options->{generate} ||= "Debug";
Condition0%0/2
$main::options->{"generate"} ||= "Debug"
l!l
00
MC/DC0%0/1
$main::options->{"generate"} ||= "Debug"
$main::options->{"generate"}
Truth table0%0/2
A
A= $main::options->{"generate"}
Aresult
11
00
163 }
164 }
165 elsif ( -t STDOUT ) {
166 # No output, and stdout is terminal.
167 # Derive output name from input name.
168 0 ▶ if ( @ARGV > 1 || ( $options->{'dump-chords'} && !@ARGV ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV > 1 or $main::options->{"dump-chords"} and not @ARGV) 0 0 0
Condition0%0/6
@ARGV > 1 or $main::options->{"dump-chords"} and not @ARGV
l!l&&r!l&&!r
000
$main::options->{"dump-chords"} and not @ARGV
!ll&&!rl&&r
000
MC/DC0%0/3
@ARGV > 1 or $main::options->{"dump-chords"} and not @ARGV
@ARGV > 1 $main::options->{"dump-chords"} not @ARGV
Truth table0%0/4
A or B and not(C)
A= @ARGV > 1B= $main::options->{"dump-chords"}C= not @ARGV
ABCresult
1XX1
0111
00X0
0100
169 # No default if more than one input document.
170 0 die("Please use \"--output\" to specify the output file name\n");
171 }
172 0 my $f = CP->sibling( $ARGV[0], ext => ".pdf" );
173 0 $options->{output} = $f;
174 0 ▶ warn("Writing output to $f\n") if $options->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"verbose"} 0 0 0
175 }
176 else {
177 # Write output to stdout.
178 0 $options->{output} = "-";
179 }
180  
181 96 ▶ $options->{generate} ||= "PDF";
Condition50%1/2
$main::options->{"generate"} ||= "PDF"
l!l
960
MC/DC0%0/1
$main::options->{"generate"} ||= "PDF"
$main::options->{"generate"}
Truth table50%1/2
A
A= $main::options->{"generate"}
Aresult
11
00
182  
183 # Register backend name and load its Configurator, if any.
184 96 my $pkg = "ChordPro::Output::".$options->{generate};
185 96 $options->{backend} = $pkg;
186 96 eval "require $pkg"."::Configurator";
187 warn("Warning: No configurator for ", $options->{generate}, "\n$@")
188 96 ▶ if $options->{trace} && $@;
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"trace"} and $@ 0 96 96
Condition33%1/3
$main::options->{"trace"} and $@
!ll&&!rl&&r
9600
MC/DC0%0/2
$main::options->{"trace"} and $@
$main::options->{"trace"} $@
Truth table33%1/3
A and B
A= $main::options->{"trace"}B= $@
ABresult
0X0
100
111
189  
190 # One configurator to bind them all.
191 # This will also call the backend Configurator, if any.
192 92 ▶ use ChordPro::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
193 96 $config = ChordPro::Config::configurator({});
194  
195 # Now load the real backend. Note that the actual module name
196 # may be changed by config.
197 96 ▶ if ( exists($config->{lc($options->{generate})})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$main::config{lc $main::options->{"generate"}} and exists $$main::config{lc $main::options->{"generate"}}{"module"}) 3 93 96
Condition100%3/3
exists $$main::config{lc $main::options->{"generate"}} and exists $$main::config{lc $main::options->{"generate"}}{"module"}
!ll&&!rl&&r
17763
MC/DC100%2/2
exists $$main::config{lc $main::options->{"generate"}} and exists $$main::config{lc $main::options->{"generate"}}{"module"}
exists $$main::config{lc $main::options->{"generate"}} exists $$main::config{lc $main::options->{"generate"}}{"module"}
Truth table100%3/3
A and B
A= exists $$main::config{lc $main::options->{"generate"}}B= exists $$main::config{lc $main::options->{"generate"}}{"module"}
ABresult
0X0
100
111
198 && exists($config->{lc($options->{generate})}->{module}) ) {
199 3 $options->{generate} = $config->{lc($options->{generate})}->{module};
200 }
201 96 $pkg = "ChordPro::Output::".$options->{generate};
202 96 eval "require $pkg;";
203 96 ▶ die("No backend for ", $options->{generate}, "\n$@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 96 96
204 96 $options->{backend} = $pkg;
205 96 ▶ $pkg->version if $options->{verbose} && $pkg->can("version");
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"verbose"} and $pkg->can("version") 0 96 96
Condition33%1/3
$main::options->{"verbose"} and $pkg->can("version")
!ll&&!rl&&r
9600
MC/DC0%0/2
$main::options->{"verbose"} and $pkg->can("version")
$main::options->{"verbose"} $pkg->can("version")
Truth table33%1/3
A and B
A= $main::options->{"verbose"}B= $pkg->can("version")
ABresult
0X0
100
111
206  
207 # Parse the input(s).
208 92 ▶ use ChordPro::Songbook;
Subroutine BEGIN: called CC=1 SCAR=0.0
209 96 my $s = ChordPro::Songbook->new;
210 96 my $res;
211  
212 # Shortcut a2crd conversion.
213 96 ▶ if ( $options->{a2crd} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::options->{"a2crd"}) 19 77 96
214 19 require ChordPro::A2Crd;
215 19 $res = ChordPro::A2Crd::a2crd();
216 19 push( @$res, '' );
217 19 goto WRITE_OUTPUT;
218 }
219  
220 # Check for metadata in filelist. Actually, this works on the
221 # command line as well, but don't tell anybody.
222 progress( phase => "Parsing", index => 0,
223 0 ▶ total => 0+grep { !/^--/ } @ARGV )
Branch: 1 branch
BranchTrueFalseTotal
if @ARGV > 1 0 77 77
224 if @ARGV > 1;
225  
226 77 my %gopts;
227 77 foreach my $file ( @ARGV ) {
228  
229 77 my @w = ( $file );
230 77 ▶ if ( $file =~ /(^|\s)--\w+/ || $file =~ /^["']/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /(^|\s)--\w+/u or $file =~ /^["']/u) 0 77 77
Condition33%1/3
$file =~ /(^|\s)--\w+/u or $file =~ /^["']/u
l!l&&r!l&&!r
0077
MC/DC0%0/2
$file =~ /(^|\s)--\w+/u or $file =~ /^["']/u
$file =~ /(^|\s)--\w+/u $file =~ /^["']/u
Truth table33%1/3
A or B
A= $file =~ /(^|\s)--\w+/uB= $file =~ /^["']/u
ABresult
1X1
011
000
231 0 @w = Text::ParseWords::shellwords($file);
232 }
233 77 my %meta;
234 my %defs;
235 77 my @cfg;
236 77 my %opts;
237 77 ▶ die("Error in filelist: $file\n")
Branch: 1 branch
BranchTrueFalseTotal
unless &Getopt::Long::GetOptionsFromArray(\@w, \%opts, "config=s\@", \@cfg, "meta=s%", \%meta, "define=s%", \%defs, "title=s", "subtitle=s", "dir:s", "filelist:s") and @w == 1 && !keys(%opts) || @w == 0 && keys %opts 0 77 77
Condition25%3/12
&Getopt::Long::GetOptionsFromArray(\@w, \%opts, "config=s\@", \@cfg, "meta=s%", \%meta, "define=s%", \%defs, "title=s", "subtitle=s", "dir:s", "filelist:s") and @w == 1 && !keys(%opts) || @w == 0 && keys %opts
!ll&&!rl&&r
0077
@w == 1 and not keys %opts or @w == 0 and keys %opts
l!l&&r!l&&!r
7700
@w == 1 and not keys %opts
!ll&&!rl&&r
0077
@w == 0 and keys %opts
!ll&&!rl&&r
000
MC/DC0%0/5
&Getopt::Long::GetOptionsFromArray(\@w, \%opts, "config=s\@", \@cfg, "meta=s%", \%meta, "define=s%", \%defs, "title=s", "subtitle=s", "dir:s", "filelist:s") and @w == 1 && !keys(%opts) || @w == 0 && keys %opts
&Getopt::Long::GetOptionsFromArray(\@w, \%opts, "config=s\@", \@cfg, "meta=s%", \%meta, "define=s%", \%defs, "title=s", "subtitle=s", "dir:s", "filelist:s") @w == 1 not keys %opts @w == 0 keys %opts
Truth table12%1/8
A and B and not(C) or D and E
A= &Getopt::Long::GetOptionsFromArray(\@w, \%opts, "config=s\@", \@cfg, "meta=s%", \%meta, "define=s%", \%defs, "title=s", "subtitle=s", "dir:s", "filelist:s")B= @w == 1C= not keys %optsD= @w == 0E= keys %opts
ABCDEresult
0XXXX0
10X0X0
10X100
1100X0
110100
111XX1
10X111
110111
238 unless Getopt::Long::GetOptionsFromArray
239 ( \@w, \%opts, 'config=s@' => \@cfg, 'meta=s%' => \%meta,
240 'define=s%' => \%defs,
241 'title=s', 'subtitle=s', 'dir:s', 'filelist:s',
242 )
243 && ( ( @w == 1 && ! keys(%opts) ) # filename
244 || ( @w == 0 && keys(%opts) ) # options
245 );
246  
247 77 for ( qw( title subtitle ) ) {
248 154 ▶ next unless defined $opts{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts{$_} 154 0 154
249 0 $options->{$_} = $opts{$_};
250 }
251 77 for ( qw( filelist dir ) ) {
252 154 ▶ next unless defined $opts{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts{$_} 154 0 154
253 0 ▶ $gopts{$_} = $opts{$_} eq "" ? undef : expand_tilde($opts{$_});
Branch: 1 branch
BranchTrueFalseTotal
$opts{$_} eq '' ? : 0 0 0
254 }
255 77 ▶ unless ( @w ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@w) 0 77 77
256 0 ▶ progress( msg => $file ) if @ARGV > 1 && $file !~ /^--/;
Branch: 1 branch
BranchTrueFalseTotal
if @ARGV > 1 and not $file =~ /^--/u 0 0 0
Condition0%0/3
@ARGV > 1 and not $file =~ /^--/u
!ll&&!rl&&r
000
MC/DC0%0/2
@ARGV > 1 and not $file =~ /^--/u
@ARGV > 1 not $file =~ /^--/u
Truth table0%0/3
A and not(B)
A= @ARGV > 1B= not $file =~ /^--/u
ABresult
0X0
100
111
257 0 next;
258 }
259  
260 77 $file = $w[0];
261 77 ▶ if ( defined($gopts{dir})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $gopts{"dir"} and not fn_is_absolute($file)) 0 77 77
Condition33%1/3
defined $gopts{"dir"} and not fn_is_absolute($file)
!ll&&!rl&&r
7700
MC/DC0%0/2
defined $gopts{"dir"} and not fn_is_absolute($file)
defined $gopts{"dir"} not fn_is_absolute($file)
Truth table33%1/3
A and not(B)
A= defined $gopts{"dir"}B= not fn_is_absolute($file)
ABresult
0X0
100
111
262 && !fn_is_absolute($file) ) {
263 0 $file = fn_catfile( $gopts{dir}, $file );
264 }
265 0 my $opts = { meta => { map { $_, [ $meta{$_} ] } keys %meta },
266 defs => \%defs };
267 77 ▶ if ( @cfg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@cfg) 0 77 77
268 0 $opts->{meta}->{__config} = \@cfg;
269 }
270 77 $opts->{generate} = $options->{generate};
271 # Wx runs on temp files, so pass real filename in.
272 77 $opts->{filesource} = $options->{filesource};
273 77 ▶ progress( msg => $file ) if @ARGV > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @ARGV > 1 0 77 77
274 77 $s->parse_file( $file, $opts );
275 }
276  
277 77 ▶ if ( $options->{'dump-chords'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::options->{"dump-chords"}) 0 77 77
278 0 my $d = ChordPro::Song->new;
279 0 $d->{title} = "ChordPro $VERSION Built-in Chords";
280 0 $d->{subtitle} = [ "https://www.chordpro.org" ];
281 0 my @body;
282 my @chords;
283  
284 0 my $prev = "";
285 0 foreach my $c ( @{ ChordPro::Chords::chordnames() } ) {
286 0 ▶ next if $c =~ /^n\.?c\.?$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $c =~ /^n\.?c\.?$/iu 0 0 0
287 0 ▶ if ( $c =~ /^(.[b#]?)/ and $1 ne $prev ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c =~ /^(.[b#]?)/u and $1 ne $prev) 0 0 0
Condition0%0/3
$c =~ /^(.[b#]?)/u and $1 ne $prev
!ll&&!rl&&r
000
MC/DC0%0/2
$c =~ /^(.[b#]?)/u and $1 ne $prev
$c =~ /^(.[b#]?)/u $1 ne $prev
Truth table0%0/3
A and B
A= $c =~ /^(.[b#]?)/uB= $1 ne $prev
ABresult
0X0
100
111
288 0 $prev = $1;
289 0 ▶ push( @body, { type => "diagrams",
Branch: 1 branch
BranchTrueFalseTotal
if @chords 0 0 0
290 context => "",
291 origin => "__CLI__",
292 chords => [ @chords ]
293 } ) if @chords;
294 0 @chords = ();
295 }
296 0 push( @chords, $c );
297 0 $d->{chordsinfo}->{$c} = ChordPro::Chords::known_chord($c);
298 }
299  
300 0 ▶ push( @body, { type => "diagrams",
Branch: 1 branch
BranchTrueFalseTotal
if @chords 0 0 0
301 context => "",
302 origin => "__CLI__",
303 chords => [ @chords ]
304 } ) if @chords;
305  
306 0 $d->{body} = \@body;
307 0 ▶ if ( @{ $s->{songs} } == 1
Branch: 1 branch
BranchTrueFalseTotal
if (@{$s->{'songs'};} == 1 and not exists $s->{'songs'}[0]{'body'}) { } 0 0 0
Condition0%0/3
@{$s->{"songs"};} == 1 and not exists $s->{"songs"}[0]{"body"}
!ll&&!rl&&r
000
MC/DC0%0/2
@{$s->{"songs"};} == 1 and not exists $s->{"songs"}[0]{"body"}
@{$s->{"songs"};} == 1 not exists $s->{"songs"}[0]{"body"}
Truth table0%0/3
A and not(B)
A= @{$s->{"songs"};} == 1B= not exists $s->{"songs"}[0]{"body"}
ABresult
0X0
100
111
308 && !exists $s->{songs}->[0]->{body} ) {
309 0 $s->{songs} = [ $d ];
310 }
311 else {
312 0 push( @{ $s->{songs} }, $d );
313 }
314 }
315  
316 # Try interpolations.
317 77 ▶ if ( $of ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($of) 77 0 77
318 77 my $f = fmt_subst( $s->{songs}->[0], $of );
319 77 ▶ if ( $f ne $of ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f ne $of) 0 77 77
320 # Replace most non-alpha by underscore (but keep the extension).
321 0 $f =~ s;(?!\.\w+$)[^\w/-];_;g;
322 0 ▶ warn("Writing output to $f\n") if $options->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"verbose"} 0 0 0
323 0 $options->{output} = $f;
324 }
325 }
326  
327 # Call backend to produce output.
328 77 $res = $pkg->generate_songbook($s);
329 77 ▶ return $res if $options->{output} eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"output"} eq "*" 12 65 77
330  
331 WRITE_OUTPUT:
332 # Some backends write output themselves, others return an
333 # array of lines to be written.
334 84 ▶ if ( $res && @$res > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res and @$res > 0) 71 13 84
Condition66%2/3
$res and @$res > 0
!ll&&!rl&&r
01371
MC/DC50%1/2
$res and @$res > 0
$res @$res > 0
Truth table66%2/3
A and B
A= $resB= @$res > 0
ABresult
0X0
100
111
335 71 ▶ if ( $of && $of ne "-" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($of and $of ne '-') { } 71 0 71
Condition33%1/3
$of and $of ne "-"
!ll&&!rl&&r
0071
MC/DC0%0/2
$of and $of ne "-"
$of $of ne "-"
Truth table33%1/3
A and B
A= $ofB= $of ne "-"
ABresult
0X0
100
111
336 71 my $fd = fs_open( $of, '>:utf8' );
337 71 ▶ push( @$res, '' ) unless $res->[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[-1] eq "" 3 68 71
338 71 print { $fd } ( join( "\n", @$res ) );
339 71 close($fd);
340 }
341 else {
342 0 binmode( STDOUT, ":utf8" );
343 0 ▶ push( @$res, '' ) unless $res->[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[-1] eq "" 0 0 0
344 0 print( join( "\n", @$res ) );
345 }
346 # Don't close STDOUT!
347 }
348  
349 84 ▶ if ( $options->{verbose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::options->{"verbose"}) 0 84 84
350 0 my $st = json_stats;
351 0 warn("JSON: xs = ", $st->{xs}, ", rr = ", $st->{rr}, "\n");
352 }
353 }
354  
355 0 ▶sub ::dump {
Subroutine dump: not called CC=1 SCAR=0.2
356 92 ▶ use ChordPro::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
357 0 ddp(@_);
358 }
359  
360 ################ Options and Configuration ################
361  
362 =head1 COMMAND LINE OPTIONS
363  
364 =over 4
365  
366 =item B<--about> (short: B<-A>)
367  
368 Prints version information about the ChordPro program. No other
369 processing will be done.
370  
371 =item B<--back-matter=>I<FILE>
372  
373 Appends the contents of the named PDF document to the output. This can
374 be used to produce documents with back matter pages.
375  
376 =item B<--config=>I<JSON> (shorter: B<--cfg>)
377  
378 A JSON file that defines the behaviour of the program and the layout
379 of the output. See L<ChordPro::Config> for details.
380  
381 This option may be specified more than once. Each additional config
382 file overrides the corresponding definitions that are currently
383 active.
384  
385 =item B<--cover=>I<FILE>
386  
387 Prepends the contents of the named PDF document to the output. This can
388 be used to add cover pages.
389  
390 See also B<--title>.
391  
392 =item B<--csv>
393  
394 When generating PDF output, also write a CSV file with titles and page
395 numbers. Some tools, e.g., MobileSheets, can use the CSV to process
396 the PDF as a collection of independent songs.
397  
398 The CSV has the same name as the PDF, with extension C<.pdf> replaced
399 by C<.csv>.
400  
401 =item B<--decapo>
402  
403 Eliminate capo settings by transposing the song.
404  
405 =item B<--diagrams=>I<WHICH>
406  
407 Prints diagrams of chords used in a song.
408  
409 I<WHICH> can be C<all> to print all chords used, C<user> to only print
410 the user-defined chords, and C<none> to suppress printing of chord
411 diagrams.
412  
413 =item B<--encoding=>I<ENC>
414  
415 Specify the encoding for input files. Default is UTF-8.
416 ISO-8859.1 (Latin-1) encoding is automatically sensed.
417  
418 =item B<--filelist=>I<FILE>
419  
420 Read the names of the files to be processed from the named file.
421  
422 This option may be specified multiple times.
423  
424 Song file names listed on the command line are processed I<after> the
425 files from the filelist arguments.
426  
427 =item B<--front-matter=>I<FILE>
428  
429 Prepends the contents of the named PDF document to the output. This can
430 be used to produce documents with front matter pages.
431  
432 =item B<--lyrics-only> (short: B<-l>)
433  
434 Only prints lyrics. All chords are suppressed.
435  
436 Useful to make prints for singers and other musicians that do not
437 require chords.
438  
439 =item B<--no-csv>
440  
441 Suppresses generating the CSV file. See B<--toc>.
442  
443 =item B<--no-strict>
444  
445 Enables liberal interpretation of the input with regard to the
446 ChordPro standard. Most notably, unknown directives will not
447 not flagged as warnings but silently ignored.
448  
449 This makes it more convenient to process ChordPro files have custom
450 directives.
451  
452 =item B<--no-toc>
453  
454 Suppresses the table of contents. See B<--toc>.
455  
456 =item B<--output=>I<FILE> (short: B<-o>)
457  
458 Designates the name of the output file where the results are written
459 to.
460  
461 The filename extension determines the type of the output. It should
462 correspond to one of the backends that are currently supported:
463  
464 =over 6
465  
466 =item pdf
467  
468 Portable document format (PDF).
469  
470 =item txt
471  
472 A textual representation of the input, mostly for visual inspection.
473  
474 =item cho
475  
476 A functional equivalent version of the ChordPro input.
477  
478 =back
479  
480 =item B<--start-page-number=>I<N> (short: B<-p>)
481  
482 Sets the starting page number for the output.
483  
484 =item B<--strict>
485  
486 Requires the input to be strictly compliant to the ChordPro standard.
487  
488 This is enabled by default. See also B<--nostrict>.
489  
490 =item B<--subtitle=>I<XXX>
491  
492 Subtitle (for songbooks).
493  
494 =item B<--title=>I<XXX>
495  
496 Title (for songbooks).
497  
498 If specified and a table of contents is requested, a nice coverpage
499 will be added.
500  
501 Note that B<--title> overrides B<--cover>.
502  
503 =item B<--toc> (short: B<-i>)
504  
505 Includes a table of contents.
506  
507 By default a table of contents is included in the PDF output when
508 it contains more than one song.
509  
510 =item B<--transpose=>I<XX> (short: -x)
511  
512 I<XX> must be a number in the range -24 .. +24, optionally followed by
513 one of C<s>, or C<f>.
514  
515 Transposes all songs by the given number of semi-tones.
516 A positive number transposes up, a negative number transposes down.
517  
518 If the resultant key requires accidentals the postfix controls whether
519 sharps or flats are used. See the docs.
520  
521 =item B<--version> (short: B<-V>)
522  
523 Prints the program version and exits.
524  
525 =back
526  
527 =head2 Chordii compatibility options
528  
529 The following Chordii command line options are recognized. Note that
530 not all of them actually do something.
531  
532 Options marked with * are better specified in the config file.
533  
534 B<Note:> Chordii used the term _grid_ for chord diagrams. It
535 should not be confused with ChordPro grids.
536  
537 =over 4
538  
539 =item B<--text-font=>I<FONT> (short: B<-T>) *
540  
541 Sets the font used to print lyrics and comments.
542  
543 I<FONT> can be either a full path name to a TrueType font file, or the
544 name of one of the standard fonts. See section L</FONTS> for more
545 details.
546  
547 =item B<--text-size=>I<N> (short: B<-t>) *
548  
549 Sets the font size for lyrics and comments.
550  
551 =item B<--chord-font=>I<FONT> (short: B<-C>) *
552  
553 Sets the font used to print the chord names.
554  
555 I<FONT> can be either a full path name to a TrueType font file, or the
556 name of one of the standard fonts. See section L</FONTS> for more
557 details.
558  
559 =item B<--chord-size=>I<N> (short: B<-c>) *
560  
561 Sets the font size for the chord names.
562  
563 =item B<--chord-grid-size=>I<N> (short: B<-s>) *
564  
565 Sets the total width of a chord diagram.
566  
567 =item B<--chord-grids>
568  
569 Prints chord diagrams of all chords used in a song.
570  
571 =item B<--no-chord-grids> (short: B<-G>) *
572  
573 Disables printing of chord diagrams of the chords used in a song.
574  
575 =item B<--easy-chord-grids>
576  
577 Not supported.
578  
579 =item B<--no-easy-chord-grids> (short: B<-g>)
580  
581 Not supported.
582  
583 =item B<--chord-grids-sorted> (short: B<-S>) *
584  
585 Prints chord diagrams of the chords used in a song, ordered by key and
586 type.
587  
588 =item B<--no-chord-grids-sorted> *
589  
590 Prints chord diagrams in the order they appear in the song.
591  
592 =item B<--user-chord-grids> *
593  
594 Prints chord diagrams of all user defined chords used in a song.
595  
596 =item B<--even-pages-number-left> (short B<-L>)
597  
598 Not supported. Use C<pdf.even-odd-pages> in the config instead.
599  
600 =item B<--odd-pages-number-left>
601  
602 Not supported. Use C<pdf.even-odd-pages> in the config instead.
603  
604 =item B<--page-size=>I<FMT> (short: B<-P>) *
605  
606 Specifies the page size for the PDF output, e.g. C<a4> (default), C<letter>.
607  
608 =item B<--single-space> (short B<-a>)) *
609  
610 When a lyrics line has no chords associated, suppresses the vertical
611 space normally occupied by the chords.
612  
613 =item B<--vertical-space=>I<N> (short: B<-w>) *
614  
615 Adds some extra vertical space between the lines.
616  
617 =item B<--2-up> (short: B<-2>)
618  
619 Not supported.
620  
621 =item B<--4-up> (short: B<-4>)
622  
623 Not supported.
624  
625 =item B<--page-number-logical> (short: B<-n>)
626  
627 Not supported.
628  
629 =item B<--dump-chords> (short: B<-D>)
630  
631 Dumps a list of built-in chords in a form dependent of the backend used.
632 The PDF backend will produce neat pages of chord diagrams.
633 The ChordPro backend will produce a list of C<define> directives.
634  
635 =item B<--dump-chords-text> (short: B<-d>)
636  
637 Dumps a list of built-in chords in the form of C<define> directives,
638 and exits.
639  
640 =back
641  
642 =head2 Configuration options
643  
644 See L<ChordPro::Config> for details about the configuration
645 files.
646  
647 Note that missing default configuration files are silently ignored.
648 Also, B<chordpro> will never create nor write configuration files.
649  
650 =over
651  
652 =item B<--nosongconfig>
653  
654 Don't use song specific config files, even if they exist.
655  
656 =item B<--sysconfig=>I<CFG>
657  
658 Designates a system specific config file.
659  
660 The default system config file depends on the operating system and user
661 environment. A common value is C</etc/chordpro.json> on Linux systems.
662  
663 This is the place where the system manager can put settings like the
664 paper size, assuming that all printers use the same size.
665  
666 =item B<--nosysconfig>
667  
668 Don't use the system specific config file, even if it exists.
669  
670 =item B<--userconfig=>I<CFG>
671  
672 Designates the config file for the user.
673  
674 The default user config file depends on the operating system and user
675 environment. Common values are C<$HOME/.config/chordpro/chordpro.json>
676 and C<$HOME/.chordpro/chordpro.json>, where C<$HOME> indicates the
677 user home directory.
678  
679 Here you can put settings for your preferred fonts and other layout
680 parameters that you want to apply to all B<chordpro> runs.
681  
682 =item B<--nouserconfig>
683  
684 Don't use the user specific config file, even if it exists.
685  
686 =item B<--config=>I<CFG> (shorter: B<--cfg>)
687  
688 Designates the config file specific for this run.
689  
690 Default is a file named C<chordpro.json> in the current directory.
691  
692 Here you can put settings that apply to the files in this
693 directory only.
694  
695 You can specify multiple config files. The settings are accumulated.
696  
697 =item B<--noconfig>
698  
699 Don't use the specific config file, even if it exists.
700  
701 =item B<--define=>I<item>
702  
703 Sets a configuration item. I<item> must be in the format of
704 colon-separated configuration keys, an equal sign, and the value. For
705 example, the equivalent of B<--diagrams=none> is
706 B<--define=diagrams.show=0>.
707  
708 B<--define> may be used multiple times to set multiple items.
709  
710 =item B<--no-default-configs> (short: B<-X>)
711  
712 Do not use any config files except the ones mentioned explicitly on
713 the command line.
714  
715 This guarantees that the program is running with the default
716 configuration.
717  
718 =item B<--print-template-config>
719  
720 Prints a simplified template configuration to standard output, and
721 exits. The configuration is commented to explain its contents.
722  
723 The config contains most of the ChordPro configuration items, all
724 commented out. It is easy to get started with configuring ChordPro
725 by enabling and modifyng just a few items at a time.
726  
727 =item B<--print-default-config>
728  
729 If used once, behaves like `--print-template-config`. This is to avoid
730 confusing novice users.
731  
732 To get the full default configuration, repeat this option.
733  
734 =item B<--print-final-config>
735  
736 Prints the final configuration (after processing all system, user and
737 other config files) to standard output, and exits.
738  
739 =item B<--convert-config=>I<file>
740  
741 This option requires a single file name argument.
742  
743 The specified config file is loaded and immedeately written out in
744 standard format, including schema comments. After this, the program
745 exits. B<No songs are processed.>
746  
747 Output goes to standard output unless `--output` is used to specify an
748 alternative.
749  
750 All other options are ignored.
751  
752 =back
753  
754 =head2 Miscellaneous options
755  
756 =over
757  
758 =item B<--help> (short: -h)
759  
760 Prints a help message. No other output is produced.
761  
762 =item B<--manual>
763  
764 Prints the manual page. No other output is produced.
765  
766 =item B<--ident>
767  
768 Shows the program name and version.
769  
770 =item B<--verbose>
771  
772 Provides more verbose information of what is going on.
773  
774 =back
775  
776 =cut
777  
778 92 ▶use Getopt::Long 2.13 qw( :config no_ignorecase );
Subroutine BEGIN: called CC=1 SCAR=0.0
779  
780 # Package name.
781 92 my $my_package;
782 # Program name and version.
783 92 my ($my_name, $my_version);
784 92 my %configs;
785  
786 96 ▶sub app_setup {
Subroutine app_setup: called CC=63 SCAR=69.6
Pod undocumented
787 96 my ($appname, $appversion, %args) = @_;
788 96 my $help = 0; # handled locally
789 96 my $manual = 0; # handled locally
790 96 my $ident = 0; # handled locally
791 96 my $about = 0; # handled locally
792 96 my $version = 0; # handled locally
793 96 my $defcfg = 0; # handled locally
794 96 my $fincfg = 0; # handled locally
795 96 my $deltacfg = 0; # handled locally
796 96 my $tmplcfg = 0; # handled locally
797 96 my $dump_chords = 0; # handled locally
798  
799 # Package name.
800 96 $my_package = $args{package};
801 # Program name and version.
802 96 ▶ if ( defined $appname ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $appname) { } 96 0 96
803 96 ($my_name, $my_version) = ($appname, $appversion);
804 }
805 else {
806 0 ($my_name, $my_version) = qw( MyProg 0.01 );
807 }
808  
809 96 my $app_lc = lc($my_name);
810 96 ▶ if ( $app_lc eq "a2crd" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($app_lc eq "a2crd") 0 96 96
811 0 $app_lc = "chordpro";
812 0 unshift( @ARGV, "--a2crd" );
813 }
814  
815 # Config files.
816 96 %configs = %{ CP->configs };
817  
818 96 my $options =
819 {
820 verbose => 0, # verbose processing
821 encoding => "", # input encoding, default UTF-8
822  
823 ### ADDITIONAL CLI OPTIONS ###
824  
825 'vertical-space' => 0, # extra vertical space between lines
826  
827 ### NON-CLI OPTIONS ###
828  
829 'chords-column' => 0, # chords in a separate column
830  
831 # Development options (not shown with -help).
832 debug => 0, # debugging
833 trace => 0, # trace (show process)
834  
835 # Service.
836 _package => $my_package,
837 _name => $my_name,
838 _version => $my_version,
839 _stdin => \*STDIN,
840 _stdout => \*STDOUT,
841 _stderr => \*STDERR,
842 _argv => [ @ARGV ],
843 };
844  
845 # Colled command line options in a hash, for they will be needed
846 # later.
847 96 my $clo = {};
848  
849 # When running in reference mode, we carefully defeat everything
850 # the user could change to the built-in default config.
851 96 my $reference = 0;
852  
853 # Sorry, layout is a bit ugly...
854 my $ok =
855 GetOptions
856 ($clo,
857  
858 ### Options ###
859  
860 "a2crd!", # perform ascii to cho
861 "crd", # input is ascii, not cho
862 "output|o=s", # Saves the output to FILE
863 "generate=s",
864 "backend-option|bo=s\%",
865 "diagrams=s", # Prints chord diagrams
866 "encoding=s",
867 "csv!", # Generates contents CSV
868 "front-matter=s", # Front matter page(s)
869 "cover=s", # Cover page(s)
870 "back-matter|back=s", # Back matter page(s)
871 "filelist=s@", # List of input files
872 "title=s", # Title (for books)
873 "subtitle=s", # Subtitle (for books)
874 "meta=s\%", # Command line meta data
875 "decapo", # remove capo
876 "fragment|F", # partial (incomplete) song
877 "strict!", # strict conformance
878  
879 ### Experimental ###
880  
881 "progress_callback=s",
882  
883 ### Standard Chordii Options ###
884  
885 "about|A+" => \$about, # About...
886 "chord-font|C=s", # Sets chord font
887 "chord-grid-size|s=f", # Sets chord diagram size [30]
888 "chord-grids-sorted|S!", # Prints chord diagrams ordered
889 "chord-size|c=i", # Sets chord size [9]
890 "dump-chords|D", # Dumps chords definitions (PostScript)
891 "dump-chords-text|d" => \$dump_chords, # Dumps chords definitions (Text)
892 0 ▶ "dump-chords-json" => sub { $dump_chords = 2}, # Dumps instrument defs (json).
Subroutine __ANON__: not called CC=1 SCAR=6.9
893 "even-pages-number-left|L", # Even pages numbers on left
894 "odd-pages-number-left", # Odd pages numbers on left
895 "lyrics-only|l", # Only prints lyrics
896 0 ▶ "G" => sub { $clo->{'chord-grids'} = 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
897 "chord-grids!", # En[dis]ables printing of chord diagrams
898 "easy-chord-grids|g!", # Do[esn't] print diagrams for built-in "easy" chords. Ignored.
899 "page-number-logical|n", # Numbers logical pages, not physical
900 "page-size|P=s", # Specifies page size [letter, a4 (default)]
901 "single-space|a!", # Automatic single space lines without chords
902 "start-page-number|p=i", # Starting page number [1]
903 "text-size|t=i", # Sets text size [12]
904 "text-font|T=s", # Sets text font
905 0 ▶ "i" => sub { $clo->{toc} = 1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
906 "toc!", # Generates a table of contents
907 "transpose|x=s", # Transposes by N semi-tones
908 "transcode|xc=s", # Transcodes to another notation
909 "user-chord-grids!", # Do[esn't] print diagrams for user defined chords.
910 "version|V" => \$version, # Prints version and exits
911 "vertical-space|w=f", # Extra vertical space between lines
912 "2-up|2", # 2 pages per sheet
913 "4-up|4", # 4 pages per sheet
914  
915 ### Configuration handling ###
916  
917 'config|cfg=s@',
918 'noconfig|no-config',
919 'sysconfig=s',
920 'nosysconfig|no-sysconfig',
921 'nolegacyconfig|no-legacyconfig', # legacy
922 'userconfig=s',
923 'nosongconfig|no-songconfig',
924 'nouserconfig|no-userconfig',
925 'nodefaultconfigs|no-default-configs|X',
926 'define=s%',
927 'print-default-config+' => \$defcfg,
928 'print-final-config' => \$fincfg,
929 'print-delta-config' => \$deltacfg,
930 'print-template-config' => \$tmplcfg,
931 'convert-config=s',
932  
933 # This aborts option scanning.
934 0 ▶ 'reference|R' => sub { $reference++;
Subroutine __ANON__: not called CC=1 SCAR=6.9
935 0 CORE::die("!FINISH!"); },
936  
937 ### Standard options ###
938  
939 'ident' => \$ident,
940 'help|h|?' => \$help,
941 0 ▶ 'help-config' => sub { $manual = 2 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
942 'manual' => \$manual,
943 'verbose|v+',
944 0 ▶ I => sub { $clo->{progress_callback} = "warn" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
945 96 'trace',
946 'debug+',
947  
948 );
949  
950 # If --reference was encountered, retry with a very restricted set
951 # of options.
952 96 ▶ if ( $reference ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reference) 0 96 96
953 0 @ARGV = @{ $options->{_argv} };
954 0 warn("Running in reference mode.\n");
955 0 $ok =
956 GetOptions
957 ($clo,
958  
959 ### Options for reference run ###
960  
961 "output|o=s", # Saves the output to FILE
962 "strict!", # strict conformance
963 "about|A" => \$about, # About...
964 "version|V" => \$version, # Prints version and exits
965 'reference|R',
966  
967 ### Standard options ###
968  
969 'ident' => \$ident,
970 'help|h|?' => \$help,
971 'verbose|v+',
972 'trace',
973 'debug+',
974  
975 );
976 0 $clo->{nodefaultconfigs} = 1;
977 0 $clo->{nosongconfig} = 1;
978 0 $::options->{reference} = 1;
979 }
980  
981 96 ▶ if ( $ok && defined $clo->{transpose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok and defined $clo->{"transpose"}) 6 90 96
Condition66%2/3
$ok and defined $clo->{"transpose"}
!ll&&!rl&&r
0906
MC/DC50%1/2
$ok and defined $clo->{"transpose"}
$ok defined $clo->{"transpose"}
Truth table66%2/3
A and B
A= $okB= defined $clo->{"transpose"}
ABresult
0X0
100
111
982 6 ▶ if ( my $tr = parse_transpose($clo->{transpose}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tr = parse_transpose($clo->{'transpose'})) { } 6 0 6
983 6 $clo->{transpose} = $tr;
984 }
985 else {
986 0 warn("Invalid transpose value: ", $clo->{transpose}, "\n" );
987 0 $ok = 0;
988 }
989 }
990  
991 96 ▶ $clo->{trace} ||= $clo->{debug};
Condition33%1/3
$clo->{"trace"} ||= $clo->{"debug"}
l!l&&r!l&&!r
0096
MC/DC0%0/2
$clo->{"trace"} ||= $clo->{"debug"}
$clo->{"trace"} $clo->{"debug"}
Truth table33%1/3
A ||= B
A= $clo->{"trace"}B= $clo->{"debug"}
ABresult
1X1
011
000
992 96 ▶ $clo->{verbose} ||= $clo->{trace};
Condition33%1/3
$clo->{"verbose"} ||= $clo->{"trace"}
l!l&&r!l&&!r
0096
MC/DC0%0/2
$clo->{"verbose"} ||= $clo->{"trace"}
$clo->{"verbose"} $clo->{"trace"}
Truth table33%1/3
A ||= B
A= $clo->{"verbose"}B= $clo->{"trace"}
ABresult
1X1
011
000
993 96 ▶ $clo->{progress_callback} //= "warn" if $clo->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $clo->{"verbose"} 0 96 96
Condition0%0/2
$clo->{"progress_callback"} //= "warn"
l!l
00
MC/DC0%0/1
$clo->{"progress_callback"} //= "warn"
$clo->{"progress_callback"}
Truth table0%0/2
A
A= $clo->{"progress_callback"}
Aresult
11
00
994  
995 96 ▶ unless ( $ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 96 96
996 # GNU convention: message to STDERR upon failure.
997 0 app_usage(\*STDERR, 2);
998 }
999  
1000 0 ▶ my $pod2usage = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1001 # Load Pod::Usage only if needed.
1002 0 require Pod::Usage;
1003 0 Pod::Usage->import;
1004 0 ▶ my $f = $manual == 2 ? "Config.pod" : "ChordPro.pod";
Branch: 1 branch
BranchTrueFalseTotal
$manual == 2 ? : 0 0 0
1005 0 unshift( @_, -input => CP->findres( $f, class => "pod" ) );
1006 0 &pod2usage;
1007 96 };
1008  
1009 # GNU convention: message to STDOUT upon request.
1010 96 ▶ app_ident(\*STDOUT) if $ident || $clo->{verbose} || $help || $manual;
Branch: 1 branch
BranchTrueFalseTotal
if $ident or $clo->{"verbose"} or $help or $manual 0 96 96
Condition33%3/9
$ident or $clo->{"verbose"} or $help or $manual
l!l&&r!l&&!r
0096
$ident or $clo->{"verbose"} or $help
l!l&&r!l&&!r
0096
$ident or $clo->{"verbose"}
l!l&&r!l&&!r
0096
MC/DC0%0/4
$ident or $clo->{"verbose"} or $help or $manual
$ident $clo->{"verbose"} $help $manual
Truth table20%1/5
A or B or C or D
A= $identB= $clo->{"verbose"}C= $helpD= $manual
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1011 96 ▶ if ( $manual or $help ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($manual or $help) 0 96 96
Condition33%1/3
$manual or $help
l!l&&r!l&&!r
0096
MC/DC0%0/2
$manual or $help
$manual $help
Truth table33%1/3
A or B
A= $manualB= $help
ABresult
1X1
011
000
1012 0 ▶ app_usage(\*STDOUT, 0) if $help;
Branch: 1 branch
BranchTrueFalseTotal
if $help 0 0 0
1013 0 ▶ $pod2usage->(VERBOSE => 2) if $manual;
Branch: 1 branch
BranchTrueFalseTotal
if $manual 0 0 0
1014 }
1015 96 ▶ app_ident(\*STDOUT, 0) if $version;
Branch: 1 branch
BranchTrueFalseTotal
if $version 0 96 96
1016  
1017 # If the user specified a config, it must exist.
1018 # Otherwise, set to a default.
1019 96 for my $config ( qw(sysconfig userconfig) ) {
1020 192 for ( $clo->{$config} ) {
1021 192 ▶ if ( defined($_) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) 0 192 192
1022 0 ▶ die("$_: $!\n") unless -r $_;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $_ 0 0 0
1023 0 next;
1024 }
1025 # Use default.
1026 192 ▶ next if $clo->{nodefaultconfigs};
Branch: 1 branch
BranchTrueFalseTotal
if $clo->{"nodefaultconfigs"} 192 0 192
1027 0 ▶ next unless $configs{$config};
Branch: 1 branch
BranchTrueFalseTotal
unless $configs{$config} 0 0 0
1028 0 $_ = $configs{$config};
1029 0 ▶ undef($_) unless -r $_;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $_ 0 0 0
1030 }
1031 }
1032 96 for my $config ( qw(config) ) {
1033 96 for ( $clo->{$config} ) {
1034 96 ▶ if ( defined($_) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) 0 96 96
1035 0 foreach my $c ( @$_ ) {
1036 0 my $try = $c;
1037 # Check for resource names.
1038 0 ▶ if ( !fs_test( 'r', $try ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (fs_test("r", $try)) 0 0 0
1039 0 $try = CP->findcfg($c);
1040 }
1041 0 ▶ die("$c: $!\n") unless $try && fs_test( 'r', $try );
Branch: 1 branch
BranchTrueFalseTotal
unless $try and fs_test("r", $try) 0 0 0
Condition0%0/3
$try and fs_test("r", $try)
!ll&&!rl&&r
000
MC/DC0%0/2
$try and fs_test("r", $try)
$try fs_test("r", $try)
Truth table0%0/3
A and B
A= $tryB= fs_test("r", $try)
ABresult
0X0
100
111
1042 0 $c = $try;
1043 }
1044 0 next;
1045 }
1046 # Use default.
1047 96 ▶ next if $clo->{nodefaultconfigs};
Branch: 1 branch
BranchTrueFalseTotal
if $clo->{"nodefaultconfigs"} 96 0 96
1048 0 ▶ next unless $configs{$config};
Branch: 1 branch
BranchTrueFalseTotal
unless $configs{$config} 0 0 0
1049 0 $_ = [ $configs{$config} ];
1050 0 ▶ undef($_) unless fs_test( 'fr', $_->[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless fs_test("fr", $_->[0]) 0 0 0
1051 }
1052 }
1053 # If no config was specified, and no default is available, force no.
1054 96 for my $config ( qw(sysconfig userconfig config ) ) {
1055 288 ▶ $clo->{"no$config"} = 1 unless $clo->{$config};
Branch: 1 branch
BranchTrueFalseTotal
unless $clo->{$config} 288 0 288
1056 }
1057 96 ▶ $clo->{nosongconfig} ||= $clo->{nodefaultconfigs};
Condition33%1/3
$clo->{"nosongconfig"} ||= $clo->{"nodefaultconfigs"}
l!l&&r!l&&!r
0960
MC/DC0%0/2
$clo->{"nosongconfig"} ||= $clo->{"nodefaultconfigs"}
$clo->{"nosongconfig"} $clo->{"nodefaultconfigs"}
Truth table33%1/3
A ||= B
A= $clo->{"nosongconfig"}B= $clo->{"nodefaultconfigs"}
ABresult
1X1
011
000
1058  
1059 # Plug in command-line options.
1060 96 @{$options}{keys %$clo} = values %$clo;
1061 96 $::options = $options;
1062 # warn(::dump($options), "\n") if $options->{debug};
1063  
1064 # To avoid confusion, produce a template if the user asks for a
1065 # default config.
1066 # Unless she insists...
1067 96 ▶ if ( $defcfg >= 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($defcfg >= 2) 0 96 96
1068 92 ▶ use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
1069 0 my $cfg = fn_catfile( CP->findresdirs("config")->[-1],
1070 "chordpro.json" );
1071 0 binmode STDOUT => ':raw';
1072 0 copy( $cfg, \*STDOUT );
1073 0 exit 0;
1074 }
1075 96 ▶ if ( $tmplcfg || $defcfg ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmplcfg or $defcfg) 0 96 96
Condition33%1/3
$tmplcfg or $defcfg
l!l&&r!l&&!r
0096
MC/DC0%0/2
$tmplcfg or $defcfg
$tmplcfg $defcfg
Truth table33%1/3
A or B
A= $tmplcfgB= $defcfg
ABresult
1X1
011
000
1076 92 ▶ use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
1077 0 my $cfg = fn_catfile( CP->findresdirs("config")->[-1],
1078 "config.tmpl" );
1079 0 binmode STDOUT => ':raw';
1080 0 copy( $cfg, \*STDOUT );
1081 0 exit 0;
1082 }
1083 96 ▶ if ( $fincfg || $deltacfg ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fincfg or $deltacfg) 0 96 96
Condition33%1/3
$fincfg or $deltacfg
l!l&&r!l&&!r
0096
MC/DC0%0/2
$fincfg or $deltacfg
$fincfg $deltacfg
Truth table33%1/3
A or B
A= $fincfgB= $deltacfg
ABresult
1X1
011
000
1084 0 print ChordPro::Config::config_final( delta => $deltacfg );
1085 0 exit 0;
1086 }
1087  
1088 96 ▶ if ( $about ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($about) 0 96 96
1089 0 $::config = ChordPro::Config::configurator({});
1090 0 app_about( \*STDOUT, $about, 0 );
1091 }
1092  
1093 96 ▶ if ( $dump_chords ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dump_chords) 0 96 96
1094 0 $::config = ChordPro::Config::configurator($options);
1095 0 require ChordPro::Chords;
1096 0 ChordPro::Chords::dump_chords($dump_chords);
1097 0 exit 0;
1098 }
1099  
1100 96 ▶ if ( $clo->{filelist} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($clo->{"filelist"}) 0 96 96
1101 0 my @files;
1102 0 foreach ( @{ $clo->{filelist} } ) {
1103 0 push( @files, "--filelist=" . qquote($_) );
1104 0 my $dir = fn_dirname($_);
1105 0 my $list = fs_load( $_, $clo );
1106 0 push( @files, "--dir=" . qquote($dir) );
1107 0 foreach ( @$list ) {
1108 0 ▶ next unless /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\S/u 0 0 0
1109 0 ▶ next if /^#/;
Branch: 1 branch
BranchTrueFalseTotal
if /^#/u 0 0 0
1110 0 s/[\r\n]+$//;
1111 0 push( @files, $_ );
1112 }
1113 0 push( @files, "--filelist", "--dir" );
1114 }
1115 0 ▶ if ( @files ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@files) 0 0 0
1116 0 ▶ if ( $files[0] =~ /\.pdf$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($files[0] =~ /\.pdf$/iu) 0 0 0
1117 0 ▶ $options->{'front-matter'} //= $files[0];
Condition0%0/3
$options->{"front-matter"} //= $files[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$options->{"front-matter"} //= $files[0]
$options->{"front-matter"} $files[0]
Truth table0%0/3
A //= B
A= $options->{"front-matter"}B= $files[0]
ABresult
1X1
011
000
1118 0 shift(@files);
1119 }
1120 0 ▶ if ( $files[-1] =~ /\.pdf$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($files[-1] =~ /\.pdf$/iu) 0 0 0
1121 0 ▶ $options->{'back-matter'} //= $files[-1];
Condition0%0/3
$options->{"back-matter"} //= $files[-1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$options->{"back-matter"} //= $files[-1]
$options->{"back-matter"} $files[-1]
Truth table0%0/3
A //= B
A= $options->{"back-matter"}B= $files[-1]
ABresult
1X1
011
000
1122 0 pop(@files);
1123 }
1124 }
1125 0 ▶ unshift( @ARGV, @files ) if @files;
Branch: 1 branch
BranchTrueFalseTotal
if @files 0 0 0
1126 }
1127  
1128 # At this point, there should be filename argument(s)
1129 # unless we're embedded or just dumping chords.
1130 app_usage(\*STDERR, 1)
1131 unless $::__EMBEDDED__
1132 || $clo->{'dump-chords'}
1133 96 ▶ || $clo->{'convert-config'}
Branch: 1 branch
BranchTrueFalseTotal
unless $main::__EMBEDDED__ or $clo->{"dump-chords"} or $clo->{"convert-config"} or @ARGV 0 96 96
Condition33%3/9
$main::__EMBEDDED__ or $clo->{"dump-chords"} or $clo->{"convert-config"} or @ARGV
l!l&&r!l&&!r
0960
$main::__EMBEDDED__ or $clo->{"dump-chords"} or $clo->{"convert-config"}
l!l&&r!l&&!r
0096
$main::__EMBEDDED__ or $clo->{"dump-chords"}
l!l&&r!l&&!r
0096
MC/DC0%0/4
$main::__EMBEDDED__ or $clo->{"dump-chords"} or $clo->{"convert-config"} or @ARGV
$main::__EMBEDDED__ $clo->{"dump-chords"} $clo->{"convert-config"} @ARGV
Truth table20%1/5
A or B or C or D
A= $main::__EMBEDDED__B= $clo->{"dump-chords"}C= $clo->{"convert-config"}D= @ARGV
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1134 || @ARGV;
1135  
1136 # Return result.
1137 96 $options;
1138 }
1139  
1140 0 ▶sub app_ident {
Subroutine app_ident: not called CC=4 SCAR=30.0
Pod undocumented
1141 0 my ($fh, $exit) = @_;
1142 0 ▶ print {$fh} ("This is ChordPro ",
Branch: 2 branches
BranchTrueFalseTotal
$main::options->{'reference'} ? : 0 0 0
$ChordPro::VERSION =~ /_/u ? : 0 0 0
1143 0 $::options->{reference} ? "reference " : "core ",
1144 $VERSION,
1145 $VERSION =~ /_/ ? " (Unsupported development snapshot)" : "",
1146 "\n"
1147 );
1148 0 ▶ exit $exit if defined $exit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $exit 0 0 0
1149 }
1150  
1151 0 ▶sub app_about {
Subroutine app_about: not called CC=4 SCAR=30.0
Pod undocumented
1152 0 my ($fh, $level, $exit) = @_;
1153  
1154 0 ▶ if ( $level > 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level > 2) { } 0 0 0
1155 0 require JSON::XS;
1156 0 select $fh; $| = 1; # otherwise no output on MacOS
1157 0 print ${fh} ( JSON::XS->new->canonical->
1158 # pretty->
1159 utf8->convert_blessed->encode(runtime_info()) );
1160 }
1161 else {
1162 0 ▶ print ${fh} <<EndOfAbout,
Branch: 1 branch
BranchTrueFalseTotal
$level > 1 ? : 0 0 0
1163  
1164 ChordPro: A lyrics and chords formatting program.
1165  
1166 ChordPro will read a text file containing the lyrics of one or many
1167 songs plus chord information. ChordPro will then generate a
1168 photo-ready, professional looking, impress-your-friends sheet-music
1169 suitable for printing on your nearest printer.
1170  
1171 To learn more about ChordPro, look for the man page or do
1172 "chordpro --help" for the list of options.
1173  
1174 For more information, see https://www.chordpro.org .
1175  
1176 Run-time information:
1177 EndOfAbout
1178 ::runtimeinfo( $level > 1 ? "extensive" : "normal" );
1179 }
1180 0 ▶ exit $exit if defined $exit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $exit 0 0 0
1181 }
1182  
1183 92 ▶use List::Util qw(uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
1184  
1185 27 ▶sub ::runtimeinfo {
Subroutine runtimeinfo: called CC=24 SCAR=39.0
1186 27 ▶ my $level = shift // "normal";
Condition100%2/2
shift() // "normal"
l!l
1314
MC/DC100%1/1
shift() // "normal"
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1187 27 my %i = %{runtime_info($level)};
1188 27 my $fmt0 = " %-26.26s %-10s";
1189 27 my $fmt2 = $fmt0 . "\n";
1190 27 my $fmt3 = $fmt0 . " (%s)\n";
1191  
1192 27 my $msg;
1193 27 for ( $i{general}->{chordpro} ) {
1194 27 ▶ if ( $_->{aux} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{'aux'}) { } 0 27 27
1195 $msg = sprintf( $fmt3,
1196 "ChordPro " . ($_->{type}//"core"), $_->{version},
1197 0 ▶ $_->{aux} );
Condition0%0/2
$_->{"type"} // "core"
l!l
00
MC/DC0%0/1
$_->{"type"} // "core"
$_->{"type"}
Truth table0%0/2
A
A= $_->{"type"}
Aresult
11
00
1198 }
1199 else {
1200 $msg = sprintf( $fmt2,
1201 27 ▶ "ChordPro " . ($_->{type}//"core"), $_->{version} );
Condition50%1/2
$_->{"type"} // "core"
l!l
270
MC/DC0%0/1
$_->{"type"} // "core"
$_->{"type"}
Truth table50%1/2
A
A= $_->{"type"}
Aresult
11
00
1202 }
1203 }
1204 27 ▶ if ( $level eq "short" ) { # used for PDF Creator info
Branch: 1 branch
BranchTrueFalseTotal
if ($level eq "short") 13 14 27
1205 13 $msg =~ s/^\s+//;
1206 13 $msg =~ s/\s+/ /g;
1207 13 $msg =~ s/\n+$//;
1208 13 return $msg;
1209 }
1210  
1211 14 for ( $i{general}{perl} ) {
1212 14 $msg .= sprintf( $fmt3, "Perl", $_->{version}, $_->{dppath} );
1213 }
1214  
1215 14 for ( $i{general}{packager} ) {
1216 14 ▶ next unless defined;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 14 0 14
1217 0 $msg .= sprintf( $fmt2, $_->{packager}." Packager", $_->{version} );
1218 }
1219  
1220 # Determine resource path.
1221 14 my @p;
1222 14 my $tag = "CHORDPRO_LIB";
1223 14 for ( @{$i{general}{library}} ) {
1224 0 $msg .= sprintf( $fmt2, $tag, $_->{dppath} );
1225 0 $tag = "";
1226 }
1227 14 for ( $i{general}{xdg_home} ) {
1228 14 ▶ next unless defined;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 14 0 14
1229 0 $msg .= sprintf( $fmt2, "XDG_CONFIG_HOME", $_->{dppath} );
1230 }
1231  
1232 14 $tag = "Resource path";
1233 14 for ( @{$i{resources}} ) {
1234 14 $msg .= sprintf( $fmt2, $tag, $_->{dppath} );
1235 14 $tag = "";
1236 }
1237  
1238 14 $tag = "FONTDIR";
1239 14 ▶ for ( @{$i{general}{fontdir}//[]} ) {
Condition50%1/2
$i{"general"}{"fontdir"} // []
l!l
014
MC/DC0%0/1
$i{"general"}{"fontdir"} // []
$i{"general"}{"fontdir"}
Truth table50%1/2
A
A= $i{"general"}{"fontdir"}
Aresult
11
00
1240 0 ▶ next unless defined;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 0 0
1241 0 $msg .= sprintf( $fmt2, $tag, $_->{dppath} );
1242 0 $tag = "";
1243 }
1244  
1245 14 for ( $i{general}{abc} ) {
1246 14 ▶ next unless defined;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 14 14
1247 14 $msg .= sprintf( $fmt2, "ABC support", $_ );
1248 }
1249  
1250 14 $msg .= "\nModules and libraries:\n";
1251 14 for ( @{$i{modules}} ) {
1252 154 ▶ if ( $level eq "normal" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level eq 'normal') { } 154 0 154
1253 154 $msg .= sprintf( $fmt2, $_->{name}, $_->{version} );
1254 }
1255 else {
1256 0 ▶ if ( defined $_->{dppath} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_->{'dppath'}) { } 0 0 0
1257 0 $msg .= sprintf( $fmt3, $_->{name}, $_->{version}, $_->{dppath} );
1258 }
1259 else {
1260 0 $msg .= sprintf( $fmt2, $_->{name}, $_->{version} );
1261 }
1262 }
1263 154 ▶ if ( $_->{library} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"library"}) 0 154 154
1264 0 ▶ if ( $_->{library} =~ /i$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{'library'} =~ /i$/u) { } 0 0 0
1265 0 $msg .= sprintf( $fmt3, " library", $_->{library}, "embedded" );
1266 }
1267 else {
1268 0 $msg .= sprintf( $fmt2, " library", $_->{library} );
1269 }
1270 }
1271 }
1272  
1273 14 return $msg;
1274 }
1275  
1276 # Gather runtime details.
1277 27 ▶sub runtime_info {
Subroutine runtime_info: called CC=16 SCAR=28.9
Pod undocumented
1278 27 ▶ my $level = shift // "normal";
Condition50%1/2
shift() // "normal"
l!l
270
MC/DC0%0/1
shift() // "normal"
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1279 27 my $cp = ChordPro::Paths->get;
1280 27 my $res;
1281  
1282 # Sometimes version numbers are localized...
1283 27 ▶ my $dd = sub { my $v = $_[0]; $v =~ s/,/./g; $v };
Subroutine __ANON__: called CC=1 SCAR=0.0
1284  
1285 27 for ( $res->{general}{chordpro} ) {
1286 27 $_->{version} = $dd->($VERSION);
1287 27 ▶ $_->{type} = $::options->{reference} ? "reference" : "core";
Branch: 1 branch
BranchTrueFalseTotal
$main::options->{'reference'} ? : 0 27 27
1288 27 ▶ $_->{aux} = "Unsupported development snapshot"
Branch: 1 branch
BranchTrueFalseTotal
if $ChordPro::VERSION =~ /_/u 0 27 27
1289 if $VERSION =~ /_/;
1290 }
1291 27 ▶ return $res if $level eq "short";
Branch: 1 branch
BranchTrueFalseTotal
if $level eq "short" 13 14 27
1292  
1293 $res->{general}{perl} =
1294 14 { version => "$^V",
1295 path => $^X,
1296 dppath => $cp->display($^X),
1297 };
1298  
1299 $res->{general}{packager} =
1300 14 ▶ { packager => CP->packager,
Branch: 1 branch
BranchTrueFalseTotal
if CP()->packager 0 14 14
1301 version => CP->packager_version,
1302 } if CP->packager;
1303  
1304 # Determine resource path.
1305 14 $res->{general}{library} = [];
1306 14 ▶ if ( defined $ENV{CHORDPRO_LIB} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"CHORDPRO_LIB"}) 0 14 14
1307 0 for ( $cp->path($ENV{CHORDPRO_LIB}) ) {
1308 0 push( @{$res->{general}{library}},
1309 { path => $_,
1310 dppath => $cp->display($_) } );
1311 }
1312 }
1313  
1314 14 ▶ if ( defined $ENV{FONTDIR} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"FONTDIR"}) 0 14 14
1315 0 for ( $cp->path($ENV{FONTDIR}) ) {
1316 0 push( @{$res->{general}{fontdir}},
1317 { path => $_,
1318 dppath => $cp->display($_) } );
1319 }
1320 }
1321  
1322 $res->{resources} =
1323 14 [ map { { path => $_, dppath => $cp->display($_) } }
1324 14 uniq( @{ $cp->resdirs } ) ];
1325  
1326 14 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require ChordPro::Delegate::ABC; my $x = "ChordPro::Delegate::ABC"->info; $res->{"general"}{"abc"} = $x->{"info"} if $x->{"info"}; 1 } } or $@ =~ /Can't locate/u or warn($@) 14 0 14
Condition33%1/3
eval { do { require ChordPro::Delegate::ABC; my $x = "ChordPro::Delegate::ABC"->info; $res->{"general"}{"abc"} = $x->{"info"} if $x->{"info"}; 1 } } or $@ =~ /Can't locate/u
l!l&&r!l&&!r
1400
MC/DC0%0/2
eval { do { require ChordPro::Delegate::ABC; my $x = "ChordPro::Delegate::ABC"->info; $res->{"general"}{"abc"} = $x->{"info"} if $x->{"info"}; 1 } } or $@ =~ /Can't locate/u
eval { do { require ChordPro::Delegate::ABC; my $x = "ChordPro::Delegate::ABC"->info; $res->{"general"}{"abc"} = $x->{"info"} if $x->{"info"}; 1 } } $@ =~ /Can't locate/u
Truth table33%1/3
A or B
A= eval { do { require ChordPro::Delegate::ABC; my $x = "ChordPro::Delegate::ABC"->info; $res->{"general"}{"abc"} = $x->{"info"} if $x->{"info"}; 1 } }B= $@ =~ /Can't locate/u
ABresult
1X1
011
000
1327 14 require ChordPro::Delegate::ABC;
1328 14 my $x = ChordPro::Delegate::ABC->info();
1329 14 ▶ $res->{general}{abc} = $x->{info} if $x->{info};
Branch: 1 branch
BranchTrueFalseTotal
if $x->{"info"} 14 0 14
1330 14 1;
1331 } or $@ =~ /Can't locate/ or warn($@);
1332  
1333 14 my @p;
1334  
1335 154 ▶ my $vv = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
1336 154 my ( $mod ) = @_;
1337 92 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1338 154 my $pm = $mod =~ s;::;/;gr . ".pm";
1339 154 my $loc = $INC{$pm};
1340 push( @p, { name => $mod,
1341 154 ▶ version => "".$dd->(${${"${mod}::"}{VERSION}}),
Branch: 1 branch
BranchTrueFalseTotal
$loc =~ m[^(.*)/\Q$pm\E$]u ? : 154 0 154
1342 path => $loc,
1343 dppath => $loc =~ /^(.*)\/\Q$pm\E$/ ? $cp->display($1) : $loc,
1344 } );
1345 14 };
1346  
1347 14 ▶ local $SIG{__WARN__} = sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
1348 14 ▶ local $SIG{__DIE__} = sub {};
Subroutine __ANON__: called CC=1 SCAR=0.0
1349 eval {
1350 0 require Wx;
1351 92 ▶ no strict 'subs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1352 0 push( @p,
1353 { name => "wxPerl", version => $dd->($Wx::VERSION) },
1354 { name => "wxWidgets", version => $dd->($Wx::wxVERSION) } );
1355 14 ▶ } if $ENV{DISPLAY};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DISPLAY"} 0 14 14
1356  
1357 14 $vv->("Storable");
1358 14 $vv->("Object::Pad");
1359 14 eval {
1360 14 require Text::Layout;
1361 14 $vv->("Text::Layout");
1362 };
1363 14 eval {
1364 14 require HarfBuzz::Shaper;
1365 0 $vv->("HarfBuzz::Shaper");
1366 0 $p[-1]->{library} = $dd->(HarfBuzz::Shaper::hb_version_string());
1367 };
1368 14 eval {
1369 14 require String::Interpolate::Named;
1370 14 $vv->("String::Interpolate::Named");
1371 };
1372 14 eval {
1373 14 require File::LoadLines;
1374 14 $vv->("File::LoadLines");
1375 };
1376 14 eval {
1377 14 require PDF::Builder;
1378 0 $vv->("PDF::Builder");
1379 };
1380 14 eval {
1381 14 require PDF::API2;
1382 14 $vv->("PDF::API2");
1383 14 eval {
1384 14 require PDF::API2::XS;
1385 0 $vv->("PDF::API2::XS");
1386 };
1387 };
1388 14 eval {
1389 14 require SVGPDF;
1390 14 $vv->("SVGPDF");
1391 };
1392 14 eval {
1393 14 require Font::TTF;
1394 14 $vv->("Font::TTF");
1395 };
1396 14 eval {
1397 14 require JavaScript::QuickJS;
1398 14 $vv->("JavaScript::QuickJS");
1399 };
1400  
1401 14 eval {
1402 14 require JSON::Relaxed;
1403 14 $vv->( "JSON::Relaxed" );
1404 };
1405  
1406 14 eval {
1407 14 require JSON::XS;
1408 14 $vv->("JSON::XS");
1409 };
1410  
1411 14 $res->{modules} = [ @p ];
1412  
1413 14 $res->{metadata} = $::config->{metadata}{keys};
1414  
1415 @p = ( qw(title subtitle),
1416 238 ▶ ( grep { !/^(sub)?title$/ } sort(@{$::config->{metadata}{keys}//[]}) ),
Condition50%1/2
$main::config->{"metadata"}{"keys"} // []
l!l
140
MC/DC0%0/1
$main::config->{"metadata"}{"keys"} // []
$main::config->{"metadata"}{"keys"}
Truth table50%1/2
A
A= $main::config->{"metadata"}{"keys"}
Aresult
11
00
1417 14 grep { !/^(sub)?title$/ } (keys(%{ChordPro::Song::_directives()})) );
1418 14 $res->{directives} = [ @p ];
1419  
1420 14 $res->{directive_abbrevs} = ChordPro::Song::_directive_abbrevs();
1421  
1422 14 return $res;
1423 }
1424  
1425 0 ▶sub splitpath {
Subroutine splitpath: not called CC=3 SCAR=24.8
Pod undocumented
1426 0 my ( $path ) = @_;
1427 0 ▶ return () unless $path;
Branch: 1 branch
BranchTrueFalseTotal
unless $path 0 0 0
1428 0 ▶ if ( $^O =~ /Win/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /Win/u) 0 0 0
1429 0 return split( /;/, $path );
1430 }
1431 0 return split( /;/, $path );
1432 }
1433  
1434 0 ▶sub app_usage {
Subroutine app_usage: not called CC=6 SCAR=37.4
Pod undocumented
1435 0 my ($fh, $exit) = @_;
1436 0 my %cfg;
1437 0 for ( qw( config userconfig sysconfig) ) {
1438 0 ▶ $cfg{$_} = $configs{$_} || "no default";
Condition0%0/2
$configs{$_} || 'no default'
l!l
00
MC/DC0%0/1
$configs{$_} || 'no default'
$configs{$_}
Truth table0%0/2
A
A= $configs{$_}
Aresult
11
00
1439 }
1440  
1441 0 ▶ if ( $::options->{reference} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::options->{"reference"}) 0 0 0
1442 0 print ${fh} <<EndOfUsage;
1443 Usage: $0 [ options ] [ file ... ]
1444  
1445 Options:
1446 --[no]strict Strict conformance
1447 --output=FILE -o Saves the output to FILE
1448 --about -A About ChordPro...
1449 --version -V Prints version and exits
1450 --help -h This message
1451 --ident Show identification
1452 --verbose Verbose information. Repeat for more.
1453 EndOfUsage
1454 0 ▶ exit $exit if defined $exit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $exit 0 0 0
1455 0 return;
1456 }
1457  
1458 ####TODO: weed out for --reference.
1459 0 print ${fh} <<EndOfUsage;
1460 Usage: $0 [ options ] [ file ... ]
1461  
1462 Options:
1463 --a2crd Perform text to ChordPro conversion only
1464 --noa2crd Do not auto-sense text to ChordPro conversion
1465 --about -A About ChordPro...
1466 --back-matter=FILE Add back matter pages from PDF document
1467 --config=JSON --cfg Config definitions (multiple)
1468 --cover=FILE Add cover pages from PDF document
1469 --crd Input is text, not ChordPro
1470 --csv (with PDF) Also generate CSV
1471 --decapo Eliminate capo settings
1472 --diagrams=WHICH Prints chord diagrams
1473 --encoding=ENC Encoding for input files (UTF-8)
1474 --filelist=FILE Reads song file names from FILE
1475 --fragment -F Partial (incomplete) song
1476 --front-matter=FILE Add front matter pages from PDF document
1477 --lyrics-only -l Only prints lyrics
1478 --meta KEY=VALUE Add meta data
1479 --output=FILE -o Saves the output to FILE
1480 --[no]strict Strict conformance
1481 --start-page-number=N -p Starting page number [1]
1482 --subtitle=VALUE Use with --title for a nice subtitle.
1483 --title=VALUE Adds a nice cover page using this title.
1484 --toc --notoc -i Generates/suppresses a table of contents
1485 --transcode=SYS -xc Transcodes to notation system
1486 --transpose=N -x Transposes by N semi-tones
1487 --version -V Prints version and exits
1488  
1489 Chordii compatibility.
1490 Options marked with * are better handled in the config file.
1491 --chord-font=FONT -C *Sets chord font
1492 --chord-grid-size=N -s *Sets chord diagram size [30]
1493 --chord-grids-sorted -S *Prints chord diagrams ordered by key
1494 --chord-size=N -c *Sets chord size [9]
1495 --dump-chords -D Dumps chords definitions (PDF)
1496 --dump-chords-text -d Dumps chords definitions (Text)
1497 --even-pages-number-left -L *Not supported
1498 --odd-pages-number-left *Not supported.
1499 --no-chord-grids -G *Disables printing of chord diagrams
1500 --no-easy-chord-grids -g Not supported
1501 --page-number-logical -n Not supported
1502 --page-size=FMT -P *Specifies page size [letter, a4 (default)]
1503 --single-space -a *Automatic single space lines without chords
1504 --text-size=N -t *Sets text size [12]
1505 --text-font=FONT -T *Sets text font
1506 --user-chord-grids *Prints the user defined chords in the song
1507 --vertical-space=N -w *Extra vertical space between lines
1508 --2-up -2 Not supported
1509 --4-up -4 Not supported
1510  
1511 Configuration options:
1512 --config=CFG Project specific config file ($cfg{config})
1513 --define=XXX=YYY Sets config item XXX to value YYY
1514 --noconfig Don't use a project specific config file
1515 --nodefaultconfigs -X Don't use any default config files
1516 --nosongconfig Don't use song specific configs
1517 --nosysconfig Don't use a system specific config file
1518 --nouserconfig Don't use a user specific config file
1519 --print-default-config Prints the default config and exits
1520 --print-delta-config Prints the diffs for the resultant config and exits
1521 --print-final-config Prints the resultant config and exits
1522 --reference -R Reference mode (no configs etc.)
1523 --sysconfig=CFG System specific config file ($cfg{sysconfig})
1524 --userconfig=CFG User specific config file ($cfg{userconfig})
1525 Missing default configuration files are silently ignored.
1526  
1527 Miscellaneous options:
1528 --help -h This message
1529 --help-config Help for ChordPro configuration
1530 --ident Show identification
1531 --manual The full manual.
1532 --verbose Verbose information. Repeat for more.
1533 EndOfUsage
1534 0 ▶ exit $exit if defined $exit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $exit 0 0 0
1535 }
1536  
1537 =head1 FONTS
1538  
1539 There are two ways to specify fonts: with a font filename, and a
1540 built-in font name.
1541  
1542 A font filename must be either and absolute filename, or a relative
1543 filename which is interpreted relative to the I<font path>, which
1544 consists of configuration setting C<fontdir>, the C<fonts> resource
1545 dir, and the contents of environment variable C<FONTDIR>. In any case,
1546 the filename should point to a valid TrueType (C<.ttf>) or OpenType
1547 (C<.otf>) font.
1548  
1549 If it is not a filename, it must be the name one of the built-in PDF core fonts:
1550  
1551 Courier Symbol
1552 Courier-Bold Times-Bold
1553 Courier-BoldOblique Times-BoldItalic
1554 Courier-Oblique Times-Italic
1555 Helvetica Times-Roman
1556 Helvetica-Bold ZapfDingbats
1557 Helvetica-BoldOblique
1558 Helvetica-Oblique
1559  
1560 =head1 MOTIVATION
1561  
1562 Why a rewrite of Chordii?
1563  
1564 Chordii is the de facto reference implementation of the ChordPro file
1565 format standard. It implements ChordPro version 4.
1566  
1567 ChordPro version 5 adds a number of new features, and this was pushing
1568 the limits of the very old program. Unicode support would have been
1569 very hard to add, and the whole program centered around PostScript
1570 generation, while nowadays PDF would be a much better alternative.
1571  
1572 So I decided to create a new reference implementation from the ground
1573 up. I chose a programming language that is flexible and very good at
1574 handling Unicode data. And that is fun to program in.
1575  
1576 =head1 CURRENT STATUS
1577  
1578 This program implements ChordPro version 5. It
1579 supports most of the features of Chordii, and a lot more:
1580  
1581 * Native PDF generation
1582  
1583 * Unicode support (all input is UTF8)
1584  
1585 * User defined chords and tuning, not limited to 6 strings.
1586  
1587 * Support for Nashville Numbering and Roman Numbering.
1588  
1589 * Support for external TrueType and OpenType fonts
1590  
1591 * Font kerning (with external TrueType fonts)
1592  
1593 * Fully customizable layout, fonts and sizes
1594  
1595 * Customizable backends for PDF, ChordPro, LilyPond*, LaTeX* and HTML*.
1596  
1597 (* = under development)
1598  
1599 =head1 AUTHOR
1600  
1601 Johan Vromans C<< <jv at CPAN dot org > >>
1602  
1603 =head1 SUPPORT
1604  
1605 ChordPro (the program) development is hosted on GitHub, repository
1606 L<https://github.com/ChordPro/chordpro>.
1607  
1608 Please report any bugs or feature requests to the GitHub issue tracker,
1609 L<https://github.com/ChordPro/chordpro/issues>.
1610  
1611 A user community discussing ChordPro can be found at
1612 L<https://groups.google.com/forum/#!forum/chordpro>.
1613  
1614 =head1 LICENSE
1615  
1616 Copyright (C) 2010,2018 Johan Vromans,
1617  
1618 This program is free software; you can redistribute it and/or modify it
1619 under the same terms as Perl itself.
1620  
1621 =cut
1622  
1623 92 1;
« lib/ChordPro/lib/SVGPDF.pm ↑ Summary lib/ChordPro/lib/SVGPDF/Path.pm »