| 1 | package Elastijk; | ||||||||||||||||||||||||||||||||||||||||||||
| 2 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | our $VERSION = "0.12"; | |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use JSON (); | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use URI::Escape qw(uri_escape_utf8); | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use Hijk; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | our $JSON = JSON->new->utf8; | |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | sub _build_hijk_request_args { | ||||||||||||||||||||||||||||||||||||||||||||
| 13 | 22 | ▶ | my $args = $_[0]; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_hijk_request_args: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 14 | 22 | my ($path, $qs, $uri_param); | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 22 | ▶ | $path = "/". join("/", (map { defined($_) ? ( uri_escape_utf8($_) ) : () } @{$args}{qw(index type id)}), (exists $args->{command} ? $args->{command} : ())); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 22 | ▶ | if ($args->{uri_param}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | $qs = join('&', map { uri_escape_utf8($_) . "=" . uri_escape_utf8($args->{uri_param}{$_}) } keys %{$args->{uri_param}}); | |||||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | (map { (exists $args->{$_})?( $_ => $args->{$_} ) :() } qw(connect_timeout read_timeout head body socket_cache on_connect)), | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
$args->{'method'} || 'GET'
$args->{'host'} || 'localhost'
$args->{'port'} || '9200'
MC/DC100%1/1
$args->{'method'} || 'GET'
$args->{'method'}
MC/DC100%1/1
$args->{'host'} || 'localhost'
$args->{'host'}
MC/DC100%1/1
$args->{'port'} || '9200'
$args->{'port'}
Truth table100%2/2
A
A= $args->{'method'}
Truth table100%2/2
A
A= $args->{'host'}
Truth table100%2/2
A
A= $args->{'port'}
| |||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | sub request { | ||||||||||||||||||||||||||||||||||||||||||||
| 30 | 14 | ▶ | my $arg = $_[0]; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 31 | 14 | ▶ | if ($arg->{body}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 32 | 5 | $arg = {%{$_[0]}}; | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 5 | $arg->{body} = $JSON->encode( $arg->{body} ); | |||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 35 | 14 | my ($status, $res_body) = request_raw($arg); | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 14 | ▶ | $res_body = $res_body ? eval { $JSON->decode($res_body) } : undef; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 14 | return $status, $res_body; | |||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | sub request_raw { | ||||||||||||||||||||||||||||||||||||||||||||
| 41 | 16 | ▶ | my $args = _build_hijk_request_args($_[0]); | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request_raw: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 16 | my $res = Hijk::request($args); | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 16 | ▶ | return (exists $res->{error}) ? (0, '{"error":1,"hijk_error":'.$res->{error}.'}') : ($res->{status}, $res->{body}); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | require Elastijk::oo; | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | return Elastijk::oo->new(@_); | |||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||