Dancer/SearchApp/Extractor/PDF.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 52 CC 2 SCAR 11.5
CC
2
Cov
0%
examine
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.1
1 package Dancer::SearchApp::Extractor::PDF;
2 use strict;
3 use Carp 'croak';
4 use Promises 'deferred';
5 use Dancer::SearchApp::HTMLSnippet;
6  
7 use vars qw($VERSION);
8 $VERSION = '0.06';
9  
10 =head1 File types
11  
12 # index pdfs page by page and link to it by #page=10
13 # rewrite Tika PDF pages to include the page number for easy snippet
14 # location
15 # lightning talk ;)
16  
17 This rewrites the HTML created by Tika for PDF files to include line
18 numbers.
19  
20 =cut
21  
22 sub examine {
23 my( $class, %options ) = @_;
24 my $info = $options{info};
25
26 my $result = deferred;
27 my $meta = $options{meta};
28 my $mime_type = $meta->{"Content-Type"};
29
30 if( $mime_type =~ m!^application/pdf$! ) {
31 my %res = (
32 url => $options{ url },
33 file => $options{ filename },
34 folder => $options{ folder },
35 );
36 my $file = $options{ filename };
37
38 my $c = $info->content;
39 my $r = Dancer::SearchApp::HTMLSnippet->cleanup_tika( $c );
40  
41 $res{ title } = $meta->{"dc:title"} || $meta->{"title"} || $file->basename;
42 $res{ author } = $meta->{"meta:author"}; # as HTML
43 $res{ language } = $meta->{"meta:language"};
44 $res{ mime_type } = $meta->{"Content-Type"};
45 $res{ content } = $r; # as HTML
46
47 $result->resolve( \%res );
48 } else {
49 $result->resolve();
50 }
51
52 $result->promise
53 }
54  
55 1;