blib/lib/PDF/pdf2json.pm

filter: Statementstmt 100% 37 / 37 Branchbran 60.0% 6 / 10 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 89.6% 52 / 58 CC 7 SCAR 14.8
CC
7
Cov
90%
pdf2json
7.3
BEGIN
1.0
BEGIN
1.0
CRAP 4.4
↑ Summary
1 package PDF::pdf2json;
2 # ABSTRACT: helper module to retrieve data from pdf2json
3 1 $PDF::pdf2json::VERSION = '0.002';
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Alien::pdf2json;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our $alien = Alien::pdf2json->new;
13  
14 2 ▶sub pdf2json {
Subroutine pdf2json: called CC=7 SCAR=19.8
Pod documented
15 2 my ($self, $pdf, %param) = @_;
16 2 ▶ $param{quiet} //= 1;
Condition50%1/2
$param{"quiet"} //= 1
l!l
02
MC/DC0%0/1
$param{"quiet"} //= 1
$param{"quiet"}
Truth table50%1/2
A
A= $param{"quiet"}
Aresult
11
00
17  
18 2 my $temp_fh = File::Temp->new ( UNLINK => 0 );
19 2 my @args = ();
20 2 ▶ if( exists $param{page} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param{"page"}) 1 1 2
21 1 ▶ die "page number must be integer" unless $param{page} =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $param{"page"} =~ /^\d+$/ 0 1 1
22 1 push @args, ( '-f', $param{page} );
23 1 push @args, ( '-l', $param{page} );
24 }
25 2 ▶ if( exists $param{quiet} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param{"quiet"}) 2 0 2
26 2 ▶ push @args, '-q' if !!$param{quiet};
Branch: 1 branch
BranchTrueFalseTotal
unless not $param{"quiet"} 2 0 2
27 }
28 2 my $cmd = [
29 $alien->pdf2json_path,
30 '-enc', 'UTF-8',
31 @args,
32 $pdf,
33 $temp_fh->filename,
34 ];
35 2 my $ret = system( @$cmd );
36 2 ▶ die "pdf2json failed" if $ret;
Branch: 1 branch
BranchTrueFalseTotal
if $ret 0 2 2
37  
38 # read data from temp file
39 2 my $json_data = file( $temp_fh->filename )->slurp();
40  
41 2 my $data = decode_json( $json_data );
42  
43 2 $data;
44 }
45  
46 1 1;
47  
48 __END__
↑ Summary