File Coverage

blib/lib/EPUB/Parser/File/Parser/OPF.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package EPUB::Parser::File::Parser::OPF;
2 14     14   77 use strict;
  14         27  
  14         487  
3 14     14   77 use warnings;
  14         21  
  14         554  
4 14     14   77 use Carp;
  14         64  
  14         789  
5 14     14   79 use parent 'EPUB::Parser::File::Parser';
  14         25  
  14         113  
6              
7             sub new {
8             my $class = shift;
9              
10             my $self = $class->SUPER::new(@_);
11             $self->set_namespace;
12              
13             return $self;
14             }
15              
16             sub set_namespace {
17             my $self = shift;
18             $self->set_pkg_namespace;
19             $self->set_metadata_namespace;
20             }
21              
22             sub set_pkg_namespace {
23             my $self = shift;
24              
25             my $pkg_ns = $self->{doc}->documentElement()->getAttribute('xmlns');
26             $self->{parser}->registerNs( pkg => $pkg_ns );
27             }
28              
29             sub set_metadata_namespace {
30             my $self = shift;
31              
32             my $meta_element = $self->{parser}->findnodes('/pkg:package/pkg:metadata')->[0];
33             my $dc_ns = $meta_element->getAttribute('xmlns:dc');
34             unless ($dc_ns) {
35             $dc_ns = $self->{parser}->findnodes('/pkg:package')->[0]->getAttribute('xmlns:dc');
36             }
37              
38             $self->{parser}->registerNs( dc => $dc_ns );
39             }
40              
41              
42             sub in_manifest { shift->context_node( 'manifest' ) }
43             sub in_metadata { shift->context_node( 'metadata' ) }
44             sub in_spine { shift->context_node( 'spine' ) }
45             sub in_guide { shift->context_node( 'guide' ) }
46              
47              
48             1;