Dancer/SearchApp/Extractor.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran n/a Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 48 CC 1 SCAR 6.9
CC
1
Cov
0%
examine
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Dancer::SearchApp::Extractor;
2 use strict;
3 #no warnings 'experimental';
4 #use feature 'signatures';
5 use Module::Pluggable search_path => __PACKAGE__, require => 1;
6 use Promises 'collect', 'deferred';
7 use Carp 'croak';
8  
9 use vars qw($VERSION);
10 $VERSION = '0.06';
11  
12 =head1 NAME
13  
14 Dancer::SearchApp::Extractor - metadata extractors
15  
16 =cut
17  
18 =head1 METHODS
19  
20 =head2 C<< ->extract( %options ) >>
21  
22 my $info = $tika->get_meta( $content );
23 my $entry = $extractor->extract(
24 url => $url,
25 info => $info,
26 #content => \$content, # if we have it
27 filename => $file, # if we have it
28 folder => $res{ folder }, # if we have it
29 )->then(sub { ... });
30
31 # Do something with the hashrefs we get back,
32 # like insert the first one into Elasticsearch
33  
34 This method goes through all installed plugins and
35 offers the file for inspection. The C<$info> parameter
36 will contain the information and content extracted by Apache Tika,
37 so especially the MIME type will be available.
38  
39 The method returns a promise so that analysis can happen in the background.
40 The promise will be passed a list of the found items that were not C<undef>.
41 Currently no ranking is performed and all plugins are treated as equally
42 applicable.
43  
44 =cut
45  
46 sub examine {
47 my( $self, %options ) = @_;
48 $options{ url }
49 or croak "Need URL option";
50 $options{ info }
51 or croak "Need info option";
52
53 return collect( map {
54 my $plugin = $_;
55 $plugin->examine(
56 # Yes, copying is a bit inefficient but saves us later headaches
57 %options
58 )
59 } ($self->plugins))->then(sub {
60 my $res = deferred;
61 $res->resolve(
62 map { @$_ }
63 grep { defined $_ and @$_ } @_
64 );
65 $res->promise
66 })->catch( sub {
67 warn __PACKAGE__ . ": @_";
68 });
69 }
70  
71 1;