| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 3 | ▶ | if ($read == 8 && $magic eq 'AT&TFORM') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$read == 8 and $magic eq "AT&TFORM"
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"
| |||||||||||||||||||||||||||||
| 43 | 1 | return 1; | |||||||||||||||||||||||||||
| 44 | } else { | ||||||||||||||||||||||||||||
| 45 | 2 | return 0; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 4 | 1; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | __END__ | ||||||||||||||||||||||||||||