File Coverage

blib/lib/EBook/Ishmael/EBook/CB7.pm
Criterion Covered Total %
statement 21 36 58.3
branch 1 6 16.6
condition n/a
subroutine 7 10 70.0
pod 0 3 0.0
total 29 55 52.7


line stmt bran cond sub pod time code
1             package EBook::Ishmael::EBook::CB7;
2 17     17   285 use 5.016;
  17         82  
3             our $VERSION = '2.03';
4 17     17   92 use strict;
  17         32  
  17         464  
5 17     17   73 use warnings;
  17         33  
  17         972  
6              
7 17     17   6412 use parent 'EBook::Ishmael::EBook::CB';
  17         4276  
  17         182  
8              
9 17     17   1109 use File::Which;
  17         39  
  17         1094  
10              
11 17     17   8968 use EBook::Ishmael::ShellQuote qw(safe_qx);
  17         54  
  17         7853  
12              
13             my $MAGIC = pack "C*", 0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c;
14              
15             my $SZIP;
16             for my $b (qw(7z 7za)) {
17             if (defined which($b)) {
18             $SZIP = $b;
19             last;
20             }
21             }
22              
23             our $CAN_TEST = defined $SZIP;
24              
25             sub heuristic {
26              
27 126     126 0 331 my $class = shift;
28 126         325 my $file = shift;
29 126         328 my $fh = shift;
30              
31 126 50       989 return 0 unless $file =~ /\.cb7$/;
32              
33 0           read $fh, my $mag, length $MAGIC;
34              
35 0           return $mag eq $MAGIC;
36              
37             }
38              
39             sub _un7zip {
40              
41 0     0     my $zip = shift;
42 0           my $out = shift;
43              
44 0 0         unless (defined $SZIP) {
45 0           die "Cannot un-7zip $zip; 7z not installed\n";
46             }
47              
48 0           safe_qx($SZIP, 'x', "-o$out", $zip);
49 0 0         unless ($? >> 8 == 0) {
50 0           die "Failed to run '$SZIP' on $zip\n";
51             }
52              
53 0           return 1;
54              
55             }
56              
57             sub extract {
58              
59 0     0 0   my $self = shift;
60 0           my $out = shift;
61              
62 0           _un7zip($self->{Source}, $out);
63              
64 0           return 1;
65              
66             }
67              
68 0     0 0   sub format { 'CB7' }
69              
70             1;