| 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
MC/DC0%0/1
$param{"quiet"} //= 1
$param{"quiet"}
Truth table50%1/2
A
A= $param{"quiet"}
| |||||||||||||
| 17 | |||||||||||||
| 18 | 2 | my $temp_fh = File::Temp->new ( UNLINK => 0 ); | |||||||||||
| 19 | 2 | my @args = (); | |||||||||||
| 20 | 2 | ▶ | if( exists $param{page} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 21 | 1 | ▶ | die "page number must be integer" unless $param{page} =~ /^\d+$/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 22 | 1 | push @args, ( '-f', $param{page} ); | |||||||||||
| 23 | 1 | push @args, ( '-l', $param{page} ); | |||||||||||
| 24 | } | ||||||||||||
| 25 | 2 | ▶ | if( exists $param{quiet} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | 2 | ▶ | push @args, '-q' if !!$param{quiet}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 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__ | ||||||||||||