Client/Role/Transport.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 8 / 8 Conditioncond 92.3% 12 / 13 MC/DCmcdc 71.4% 5 / 7 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 93.4% 71 / 76 CC 11 SCAR 20.6
CC
11
Cov
98%
tidy_request
11.0
BEGIN
1.0
BEGIN
1.0
CRAP 7.9
« Client/Role/CxnPool/Sniff.pm ↑ Summary Client/Error.pm »
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::Transport;
24 56 $OpenSearch::Client::Role::Transport::VERSION = '3.007011';
25 56 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 56 requires qw(perform_request);
28  
29 56 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 56 ▶use OpenSearch::Client::Util qw(parse_params is_compat);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 56 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 56 has 'serializer' => ( is => 'ro', required => 1 );
34 56 has 'logger' => ( is => 'ro', required => 1 );
35 56 has 'send_body_as_source' => ( is => 'ro', default => 0 );
36 56 has 'cxn_pool' => ( is => 'ro', required => 1 );
37  
38 #===================================
39 100 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
40 #===================================
41 100 my $self = shift;
42 100 my $pool = $self->cxn_pool;
43 100 is_compat( 'cxn_pool', $self, $pool );
44 100 is_compat( 'cxn', $self, $pool->cxn_factory->cxn_class );
45 100 return $self;
46 }
47  
48 #===================================
49 175 ▶sub tidy_request {
Subroutine tidy_request: called CC=11 SCAR=24.0
Pod undocumented
50 #===================================
51 175 my ( $self, $params ) = parse_params(@_);
52 175 ▶ $params->{method} ||= 'GET';
Condition100%2/2
$params->{"method"} ||= "GET"
l!l
21154
MC/DC100%1/1
$params->{"method"} ||= "GET"
$params->{"method"}
Truth table100%2/2
A
A= $params->{"method"}
Aresult
11
00
53 175 ▶ $params->{path} ||= '/';
Condition100%2/2
$params->{"path"} ||= "/"
l!l
26149
MC/DC100%1/1
$params->{"path"} ||= "/"
$params->{"path"}
Truth table100%2/2
A
A= $params->{"path"}
Aresult
11
00
54 175 ▶ $params->{qs} ||= {};
Condition100%2/2
$params->{"qs"} ||= {}
l!l
20155
MC/DC100%1/1
$params->{"qs"} ||= {}
$params->{"qs"}
Truth table100%2/2
A
A= $params->{"qs"}
Aresult
11
00
55 175 ▶ $params->{ignore} ||= [];
Condition100%2/2
$params->{"ignore"} ||= []
l!l
19156
MC/DC100%1/1
$params->{"ignore"} ||= []
$params->{"ignore"}
Truth table100%2/2
A
A= $params->{"ignore"}
Aresult
11
00
56 175 my $body = $params->{body};
57 175 ▶ return $params unless defined $body;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body 167 8 175
58  
59 8 ▶ $params->{serialize} ||= 'std';
Condition100%2/2
$params->{"serialize"} ||= "std"
l!l
17
MC/DC100%1/1
$params->{"serialize"} ||= "std"
$params->{"serialize"}
Truth table100%2/2
A
A= $params->{"serialize"}
Aresult
11
00
60 $params->{data}
61 8 ▶ = $params->{serialize} eq 'std'
Branch: 1 branch
BranchTrueFalseTotal
$params->{'serialize'} eq 'std' ? : 7 1 8
62 ? $self->serializer->encode($body)
63 : $self->serializer->encode_bulk($body);
64  
65 8 ▶ if ( $self->send_body_as_source ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->send_body_as_source) 1 7 8
66 1 $params->{qs}{source} = delete $params->{data};
67 1 delete $params->{body};
68 }
69
70 8 ▶ if ( $params->{serialize} eq 'bulk' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"serialize"} eq "bulk") 1 7 8
71 1 $params->{mime_type} = 'application/x-ndjson';
72 }
73
74 8 ▶ $params->{mime_type} ||= $self->serializer->mime_type;
Condition66%2/3
$params->{"mime_type"} ||= $self->serializer->mime_type
l!l&&r!l&&!r
260
MC/DC0%0/2
$params->{"mime_type"} ||= $self->serializer->mime_type
$params->{"mime_type"} $self->serializer->mime_type
Truth table66%2/3
A ||= B
A= $params->{"mime_type"}B= $self->serializer->mime_type
ABresult
1X1
011
000
75 8 return $params;
76  
77 }
78  
79 56 1;
80  
81 __END__
« Client/Role/CxnPool/Sniff.pm ↑ Summary Client/Error.pm »