line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Elastijk; |
2
|
10
|
|
|
10
|
|
184375
|
use strict; |
|
10
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
241
|
|
3
|
10
|
|
|
10
|
|
30
|
use warnings; |
|
10
|
|
|
|
|
13
|
|
|
10
|
|
|
|
|
329
|
|
4
|
|
|
|
|
|
|
our $VERSION = "0.11"; |
5
|
|
|
|
|
|
|
|
6
|
10
|
|
|
10
|
|
5161
|
use JSON (); |
|
10
|
|
|
|
|
91616
|
|
|
10
|
|
|
|
|
273
|
|
7
|
10
|
|
|
10
|
|
4139
|
use URI::Escape qw(uri_escape_utf8); |
|
10
|
|
|
|
|
14476
|
|
|
10
|
|
|
|
|
556
|
|
8
|
10
|
|
|
10
|
|
3585
|
use Hijk; |
|
10
|
|
|
|
|
97661
|
|
|
10
|
|
|
|
|
3115
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $JSON = JSON->new->utf8; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _build_hijk_request_args { |
13
|
22
|
|
|
22
|
|
1941
|
my $args = $_[0]; |
14
|
22
|
|
|
|
|
21
|
my ($path, $qs, $uri_param); |
15
|
22
|
100
|
|
|
|
25
|
$path = "/". join("/", (map { defined($_) ? ( uri_escape_utf8($_) ) : () } @{$args}{qw(index type id)}), (exists $args->{command} ? $args->{command} : ())); |
|
66
|
100
|
|
|
|
345
|
|
|
22
|
|
|
|
|
40
|
|
16
|
22
|
100
|
|
|
|
87
|
if ($args->{uri_param}) { |
17
|
4
|
|
|
|
|
5
|
$qs = join('&', map { uri_escape_utf8($_) . "=" . uri_escape_utf8($args->{uri_param}{$_}) } keys %{$args->{uri_param}}); |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
10
|
|
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
return { |
20
|
|
|
|
|
|
|
method => $args->{method} || 'GET', |
21
|
|
|
|
|
|
|
host => $args->{host} || 'localhost', |
22
|
|
|
|
|
|
|
port => $args->{port} || '9200', |
23
|
|
|
|
|
|
|
path => $path, |
24
|
|
|
|
|
|
|
$qs?( query_string => $qs) :(), |
25
|
22
|
100
|
100
|
|
|
196
|
(map { (exists $args->{$_})?( $_ => $args->{$_} ) :() } qw(connect_timeout read_timeout head body socket_cache on_connect)), |
|
132
|
100
|
100
|
|
|
191
|
|
|
|
|
100
|
|
|
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub request { |
30
|
14
|
|
|
14
|
1
|
14
|
my $arg = $_[0]; |
31
|
14
|
100
|
|
|
|
26
|
if ($arg->{body}) { |
32
|
5
|
|
|
|
|
4
|
$arg = {%{$_[0]}}; |
|
5
|
|
|
|
|
18
|
|
33
|
5
|
|
|
|
|
65
|
$arg->{body} = $JSON->encode( $arg->{body} ); |
34
|
|
|
|
|
|
|
} |
35
|
14
|
|
|
|
|
19
|
my ($status, $res_body) = request_raw($arg); |
36
|
14
|
100
|
|
|
|
31
|
$res_body = $res_body ? eval { $JSON->decode($res_body) } : undef; |
|
1
|
|
|
|
|
6
|
|
37
|
14
|
|
|
|
|
34
|
return $status, $res_body; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub request_raw { |
41
|
16
|
|
|
16
|
1
|
785
|
my $args = _build_hijk_request_args($_[0]); |
42
|
16
|
|
|
|
|
38
|
my $res = Hijk::request($args); |
43
|
16
|
100
|
|
|
|
88
|
return (exists $res->{error}) ? (0, '{"error":1,"hijk_error":'.$res->{error}.'}') : ($res->{status}, $res->{body}); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new { |
47
|
3
|
|
|
3
|
0
|
3584
|
shift; |
48
|
3
|
|
|
|
|
1062
|
require Elastijk::oo; |
49
|
3
|
|
|
|
|
22
|
return Elastijk::oo->new(@_); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |