blib/lib/Elastijk.pm

filter: Statementstmt 100% 44 / 44 Branchbran 100% 16 / 16 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 9 / 9 Podpod 66.6% 2 / 3 totaltotal 98.7% 80 / 81 SCAR 24.8
CC
12
Cov
100%
_build_hijk_request_args
9.0
request
3.0
request_raw
2.0
CRAP 12.0
« blib/lib/Elastijk/oo.pm ↑ Summary Build »
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
BranchTrueFalseTotal
defined $_ ? : 30 36 66
exists $args->{'command'} ? : 7 15 22
16 22 ▶ if ($args->{uri_param}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"uri_param"}) 4 18 22
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
BranchTrueFalseTotal
$qs ? : 4 18 22
exists $args->{$_} ? : 9 123 132
Condition100%6/6
$args->{'method'} || 'GET'
l!l
193
$args->{'host'} || 'localhost'
l!l
202
$args->{'port'} || '9200'
l!l
202
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'}
Aresult
11
00
Truth table100%2/2
A
A= $args->{'host'}
Aresult
11
00
Truth table100%2/2
A
A= $args->{'port'}
Aresult
11
00
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
BranchTrueFalseTotal
if ($arg->{"body"}) 5 9 14
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
BranchTrueFalseTotal
$res_body ? : 1 13 14
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
BranchTrueFalseTotal
exists $res->{'error'} ? : 2 14 16
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__
« blib/lib/Elastijk/oo.pm ↑ Summary Build »