App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro/Config.pm view on Meta::CPAN
$cfg->{pdf}->{fonts}->{$ff}->{background} //= "background";
for ( qw(name file description size) ) {
delete( $cfg->{pdf}->{fonts}->{$ff}->{$_} )
unless defined( $cfg->{pdf}->{fonts}->{$ff}->{$_} );
}
}
if ( defined $options->{diagrams} ) {
warn( "Invalid value for diagrams: ",
$options->{diagrams}, "\n" )
unless $options->{diagrams} =~ /^(all|none|user)$/i;
$cfg->{diagrams}->{show} = lc $options->{'diagrams'};
}
elsif ( defined $options->{'user-chord-grids'} ) {
$cfg->{diagrams}->{show} =
$options->{'user-chord-grids'} ? "user" : 0;
}
elsif ( defined $options->{'chord-grids'} ) {
$cfg->{diagrams}->{show} =
$options->{'chord-grids'} ? "all" : 0;
}
for ( qw( transpose transcode decapo lyrics-only strict ) ) {
next unless defined $options->{$_};
$cfg->{settings}->{$_} = $options->{$_};
}
for ( "cover", "front-matter", "back-matter" ) {
next unless defined $options->{$_};
$cfg->{pdf}->{songbook}->{$_} = $options->{$_};
}
if ( defined $options->{'chord-grids-sorted'} ) {
$cfg->{diagrams}->{sorted} = $options->{'chord-grids-sorted'};
}
# For convenience...
bless( $cfg, __PACKAGE__ );
return $cfg if $options->{'cfg-print'};
# Backend specific configs.
$backend_configurator->($cfg) if $backend_configurator;
# Locking the hash is mainly for development.
$cfg->lock;
if ( $options->{verbose} > 1 ) {
my $cp = ChordPro::Chords::get_parser() // "";
warn("Parsers:\n");
while ( my ($k, $v) = each %{ChordPro::Chords::Parser->parsers} ) {
warn( " $k",
$v eq $cp ? " (active)": "",
"\n");
}
}
return $cfg;
}
# Get the decoded contents of a single config file.
sub get_config ( $file ) {
Carp::confess("FATAL: Undefined config") unless defined $file;
my $verbose = $options->{verbose};
warn("Reading: $file\n") if $verbose > 1;
$file = expand_tilde($file);
if ( $file =~ /\.json$/i ) {
if ( my $lines = fs_load( $file, { split => 1, fail => "soft" } ) ) {
my $new = json_load( join( "\n", @$lines, '' ), $file );
warn("JSON: $file ($ChordPro::Utils::json_last)\n") if $verbose > 1;
precheck( $new, $file );
return __PACKAGE__->new($new);
}
else {
die("Cannot open config $file [$!]\n");
}
}
elsif ( $file =~ /\.prp$/i ) {
if ( fs_test( efr => $file ) ) {
require ChordPro::Config::Properties;
my $cfg = Data::Properties->new;
$cfg->parse_file($file);
return __PACKAGE__->new($cfg->data);
}
else {
die("Cannot open config $file [$!]\n");
}
}
else {
Carp::confess("Unrecognized config type: $file\n");
}
}
# Check config for includes, and prepend them.
sub prep_configs ( $cfg, $src ) {
$cfg->{_src} = $src;
my @res;
# If there are includes, add them first.
my ( $vol, $dir, undef ) = fn_splitpath($cfg->{_src});
foreach my $c ( @{ $cfg->{include} } ) {
# Check for resource names.
if ( $c !~ m;[/.]; ) {
$c = CP->findcfg($c);
}
elsif ( $dir ne ""
&& !fn_is_absolute($c) ) {
# Prepend dir of the caller, if needed.
$c = fn_catpath( $vol, $dir, $c );
}
my $cfg = get_config($c);
# Recurse.
push( @res, $cfg->prep_configs($c) );
}
# Push this and return.
$cfg->split_fc_aliases;
$cfg->expand_font_shortcuts;
push( @res, $cfg );
( run in 0.464 second using v1.01-cache-2.11-cpan-a1f116cd669 )