App-Music-ChordPro
view release on metacpan or search on metacpan
lib/ChordPro.pm view on Meta::CPAN
if ( $of =~ /\.pdf$/i ) {
$options->{generate} ||= "PDF";
}
elsif ( $of =~ /\.ly$/i ) {
$options->{generate} ||= "LilyPond";
}
elsif ( $of =~ /\.(tex|ltx)$/i ) {
$options->{generate} ||= "LaTeX";
}
elsif ( $of =~ /\.cho$/i ) {
$options->{generate} ||= "ChordPro";
}
elsif ( $of =~ /\.msp$/i ) {
$options->{generate} ||= "ChordPro";
$options->{'backend-option'}->{variant} = "msp";
}
elsif ( $of =~ /\.(crd|txt)$/i ) {
$options->{generate} ||= "Text";
}
elsif ( $of =~ /\.html?$/i ) {
$options->{generate} ||= "HTML";
}
elsif ( $of =~ /\.mma?$/i ) {
$options->{generate} ||= "MMA";
}
elsif ( $of =~ /\.(md|markdown)$/i ) {
$options->{generate} ||= "Markdown";
}
elsif ( $of =~ /\.meta$/i ) {
$options->{generate} ||= "Meta";
}
elsif ( $of =~ /\.(debug)$/i ) {
$options->{generate} ||= "Debug";
}
}
elsif ( -t STDOUT ) {
# No output, and stdout is terminal.
# Derive output name from input name.
if ( @ARGV > 1 || ( $options->{'dump-chords'} && !@ARGV ) ) {
# No default if more than one input document.
die("Please use \"--output\" to specify the output file name\n");
}
my $f = CP->sibling( $ARGV[0], ext => ".pdf" );
$options->{output} = $f;
warn("Writing output to $f\n") if $options->{verbose};
}
else {
# Write output to stdout.
$options->{output} = "-";
}
$options->{generate} ||= "PDF";
# Register backend name and load its Configurator, if any.
my $pkg = "ChordPro::Output::".$options->{generate};
$options->{backend} = $pkg;
eval "require $pkg"."::Configurator";
warn("Warning: No configurator for ", $options->{generate}, "\n$@")
if $options->{trace} && $@;
# One configurator to bind them all.
# This will also call the backend Configurator, if any.
use ChordPro::Config;
$config = ChordPro::Config::configurator({});
# Now load the real backend. Note that the actual module name
# may be changed by config.
if ( exists($config->{lc($options->{generate})})
&& exists($config->{lc($options->{generate})}->{module}) ) {
$options->{generate} = $config->{lc($options->{generate})}->{module};
}
$pkg = "ChordPro::Output::".$options->{generate};
eval "require $pkg;";
die("No backend for ", $options->{generate}, "\n$@") if $@;
$options->{backend} = $pkg;
$pkg->version if $options->{verbose} && $pkg->can("version");
# Parse the input(s).
use ChordPro::Songbook;
my $s = ChordPro::Songbook->new;
my $res;
# Shortcut a2crd conversion.
if ( $options->{a2crd} ) {
require ChordPro::A2Crd;
$res = ChordPro::A2Crd::a2crd();
push( @$res, '' );
goto WRITE_OUTPUT;
}
# Check for metadata in filelist. Actually, this works on the
# command line as well, but don't tell anybody.
progress( phase => "Parsing", index => 0,
total => 0+grep { !/^--/ } @ARGV )
if @ARGV > 1;
my %gopts;
foreach my $file ( @ARGV ) {
my @w = ( $file );
if ( $file =~ /(^|\s)--\w+/ || $file =~ /^["']/ ) {
@w = Text::ParseWords::shellwords($file);
}
my %meta;
my %defs;
my @cfg;
my %opts;
die("Error in filelist: $file\n")
unless Getopt::Long::GetOptionsFromArray
( \@w, \%opts, 'config=s@' => \@cfg, 'meta=s%' => \%meta,
'define=s%' => \%defs,
'title=s', 'subtitle=s', 'dir:s', 'filelist:s',
)
&& ( ( @w == 1 && ! keys(%opts) ) # filename
|| ( @w == 0 && keys(%opts) ) # options
);
for ( qw( title subtitle ) ) {
next unless defined $opts{$_};
$options->{$_} = $opts{$_};
}
( run in 1.991 second using v1.01-cache-2.11-cpan-2398b32b56e )