line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer2::Plugin::ElasticSearch; |
2
|
|
|
|
|
|
|
$Dancer2::Plugin::ElasticSearch::VERSION = '0.004'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Dancer2 plugin for obtaining Search::Elasticsearch handles |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
652194
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
7
|
1
|
|
|
1
|
|
16
|
use 5.012; |
|
1
|
|
|
|
|
3
|
|
8
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
9
|
1
|
|
|
1
|
|
5
|
use autodie; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
10
|
1
|
|
|
1
|
|
4205
|
use utf8; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
7
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
472
|
use Search::Elasticsearch; |
|
1
|
|
|
|
|
20296
|
|
|
1
|
|
|
|
|
23
|
|
13
|
1
|
|
|
1
|
|
434
|
use Dancer2::Plugin; |
|
1
|
|
|
|
|
10778
|
|
|
1
|
|
|
|
|
7
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $handles = {}; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
register 'elastic' => sub { |
18
|
1
|
|
|
1
|
|
142960
|
my ($dsl, $name) = @_; |
19
|
1
|
|
50
|
|
|
27
|
$name //= 'default'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# the classic fork/thread-safety mantra |
22
|
1
|
50
|
|
|
|
6
|
my $pid_tid = $$ . ($INC{'threads.pm'} ? '_' . threads->tid : ''); |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
3
|
my $elastic; |
25
|
1
|
50
|
|
|
|
4
|
if ($elastic = $handles->{$pid_tid}{$name}) { |
26
|
|
|
|
|
|
|
# got one from the cache. done |
27
|
|
|
|
|
|
|
} else { |
28
|
|
|
|
|
|
|
# no handle in the cache, create one and stash it |
29
|
1
|
|
|
|
|
5
|
my $plugin_config = plugin_setting(); |
30
|
1
|
50
|
|
|
|
135
|
unless (exists $plugin_config->{$name}) { |
31
|
0
|
|
|
|
|
0
|
die "No config for ElasticSearch client '$name'"; |
32
|
|
|
|
|
|
|
} |
33
|
1
|
|
|
|
|
3
|
my $config = $plugin_config->{$name}; |
34
|
1
|
|
50
|
|
|
4
|
my $params = $config->{params} // {}; |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
2
|
$elastic = Search::Elasticsearch->new(%{$params}); |
|
1
|
|
|
|
|
74
|
|
37
|
|
|
|
|
|
|
# try the connection; the ES client will throw a NoNodes |
38
|
|
|
|
|
|
|
# exception if something is wrong |
39
|
1
|
|
|
|
|
189669
|
$elastic->ping; |
40
|
0
|
|
|
|
|
|
$handles->{$pid_tid}{$name} = $elastic; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return $elastic; |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
register_plugin; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |