OCR.pm

filter: Statementstmt 43.9% 29 / 66 Branchbran 27.7% 5 / 18 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 50.0% 7 / 14 Podpod 55.5% 5 / 9 totaltotal 41.8% 46 / 110 CC 13 SCAR 18.5
CC
13
Cov
40%
_get_ocr
20.0
abs_images
6.3
get_ocr
6.0
CRAP 6.4
↑ Summary OCR/Thorough.pm »
1 package PDF::OCR;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use vars qw($VERSION $DEBUG);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 $VERSION = sprintf "%d.%02d", q$Revision: 1.11 $ =~ /(\d+)/g;
6  
7 0 ▶sub DEBUG : lvalue { $DEBUG }
Subroutine DEBUG: not called CC=1 SCAR=6.9
Pod undocumented
8  
9 1 ▶sub new {
Subroutine new: called CC=5 SCAR=16.6
Pod documented
10 1 my($class, $arg) = @_;
11 1 ▶ $arg or croak("missing argument to constructor");
Branch: 1 branch
BranchTrueFalseTotal
$arg or croak("missing argument to constructor") 1 0 1
12 1 my $self = {};
13  
14
15 1 require Cwd;
16 1 ▶ my $abs = Cwd::abs_path($arg)
Branch: 1 branch
BranchTrueFalseTotal
my $abs = Cwd::abs_path($arg) or croak("[$arg] not resolving with Cwd::abs_path()") 1 0 1
17 or croak("[$arg] not resolving with Cwd::abs_path()");
18  
19 1 ▶ $abs=~/\.pdf$/i
Branch: 1 branch
BranchTrueFalseTotal
$abs =~ /\.pdf$/i or croak("[$arg] cant match pdf ext in filename") 1 0 1
20 or croak("[$arg] cant match pdf ext in filename");
21  
22 1 ▶ -f $abs
Branch: 1 branch
BranchTrueFalseTotal
-f $abs or croak("[$abs] is not file.") 1 0 1
23 or croak("[$abs] is not file.");
24  
25 1 $self->{abs_pdf} = $abs;
26
27 1 bless $self,$class;
28 1 return $self;
29 }
30  
31 0 ▶sub abs_pdf {
Subroutine abs_pdf: not called CC=1 SCAR=6.9
Pod undocumented
32 0 my $self = shift;
33 0 return $self->{abs_pdf};
34 }
35  
36 0 ▶sub abs_tmp {
Subroutine abs_tmp: not called CC=1 SCAR=6.9
Pod undocumented
37 0 my $self= shift;
38 0 return $self->{abs_tmp};
39 }
40  
41  
42 2 ▶sub abs_images {
Subroutine abs_images: called CC=3 SCAR=18.4
Pod documented
43 2 my $self = shift;
44  
45 2 ▶ unless( defined $self->{abs_images}){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"abs_images"}) 2 0 2
46 2 require PDF::GetImages;
47 0 my $images = PDF::GetImages::pdfimages($self->abs_pdf);
48 0 ▶ unless( scalar @$images ){
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$images) 0 0 0
49 0 warn("no images in ".$self->abs_pdf);
50 0 $self->{abs_images} = [];
51 0 return [];
52 }
53 0 $self->{abs_images} = $images;
54 }
55
56 0 return $self->{abs_images};
57 }
58  
59 0 ▶sub abs_images_count {
Subroutine abs_images_count: not called CC=1 SCAR=6.9
Pod undocumented
60 0 my $self = shift;
61 0 return scalar @{$self->abs_images};
62 }
63  
64  
65  
66  
67 0 ▶sub get_ocr {
Subroutine get_ocr: not called CC=2 SCAR=17.9
Pod documented
68 0 my ($self,$abs)= @_;
69
70 0 ▶ if(defined $abs){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $abs) 0 0 0
71 0 return $self->_get_ocr($abs);
72 }
73  
74 0 my $ocr = join( "\f", @{$self->get_ocr_arrayref} );
75 0 return $ocr;
76 }
77  
78  
79  
80  
81  
82 0 ▶sub _get_ocr {
Subroutine _get_ocr: not called CC=4 SCAR=30.0
83 0 my ($self,$abs)= @_;
84 0 ▶ defined $abs or confess('missing arg');
Branch: 1 branch
BranchTrueFalseTotal
defined $abs or confess("missing arg") 0 0 0
85 0 ▶ $self->{ocr} ||={};
Condition0%0/2
$self->{"ocr"} ||= {}
l!l
00
MC/DC0%0/1
$self->{"ocr"} ||= {}
$self->{"ocr"}
Truth table0%0/2
A
A= $self->{"ocr"}
Aresult
11
00
86 0 ▶ unless( defined $self->{ocr}->{$abs} ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"ocr"}{$abs}) 0 0 0
87 # TODO could check that this *IS* one of the files extracted
88 0 require Image::OCR::Tesseract;
89 0 my $content = Image::OCR::Tesseract::get_ocr($abs);
90 0 $self->{ocr}->{$abs} = $content;
91 }
92  
93 0 return $self->{ocr}->{$abs};
94 }
95  
96  
97  
98  
99 0 ▶sub get_ocr_arrayref {
Subroutine get_ocr_arrayref: not called CC=2 SCAR=17.9
Pod documented
100 0 my ($self)= @_;
101
102 0 my $ocr = [];
103 0 for( @{$self->abs_images} ){
104 0 push @$ocr, $self->get_ocr($_);
105 }
106  
107 0 return $ocr;
108 }
109  
110  
111 1 ▶sub cleanup {
Subroutine cleanup: called CC=2 SCAR=8.1
Pod documented
112 1 my $self = shift;
113
114 1 for(@{$self->abs_images}){
115 0 unlink $_;
116 }
117 0 return 1;
118 }
119  
120 1 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
121 1 my $self = shift;
122 1 $self->cleanup;
123 }
124  
125  
126 1 1;
127  
128  
129 __END__
↑ Summary OCR/Thorough.pm »