blib/lib/DjVu/Detect.pm

filter: Statementstmt 94.7% 36 / 38 Branchbran 70.0% 7 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 92.0% 58 / 63 CC 7 SCAR 10.8
CC
7
Cov
90%
detect_djvu_file
5.0
detect_djvu_chunk
3.3
BEGIN
1.0
CRAP 2.9
↑ Summary
1 package DjVu::Detect;
2  
3 4 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Alien::DjVuLibre;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use File::Spec::Functions qw(catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 Readonly::Array our @EXPORT_OK => qw(detect_djvu_chunk detect_djvu_file);
12  
13 4 our $VERSION = 0.05;
14  
15 2 ▶sub detect_djvu_chunk {
Subroutine detect_djvu_chunk: called CC=3 SCAR=12.0
Pod documented
16 2 my ($file, $chunk_name) = @_;
17  
18 2 my $djvudump = catfile(Alien::DjVuLibre->bin_dir, 'djvudump');
19 2 ▶ if (! -e $djvudump) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $djvudump) 0 2 2
20 0 err "Program 'djvudump' doesn't exists.";
21 }
22  
23 2 my $djvudump_output = `$djvudump $file`;
24  
25 2 ▶ if ($djvudump_output =~ m/$chunk_name/ms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($djvudump_output =~ /$chunk_name/ms) { } 0 2 2
26 0 return 1;
27 } else {
28 2 return 0;
29 }
30 }
31  
32 # Detect DjVu file.
33 4 ▶sub detect_djvu_file {
Subroutine detect_djvu_file: called CC=5 SCAR=16.1
Pod documented
34 4 my $file = shift;
35  
36 4 my $dwg_flag = 0;
37 4 ▶ open my $fh, '<', $file or err "Cannot open file '$file'.";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or err("Cannot open file '${file}'.") 3 1 4
38 3 my $magic;
39 3 my $read = read $fh, $magic, 8;
40 3 ▶ close $fh or err "Cannot close file '$file'.";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or err("Cannot close file '${file}'.") 3 0 3
41  
42 3 ▶ if ($read == 8 && $magic eq 'AT&TFORM') {
Branch: 1 branch
BranchTrueFalseTotal
if ($read == 8 and $magic eq 'AT&TFORM') { } 1 2 3
Condition100%3/3
$read == 8 and $magic eq "AT&TFORM"
!ll&&!rl&&r
111
MC/DC100%2/2
$read == 8 and $magic eq "AT&TFORM"
$read == 8 $magic eq "AT&TFORM"
Truth table100%3/3
A and B
A= $read == 8B= $magic eq "AT&TFORM"
ABresult
0X0
100
111
43 1 return 1;
44 } else {
45 2 return 0;
46 }
47 }
48  
49 4 1;
50  
51 __END__
↑ Summary