| line | stmt | bran | cond | sub | pod | time | code | 
| 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 |  |  |  |  |  |  | $Search::Elasticsearch::Role::Transport::VERSION = '8.00'; | 
| 7 | 55 |  |  | 55 |  | 31606 | use Moo::Role; | 
|  | 55 |  |  |  |  | 128 |  | 
|  | 55 |  |  |  |  | 528 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | requires qw(perform_request); | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 55 |  |  | 55 |  | 19095 | use Try::Tiny; | 
|  | 55 |  |  |  |  | 169 |  | 
|  | 55 |  |  |  |  | 2993 |  | 
| 12 | 55 |  |  | 55 |  | 355 | use Search::Elasticsearch::Util qw(parse_params is_compat); | 
|  | 55 |  |  |  |  | 104 |  | 
|  | 55 |  |  |  |  | 412 |  | 
| 13 | 55 |  |  | 55 |  | 18200 | use namespace::clean; | 
|  | 55 |  |  |  |  | 116 |  | 
|  | 55 |  |  |  |  | 300 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | has 'serializer'       => ( is => 'ro', required => 1 ); | 
| 16 |  |  |  |  |  |  | has 'logger'           => ( is => 'ro', required => 1 ); | 
| 17 |  |  |  |  |  |  | has 'send_get_body_as' => ( is => 'ro', default  => 'GET' ); | 
| 18 |  |  |  |  |  |  | has 'cxn_pool'         => ( is => 'ro', required => 1 ); | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | #=================================== | 
| 21 |  |  |  |  |  |  | sub BUILD { | 
| 22 |  |  |  |  |  |  | #=================================== | 
| 23 | 100 |  |  | 100 | 0 | 86220 | my $self = shift; | 
| 24 | 100 |  |  |  |  | 338 | my $pool = $self->cxn_pool; | 
| 25 | 100 |  |  |  |  | 425 | is_compat( 'cxn_pool', $self, $pool ); | 
| 26 | 100 |  |  |  |  | 1911 | is_compat( 'cxn',      $self, $pool->cxn_factory->cxn_class ); | 
| 27 | 100 |  |  |  |  | 1704 | return $self; | 
| 28 |  |  |  |  |  |  | } | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | #=================================== | 
| 31 |  |  |  |  |  |  | sub tidy_request { | 
| 32 |  |  |  |  |  |  | #=================================== | 
| 33 | 175 |  |  | 175 | 0 | 18910 | my ( $self, $params ) = parse_params(@_); | 
| 34 | 175 |  | 100 |  |  | 937 | $params->{method} ||= 'GET'; | 
| 35 | 175 |  | 100 |  |  | 705 | $params->{path}   ||= '/'; | 
| 36 | 175 |  | 100 |  |  | 689 | $params->{qs}     ||= {}; | 
| 37 | 175 |  | 100 |  |  | 716 | $params->{ignore} ||= []; | 
| 38 | 175 |  |  |  |  | 292 | my $body = $params->{body}; | 
| 39 | 175 | 100 |  |  |  | 517 | return $params unless defined $body; | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 8 |  | 100 |  |  | 38 | $params->{serialize} ||= 'std'; | 
| 42 |  |  |  |  |  |  | $params->{data} | 
| 43 | 8 | 100 |  |  |  | 61 | = $params->{serialize} eq 'std' | 
| 44 |  |  |  |  |  |  | ? $self->serializer->encode($body) | 
| 45 |  |  |  |  |  |  | : $self->serializer->encode_bulk($body); | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 8 | 50 |  |  |  | 121 | if ( $params->{method} eq 'GET' ) { | 
| 48 | 8 |  |  |  |  | 27 | my $send_as = $self->send_get_body_as; | 
| 49 | 8 | 100 |  |  |  | 29 | if ( $send_as eq 'POST' ) { | 
|  |  | 100 |  |  |  |  |  | 
| 50 | 1 |  |  |  |  | 3 | $params->{method} = 'POST'; | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  | elsif ( $send_as eq 'source' ) { | 
| 53 | 1 |  |  |  |  | 3 | $params->{qs}{source} = delete $params->{data}; | 
| 54 | 1 |  |  |  |  | 3 | delete $params->{body}; | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 8 |  | 66 |  |  | 53 | $params->{mime_type} ||= $self->serializer->mime_type; | 
| 59 | 8 |  |  |  |  | 25 | return $params; | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | 1; | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | #ABSTRACT: Transport role providing interface between the client class and the Elasticsearch cluster | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | __END__ |