App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro/Config.pm view on Meta::CPAN
$options = { %{$options//{}}, %$opts };
}
my @cfg;
my $verbose = $options->{verbose} //= 0;
# Load defaults.
warn("Reading: <builtin>\n") if $verbose > 1;
my $cfg = pristine_config();
# Default first.
@cfg = prep_configs( $cfg, "<builtin>" );
# Bubble default config to be the first.
unshift( @cfg, pop(@cfg) ) if @cfg > 1;
# Collect other config files.
my $add_config = sub {
my $fn = shift;
$cfg = get_config( $fn );
push( @cfg, $cfg->prep_configs($fn) );
};
foreach my $c ( qw( sysconfig userconfig config ) ) {
next if $options->{"no$c"};
if ( ref($options->{$c}) eq 'ARRAY' ) {
$add_config->($_) foreach @{ $options->{$c} };
}
else {
warn("Adding config for $c\n") if $verbose;
$add_config->( $options->{$c} );
}
}
# Now we have a list of all config files. Weed out dups.
for ( my $a = 0; $a < @cfg; $a++ ) {
if ( $a && $cfg[$a]->{_src} eq $cfg[$a-1]->{_src} ) {
if ( $a == $#cfg ) {
# If this is the last entry, splice/redo will create
# a new, empty entry triggering issue #550.
pop(@cfg);
last;
}
splice( @cfg, $a, 1 );
redo;
}
warn("Config[$a]: ", $cfg[$a]->{_src}, "\n" )
if $verbose;
}
$cfg = shift(@cfg);
warn("Process: $cfg->{_src}\n") if $verbose > 1;
# Presets.
if ( $options->{reference} ) {
$cfg->{user}->{name} = "chordpro";
$cfg->{user}->{fullname} = ::runtimeinfo("short");
}
else {
$cfg->{user}->{name} =
lc( $ENV{USER} || $ENV{LOGNAME}
|| getlogin() || getpwuid($<) || "chordpro" );
$cfg->{user}->{fullname} = eval { (getpwuid($<))[6] } || "";
}
# Add some extra entries to prevent warnings.
for ( qw(title subtitle footer) ) {
next if exists($cfg->{pdf}->{formats}->{first}->{$_});
$cfg->{pdf}->{formats}->{first}->{$_} = "";
}
my $backend_configurator =
UNIVERSAL::can( $options->{backend}, "configurator" );
# Apply config files
foreach my $new ( @cfg ) {
my $file = $new->{_src}; # for diagnostics
# Handle obsolete keys.
my $ps = $new->{pdf};
if ( exists $ps->{diagramscolumn} ) {
$ps->{diagrams}->{show} //= "right";
delete $ps->{diagramscolumn};
warn("$file: pdf.diagramscolumn is obsolete, use pdf.diagrams.show instead\n");
}
if ( exists $ps->{formats}->{default}->{'toc-title'} ) {
$new->{toc}->{title} //= $ps->{formats}->{default}->{'toc-title'};
delete $ps->{formats}->{default}->{'toc-title'};
warn("$file: pdf.formats.default.toc-title is obsolete, use toc.title instead\n");
}
# Page controls.
# Check for old and newer keywords conflicts.
if ( $ps->{songbook}
&& is_hashref($ps->{songbook})
&& %{$ps->{songbook}} ) {
# Using new style page controls.
my @depr;
for ( qw( front-matter back-matter sort-pages ) ) {
push( @depr, $_) if $ps->{$_};
}
push( @depr, "even-odd-songs" )
if defined($ps->{'even-odd-songs'}) && $ps->{'even-odd-songs'} <= 0;
push( @depr, "pagealign-songs" )
if defined($ps->{'pagealign-songs'}) && $ps->{'pagealign-songs'} != 1;
if ( @depr ) {
warn("Config \"$file\" uses \"pdf.songbook\", ignoring ",
enumerated( map { qq{"pdf.$_"} } @depr ), "\n" );
delete $ps->{$_} for @depr;
}
}
else {
migrate_songbook_pagectrl( $new, $ps );
}
# use DDP; p $ps->{songbook}, as => "after \"$file\"";
# Process.
local $::config = dclone($cfg);
process_config( $new, $file );
# Merge final.
$cfg = hmerge( $cfg, $new );
# die("PANIC! Config merge error")
# unless UNIVERSAL::isa( $cfg->{settings}->{strict}, 'JSON::Boolean' );
( run in 1.930 second using v1.01-cache-2.11-cpan-39bf76dae61 )