Elasticsearch/Role/Cxn.pm

filter: Statementstmt 77.2% 183 / 237 Branchbran 50.0% 46 / 92 Conditioncond 69.8% 37 / 53 MC/DCmcdc 43.3% 13 / 30 Subroutinesub 91.6% 33 / 36 Podpod 75.0% 9 / 12 totaltotal 69.7% 321 / 460 CC 69 SCAR 30.4
CC
69
Cov
70%
_munge_elasticsearch_exception
60.1
_compress_body
30.0
_decompress_body
27.5
CRAP 21.0
« Elasticsearch/Role/API.pm ↑ Summary Elasticsearch/Client/7_0/Bulk.pm »
1 # Licensed to Elasticsearch B.V under one or more agreements.
2 # Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3 # See the LICENSE file in the project root for more information
4  
5 package Search::Elasticsearch::Role::Cxn;
6 55 $Search::Elasticsearch::Role::Cxn::VERSION = '7.30_1'; # TRIAL
7  
8 55 $Search::Elasticsearch::Role::Cxn::VERSION = '7.301';
9 55 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 55 ▶use Search::Elasticsearch::Util qw(parse_params throw to_list);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 55 ▶use List::Util qw(min);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 55 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 55 ▶use URI();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 55 ▶use IO::Compress::Deflate();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 55 ▶use IO::Uncompress::Inflate();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 55 ▶use IO::Compress::Gzip();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 55 ▶use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 55 ▶use Search::Elasticsearch::Util qw(to_list);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 55 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 55 ▶use Net::IP;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 55 requires qw(perform_request error_from_text handle);
23  
24 55 has 'host' => ( is => 'ro', required => 1 );
25 55 has 'port' => ( is => 'ro', required => 1 );
26 55 has 'uri' => ( is => 'ro', required => 1 );
27 55 has 'request_timeout' => ( is => 'ro', default => 30 );
28 55 has 'ping_timeout' => ( is => 'ro', default => 2 );
29 55 has 'sniff_timeout' => ( is => 'ro', default => 1 );
30 55 has 'sniff_request_timeout' => ( is => 'ro', default => 2 );
31 55 has 'next_ping' => ( is => 'rw', default => 0 );
32 55 has 'ping_failures' => ( is => 'rw', default => 0 );
33 55 has 'dead_timeout' => ( is => 'ro', default => 60 );
34 55 has 'max_dead_timeout' => ( is => 'ro', default => 3600 );
35 55 has 'serializer' => ( is => 'ro', required => 1 );
36 55 has 'logger' => ( is => 'ro', required => 1 );
37 175 ▶has 'handle_args' => ( is => 'ro', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
38 172 ▶has 'default_qs_params' => ( is => 'ro', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
39 55 has 'scheme' => ( is => 'ro' );
40 55 has 'is_https' => ( is => 'ro' );
41 55 has 'userinfo' => ( is => 'ro' );
42 55 has 'max_content_length' => ( is => 'ro' );
43 55 has 'default_headers' => ( is => 'ro' );
44 55 has 'deflate' => ( is => 'ro' );
45 55 has 'gzip' => ( is => 'ro' );
46 55 has 'ssl_options' => ( is => 'ro', predicate => 'has_ssl_options' );
47 55 has 'handle' => ( is => 'lazy', clearer => 1 );
48 55 has '_pid' => ( is => 'rw', default => $$ );
49  
50 55 my %Code_To_Error = (
51 400 => 'Request',
52 401 => 'Unauthorized',
53 403 => 'Forbidden',
54 404 => 'Missing',
55 408 => 'RequestTimeout',
56 409 => 'Conflict',
57 413 => 'ContentLength',
58 502 => 'BadGateway',
59 503 => 'Unavailable',
60 504 => 'GatewayTimeout'
61 );
62  
63 #===================================
64 611 ▶sub stringify { shift->uri . '' }
Subroutine stringify: called CC=1 SCAR=0.0
Pod undocumented
65 #===================================
66  
67 #===================================
68 sub get_user_agent {
69 #===================================
70 176 ▶ return sprintf("elasticsearch-perl/%s (%s; perl %s)", $Search::Elasticsearch::VERSION, $^O, $]);
Subroutine get_user_agent: called CC=1 SCAR=0.0
Pod undocumented
71 }
72  
73 #===================================
74 sub BUILDARGS {
75 #===================================
76 175 ▶ my ( $class, $params ) = parse_params(@_);
Subroutine BUILDARGS: called CC=23 SCAR=31.6
Pod undocumented
77  
78 my $node = $params->{node}
79 175 ▶ || { host => 'localhost', port => '9200' };
Condition50%1/2
$params->{'node'} || {'host', 'localhost', 'port', '9200'}
l!l
1750
MC/DC0%0/1
$params->{'node'} || {'host', 'localhost', 'port', '9200'}
$params->{'node'}
Truth table50%1/2
A
A= $params->{'node'}
Aresult
11
00
80  
81 175 ▶ unless ( ref $node eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $node eq "HASH") 170 5 175
82 170 ▶ $node = "[$node]" if Net::IP::ip_is_ipv6($node);
Branch: 1 branch
BranchTrueFalseTotal
if Net::IP::ip_is_ipv6($node) 2 168 170
83 170 ▶ unless ( $node =~ m{^http(s)?://} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($node =~ m[^http(s)?://]) 124 46 170
84 124 ▶ $node = ( $params->{use_https} ? 'https://' : 'http://' ) . $node;
Branch: 1 branch
BranchTrueFalseTotal
$params->{'use_https'} ? : 1 123 124
85 }
86 170 ▶ if ( $params->{port} && $node !~ m{//[^/\[]+:\d+} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"port"} and not $node =~ m(//[^/\[]+:\d+)) 3 167 170
Condition100%3/3
$params->{"port"} and not $node =~ m(//[^/\[]+:\d+)
!ll&&!rl&&r
16613
MC/DC100%2/2
$params->{"port"} and not $node =~ m(//[^/\[]+:\d+)
$params->{"port"} not $node =~ m(//[^/\[]+:\d+)
Truth table100%3/3
A and not(B)
A= $params->{"port"}B= not $node =~ m(//[^/\[]+:\d+)
ABresult
0X0
100
111
87 3 $node =~ s{(//[^/]+)}{$1:$params->{port}};
88 }
89 170 my $uri = URI->new($node);
90 170 $node = {
91 scheme => $uri->scheme,
92 host => $uri->host,
93 port => $uri->port,
94 path => $uri->path,
95 userinfo => $uri->userinfo
96 };
97 }
98  
99 175 ▶ my $host = $node->{host} || 'localhost';
Condition100%2/2
$node->{'host'} || 'localhost'
l!l
1732
MC/DC100%1/1
$node->{'host'} || 'localhost'
$node->{'host'}
Truth table100%2/2
A
A= $node->{'host'}
Aresult
11
00
100 175 ▶ my $userinfo = $node->{userinfo} || $params->{userinfo} || '';
Condition100%5/5
$node->{'userinfo'} || $params->{'userinfo'} || ''
l!l
3172
$node->{"userinfo"} or $params->{"userinfo"}
l!l&&r!l&&!r
21172
MC/DC100%2/2
$node->{'userinfo'} || $params->{'userinfo'} || ''
$node->{"userinfo"} $params->{"userinfo"}
Truth table100%3/3
A or B
A= $node->{"userinfo"}B= $params->{"userinfo"}
ABresult
1X1
011
000
101 my $scheme
102 175 ▶ = $node->{scheme} || ( $params->{use_https} ? 'https' : 'http' );
Branch: 1 branch
BranchTrueFalseTotal
$params->{'use_https'} ? : 0 5 5
Condition66%2/3
$node->{'scheme'} || ($params->{'use_https'} ? 'https' : 'http')
l!l&&r!l&&!r
17050
MC/DC0%0/2
$node->{'scheme'} || ($params->{'use_https'} ? 'https' : 'http')
$node->{'scheme'} ($params->{'use_https'} ? 'https' : 'http')
Truth table66%2/3
A || B
A= $node->{'scheme'}B= ($params->{'use_https'} ? 'https' : 'http')
ABresult
1X1
011
000
103 my $port
104 = $node->{port}
105 || $params->{port}
106 175 ▶ || ( $scheme eq 'http' ? 80 : 443 );
Branch: 1 branch
BranchTrueFalseTotal
$scheme eq 'http' ? : 4 0 4
Condition66%4/6
$node->{'port'} || $params->{'port'} || ($scheme eq 'http' ? 80 : 443)
l!l&&r!l&&!r
17140
$node->{"port"} or $params->{"port"}
l!l&&r!l&&!r
17104
MC/DC0%0/3
$node->{'port'} || $params->{'port'} || ($scheme eq 'http' ? 80 : 443)
$node->{"port"} $params->{"port"} ($scheme eq 'http' ? 80 : 443)
Truth table50%2/4
A or B || C
A= $node->{"port"}B= $params->{"port"}C= ($scheme eq 'http' ? 80 : 443)
ABCresult
1XX1
01X1
0011
0000
107 175 ▶ my $path = $node->{path} || $params->{path_prefix} || '';
Condition100%5/5
$node->{'path'} || $params->{'path_prefix'} || ''
l!l
10165
$node->{"path"} or $params->{"path_prefix"}
l!l&&r!l&&!r
91165
MC/DC100%2/2
$node->{'path'} || $params->{'path_prefix'} || ''
$node->{"path"} $params->{"path_prefix"}
Truth table100%3/3
A or B
A= $node->{"path"}B= $params->{"path_prefix"}
ABresult
1X1
011
000
108 175 $path =~ s{^/?}{/}g;
109 175 $path =~ s{/+$}{};
110  
111 175 ▶ my %default_headers = %{ $params->{default_headers} || {} };
Branch: 1 branch
BranchTrueFalseTotal
$params->{"default_headers"} or {} 175 0 175
112  
113 175 ▶ if ($userinfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($userinfo) 3 172 175
114 3 require MIME::Base64;
115 3 my $auth = MIME::Base64::encode_base64( $userinfo, "" );
116 3 chomp $auth;
117 3 $default_headers{Authorization} = "Basic $auth";
118 }
119  
120 175 ▶ if ( $params->{gzip} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($params->{'gzip'}) { } 0 175 175
elsif ($params->{'deflate'}) { } 1 174 175
121 0 $default_headers{'Accept-Encoding'} = "gzip";
122 }
123  
124 elsif ( $params->{deflate} ) {
125 1 $default_headers{'Accept-Encoding'} = "deflate";
126 }
127  
128 175 $default_headers{'User-Agent'} = $class->get_user_agent();
129  
130 175 $params->{scheme} = $scheme;
131 175 $params->{is_https} = $scheme eq 'https';
132 175 $params->{host} = $host;
133 175 $params->{port} = $port;
134 175 $params->{path} = $path;
135 175 $params->{userinfo} = $userinfo;
136 175 ▶ $host = "[$host]" if Net::IP::ip_is_ipv6($host);
Branch: 1 branch
BranchTrueFalseTotal
if Net::IP::ip_is_ipv6($host) 6 169 175
137 175 $params->{uri} = URI->new("$scheme://$host:$port$path");
138 175 $params->{default_headers} = \%default_headers;
139  
140 175 return $params;
141 }
142  
143 #===================================
144 before 'handle' => sub {
145 #===================================
146 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=2 SCAR=17.9
147 0 ▶ if ( $$ != $self->_pid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$ != $self->_pid) 0 0 0
148 0 $self->clear_handle;
149 0 $self->_pid($$);
150 }
151 55 };
152  
153 #===================================
154 182 ▶sub is_live { !shift->next_ping }
Subroutine is_live: called CC=1 SCAR=0.0
Pod documented
155 128 ▶sub is_dead { !!shift->next_ping }
Subroutine is_dead: called CC=1 SCAR=0.0
Pod documented
156 #===================================
157  
158 #===================================
159 sub mark_live {
160 #===================================
161 149 ▶ my $self = shift;
Subroutine mark_live: called CC=1 SCAR=0.0
Pod documented
162 149 $self->ping_failures(0);
163 149 $self->next_ping(0);
164 }
165  
166 #===================================
167 sub mark_dead {
168 #===================================
169 143 ▶ my $self = shift;
Subroutine mark_dead: called CC=1 SCAR=0.0
Pod documented
170 143 my $fails = $self->ping_failures;
171 143 $self->ping_failures( $fails + 1 );
172  
173 143 my $timeout
174 = min( $self->dead_timeout * 2**$fails, $self->max_dead_timeout );
175 143 my $next = $self->next_ping( time() + $timeout );
176  
177 143 $self->logger->infof( 'Marking [%s] as dead. Next ping at: %s',
178 $self->stringify, scalar localtime($next) );
179  
180 }
181  
182 #===================================
183 sub force_ping {
184 #===================================
185 121 ▶ my $self = shift;
Subroutine force_ping: called CC=1 SCAR=0.0
Pod documented
186 121 $self->ping_failures(0);
187 121 $self->next_ping(-1);
188 }
189  
190 #===================================
191 sub pings_ok {
192 #===================================
193 47 ▶ my $self = shift;
Subroutine pings_ok: called CC=1 SCAR=0.0
Pod documented
194 47 $self->logger->infof( 'Pinging [%s]', $self->stringify );
195 return try {
196 47 ▶ $self->perform_request(
Subroutine __ANON__: called CC=1 SCAR=0.0
197 { method => 'HEAD',
198 path => '/',
199 timeout => $self->ping_timeout,
200 }
201 );
202 33 $self->logger->infof( 'Marking [%s] as live', $self->stringify );
203 33 $self->mark_live;
204 33 1;
205 }
206 catch {
207 14 ▶ $self->logger->debug("$_");
Subroutine __ANON__: called CC=1 SCAR=0.0
208 14 $self->mark_dead;
209 14 0;
210 47 };
211 }
212  
213 #===================================
214 sub sniff {
215 #===================================
216 38 ▶ my $self = shift;
Subroutine sniff: called CC=1 SCAR=0.0
Pod documented
217 38 $self->logger->infof( 'Sniffing [%s]', $self->stringify );
218 return try {
219 $self->perform_request(
220 { method => 'GET',
221 path => '/_nodes/http',
222 qs => { timeout => $self->sniff_timeout . 's' },
223 timeout => $self->sniff_request_timeout,
224 }
225 38 ▶ )->{nodes};
Subroutine __ANON__: called CC=1 SCAR=0.0
226 }
227 catch {
228 13 ▶ $self->logger->debug($_);
Subroutine __ANON__: called CC=1 SCAR=0.0
229 13 return;
230 38 };
231 }
232  
233 #===================================
234 sub build_uri {
235 #===================================
236 5 ▶ my ( $self, $params ) = @_;
Subroutine build_uri: called CC=2 SCAR=6.9
Pod documented
237 5 my $uri = $self->uri->clone;
238 5 $uri->path( $uri->path . $params->{path} );
239 5 ▶ my %qs = ( %{ $self->default_qs_params }, %{ $params->{qs} || {} } );
Branch: 1 branch
BranchTrueFalseTotal
$params->{"qs"} or {} 3 2 5
240 5 $uri->query_form( \%qs );
241 5 return $uri;
242 }
243  
244 #===================================
245 before 'perform_request' => sub {
246 #===================================
247 233 ▶ my ( $self, $params ) = @_;
Subroutine __ANON__: called CC=4 SCAR=23.7
248 233 ▶ return unless defined $params->{data};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"data"} 233 0 233
249  
250 0 $self->_compress_body($params);
251  
252 0 ▶ my $max = $self->max_content_length
Branch: 1 branch
BranchTrueFalseTotal
my $max = $self->max_content_length or return 0 0 0
253 or return;
254  
255 0 ▶ return if length( $params->{data} ) < $max;
Branch: 1 branch
BranchTrueFalseTotal
if length $params->{"data"} < $max 0 0 0
256  
257 0 $self->logger->throw_error( 'ContentLength',
258 "Body is longer than max_content_length ($max)",
259 );
260 55 };
261  
262 #===================================
263 sub _compress_body {
264 #===================================
265 0 ▶ my ( $self, $params ) = @_;
Subroutine _compress_body: not called CC=5 SCAR=34.0
266 0 my $output;
267 0 ▶ if ( $self->gzip ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->gzip) { } 0 0 0
elsif ($self->deflate) { } 0 0 0
268 0 ▶ IO::Compress::Gzip::gzip( \( $params->{data} ), \$output )
Branch: 1 branch
BranchTrueFalseTotal
IO::Compress::Gzip::gzip(\$params->{"data"}, \$output) or throw("Request", "Couldn't gzip request: $IO::Compress::Gzip::GzipError") 0 0 0
269 or throw( 'Request',
270 "Couldn't gzip request: $IO::Compress::Gzip::GzipError" );
271 0 $params->{data} = $output;
272 0 $params->{encoding} = 'gzip';
273 }
274 elsif ( $self->deflate ) {
275 0 ▶ IO::Compress::Deflate::deflate( \( $params->{data} ), \$output )
Branch: 1 branch
BranchTrueFalseTotal
IO::Compress::Deflate::deflate(\$params->{"data"}, \$output) or throw("Request", "Couldn't deflate request: $IO::Compress::Deflate::DeflateError") 0 0 0
276 or throw( 'Request',
277 "Couldn't deflate request: $IO::Compress::Deflate::DeflateError" );
278 0 $params->{data} = $output;
279 0 $params->{encoding} = 'deflate';
280 }
281 }
282  
283 #===================================
284 sub _decompress_body {
285 #===================================
286 238 ▶ my ( $self, $body_ref, $headers ) = @_;
Subroutine _decompress_body: called CC=6 SCAR=33.1
287 238 ▶ if ( my $encoding = $headers->{'content-encoding'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $encoding = $headers->{"content-encoding"}) 0 238 238
288 0 my $output;
289 0 ▶ if ( $encoding eq 'gzip' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($encoding eq 'gzip') { } 0 0 0
elsif ($encoding eq 'deflate') { } 0 0 0
290 0 ▶ IO::Uncompress::Gunzip::gunzip( $body_ref, \$output )
Branch: 1 branch
BranchTrueFalseTotal
IO::Uncompress::Gunzip::gunzip($body_ref, \$output) or throw("Request", "Couldn't gunzip response: $IO::Uncompress::Gunzip::GunzipError") 0 0 0
291 or throw(
292 'Request',
293 "Couldn't gunzip response: $IO::Uncompress::Gunzip::GunzipError"
294 );
295 }
296 elsif ( $encoding eq 'deflate' ) {
297 0 ▶ IO::Uncompress::Inflate::inflate( $body_ref, \$output,
Branch: 1 branch
BranchTrueFalseTotal
IO::Uncompress::Inflate::inflate($body_ref, \$output, "Transparent", 0) or throw("Request", "Couldn't inflate response: $IO::Uncompress::Inflate::InflateError") 0 0 0
298 Transparent => 0 )
299 or throw(
300 'Request',
301 "Couldn't inflate response: $IO::Uncompress::Inflate::InflateError"
302 );
303 }
304 else {
305 0 throw( 'Request', "Unknown content-encoding: $encoding" );
306 }
307 0 ${$body_ref} = $output;
308 }
309 }
310  
311 #===================================
312 sub process_response {
313 #===================================
314 238 ▶ my ( $self, $params, $code, $msg, $body, $headers ) = @_;
Subroutine process_response: called CC=21 SCAR=32.8
Pod documented
315 238 $self->_decompress_body( \$body, $headers );
316  
317 238 ▶ my ($mime_type) = split /\s*;\s*/, ( $headers->{'content-type'} || '' );
Condition100%2/2
$headers->{'content-type'} || ''
l!l
2344
MC/DC100%1/1
$headers->{'content-type'} || ''
$headers->{'content-type'}
Truth table100%2/2
A
A= $headers->{'content-type'}
Aresult
11
00
318  
319 238 ▶ my $is_encoded = $mime_type && $mime_type ne 'text/plain';
Condition100%3/3
$mime_type && $mime_type ne 'text/plain'
!ll&&!rl&&r
41233
MC/DC100%2/2
$mime_type && $mime_type ne 'text/plain'
$mime_type $mime_type ne 'text/plain'
Truth table100%3/3
A && B
A= $mime_typeB= $mime_type ne 'text/plain'
ABresult
0X0
100
111
320  
321 # Deprecation warnings
322 238 ▶ if ( my $warnings = $headers->{warning} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $warnings = $headers->{"warning"}) 0 238 238
323 0 my $warning_string = _parse_warnings($warnings);
324 0 my %temp = (%$params);
325 0 delete $temp{data};
326 0 $self->logger->deprecation( $warning_string, \%temp );
327 }
328  
329 # Request is successful
330  
331 238 ▶ if ( $code >= 200 and $code <= 209 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code >= 200 and $code <= 209) 176 62 238
Condition66%2/3
$code >= 200 and $code <= 209
!ll&&!rl&&r
062176
MC/DC50%1/2
$code >= 200 and $code <= 209
$code >= 200 $code <= 209
Truth table66%2/3
A and B
A= $code >= 200B= $code <= 209
ABresult
0X0
100
111
332 176 ▶ if ( defined $body and length $body ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $body and length $body) 141 35 176
Condition100%3/3
defined $body and length $body
!ll&&!rl&&r
341141
MC/DC100%2/2
defined $body and length $body
defined $body length $body
Truth table100%3/3
A and B
A= defined $bodyB= length $body
ABresult
0X0
100
111
333 141 ▶ $body = $self->serializer->decode($body)
Branch: 1 branch
BranchTrueFalseTotal
if $is_encoded 140 1 141
334 if $is_encoded;
335 141 return $code, $body;
336 }
337 35 ▶ return ( $code, 1 ) if $params->{method} eq 'HEAD';
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"method"} eq "HEAD" 34 1 35
338 1 return ( $code, '' );
339 }
340  
341 # Check if the error should be ignored
342 62 my @ignore = to_list( $params->{ignore} );
343 62 ▶ push @ignore, 404 if $params->{method} eq 'HEAD';
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"method"} eq "HEAD" 11 51 62
344 62 ▶ return ($code) if grep { $_ eq $code } @ignore;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $code;} @ignore 2 60 62
345  
346 # Determine error type
347 60 my $error_type = $Code_To_Error{$code};
348 60 ▶ unless ($error_type) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($error_type) 49 11 60
349 49 ▶ if ( defined $body and length $body ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $body and length $body) 0 49 49
Condition33%1/3
defined $body and length $body
!ll&&!rl&&r
4900
MC/DC0%0/2
defined $body and length $body
defined $body length $body
Truth table33%1/3
A and B
A= defined $bodyB= length $body
ABresult
0X0
100
111
350 0 $msg = $body;
351 0 $body = undef;
352 }
353 49 $error_type = $self->error_from_text( $code, $msg );
354 }
355  
356 60 ▶ delete $params->{data} if $params->{body};
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"body"} 0 60 60
357 60 my %error_args = ( status_code => $code, request => $params );
358  
359 # Extract error message from the body, if present
360  
361 60 ▶ if ( $body = $self->serializer->decode($body) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($body = $self->serializer->decode($body)) 2 58 60
362 2 $error_args{body} = $body;
363 2 ▶ $msg = $self->_munge_elasticsearch_exception($body) || $msg;
Condition33%1/3
$self->_munge_elasticsearch_exception($body) || $msg
l!l&&r!l&&!r
200
MC/DC0%0/2
$self->_munge_elasticsearch_exception($body) || $msg
$self->_munge_elasticsearch_exception($body) $msg
Truth table33%1/3
A || B
A= $self->_munge_elasticsearch_exception($body)B= $msg
ABresult
1X1
011
000
364  
365 2 ▶ $error_args{current_version} = $1
Branch: 1 branch
BranchTrueFalseTotal
if $error_type eq "Conflict" and $msg =~ /: version conflict, current (?:version )?\[(\d+)\]/ 0 2 2
Condition33%1/3
$error_type eq "Conflict" and $msg =~ /: version conflict, current (?:version )?\[(\d+)\]/
!ll&&!rl&&r
200
MC/DC0%0/2
$error_type eq "Conflict" and $msg =~ /: version conflict, current (?:version )?\[(\d+)\]/
$error_type eq "Conflict" $msg =~ /: version conflict, current (?:version )?\[(\d+)\]/
Truth table33%1/3
A and B
A= $error_type eq "Conflict"B= $msg =~ /: version conflict, current (?:version )?\[(\d+)\]/
ABresult
0X0
100
111
366 if $error_type eq 'Conflict'
367 and $msg =~ /: version conflict, current (?:version )?\[(\d+)\]/;
368 }
369 60 ▶ $msg ||= $error_type;
Condition33%1/3
$msg ||= $error_type
l!l&&r!l&&!r
6000
MC/DC0%0/2
$msg ||= $error_type
$msg $error_type
Truth table33%1/3
A ||= B
A= $msgB= $error_type
ABresult
1X1
011
000
370  
371 60 chomp $msg;
372 60 throw( $error_type, "[" . $self->stringify . "]-[$code] $msg",
373 \%error_args );
374 }
375  
376 #===================================
377 sub _parse_warnings {
378 #===================================
379 0 ▶ my @warnings = ref $_[0] eq 'ARRAY' ? @{ shift() } : shift();
Subroutine _parse_warnings: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 0 0
380 0 my @str;
381 0 for (@warnings) {
382 0 ▶ if ( $_ =~ /^\d+\s+\S+\s+"((?:\\"|[^"])+)"/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^\d+\s+\S+\s+"((?:\\"|[^"])+)"/) { } 0 0 0
383 0 my $msg = $1;
384 0 $msg =~ s/\\"/"/g, push @str, $msg;
385 }
386 else {
387 0 push @str, $_;
388 }
389 }
390 0 return join "; ", @str;
391 }
392  
393 #===================================
394 sub _munge_elasticsearch_exception {
395 #===================================
396 2 ▶ my ( $self, $body ) = @_;
Subroutine _munge_elasticsearch_exception: called CC=10 SCAR=41.0
397 2 ▶ return $body unless ref $body eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $body eq "HASH" 0 2 2
398 2 ▶ my $error = $body->{error} || return;
Condition50%1/2
$body->{'error'} || (return)
l!l
20
MC/DC0%0/1
$body->{'error'} || (return)
$body->{'error'}
Truth table50%1/2
A
A= $body->{'error'}
Aresult
11
00
399 2 ▶ return $error unless ref $error eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $error eq "HASH" 2 0 2
400  
401 0 ▶ my $root_causes = $error->{root_cause} || [];
Condition0%0/2
$error->{'root_cause'} || []
l!l
00
MC/DC0%0/1
$error->{'root_cause'} || []
$error->{'root_cause'}
Truth table0%0/2
A
A= $error->{'root_cause'}
Aresult
11
00
402 0 ▶ unless (@$root_causes) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$root_causes) 0 0 0
403 0 ▶ my $msg = "[" . $error->{type} . "] " if $error->{type};
Branch: 1 branch
BranchTrueFalseTotal
if $error->{"type"} 0 0 0
404 0 ▶ $msg .= $error->{reason} if $error->{reason};
Branch: 1 branch
BranchTrueFalseTotal
if $error->{"reason"} 0 0 0
405 0 return $msg;
406 }
407  
408 0 my $json = $self->serializer;
409 0 my @msgs;
410 0 for (@$root_causes) {
411 0 my %cause = (%$_);
412 my $msg
413 0 = "[" . ( delete $cause{type} ) . "] " . ( delete $cause{reason} );
414 0 ▶ if ( keys %cause ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %cause) 0 0 0
415 0 $msg .= ", with: " . $json->encode( \%cause );
416 }
417 0 push @msgs, $msg;
418 }
419 0 return ( join ", ", @msgs );
420 }
421  
422 55 1;
423  
424 # ABSTRACT: Provides common functionality to HTTP Cxn implementations
425  
426 __END__
« Elasticsearch/Role/API.pm ↑ Summary Elasticsearch/Client/7_0/Bulk.pm »