Aozora2Epub

 view release on metacpan or  search on metacpan

script/aozora2epub  view on Meta::CPAN

#!perl
use utf8;
use strict;
use warnings;
use Aozora2Epub;
use Getopt::Long;
use Path::Tiny;

our $VERSION = '0.03';

binmode(STDERR, "utf8");
binmode(STDOUT, "utf8");

my $cmd_name = path($0)->basename;

my ($output, $title, $author, $cover, $no_okuzuke, $use_subtitle);
Getopt::Long::Configure ("bundling");
GetOptions("o|output=s" => \$output,
           "t|title=s" => \$title,
           "a|author=s" => \$author,
           "use-subtitle" => \$use_subtitle,
           "c|cover=s" => \$cover,
           "no-okuzuke" => \$no_okuzuke,
           "h|help" => sub { usage(0) },
           "version" => sub { show_version(); exit 0; },
       ) or usage(1, 1);

sub show_version {
    print "$cmd_name version $VERSION ($0)\n";
    print "Running under Perl $^V ($^X)\n\n";
}

sub load_argv_from_stdin {

    my @argv;
    while(defined(my $line = <STDIN>)){
        chomp $line;
        $line =~ s/#.+$//; # comment
        $line =~ s/^\s+//; # trim spaces
        $line =~ s/\s+$//; # trim spaces

        push @argv, $line if $line;
    }
    return @argv;
}

my @files = @ARGV;
if (@files == 0 && !-t STDIN) {
    @files = load_argv_from_stdin();
}

@files or usage(1, 1, "$cmd_name requires one or more arguments");

my $ae = (@files > 1 ? Aozora2Epub->new() : Aozora2Epub->new(shift @files));
$ae->title($title) if $title;
$ae->author($author) if $author;

my %append_options;
$append_options{use_subtitle} = 1 if $use_subtitle;
for my $f (@files) {
    $ae->append($f, %append_options);
}

if ($no_okuzuke) {
    $ae->bib_info(undef);
}

my %options;
$options{output} = $output if $output;
if ($cover) {
    unless (do { my $fh; open $fh, "<", $cover and close $fh; }) {
        print STDERR "$cover: $!\n";



( run in 1.141 second using v1.01-cache-2.11-cpan-99c4e6809bf )