Cxn/AEHTTP.pm

filter: Statementstmt 74.0% 20 / 27 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 1 totaltotal 58.1% 25 / 43 CC 5 SCAR 21.8
CC
5
Cov
57%
error_from_text
20.0
_build__tls_ctx
6.0
BEGIN
1.0
CRAP 8.8
« Client/6_0/Async/Bulk.pm ↑ Summary CxnPool/Async/Sniff.pm »
1 package Search::Elasticsearch::Cxn::AEHTTP;
2 24 $Search::Elasticsearch::Cxn::AEHTTP::VERSION = '6.80';
3 24 ▶use AnyEvent::HTTP qw(http_request);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use Promises qw(deferred);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 24 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 24 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 24 with 'Search::Elasticsearch::Role::Cxn::Async';
9 24 with 'Search::Elasticsearch::Role::Cxn',
10 'Search::Elasticsearch::Role::Is_Async';
11  
12 24 has '_tls_ctx' => ( is => 'lazy' );
13  
14 24 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #===================================
17 sub _build__tls_ctx {
18 #===================================
19 0 ▶ my $self = shift;
Subroutine _build__tls_ctx: not called CC=2 SCAR=17.9
20 0 ▶ return 'low' unless $self->has_ssl_options;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_ssl_options 0 0 0
21 0 require AnyEvent::TLS;
22 0 return AnyEvent::TLS->new( %{ $self->ssl_options } );
23 }
24  
25 #===================================
26 sub perform_request {
27 #===================================
28 my ( $self, $params ) = @_;
29 my $uri = $self->build_uri($params);
30 my $method = $params->{method};
31 my %headers = ( %{ $self->default_headers } );
32 my $data = $params->{data};
33 if ( defined $data ) {
34 $headers{'Content-Type'} = $params->{mime_type};
35 $headers{'Content-Encoding'} = $params->{encoding}
36 if $params->{encoding};
37 }
38  
39 my $deferred = deferred;
40  
41 http_request(
42 $method => $uri,
43 headers => \%headers,
44 timeout => $params->{timeout} || $self->request_timeout,
45 body => $data,
46 persistent => 0,
47 session => $self->_pid,
48 ( %{ $self->handle_args } ),
49 ( $self->is_https ? ( tls_ctx => $self->_tls_ctx ) : () ),
50 sub {
51 my ( $body, $headers ) = @_;
52 try {
53 my ( $code, $response ) = $self->process_response(
54 $params, # request
55 delete $headers->{Status}, # code
56 delete $headers->{Reason}, # msg
57 $body, # body
58 $headers # headers
59 );
60 $deferred->resolve( $code, $response );
61 }
62 catch {
63 $deferred->reject($_);
64 }
65  
66 }
67 );
68 $deferred->promise;
69 }
70  
71 #===================================
72 sub error_from_text {
73 #===================================
74 0 ▶ local $_ = $_[2];
Subroutine error_from_text: not called CC=4 SCAR=30.0
Pod undocumented
75 return
76 0 ▶ /[Tt]imed out/ ? 'Timeout'
Branch: 3 branches
BranchTrueFalseTotal
/[Tt]imed out/ ? : 0 0 0
/certificate verify failed/ ? : 0 0 0
/Invalid argument/ ? : 0 0 0
77 : /certificate verify failed/ ? 'SSL'
78 : /Invalid argument/ ? 'Cxn'
79 : 'Request';
80 }
81  
82 24 1;
83  
84 # ABSTRACT: An async Cxn implementation which uses AnyEvent::HTTP
85  
86 __END__
« Client/6_0/Async/Bulk.pm ↑ Summary CxnPool/Async/Sniff.pm »