blib/lib/Elastijk/oo.pm

filter: Statementstmt 48.6% 36 / 74 Branchbran 8.3% 1 / 12 Conditioncond 9.0% 1 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 65.0% 13 / 20 Podpod 0.0% 0 / 14 totaltotal 36.9% 51 / 138 SCAR 37.9
CC
12
Cov
39%
scan_scroll
72.0
bulk
6.0
__fleshen_request_args
3.3
CRAP 44.4
↑ Summary blib/lib/Elastijk.pm »
1 package Elastijk::oo;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Elastijk;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 sub new {
7 100005 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
8 100005 return bless { host => "localhost", port => "9200", @_ }, $class;
9 }
10  
11 {
12 3 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 100002 ▶ *Elastijk::new = sub { shift; Elastijk::oo->new(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
14 };
15  
16 sub __fleshen_request_args {
17 14 ▶ my ($self, $args) = @_;
Subroutine __fleshen_request_args: called CC=3 SCAR=12.0
18 14 ▶ $args->{$_} ||= $self->{$_} for grep { exists $self->{$_} } qw(host port index type head socket_cache on_connect connect_timeout read_timeout);
Condition33%1/3
$args->{$_} ||= $self->{$_}
l!l&&r!l&&!r
0310
MC/DC0%0/2
$args->{$_} ||= $self->{$_}
$args->{$_} $self->{$_}
Truth table33%1/3
A ||= B
A= $args->{$_}B= $self->{$_}
ABresult
1X1
011
000
19 }
20  
21 sub request {
22 14 ▶ my ($self, %args) = @_;
Subroutine request: called CC=1 SCAR=0.0
Pod undocumented
23 14 __fleshen_request_args($self, \%args);
24 14 return Elastijk::request(\%args);
25 }
26  
27 sub request_raw {
28 0 ▶ my ($self, %args) = @_;
Subroutine request_raw: not called CC=1 SCAR=6.9
Pod undocumented
29 0 __fleshen_request_args($self, \%args);
30 0 return Elastijk::request_raw(\%args);
31 }
32  
33 sub index {
34 1 ▶ my ($self, %args) = @_;
Subroutine index: called CC=2 SCAR=7.2
Pod undocumented
35 1 ▶ return $self->request(method => ( exists $args{id} ? "PUT" : "POST" ), %args);
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'id'} ? : 1 0 1
36 }
37  
38 sub get {
39 1 ▶ my $self = shift;
Subroutine get: called CC=1 SCAR=0.0
Pod undocumented
40 1 return $self->request(method => "GET", @_);
41 }
42  
43 sub put {
44 0 ▶ my $self = shift;
Subroutine put: not called CC=1 SCAR=6.9
Pod undocumented
45 0 $self->request(method => "PUT", @_);
46 }
47  
48 sub delete {
49 1 ▶ my $self = shift;
Subroutine delete: called CC=1 SCAR=0.0
Pod undocumented
50 1 return $self->request(method => "DELETE", @_);
51 }
52  
53 sub head {
54 0 ▶ my $self = shift;
Subroutine head: not called CC=1 SCAR=6.9
Pod undocumented
55 0 return $self->request(method => "HEAD", @_);
56 }
57  
58 sub post {
59 0 ▶ my $self = shift;
Subroutine post: not called CC=1 SCAR=6.9
Pod undocumented
60 0 return $self->request(method => "POST", @_);
61 }
62  
63 sub exists {
64 6 ▶ my $self = shift;
Subroutine exists: called CC=1 SCAR=0.0
Pod undocumented
65 6 my ($status,$res) = $self->request(method => "HEAD", @_);
66 6 return ($status,'2' eq substr($status,0,1));
67 }
68  
69 sub search {
70 4 ▶ my $self = shift;
Subroutine search: called CC=1 SCAR=0.0
Pod undocumented
71 4 return $self->request(command => "_search", method => "GET", @_);
72 }
73  
74 sub count {
75 0 ▶ my $self = shift;
Subroutine count: not called CC=1 SCAR=6.9
Pod undocumented
76 0 my ($status,$res) = $self->request(command => "_count", method => "GET", @_);
77 0 return ($status, $res->{count});
78 }
79  
80  
81 sub bulk {
82 0 ▶ my ($self, %args) = @_;
Subroutine bulk: not called CC=2 SCAR=17.9
Pod undocumented
83 0 $args{body} = join("", map { $Elastijk::JSON->encode($_)."\n" } @{$args{body}});
84 0 my ($status,$res) = $self->request_raw(method => "POST", command => "_bulk", %args);
85 0 ▶ $res = $Elastijk::JSON->decode($res) if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
86 0 return ($status, $res);
87 }
88  
89 sub scan_scroll {
90 0 ▶ my ($self, %args) = @_;
Subroutine scan_scroll: not called CC=8 SCAR=42.8
Pod undocumented
91 0 my $on_response_callback = delete $args{on_response};
92  
93 0 ▶ my %uri_param = %{ delete($args{uri_param}) || {} };
Branch: 1 branch
BranchTrueFalseTotal
delete $args{"uri_param"} or {} 0 0 0
94 0 $uri_param{search_type} = "scan";
95 0 ▶ $uri_param{scroll} ||= "10m";
Condition0%0/2
$uri_param{"scroll"} ||= "10m"
l!l
00
MC/DC0%0/1
$uri_param{"scroll"} ||= "10m"
$uri_param{"scroll"}
Truth table0%0/2
A
A= $uri_param{"scroll"}
Aresult
11
00
96 0 my $scroll_id;
97 0 my ($status, $res) = $self->get(%args, command => "_search", uri_param => \%uri_param);
98 0 ▶ if (substr($status,0,1) ne '2') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($status, 0, 1) ne 2) 0 0 0
99 0 return;
100 }
101  
102 0 while (1) {
103 0 $scroll_id = $res->{_scroll_id};
104 ($status,$res) = $self->get(
105 index => "_search", type => "scroll", #WTF
106 0 uri_param => { scroll => $uri_param{scroll}, scroll_id => $scroll_id }
107 );
108 0 ▶ if (substr($status,0,1) eq '2' && @{$res->{hits}{hits}} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($status, 0, 1) eq '2' and @{$res->{'hits'}{'hits'};} > 0) { } 0 0 0
Condition0%0/3
substr($status, 0, 1) eq 2 and @{$res->{"hits"}{"hits"};} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
substr($status, 0, 1) eq 2 and @{$res->{"hits"}{"hits"};} > 0
substr($status, 0, 1) eq 2 @{$res->{"hits"}{"hits"};} > 0
Truth table0%0/3
A and B
A= substr($status, 0, 1) eq 2B= @{$res->{"hits"}{"hits"};} > 0
ABresult
0X0
100
111
109 0 my $r = $on_response_callback->($status, $res);
110 0 ▶ last if defined($r) && !$r;
Branch: 1 branch
BranchTrueFalseTotal
if defined $r and not $r 0 0 0
Condition0%0/3
defined $r and not $r
!ll&&!rl&&r
000
MC/DC0%0/2
defined $r and not $r
defined $r not $r
Truth table0%0/3
A and not(B)
A= defined $rB= not $r
ABresult
0X0
100
111
111 0 $scroll_id = $res->{_scroll_id};
112 } else {
113 0 last;
114 }
115 }
116 }
117  
118 3 1;
↑ Summary blib/lib/Elastijk.pm »