| 1 | package EBook::Ishmael::EBook::CB; | ||||||||||||||||||||||||||||||
| 2 | 17 | ▶ | use 5.016; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 3 | 17 | our $VERSION = '2.04'; | |||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | 17 | ▶ | use File::Which; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 10 | 17 | ▶ | use List::Util qw(max); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||
| 12 | 17 | ▶ | use EBook::Ishmael::Dir; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 13 | 17 | ▶ | use EBook::Ishmael::ImageID qw(image_path_id); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 14 | 17 | ▶ | use EBook::Ishmael::EBook::Metadata; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 15 | 17 | ▶ | use EBook::Ishmael::Unzip qw(safe_tmp_unzip); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | # Not an ebook format itself, just a base class from which actual comic book | ||||||||||||||||||||||||||||||
| 18 | # archives derive themselves. | ||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub heuristic { 0 } | ||||||||||||||||||||||||||||
|
Subroutine
heuristic: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||
| 22 | sub _images { | ||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||
| 24 | 20 | ▶ | my $dir = shift; | ||||||||||||||||||||||||||||
|
Subroutine
_images: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||
| 26 | 20 | my @img; | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||
| 28 | 20 | for my $f (dir($dir)) { | |||||||||||||||||||||||||||||
| 29 | 290 | ▶ | if (-d $f) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 30 | 10 | push @img, _images($f); | |||||||||||||||||||||||||||||
| 31 | } elsif (-f $f) { | ||||||||||||||||||||||||||||||
| 32 | 280 | my $format = image_path_id($f); | |||||||||||||||||||||||||||||
| 33 | 280 | ▶ | next if not defined $format; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 34 | 280 | push @img, [ $f, $format ]; | |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||
| 38 | 20 | return @img; | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||
| 42 | sub new { | ||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||
| 44 | 10 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 45 | 10 | my $file = shift; | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||
| 47 | 10 | my $self = { | |||||||||||||||||||||||||||||
| 48 | Source => undef, | ||||||||||||||||||||||||||||||
| 49 | Metadata => EBook::Ishmael::EBook::Metadata->new, | ||||||||||||||||||||||||||||||
| 50 | _images => [], | ||||||||||||||||||||||||||||||
| 51 | _tmpdir => undef, | ||||||||||||||||||||||||||||||
| 52 | }; | ||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | 10 | bless $self, $class; | |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||
| 56 | 10 | my $title = (fileparse($file, qr/\.[^.]*/))[0]; | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||
| 58 | 10 | $self->{Source} = File::Spec->rel2abs($file); | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||
| 60 | 10 | $self->{_tmpdir} = safe_tmp_unzip; | |||||||||||||||||||||||||||||
| 61 | 10 | $self->extract($self->{_tmpdir}); | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||
| 63 | 10 | @{ $self->{_images} } = _images($self->{_tmpdir}); | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||
| 65 | 10 | ▶ | unless (@{ $self->{_images} }) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 66 | 0 | die "$self->{Source}: Found no images in comic book archive\n"; | |||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||
| 69 | 10 | $self->{Metadata}->set_title($title); | |||||||||||||||||||||||||||||
| 70 | 10 | $self->{Metadata}->set_modified((stat $self->{Source})[9]); | |||||||||||||||||||||||||||||
| 71 | 10 | $self->{Metadata}->set_format($self->format); | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||
| 73 | 10 | return $self; | |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||
| 77 | sub extract { | ||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | die sprintf "%s does not implement the extract() method\n", __PACKAGE__; | ||||||||||||||||||||||||||||
|
Subroutine
extract: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub format { undef } | ||||||||||||||||||||||||||||
|
Subroutine
format: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||
| 83 | # Comic Book archives have no HTML | ||||||||||||||||||||||||||||||
| 84 | sub html { | ||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||
| 86 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
html: called CC=5 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 87 | 3 | my $out = shift; | |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||
| 89 | 3 | my $html = ''; | |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||
| 91 | 3 | ▶ | open my $fh, '>', $out // \$html | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
$out // \$html
$out // "in-memory scalar"
MC/DC0%0/1
$out // \$html
$out
MC/DC0%0/1
$out // "in-memory scalar"
$out
Truth table50%1/2
A
A= $out
Truth table0%0/2
A
A= $out
| |||||||||||||||||||||||||||||||
| 92 | or die sprintf "Failed to open %s for writing: $!\n", $out // 'in-memory scalar'; | ||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||
| 94 | 3 | print { $fh } ''; | |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||
| 96 | 3 | close $fh; | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||
| 98 | 3 | ▶ | return $out // $html; | ||||||||||||||||||||||||||||
|
Condition33%1/3
$out // $html
MC/DC0%0/2
$out // $html
$out
$html
Truth table33%1/3
A // B
A= $outB= $html
| |||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||
| 102 | # ... or text of any kind | ||||||||||||||||||||||||||||||
| 103 | sub raw { | ||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||
| 105 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
raw: called CC=5 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 106 | 3 | my $out = shift; | |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||
| 108 | 3 | my $raw = ''; | |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||
| 110 | 3 | ▶ | open my $fh, '>', $out // \$raw | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
$out // \$raw
$out // "in-memory scalar"
MC/DC0%0/1
$out // \$raw
$out
MC/DC0%0/1
$out // "in-memory scalar"
$out
Truth table50%1/2
A
A= $out
Truth table0%0/2
A
A= $out
| |||||||||||||||||||||||||||||||
| 111 | or die sprintf "Failed to open %s for writing: $!\n", $out // 'in-memory scalar'; | ||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||
| 113 | 3 | print { $fh } ''; | |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||
| 115 | 3 | close $fh; | |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||
| 117 | 3 | ▶ | return $out // $raw; | ||||||||||||||||||||||||||||
|
Condition33%1/3
$out // $raw
MC/DC0%0/2
$out // $raw
$out
$raw
Truth table33%1/3
A // B
A= $outB= $raw
| |||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||
| 121 | sub metadata { | ||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||
| 123 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
metadata: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||
| 125 | 6 | return $self->{Metadata}; | |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||
| 129 | sub has_cover { | ||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||
| 131 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
has_cover: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||
| 133 | 4 | return !! scalar @{ $self->{_images} }; | |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||
| 137 | sub cover { | ||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||
| 139 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
cover: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||
| 141 | 2 | ▶ | return (undef, undef) unless $self->has_cover; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||
| 143 | 2 | ▶ | open my $fh, '<', $self->{_images}[0][0] | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 144 | or die "Failed to open $self->{_images}[0][0] for reading: $!\n"; | ||||||||||||||||||||||||||||||
| 145 | 2 | binmode $fh; | |||||||||||||||||||||||||||||
| 146 | 2 | my $img = do { local $/; readline $fh }; | |||||||||||||||||||||||||||||
| 147 | 2 | close $fh; | |||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||
| 149 | 2 | return ($img, $self->{_images}[0][1]); | |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||
| 153 | sub image_num { | ||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||
| 155 | 58 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
image_num: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||
| 157 | 58 | return scalar @{ $self->{_images} }; | |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||
| 161 | sub image { | ||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||
| 163 | 56 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
image: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 164 | 56 | my $n = shift; | |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||
| 166 | 56 | ▶ | if ($n >= $self->image_num) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 167 | 0 | return (undef, undef); | |||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||
| 170 | 56 | ▶ | open my $fh, '<', $self->{_images}[$n][0] | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 171 | or die "Failed to open $self->{_images}[$n][0] for reading: $!\n"; | ||||||||||||||||||||||||||||||
| 172 | 56 | binmode $fh; | |||||||||||||||||||||||||||||
| 173 | 56 | my $img = do { local $/; readline $fh }; | |||||||||||||||||||||||||||||
| 174 | 56 | close $fh; | |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||
| 176 | 56 | return ($img, $self->{_images}[$n][1]); | |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||
| 180 | 17 | 1; | |||||||||||||||||||||||||||||