| 1 | # OpenSearch::Client is an unofficial client for OpenSearch. | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # It is derived from Search::Elasticsearch version 7.714 | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # License details from the original work are contained in the | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # NOTICE file distributed with this work. | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # OpenSearch::Client | ||||||||||||||||||||||||||||||||||||||||||
| 8 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # Copyright 2026 Mark Dootson | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||||||||||||||||
| 20 | # See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # limitations under the License. | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | package OpenSearch::Client::Role::Cxn; | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 56 | $OpenSearch::Client::Role::Cxn::VERSION = '3.007011'; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 56 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 56 | ▶ | use OpenSearch::Client::Util qw(parse_params throw to_list); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 56 | ▶ | use List::Util qw(min); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 56 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 56 | ▶ | use URI(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 56 | ▶ | use IO::Compress::Deflate(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 56 | ▶ | use IO::Uncompress::Inflate(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 56 | ▶ | use IO::Compress::Gzip(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 56 | ▶ | use IO::Uncompress::Gunzip qw(gunzip $GunzipError); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 56 | ▶ | use OpenSearch::Client::Util qw(to_list); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 56 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 56 | ▶ | use Net::IP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 56 | requires qw(perform_request error_from_text handle); | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 56 | has 'host' => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 56 | has 'port' => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 56 | has 'uri' => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 56 | has 'request_timeout' => ( is => 'ro', default => 30 ); | |||||||||||||||||||||||||||||||||||||||||
| 44 | 56 | has 'ping_timeout' => ( is => 'ro', default => 2 ); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 56 | has 'sniff_timeout' => ( is => 'ro', default => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 46 | 56 | has 'sniff_request_timeout' => ( is => 'ro', default => 2 ); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 56 | has 'next_ping' => ( is => 'rw', default => 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 56 | has 'ping_failures' => ( is => 'rw', default => 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 56 | has 'dead_timeout' => ( is => 'ro', default => 60 ); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 56 | has 'max_dead_timeout' => ( is => 'ro', default => 3600 ); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 56 | has 'serializer' => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 56 | has 'logger' => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 175 | ▶ | has 'handle_args' => ( is => 'ro', default => sub { {} } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 172 | ▶ | has 'default_qs_params' => ( is => 'ro', default => sub { {} } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 56 | has 'scheme' => ( is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||
| 56 | 56 | has 'is_https' => ( is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||
| 57 | 56 | has 'userinfo' => ( is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 56 | has 'max_content_length' => ( is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||
| 59 | 56 | has 'default_headers' => ( is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||
| 60 | 56 | has 'deflate' => ( is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 56 | has 'gzip' => ( is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 56 | has 'ssl_options' => ( is => 'ro', predicate => 'has_ssl_options' ); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 56 | has 'handle' => ( is => 'lazy', clearer => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 64 | 56 | has '_pid' => ( is => 'rw', default => $$ ); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 56 | has 'http_proxy' => ( is => 'ro', predicate => 'has_http_proxy' ); | |||||||||||||||||||||||||||||||||||||||||
| 66 | 56 | has 'https_proxy' => ( is => 'ro', predicate => 'has_https_proxy' ); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 56 | has 'no_proxy' => ( is => 'ro', predicate => 'has_no_proxy' ); | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 56 | my %Code_To_Error = ( | |||||||||||||||||||||||||||||||||||||||||
| 70 | 400 => 'Request', | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 401 => 'Unauthorized', | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 403 => 'Forbidden', | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 404 => 'Missing', | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 408 => 'RequestTimeout', | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 409 => 'Conflict', | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 413 => 'ContentLength', | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 502 => 'BadGateway', | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 503 => 'Unavailable', | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 504 => 'GatewayTimeout' | ||||||||||||||||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 611 | ▶ | sub stringify { shift->uri . '' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 176 | ▶ | sub get_user_agent { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_user_agent: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 176 | return sprintf("opensearch-client-perl/%s (%s; perl %s)", $OpenSearch::Client::VERSION, $^O, $]); | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 175 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=27 SCAR=33.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 175 | my ( $class, $params ) = parse_params(@_); | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | my $node = $params->{node} | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 175 | ▶ | || { host => 'localhost', port => '9200' }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$params->{'node'} || {'host', 'localhost', 'port', '9200'}
MC/DC0%0/1
$params->{'node'} || {'host', 'localhost', 'port', '9200'}
$params->{'node'}
Truth table50%1/2
A
A= $params->{'node'}
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 175 | ▶ | unless ( ref $node eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 170 | ▶ | $node = "[$node]" if Net::IP::ip_is_ipv6($node); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 170 | ▶ | unless ( $node =~ m{^http(s)?://} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 124 | ▶ | $node = ( $params->{use_https} ? 'https://' : 'http://' ) . $node; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 170 | ▶ | if ( $params->{port} && $node !~ m{//[^/\[]+:\d+} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$params->{"port"} and not $node =~ m(//[^/\[]+:\d+)
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+)
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | $node =~ s{(//[^/]+)}{$1:$params->{port}}; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 170 | my $uri = URI->new($node); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 170 | $node = { | |||||||||||||||||||||||||||||||||||||||||
| 110 | scheme => $uri->scheme, | ||||||||||||||||||||||||||||||||||||||||||
| 111 | host => $uri->host, | ||||||||||||||||||||||||||||||||||||||||||
| 112 | port => $uri->port, | ||||||||||||||||||||||||||||||||||||||||||
| 113 | path => $uri->path, | ||||||||||||||||||||||||||||||||||||||||||
| 114 | userinfo => $uri->userinfo | ||||||||||||||||||||||||||||||||||||||||||
| 115 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | { | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 175 | my $n_username = delete $node->{username}; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 175 | my $n_password = delete $node->{password}; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 175 | ▶ | if (!$node->{userinfo} && $n_username && $n_password) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not $node->{"userinfo"} and $n_username and $n_password
not $node->{"userinfo"} and $n_username
MC/DC0%0/3
not $node->{"userinfo"} and $n_username and $n_password
not $node->{"userinfo"}
$n_username
$n_password
Truth table50%2/4
not(A) and B and C
A= not $node->{"userinfo"}B= $n_usernameC= $n_password
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $node->{userinfo} = sprintf('%s:%s', $n_username , $n_password ); | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 175 | ▶ | my $host = $node->{host} || 'localhost'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$node->{'host'} || 'localhost'
MC/DC100%1/1
$node->{'host'} || 'localhost'
$node->{'host'}
Truth table100%2/2
A
A= $node->{'host'}
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 175 | ▶ | my $userinfo = $node->{userinfo} || $params->{userinfo} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/5
$node->{'userinfo'} || $params->{'userinfo'} || ''
$node->{"userinfo"} or $params->{"userinfo"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | my $scheme | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 175 | ▶ | = $node->{scheme} || ( $params->{use_https} ? 'https' : 'http' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$node->{'scheme'} || ($params->{'use_https'} ? 'https' : 'http')
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')
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | my $port | ||||||||||||||||||||||||||||||||||||||||||
| 130 | = $node->{port} | ||||||||||||||||||||||||||||||||||||||||||
| 131 | || $params->{port} | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 175 | ▶ | || ( $scheme eq 'http' ? 80 : 443 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$node->{'port'} || $params->{'port'} || ($scheme eq 'http' ? 80 : 443)
$node->{"port"} or $params->{"port"}
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 175 | ▶ | my $path = $node->{path} || $params->{path_prefix} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/5
$node->{'path'} || $params->{'path_prefix'} || ''
$node->{"path"} or $params->{"path_prefix"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 175 | $path =~ s{^/?}{/}g; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 175 | $path =~ s{/+$}{}; | |||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 175 | ▶ | my %default_headers = %{ $params->{default_headers} || {} }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$params->{'default_headers'} || {}
MC/DC0%0/1
$params->{'default_headers'} || {}
$params->{'default_headers'}
Truth table50%1/2
A
A= $params->{'default_headers'}
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 175 | ▶ | if ($userinfo) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 3 | require MIME::Base64; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 3 | my $auth = MIME::Base64::encode_base64( $userinfo, "" ); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 3 | chomp $auth; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 3 | $default_headers{Authorization} = "Basic $auth"; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 175 | ▶ | if ( $params->{application_id} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $default_headers{'X-Opaque-Id'} = $params->{application_id}; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 175 | ▶ | if ( $params->{gzip} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $default_headers{'Accept-Encoding'} = "gzip"; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | elsif ( $params->{deflate} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | $default_headers{'Accept-Encoding'} = "deflate"; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 175 | $default_headers{'User-Agent'} = $class->get_user_agent(); | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 175 | $params->{scheme} = $scheme; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 175 | $params->{is_https} = $scheme eq 'https'; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 175 | $params->{host} = $host; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 175 | $params->{port} = $port; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 175 | $params->{path} = $path; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 175 | $params->{userinfo} = $userinfo; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 175 | ▶ | $host = "[$host]" if Net::IP::ip_is_ipv6($host); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 175 | $params->{uri} = URI->new("$scheme://$host:$port$path"); | |||||||||||||||||||||||||||||||||||||||||
| 168 | 175 | $params->{default_headers} = \%default_headers; | |||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 175 | return $params; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | before 'handle' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if ( $$ != $self->_pid ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $self->clear_handle; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $self->_pid($$); | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 56 | }; | |||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 182 | ▶ | sub is_live { !shift->next_ping } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_live: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 128 | ▶ | sub is_dead { !!shift->next_ping } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_dead: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 149 | ▶ | sub mark_live { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mark_live: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 149 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 149 | $self->ping_failures(0); | |||||||||||||||||||||||||||||||||||||||||
| 193 | 149 | $self->next_ping(0); | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 143 | ▶ | sub mark_dead { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mark_dead: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 143 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 143 | my $fails = $self->ping_failures; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 143 | $self->ping_failures( $fails + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 143 | my $timeout | |||||||||||||||||||||||||||||||||||||||||
| 204 | = min( $self->dead_timeout * 2**$fails, $self->max_dead_timeout ); | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 143 | my $next = $self->next_ping( time() + $timeout ); | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 143 | $self->logger->infof( 'Marking [%s] as dead. Next ping at: %s', | |||||||||||||||||||||||||||||||||||||||||
| 208 | $self->stringify, scalar localtime($next) ); | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 121 | ▶ | sub force_ping { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
force_ping: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 121 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 121 | $self->ping_failures(0); | |||||||||||||||||||||||||||||||||||||||||
| 217 | 121 | $self->next_ping(-1); | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 47 | ▶ | sub pings_ok { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pings_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 47 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 47 | $self->logger->infof( 'Pinging [%s]', $self->stringify ); | |||||||||||||||||||||||||||||||||||||||||
| 225 | 47 | ▶ | return try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 47 | $self->perform_request( | |||||||||||||||||||||||||||||||||||||||||
| 227 | { method => 'HEAD', | ||||||||||||||||||||||||||||||||||||||||||
| 228 | path => '/', | ||||||||||||||||||||||||||||||||||||||||||
| 229 | timeout => $self->ping_timeout, | ||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 33 | $self->logger->infof( 'Marking [%s] as live', $self->stringify ); | |||||||||||||||||||||||||||||||||||||||||
| 233 | 33 | $self->mark_live; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 33 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 14 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 14 | $self->logger->debug("$_"); | |||||||||||||||||||||||||||||||||||||||||
| 238 | 14 | $self->mark_dead; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 14 | 0; | |||||||||||||||||||||||||||||||||||||||||
| 240 | 47 | }; | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 38 | ▶ | sub sniff { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sniff: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 38 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 38 | $self->logger->infof( 'Sniffing [%s]', $self->stringify ); | |||||||||||||||||||||||||||||||||||||||||
| 248 | 38 | ▶ | return try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | $self->perform_request( | ||||||||||||||||||||||||||||||||||||||||||
| 250 | { method => 'GET', | ||||||||||||||||||||||||||||||||||||||||||
| 251 | path => '/_nodes/http', | ||||||||||||||||||||||||||||||||||||||||||
| 252 | qs => { timeout => $self->sniff_timeout . 's' }, | ||||||||||||||||||||||||||||||||||||||||||
| 253 | timeout => $self->sniff_request_timeout, | ||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 38 | )->{nodes}; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 13 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 13 | $self->logger->debug($_); | |||||||||||||||||||||||||||||||||||||||||
| 259 | 13 | return; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 38 | }; | |||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 5 | ▶ | sub build_uri { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_uri: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 5 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 5 | my $uri = $self->uri->clone; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 5 | $uri->path( $uri->path . $params->{path} ); | |||||||||||||||||||||||||||||||||||||||||
| 269 | 5 | ▶ | my %qs = ( %{ $self->default_qs_params }, %{ $params->{qs} || {} } ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$params->{'qs'} || {}
MC/DC100%1/1
$params->{'qs'} || {}
$params->{'qs'}
Truth table100%2/2
A
A= $params->{'qs'}
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 5 | $uri->query_form( \%qs ); | |||||||||||||||||||||||||||||||||||||||||
| 271 | 5 | return $uri; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 233 | ▶ | before 'perform_request' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=23.7
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 233 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 233 | ▶ | return unless defined $params->{data}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $self->_compress_body($params); | |||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | my $max = $self->max_content_length | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | return if length( $params->{data} ) < $max; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | $self->logger->throw_error( 'ContentLength', | |||||||||||||||||||||||||||||||||||||||||
| 288 | "Body is longer than max_content_length ($max)", | ||||||||||||||||||||||||||||||||||||||||||
| 289 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 56 | }; | |||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | sub _compress_body { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compress_body: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my $output; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | if ( $self->gzip ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | IO::Compress::Gzip::gzip( \( $params->{data} ), \$output ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | or throw( 'Request', | ||||||||||||||||||||||||||||||||||||||||||
| 300 | "Couldn't gzip request: $IO::Compress::Gzip::GzipError" ); | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $params->{data} = $output; | |||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $params->{encoding} = 'gzip'; | |||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | elsif ( $self->deflate ) { | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | IO::Compress::Deflate::deflate( \( $params->{data} ), \$output ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | or throw( 'Request', | ||||||||||||||||||||||||||||||||||||||||||
| 307 | "Couldn't deflate request: $IO::Compress::Deflate::DeflateError" ); | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $params->{data} = $output; | |||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $params->{encoding} = 'deflate'; | |||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 238 | ▶ | sub _decompress_body { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decompress_body: called CC=6 SCAR=33.1
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 238 | my ( $self, $body_ref, $headers ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 238 | ▶ | if ( my $encoding = $headers->{'content-encoding'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $output; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | if ( $encoding eq 'gzip' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | IO::Uncompress::Gunzip::gunzip( $body_ref, \$output ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | or throw( | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 'Request', | ||||||||||||||||||||||||||||||||||||||||||
| 323 | "Couldn't gunzip response: $IO::Uncompress::Gunzip::GunzipError" | ||||||||||||||||||||||||||||||||||||||||||
| 324 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | elsif ( $encoding eq 'deflate' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | IO::Uncompress::Inflate::inflate( $body_ref, \$output, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | Transparent => 0 ) | ||||||||||||||||||||||||||||||||||||||||||
| 329 | or throw( | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 'Request', | ||||||||||||||||||||||||||||||||||||||||||
| 331 | "Couldn't inflate response: $IO::Uncompress::Inflate::InflateError" | ||||||||||||||||||||||||||||||||||||||||||
| 332 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | throw( 'Request', "Unknown content-encoding: $encoding" ); | |||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ${$body_ref} = $output; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 238 | ▶ | sub process_response { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_response: called CC=21 SCAR=32.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 238 | my ( $self, $params, $code, $msg, $body, $headers ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 238 | $self->_decompress_body( \$body, $headers ); | |||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | 238 | ▶ | my ($mime_type) = split /\s*;\s*/, ( $headers->{'content-type'} || '' ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$headers->{'content-type'} || ''
MC/DC100%1/1
$headers->{'content-type'} || ''
$headers->{'content-type'}
Truth table100%2/2
A
A= $headers->{'content-type'}
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 238 | ▶ | my $is_encoded = $mime_type && $mime_type ne 'text/plain'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$mime_type && $mime_type ne 'text/plain'
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'
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | # Deprecation warnings | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 238 | ▶ | if ( my $warnings = $headers->{warning} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | my $warning_string = _parse_warnings($warnings); | |||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | my %temp = (%$params); | |||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | delete $temp{data}; | |||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | $self->logger->deprecation( $warning_string, \%temp ); | |||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | # Request is successful | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 238 | ▶ | if ( $code >= 200 and $code <= 209 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$code >= 200 and $code <= 209
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
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 176 | ▶ | if ( defined $body and length $body ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $body and length $body
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
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 141 | ▶ | $body = $self->serializer->decode($body) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | if $is_encoded; | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 141 | return $code, $body; | |||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 35 | ▶ | return ( $code, 1 ) if $params->{method} eq 'HEAD'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 1 | return ( $code, '' ); | |||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | # Check if the error should be ignored | ||||||||||||||||||||||||||||||||||||||||||
| 372 | 62 | my @ignore = to_list( $params->{ignore} ); | |||||||||||||||||||||||||||||||||||||||||
| 373 | 62 | ▶ | push @ignore, 404 if $params->{method} eq 'HEAD'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | 62 | ▶ | return ($code) if grep { $_ eq $code } @ignore; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | # Determine error type | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 60 | my $error_type = $Code_To_Error{$code}; | |||||||||||||||||||||||||||||||||||||||||
| 378 | 60 | ▶ | unless ($error_type) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 49 | ▶ | if ( defined $body and length $body ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $body and length $body
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
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | $msg = $body; | |||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $body = undef; | |||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 49 | $error_type = $self->error_from_text( $code, $msg ); | |||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 60 | ▶ | delete $params->{data} if $params->{body}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 60 | my %error_args = ( status_code => $code, request => $params ); | |||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | # Extract error message from the body, if present | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 60 | ▶ | if ( $body = $self->serializer->decode($body) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 2 | $error_args{body} = $body; | |||||||||||||||||||||||||||||||||||||||||
| 393 | 2 | ▶ | $msg = $self->_munge_opensearch_exception($body) || $msg; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->_munge_opensearch_exception($body) || $msg
MC/DC0%0/2
$self->_munge_opensearch_exception($body) || $msg
$self->_munge_opensearch_exception($body)
$msg
Truth table33%1/3
A || B
A= $self->_munge_opensearch_exception($body)B= $msg
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 2 | ▶ | $error_args{current_version} = $1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$error_type eq "Conflict" and $msg =~ /: version conflict, current (?:version )?\[(\d+)\]/
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+)\]/
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | if $error_type eq 'Conflict' | ||||||||||||||||||||||||||||||||||||||||||
| 397 | and $msg =~ /: version conflict, current (?:version )?\[(\d+)\]/; | ||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 60 | ▶ | $msg ||= $error_type; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$msg ||= $error_type
MC/DC0%0/2
$msg ||= $error_type
$msg
$error_type
Truth table33%1/3
A ||= B
A= $msgB= $error_type
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 60 | chomp $msg; | |||||||||||||||||||||||||||||||||||||||||
| 402 | 60 | throw( $error_type, "[" . $self->stringify . "]-[$code] $msg", | |||||||||||||||||||||||||||||||||||||||||
| 403 | \%error_args ); | ||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | sub _parse_warnings { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_warnings: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | my @warnings = ref $_[0] eq 'ARRAY' ? @{ shift() } : shift(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | my @str; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | for (@warnings) { | |||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | if ( $_ =~ /^\d+\s+\S+\s+"((?:\\"|[^"])+)"/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | my $msg = $1; | |||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | $msg =~ s/\\"/"/g, push @str, $msg; | |||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | push @str, $_; | |||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | return join "; ", @str; | |||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 424 | 2 | ▶ | sub _munge_opensearch_exception { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_munge_opensearch_exception: called CC=10 SCAR=41.0
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | #=================================== | ||||||||||||||||||||||||||||||||||||||||||
| 426 | 2 | my ( $self, $body ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 427 | 2 | ▶ | return $body unless ref $body eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 2 | ▶ | my $error = $body->{error} || return; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$body->{'error'} || (return)
MC/DC0%0/1
$body->{'error'} || (return)
$body->{'error'}
Truth table50%1/2
A
A= $body->{'error'}
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 2 | ▶ | return $error unless ref $error eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | my $root_causes = $error->{root_cause} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$error->{'root_cause'} || []
MC/DC0%0/1
$error->{'root_cause'} || []
$error->{'root_cause'}
Truth table0%0/2
A
A= $error->{'root_cause'}
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | unless (@$root_causes) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | my $msg = "[" . $error->{type} . "] " if $error->{type}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | $msg .= $error->{reason} if $error->{reason}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | return $msg; | |||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | my $json = $self->serializer; | |||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | my @msgs; | |||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | for (@$root_causes) { | |||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my %cause = (%$_); | |||||||||||||||||||||||||||||||||||||||||
| 442 | my $msg | ||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | = "[" . ( delete $cause{type} ) . "] " . ( delete $cause{reason} ); | |||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | if ( keys %cause ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | $msg .= ", with: " . $json->encode( \%cause ); | |||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | push @msgs, $msg; | |||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | return ( join ", ", @msgs ); | |||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 56 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | __END__ | ||||||||||||||||||||||||||||||||||||||||||