Elasticsearch/Role/Client/Direct.pm

filter: Statementstmt 35.4% 34 / 96 Branchbran 10.5% 4 / 38 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 47.0% 8 / 17 Podpod 0.0% 0 / 1 totaltotal 25.9% 46 / 177 CC 32 SCAR 39.7
CC
32
Cov
25%
_parse_path
152.8
_parse_qs
42.0
_parse_body
30.0
CRAP 53.2
↑ Summary Elasticsearch/Client/6_0/Role/Bulk.pm »
1 package Search::Elasticsearch::Role::Client::Direct;
2 55 $Search::Elasticsearch::Role::Client::Direct::VERSION = '6.80';
3 55 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 55 with 'Search::Elasticsearch::Role::Client';
5 55 ▶use Search::Elasticsearch::Util qw(load_plugin is_compat throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 55 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 55 ▶use Package::Stash 0.34 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 55 ▶use Any::URI::Escape qw(uri_escape);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 55 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 #===================================
13 sub parse_request {
14 #===================================
15 0 ▶ my $self = shift;
Subroutine parse_request: not called CC=3 SCAR=24.8
Pod undocumented
16 0 ▶ my $defn = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
17 0 ▶ my $params = { ref $_[0] ? %{ shift() } : @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
18  
19 0 my $request;
20 try {
21 $request = {
22 ignore => delete $params->{ignore} || [],
23 method => $defn->{method} || 'GET',
24 serialize => $defn->{serialize} || 'std',
25 path => $self->_parse_path( $defn, $params ),
26 body => $self->_parse_body( $defn->{body}, $params ),
27 0 ▶ qs => $self->_parse_qs( $defn->{qs}, $params ),
Subroutine __ANON__: not called CC=4 SCAR=30.0
Condition0%0/6
delete $params->{'ignore'} || []
l!l
00
$defn->{'method'} || 'GET'
l!l
00
$defn->{'serialize'} || 'std'
l!l
00
MC/DC0%0/1
delete $params->{'ignore'} || []
delete $params->{'ignore'}
MC/DC0%0/1
$defn->{'method'} || 'GET'
$defn->{'method'}
MC/DC0%0/1
$defn->{'serialize'} || 'std'
$defn->{'serialize'}
Truth table0%0/2
A
A= delete $params->{'ignore'}
Aresult
11
00
Truth table0%0/2
A
A= $defn->{'method'}
Aresult
11
00
Truth table0%0/2
A
A= $defn->{'serialize'}
Aresult
11
00
28 };
29 }
30 catch {
31 0 ▶ chomp $_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
32 0 ▶ my $name = $defn->{name} || '<unknown method>';
Condition0%0/2
$defn->{'name'} || '<unknown method>'
l!l
00
MC/DC0%0/1
$defn->{'name'} || '<unknown method>'
$defn->{'name'}
Truth table0%0/2
A
A= $defn->{'name'}
Aresult
11
00
33 0 $self->logger->throw_error( 'Param', "$_ in ($name) request. " );
34 0 };
35 0 return $request;
36 }
37  
38 #===================================
39 sub _parse_path {
40 #===================================
41 0 ▶ my ( $self, $defn, $params ) = @_;
Subroutine _parse_path: not called CC=13 SCAR=50.3
42 return delete $params->{path}
43 0 ▶ if $params->{path};
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"path"} 0 0 0
44 0 my $paths = $defn->{paths};
45 0 my $parts = $defn->{parts};
46  
47 0 my %args;
48 0 keys %$parts;
49 55 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
50 0 ▶ while ( my ( $key, $req ) = each %$parts ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$parts) 0 0 0
51 0 my $val = delete $params->{$key};
52 0 ▶ if ( ref $val eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq "ARRAY") 0 0 0
53 die "Param ($key) must contain a single value\n"
54 0 ▶ if @$val > 1 and not $req->{multi};
Branch: 1 branch
BranchTrueFalseTotal
if @$val > 1 and not $req->{"multi"} 0 0 0
Condition0%0/3
@$val > 1 and not $req->{"multi"}
!ll&&!rl&&r
000
MC/DC0%0/2
@$val > 1 and not $req->{"multi"}
@$val > 1 not $req->{"multi"}
Truth table0%0/3
A and not(B)
A= @$val > 1B= not $req->{"multi"}
ABresult
0X0
100
111
55 0 $val = join ",", @$val;
56 }
57 0 ▶ if ( !length $val ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $val) 0 0 0
58 die "Missing required param ($key)\n"
59 0 ▶ if $req->{required};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"required"} 0 0 0
60 0 next;
61 }
62 0 utf8::encode($val);
63 0 $args{$key} = uri_escape($val);
64 }
65 0 PATH: for my $path (@$paths) {
66 0 my @keys = keys %{ $path->[0] };
67 0 ▶ next PATH unless @keys == keys %args;
Branch: 1 branch
BranchTrueFalseTotal
unless @keys == keys %args 0 0 0
68 0 for (@keys) {
69 0 ▶ next PATH unless exists $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{$_} 0 0 0
70 }
71 0 my ( $pos, @parts ) = @$path;
72 0 for ( keys %$pos ) {
73 0 $parts[ $pos->{$_} ] = $args{$_};
74 }
75 0 return join "/", '', @parts;
76 }
77  
78 throw(
79 0 'Internal',
80 "Couldn't determine path",
81 { params => $params, defn => $defn }
82 );
83 }
84  
85 #===================================
86 sub _parse_body {
87 #===================================
88 0 ▶ my ( $self, $defn, $params ) = @_;
Subroutine _parse_body: not called CC=5 SCAR=34.0
89 0 ▶ if ( defined $defn ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $defn) 0 0 0
90 die("Missing required param (body)\n")
91 0 ▶ if $defn->{required} && !$params->{body};
Branch: 1 branch
BranchTrueFalseTotal
if $defn->{"required"} and not $params->{"body"} 0 0 0
Condition0%0/3
$defn->{"required"} and not $params->{"body"}
!ll&&!rl&&r
000
MC/DC0%0/2
$defn->{"required"} and not $params->{"body"}
$defn->{"required"} not $params->{"body"}
Truth table0%0/3
A and not(B)
A= $defn->{"required"}B= not $params->{"body"}
ABresult
0X0
100
111
92 0 return delete $params->{body};
93 }
94 0 ▶ die("Unknown param (body)\n") if $params->{body};
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"body"} 0 0 0
95 0 return undef;
96 }
97  
98 #===================================
99 sub _parse_qs {
100 #===================================
101 0 ▶ my ( $self, $handlers, $params ) = @_;
Subroutine _parse_qs: not called CC=6 SCAR=37.4
102 0 ▶ die "No (qs) defined\n" unless $handlers;
Branch: 1 branch
BranchTrueFalseTotal
unless $handlers 0 0 0
103 0 my %qs;
104  
105 0 ▶ if ( my $raw = delete $params->{params} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $raw = delete $params->{"params"}) 0 0 0
106 0 ▶ die("Arg (params) shoud be a hashref\n")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $raw eq "HASH" 0 0 0
107 unless ref $raw eq 'HASH';
108 0 %qs = %$raw;
109 }
110  
111 0 for my $key ( keys %$params ) {
112 0 ▶ my $handler = $handlers->{$key}
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $handlers->{$key} or die "Unknown param ($key)\n" 0 0 0
113 or die("Unknown param ($key)\n");
114 0 $qs{$key} = $handler->( delete $params->{$key} );
115 }
116 0 return \%qs;
117 }
118  
119 #===================================
120 sub _install_api {
121 #===================================
122 55 ▶ my ( $class, $group ) = @_;
Subroutine _install_api: called CC=5 SCAR=16.4
123 55 my $defns = $class->api;
124 55 my $stash = Package::Stash->new($class);
125  
126 55 ▶ my $group_qr = $group ? qr/$group\./ : qr//;
Branch: 1 branch
BranchTrueFalseTotal
$group ? : 0 55 55
127 55 for my $action ( keys %$defns ) {
128 14190 ▶ my ($name) = ( $action =~ /^$group_qr([^.]+)$/ )
Branch: 1 branch
BranchTrueFalseTotal
my($name) = $action =~ /^$group_qr([^.]+)$/ or next 12210 1980 14190
129 or next;
130 1980 ▶ next if $stash->has_symbol( '&' . $name );
Branch: 1 branch
BranchTrueFalseTotal
if $stash->has_symbol('&' . $name) 0 1980 1980
131  
132 1980 my %defn = ( name => $name, %{ $defns->{$action} } );
133 $stash->add_symbol(
134 '&' . $name => sub {
135 0 ▶ shift->perform_request( \%defn, @_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
136 }
137 1980 );
138 }
139 }
140  
141 #===================================
142 sub _build_namespace {
143 #===================================
144 0 ▶ my ( $self, $ns ) = @_;
Subroutine _build_namespace: not called CC=1 SCAR=6.9
145 0 my $class = load_plugin( $self->_namespace, [$ns] );
146 0 return $class->new(
147 { transport => $self->transport,
148 logger => $self->logger
149 }
150 );
151 }
152  
153 #===================================
154 sub _build_helper {
155 #===================================
156 0 ▶ my ( $self, $name, $sub_class ) = @_;
Subroutine _build_helper: not called CC=1 SCAR=6.9
157 0 my $class = load_plugin( 'Search::Elasticsearch', $sub_class );
158 0 is_compat( $name . '_helper_class', $self->transport, $class );
159 0 return $class;
160 }
161  
162 55 1;
163  
164 # ABSTRACT: Request parsing for Direct clients
165  
166 __END__
↑ Summary Elasticsearch/Client/6_0/Role/Bulk.pm »