EBook-Tools

 view release on metacpan or  search on metacpan

scripts/ebook.pl  view on Meta::CPAN

            foreach my $subject(@extra) {
                $ebook->delete_subject('text' => $subject);
            }
        }
        else {
            $ebook->add_subject('text' => $value,
                                'id' => $id);
            foreach my $subject(@extra) {
                $ebook->add_subject('text' => $subject);
            }
        }
    }
    elsif ($element =~ /^ti/) {
        $ebook->set_title('text' => $value,
                          'id' => $id);
    }
    elsif ($element =~ /^ty/) {
        $ebook->set_type('text' => $value,
                         'id' => $id);
    }
    else {
        print "Unrecognized metadata element '",$element,"'!\n";
        exit(EXIT_BADOPTION);
    }

    $ebook->save;
    $ebook->print_errors;
    $ebook->print_warnings;
    return 0;
}


=head2 C<splitmeta>

Split the <metadata>...</metadata> block out of a pseudo-HTML file
that contains one.

=cut

sub splitmeta
{
    my ($infile,$opffile) = @_;
    if(!$infile) { die("You must specify a file to parse.\n"); }
    $opffile = $opt{opffile} if(!$opffile);

    my $ebook;

    $opffile = split_metadata($infile,$opffile);

    if(!$opffile)
    {
        print {*STDERR} "No metadata block was found in '",$infile,"'\n";
        exit(EXIT_BADINPUT);
    }

    $ebook = EBook::Tools->new($opffile);
    $ebook->fix_oeb12 if($opt{oeb12});
    $ebook->fix_opf20 if($opt{opf20});
    $ebook->fix_mobi if($opt{mobi});

    # The split metadata never includes manifest/spine info, so add in the
    # HTML file now
    $ebook->add_document($infile,'item-maintext');
    $ebook->fix_misc;
    $ebook->save;

    if($ebook->errors)
    {
        $ebook->print_errors;
        $ebook->print_warnings if($ebook->warnings);
        exit(EXIT_TOOLSERROR);
    }
    $ebook->print_warnings if($ebook->warnings);
    return 0;
}


=head2 C<splitpre>

Split <pre>...</pre> blocks out of an existing HTML file, wrapping
each one found into a separate HTML file.

The first non-option argument is taken to be the input file.  The
second non-option argument is taken to be the basename of the output
files.

=cut

sub splitpre
{
    my ($infile,$outfilebase) = @_;
    if(!$infile)
    {
        print {*STDERR} "You must specify a file to parse.\n";
        exit(EXIT_BADOPTION);
    }
    split_pre($infile,$outfilebase);
    return 0;
}


=head2 C<stripscript>

Strips <script>...</script> blocks out of a HTML file.

The first non-option argument is taken to be the input file.  The
second non-option argument is taken to be the output file.  If the
latter is not specified, the input file will be overwritten.

=head3 Options

=over

=item * C<--noscript>

Strips <noscript>...</noscript> blocks as well.

=back

=cut



( run in 0.660 second using v1.01-cache-2.11-cpan-5511b514fd6 )