EBook-FB2

 view release on metacpan or  search on metacpan

lib/EBook/FB2/Binary.pm  view on Meta::CPAN


sub load
{
    my ($self, $node) = @_;

    my @nodes = $node->findnodes('@id');
    if (@nodes) {
        $self->id($nodes[0]->getValue());
    }

    @nodes = $node->findnodes('@content-type');
    if (@nodes) {
        $self->content_type($nodes[0]->getValue());
    }

    # XXX: eval this, it might fail with invalid data
    my $decoded = MIME::Base64::decode($node->string_value());
    $self->data($decoded)
}

1;

lib/EBook/FB2/Binary.pm  view on Meta::CPAN

=item id()

Returns id of binary element

=item data()

Returns content of binary element (base64-decoded)

=item content_type()

Returns content-type of binary element

=back

=head1 AUTHOR

Oleksandr Tymoshenko, E<lt>gonzo@bluezbox.comE<gt>

=head1 BUGS

Please report any bugs or feature requests to  E<lt>gonzo@bluezbox.comE<gt>

t/05-binary.t  view on Meta::CPAN

#!perl -T

use Test::More tests => 3;
use XML::DOM;
use XML::DOM::XPath;
use EBook::FB2::Binary;

my $binary_data = <<__EOBIN__;
<binary id="id.png" content-type="content/type">
dGVzdHRlc3Q=
</binary>
__EOBIN__

my $parser = XML::DOM::Parser->new();
my $xp = $parser->parse($binary_data);
my $binary = EBook::FB2::Binary->new;
my @nodes = $xp->findnodes("/binary");
$binary->load($nodes[0]);
is($binary->id, 'id.png');

t/09-fb2.t  view on Meta::CPAN

<FictionBook>
    <description>
      <title-info></title-info>
      <document-info>
          <date></date>
          <id></id>
      </document-info>
    </description>
    <body><section>1</section></body>
    <body><section>4</section></body>
    <binary id="id1.png" content-type="content/type">dGVzdHRlc3Q=</binary>
    <binary id="id2.png" content-type="content/type">dGVzdHRlc3Q=</binary>
    <binary id="id3.png" content-type="content/type">dGVzdHRlc3Q=</binary>
</FictionBook>

__EOXML__


my ($fh, $filename) = tempfile();
print $fh $data;
close $fh;
my $fb2 = EBook::FB2->new;
$fb2->load($filename);



( run in 1.994 second using v1.01-cache-2.11-cpan-524268b4103 )