| 1 | # Licensed to Elasticsearch B.V under one or more agreements. | ||||||||||||||||||||
| 2 | # Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||||||||||||||||||||
| 3 | # See the LICENSE file in the project root for more information | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | package Search::Elasticsearch::Role::Transport; | ||||||||||||||||||||
| 6 | 55 | $Search::Elasticsearch::Role::Transport::VERSION = '8.12'; | |||||||||||||||||||
| 7 | 55 | ▶ | use Moo::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 55 | requires qw(perform_request); | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 55 | ▶ | use Try::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 55 | ▶ | use Search::Elasticsearch::Util qw(parse_params is_compat); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 55 | ▶ | use namespace::clean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 55 | has 'serializer' => ( is => 'ro', required => 1 ); | |||||||||||||||||||
| 16 | 55 | has 'logger' => ( is => 'ro', required => 1 ); | |||||||||||||||||||
| 17 | 55 | has 'send_get_body_as' => ( is => 'ro', default => 'GET' ); | |||||||||||||||||||
| 18 | 55 | has 'cxn_pool' => ( is => 'ro', required => 1 ); | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | #=================================== | ||||||||||||||||||||
| 21 | 100 | ▶ | sub BUILD { | ||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 22 | #=================================== | ||||||||||||||||||||
| 23 | 100 | my $self = shift; | |||||||||||||||||||
| 24 | 100 | my $pool = $self->cxn_pool; | |||||||||||||||||||
| 25 | 100 | is_compat( 'cxn_pool', $self, $pool ); | |||||||||||||||||||
| 26 | 100 | is_compat( 'cxn', $self, $pool->cxn_factory->cxn_class ); | |||||||||||||||||||
| 27 | 100 | return $self; | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | #=================================== | ||||||||||||||||||||
| 31 | 175 | ▶ | sub tidy_request { | ||||||||||||||||||
|
Subroutine
tidy_request: called CC=12 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||
| 32 | #=================================== | ||||||||||||||||||||
| 33 | 175 | my ( $self, $params ) = parse_params(@_); | |||||||||||||||||||
| 34 | 175 | ▶ | $params->{method} ||= 'GET'; | ||||||||||||||||||
|
Condition100%2/2
$params->{"method"} ||= "GET"
MC/DC100%1/1
$params->{"method"} ||= "GET"
$params->{"method"}
Truth table100%2/2
A
A= $params->{"method"}
| |||||||||||||||||||||
| 35 | 175 | ▶ | $params->{path} ||= '/'; | ||||||||||||||||||
|
Condition100%2/2
$params->{"path"} ||= "/"
MC/DC100%1/1
$params->{"path"} ||= "/"
$params->{"path"}
Truth table100%2/2
A
A= $params->{"path"}
| |||||||||||||||||||||
| 36 | 175 | ▶ | $params->{qs} ||= {}; | ||||||||||||||||||
|
Condition100%2/2
$params->{"qs"} ||= {}
MC/DC100%1/1
$params->{"qs"} ||= {}
$params->{"qs"}
Truth table100%2/2
A
A= $params->{"qs"}
| |||||||||||||||||||||
| 37 | 175 | ▶ | $params->{ignore} ||= []; | ||||||||||||||||||
|
Condition100%2/2
$params->{"ignore"} ||= []
MC/DC100%1/1
$params->{"ignore"} ||= []
$params->{"ignore"}
Truth table100%2/2
A
A= $params->{"ignore"}
| |||||||||||||||||||||
| 38 | 175 | my $body = $params->{body}; | |||||||||||||||||||
| 39 | 175 | ▶ | return $params unless defined $body; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 8 | ▶ | $params->{serialize} ||= 'std'; | ||||||||||||||||||
|
Condition100%2/2
$params->{"serialize"} ||= "std"
MC/DC100%1/1
$params->{"serialize"} ||= "std"
$params->{"serialize"}
Truth table100%2/2
A
A= $params->{"serialize"}
| |||||||||||||||||||||
| 42 | $params->{data} | ||||||||||||||||||||
| 43 | 8 | ▶ | = $params->{serialize} eq 'std' | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | ? $self->serializer->encode($body) | ||||||||||||||||||||
| 45 | : $self->serializer->encode_bulk($body); | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 8 | ▶ | if ( $params->{method} eq 'GET' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | 8 | my $send_as = $self->send_get_body_as; | |||||||||||||||||||
| 49 | 8 | ▶ | if ( $send_as eq 'POST' ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 50 | 1 | $params->{method} = 'POST'; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | elsif ( $send_as eq 'source' ) { | ||||||||||||||||||||
| 53 | 1 | $params->{qs}{source} = delete $params->{data}; | |||||||||||||||||||
| 54 | 1 | delete $params->{body}; | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 8 | ▶ | $params->{mime_type} ||= $self->serializer->mime_type; | ||||||||||||||||||
|
Condition66%2/3
$params->{"mime_type"} ||= $self->serializer->mime_type
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
| |||||||||||||||||||||
| 59 | 8 | return $params; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 55 | 1; | |||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | #ABSTRACT: Transport role providing interface between the client class and the Elasticsearch cluster | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||