line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Elastijk; |
2
|
11
|
|
|
11
|
|
1041040
|
use strict; |
|
11
|
|
|
|
|
105
|
|
|
11
|
|
|
|
|
264
|
|
3
|
11
|
|
|
11
|
|
50
|
use warnings; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
384
|
|
4
|
|
|
|
|
|
|
our $VERSION = "0.13"; |
5
|
|
|
|
|
|
|
|
6
|
11
|
|
|
11
|
|
5422
|
use JSON (); |
|
11
|
|
|
|
|
101080
|
|
|
11
|
|
|
|
|
261
|
|
7
|
11
|
|
|
11
|
|
4090
|
use URI::Escape qw(uri_escape_utf8); |
|
11
|
|
|
|
|
11776
|
|
|
11
|
|
|
|
|
545
|
|
8
|
11
|
|
|
11
|
|
4126
|
use Hijk; |
|
11
|
|
|
|
|
80592
|
|
|
11
|
|
|
|
|
4238
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $JSON = JSON->new->utf8; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _build_hijk_request_args { |
13
|
24
|
|
|
24
|
|
3610
|
my $args = $_[0]; |
14
|
24
|
|
|
|
|
32
|
my ($path, $qs, $uri_param); |
15
|
24
|
100
|
|
|
|
60
|
$path = (exists $args->{path}) ? $args->{path} : ("/". join("/", (map { defined($_) ? ( uri_escape_utf8($_) ) : () } @{$args}{qw(index type id)}), (exists $args->{command} ? $args->{command} : ()))); |
|
66
|
100
|
|
|
|
486
|
|
|
22
|
100
|
|
|
|
49
|
|
16
|
24
|
100
|
|
|
|
135
|
if ($args->{uri_param}) { |
17
|
4
|
|
|
|
|
8
|
$qs = join('&', map { uri_escape_utf8($_) . "=" . uri_escape_utf8($args->{uri_param}{$_}) } keys %{$args->{uri_param}}); |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
11
|
|
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
return { |
20
|
|
|
|
|
|
|
method => $args->{method} || 'GET', |
21
|
|
|
|
|
|
|
host => $args->{host} || 'localhost', |
22
|
|
|
|
|
|
|
port => $args->{port} || '9200', |
23
|
|
|
|
|
|
|
path => $path, |
24
|
|
|
|
|
|
|
head => [ |
25
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
26
|
0
|
|
|
|
|
0
|
( (exists $args->{head}) ? (@{$args->{head}}) : ()), |
27
|
|
|
|
|
|
|
], |
28
|
|
|
|
|
|
|
$qs?( query_string => $qs) :(), |
29
|
24
|
50
|
100
|
|
|
287
|
(map { (exists $args->{$_})?( $_ => $args->{$_} ) :() } qw(connect_timeout read_timeout body socket_cache on_connect)), |
|
120
|
100
|
100
|
|
|
230
|
|
|
|
100
|
100
|
|
|
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub request { |
34
|
16
|
|
|
16
|
1
|
22
|
my $arg = $_[0]; |
35
|
16
|
100
|
|
|
|
30
|
if ($arg->{body}) { |
36
|
5
|
|
|
|
|
7
|
$arg = {%{$_[0]}}; |
|
5
|
|
|
|
|
18
|
|
37
|
5
|
|
|
|
|
55
|
$arg->{body} = $JSON->encode( $arg->{body} ); |
38
|
|
|
|
|
|
|
} |
39
|
16
|
|
|
|
|
30
|
my ($status, $res_body) = request_raw($arg); |
40
|
16
|
100
|
|
|
|
32
|
$res_body = $res_body ? eval { $JSON->decode($res_body) } : undef; |
|
1
|
|
|
|
|
5
|
|
41
|
16
|
|
|
|
|
41
|
return $status, $res_body; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub request_raw { |
45
|
18
|
|
|
18
|
1
|
1739
|
my $args = _build_hijk_request_args($_[0]); |
46
|
18
|
|
|
|
|
43
|
my $res = Hijk::request($args); |
47
|
18
|
100
|
|
|
|
118
|
return (exists $res->{error}) ? (0, '{"error":1,"hijk_error":'.$res->{error}.'}') : ($res->{status}, $res->{body}); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new { |
51
|
3
|
|
|
3
|
0
|
6845
|
shift; |
52
|
3
|
|
|
|
|
1121
|
require Elastijk::oo; |
53
|
3
|
|
|
|
|
28
|
return Elastijk::oo->new(@_); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__ |