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