| 1 | package EPUB::Parser::File::OPF::Context::Manifest; | ||||||||||||
| 2 | 8 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 8 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 8 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 8 | ▶ | use Smart::Args; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 8 | ▶ | use parent 'EPUB::Parser::File::OPF::Context'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 8 | ▶ | use EPUB::Parser::Util::AttributePacker; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 4 | ▶ | sub nav_path { | ||||||||||
|
Subroutine
nav_path: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 10 | 4 | my $self = shift; | |||||||||||
| 11 | 4 | my $nav_path = $self->parser->single('pkg:item[@properties="nav"]/@href'); | |||||||||||
| 12 | |||||||||||||
| 13 | 4 | ▶ | croak '<item properties="nav" /> is required for epub3' unless $nav_path; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 14 | |||||||||||||
| 15 | 4 | return $nav_path->string_value; | |||||||||||
| 16 | } | ||||||||||||
| 17 | |||||||||||||
| 18 | 2 | ▶ | sub cover_image_path { | ||||||||||
|
Subroutine
cover_image_path: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 19 | 2 | args( | |||||||||||
| 20 | my $self, | ||||||||||||
| 21 | my $abs => { optional => 1 }, | ||||||||||||
| 22 | ); | ||||||||||||
| 23 | 2 | my $cover_img_path = $self->parser->single('pkg:item[@properties="cover-image"]/@href'); | |||||||||||
| 24 | |||||||||||||
| 25 | 2 | ▶ | return unless $cover_img_path; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | |||||||||||||
| 27 | 2 | ▶ | if ($abs) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | 1 | return $self->{opf}->dir . '/' . $cover_img_path->string_value; | |||||||||||
| 29 | }else{ | ||||||||||||
| 30 | 1 | return $cover_img_path->string_value; | |||||||||||
| 31 | } | ||||||||||||
| 32 | } | ||||||||||||
| 33 | |||||||||||||
| 34 | 8 | ▶ | sub attr_by_media_type { | ||||||||||
|
Subroutine
attr_by_media_type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 35 | 8 | my $self = shift; | |||||||||||
| 36 | 8 | my $nodes = $self->parser->find('pkg:item'); | |||||||||||
| 37 | 8 | EPUB::Parser::Util::AttributePacker->grouped_list($nodes, { group => 'media-type'}); | |||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | 7 | ▶ | sub attr_by_id { | ||||||||||
|
Subroutine
attr_by_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 41 | 7 | my $self = shift; | |||||||||||
| 42 | 7 | my $nodes = $self->parser->find('pkg:item'); | |||||||||||
| 43 | 7 | EPUB::Parser::Util::AttributePacker->by_uniq_key($nodes, { key => 'id'}); | |||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | |||||||||||||
| 47 | 12 | ▶ | sub _items_path { | ||||||||||
|
Subroutine
_items_path: called CC=2 SCAR=6.9
| |||||||||||||
| 48 | 12 | args( | |||||||||||
| 49 | my $self, | ||||||||||||
| 50 | my $href => 'ArrayRef', | ||||||||||||
| 51 | my $abs => { optional => 1 }, | ||||||||||||
| 52 | ); | ||||||||||||
| 53 | |||||||||||||
| 54 | 12 | my $base_dir = ''; | |||||||||||
| 55 | 12 | ▶ | if ($abs) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 56 | 11 | $base_dir = $self->{opf}->dir . '/'; | |||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | 12 | [map { $base_dir . $_ } @$href]; | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | 1 | ▶ | sub items_path { | ||||||||||
|
Subroutine
items_path: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||
| 63 | 1 | my $self = shift; | |||||||||||
| 64 | 1 | ▶ | my $args = shift || {}; | ||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 65 | |||||||||||||
| 66 | 1 | ▶ | my @href = map { $_->{href} } values %{ $self->attr_by_id || {} }; | ||||||||||
|
Condition50%1/2
$self->attr_by_id || {}
MC/DC0%0/1
$self->attr_by_id || {}
$self->attr_by_id
Truth table50%1/2
A
A= $self->attr_by_id
| |||||||||||||
| 67 | |||||||||||||
| 68 | 1 | $self->_items_path({ %$args, href => \@href }); | |||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | 7 | ▶ | sub items_path_by_media_type { | ||||||||||
|
Subroutine
items_path_by_media_type: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 72 | 7 | args( | |||||||||||
| 73 | my $self, | ||||||||||||
| 74 | my $abs => { optional => 1 }, | ||||||||||||
| 75 | my $regexp, | ||||||||||||
| 76 | ); | ||||||||||||
| 77 | |||||||||||||
| 78 | 7 | ▶ | my $attr = $self->attr_by_media_type || {}; | ||||||||||
|
Condition50%1/2
$self->attr_by_media_type || {}
MC/DC0%0/1
$self->attr_by_media_type || {}
$self->attr_by_media_type
Truth table50%1/2
A
A= $self->attr_by_media_type
| |||||||||||||
| 79 | 7 | my @href; | |||||||||||
| 80 | 7 | for my $media_type ( keys %$attr ) { | |||||||||||
| 81 | 28 | ▶ | next unless $media_type =~ $regexp; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | 8 | push @href, map { $_->{href} } @{$attr->{$media_type}}; | |||||||||||
| 83 | } | ||||||||||||
| 84 | |||||||||||||
| 85 | 7 | $self->_items_path({ abs => $abs, href => \@href }); | |||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | |||||||||||||
| 89 | 10 | ▶ | sub _items { | ||||||||||
|
Subroutine
_items: called CC=2 SCAR=7.0
| |||||||||||||
| 90 | 10 | my $self = shift; | |||||||||||
| 91 | 10 | my $paths = shift; | |||||||||||
| 92 | my $it = $self->{opf}->{zip}->get_members({ | ||||||||||||
| 93 | 10 | files_path => $paths, | |||||||||||
| 94 | }); | ||||||||||||
| 95 | 10 | ▶ | return wantarray ? $it->all : $it; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 96 | } | ||||||||||||
| 97 | |||||||||||||
| 98 | 1 | ▶ | sub items { | ||||||||||
|
Subroutine
items: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 99 | 1 | my $self = shift; | |||||||||||
| 100 | 1 | $self->_items( $self->items_path({ abs => 1 }) ); | |||||||||||
| 101 | } | ||||||||||||
| 102 | |||||||||||||
| 103 | |||||||||||||
| 104 | 3 | ▶ | sub items_by_media { | ||||||||||
|
Subroutine
items_by_media: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 105 | 3 | my $self = shift; | |||||||||||
| 106 | 3 | $self->_items( $self->items_path_by_media_type({ abs => 1, regexp => qr{image/ | video/ | audio/}ix }) ); | |||||||||||
| 107 | } | ||||||||||||
| 108 | |||||||||||||
| 109 | 4 | ▶ | sub items_by_media_type { | ||||||||||
|
Subroutine
items_by_media_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 110 | 4 | args( | |||||||||||
| 111 | my $self, | ||||||||||||
| 112 | my $regexp, | ||||||||||||
| 113 | ); | ||||||||||||
| 114 | 4 | $self->_items( $self->items_path_by_media_type({ abs => 1, regexp => $regexp }) ); | |||||||||||
| 115 | } | ||||||||||||
| 116 | |||||||||||||
| 117 | |||||||||||||
| 118 | 8 | 1; | |||||||||||
| 119 | |||||||||||||
| 120 | __END__ | ||||||||||||