line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Apache::Tika::Async; |
2
|
1
|
|
|
1
|
|
537
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
3
|
1
|
|
|
1
|
|
6
|
use Moo 2; |
|
1
|
|
|
|
|
18
|
|
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
1015
|
use JSON::XS qw(decode_json); |
|
1
|
|
|
|
|
4918
|
|
|
1
|
|
|
|
|
581
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Apache::Tika::Async - connect to Apache Tika |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Apache::Tika::Async; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $tika= Apache::Tika::Async->new; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $fn= shift; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Data::Dumper; |
21
|
|
|
|
|
|
|
my $info = $tika->get_all( $fn ); |
22
|
|
|
|
|
|
|
print Dumper $info->meta($fn); |
23
|
|
|
|
|
|
|
print $info->content($fn); |
24
|
|
|
|
|
|
|
# ... |
25
|
|
|
|
|
|
|
print $info->meta->{"meta:language"}; |
26
|
|
|
|
|
|
|
# en |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has java => ( |
31
|
|
|
|
|
|
|
is => 'rw', |
32
|
|
|
|
|
|
|
#isa => 'Str', |
33
|
|
|
|
|
|
|
default => 'java', |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has 'jarfile' => ( |
37
|
|
|
|
|
|
|
is => 'rw', |
38
|
|
|
|
|
|
|
#isa => 'Str', |
39
|
|
|
|
|
|
|
#default => 'jar/tika-server-1.5-20130816.014724-18.jar', |
40
|
|
|
|
|
|
|
default => sub { |
41
|
|
|
|
|
|
|
# Do a natural sort on the dot-version |
42
|
|
|
|
|
|
|
(sort { my $ad; $a =~ /server-1.(\d+)/ and $ad=$1; |
43
|
|
|
|
|
|
|
my $bd; $b =~ /server-1.(\d+)/ and $bd=$1; |
44
|
|
|
|
|
|
|
$bd <=> $ad |
45
|
|
|
|
|
|
|
} glob 'jar/tika-server-*.jar')[0] |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has java_args => ( |
50
|
|
|
|
|
|
|
is => 'rw', |
51
|
|
|
|
|
|
|
#isa => 'Array', |
52
|
|
|
|
|
|
|
builder => sub { [ |
53
|
|
|
|
|
|
|
# So that Tika can re-read some problematic PDF files better |
54
|
0
|
|
|
0
|
|
|
'-Dorg.apache.pdfbox.baseParser.pushBackSize=1000000' |
55
|
|
|
|
|
|
|
] }, |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
has tika_args => ( |
59
|
|
|
|
|
|
|
is => 'rw', |
60
|
|
|
|
|
|
|
#isa => 'Array', |
61
|
|
|
|
|
|
|
default => sub { [ ] }, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub cmdline { |
65
|
0
|
|
|
0
|
0
|
|
my( $self )= @_; |
66
|
|
|
|
|
|
|
$self->java, |
67
|
0
|
|
|
|
|
|
@{$self->java_args}, |
68
|
|
|
|
|
|
|
'-jar', |
69
|
|
|
|
|
|
|
$self->jarfile, |
70
|
0
|
|
|
|
|
|
@{$self->tika_args}, |
|
0
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
}; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub fetch { |
74
|
0
|
|
|
0
|
0
|
|
my( $self, %options )= @_; |
75
|
0
|
|
|
|
|
|
my @cmd= $self->cmdline; |
76
|
0
|
|
|
|
|
|
push @cmd, $options{ type }; |
77
|
0
|
|
|
|
|
|
push @cmd, $options{ filename }; |
78
|
0
|
|
|
|
|
|
@cmd= map { qq{"$_"} } @cmd; |
|
0
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
die "Fetching from local process is currently disabled"; |
80
|
|
|
|
|
|
|
#warn "[@cmd]"; |
81
|
0
|
|
|
|
|
|
''.`@cmd` |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub decode_csv { |
85
|
0
|
|
|
0
|
0
|
|
my( $self, $line )= @_; |
86
|
0
|
|
|
|
|
|
$line =~ m!"([^"]+)"!g; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub get_meta { |
90
|
0
|
|
|
0
|
0
|
|
my( $self, $file )= @_; |
91
|
|
|
|
|
|
|
#return decode_json($self->fetch( filename => $file, type => 'meta' )); |
92
|
|
|
|
|
|
|
# Hacky CSV-to-hash decode :-/ |
93
|
0
|
|
|
|
|
|
return $self->fetch( filename => $file, type => 'meta' )->meta; |
94
|
|
|
|
|
|
|
}; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub get_text { |
97
|
0
|
|
|
0
|
0
|
|
my( $self, $file )= @_; |
98
|
0
|
|
|
|
|
|
return $self->fetch( filename => $file, type => 'text' ); |
99
|
|
|
|
|
|
|
}; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub get_test { |
102
|
0
|
|
|
0
|
0
|
|
my( $self, $file )= @_; |
103
|
0
|
|
|
|
|
|
return $self->fetch( filename => $file, type => 'test' ); |
104
|
|
|
|
|
|
|
}; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub get_all { |
107
|
0
|
|
|
0
|
0
|
|
my( $self, $file )= @_; |
108
|
0
|
|
|
|
|
|
return $self->fetch( filename => $file, type => 'all' ); |
109
|
|
|
|
|
|
|
}; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub get_language { |
112
|
0
|
|
|
0
|
0
|
|
my( $self, $file )= @_; |
113
|
0
|
|
|
|
|
|
return $self->fetch( filename => $file, type => 'language' ); |
114
|
|
|
|
|
|
|
}; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 REPOSITORY |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
The public repository of this module is |
123
|
|
|
|
|
|
|
L. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SUPPORT |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
The public support forum of this module is |
128
|
|
|
|
|
|
|
L. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 BUG TRACKER |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Please report bugs in this module via the RT CPAN bug queue at |
133
|
|
|
|
|
|
|
L |
134
|
|
|
|
|
|
|
or via mail to L. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 AUTHOR |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Max Maischein C |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 COPYRIGHT (c) |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Copyright 2014-2019 by Max Maischein C. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 LICENSE |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This module is released under the same terms as Perl itself. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |