blib/lib/EBook/Ishmael/EBook/CBR.pm

filter: Statementstmt 62.2% 28 / 45 Branchbran 25.0% 2 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 3 totaltotal 56.0% 37 / 66 CC 4 SCAR 13.6
CC
4
Cov
57%
_unrar
12.0
heuristic
2.2
extract
2.0
CRAP 3.9
« blib/lib/EBook/Ishmael/EBook/CB7.pm ↑ Summary blib/lib/EBook/Ishmael/CharDet/Big5.pm »
1 package EBook::Ishmael::EBook::CBR;
2 17 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 17 our $VERSION = '2.03';
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 parent 'EBook::Ishmael::EBook::CB';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 17 ▶use File::Which;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 17 ▶use EBook::Ishmael::ShellQuote qw(safe_qx);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # TODO: Create new CBR test file that uses older RAR version, so that tests
14 # on systems with older unrar's can pass.
15  
16 17 my $MAGIC = pack "C*", 0x52, 0x61, 0x72, 0x21, 0x1a, 0x07;
17  
18 17 my $UNRAR;
19 17 for my $b (qw(unrar UnRAR)) {
20 34 ▶ if (defined which($b)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined which($b)) 0 34 34
21 0 $UNRAR = $b;
22 0 last;
23 }
24 }
25  
26 17 our $CAN_TEST = defined $UNRAR;
27  
28 sub heuristic {
29  
30 126 ▶ my $class = shift;
Subroutine heuristic: called CC=2 SCAR=7.9
Pod undocumented
31 126 my $file = shift;
32 126 my $fh = shift;
33  
34 126 ▶ return 0 unless $file =~ /\.cbr$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /\.cbr$/u 126 0 126
35  
36 0 read $fh, my $mag, length $MAGIC;
37  
38 0 return $mag eq $MAGIC;
39  
40 }
41  
42 sub _unrar {
43  
44 0 ▶ my $rar = shift;
Subroutine _unrar: not called CC=3 SCAR=24.8
45 0 my $out = shift;
46  
47 0 ▶ unless (defined $UNRAR) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $UNRAR) 0 0 0
48 0 die "Cannot unrar $rar; unrar not installed\n";
49 }
50  
51 0 safe_qx($UNRAR, 'x', $rar, $out);
52 0 ▶ unless ($? >> 8 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($? >> 8 == 0) 0 0 0
53 0 die "Failed to run '$UNRAR' on $rar\n";
54 }
55  
56 0 return 1;
57  
58 }
59  
60 sub extract {
61  
62 0 ▶ my $self = shift;
Subroutine extract: not called CC=1 SCAR=6.9
Pod undocumented
63 0 my $out = shift;
64  
65 0 _unrar($self->{Source}, $out);
66  
67 0 return 1;
68  
69 }
70  
71 0 ▶sub format { 'CBR' }
Subroutine format: not called CC=1 SCAR=6.9
Pod undocumented
72  
73 17 1;
« blib/lib/EBook/Ishmael/EBook/CB7.pm ↑ Summary blib/lib/EBook/Ishmael/CharDet/Big5.pm »