File Coverage

blib/lib/Kubernetes/REST/HTTPTinyIO.pm
Criterion Covered Total %
statement 15 19 78.9
branch 0 6 0.0
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 20 32 62.5


line stmt bran cond sub pod time code
1             package Kubernetes::REST::HTTPTinyIO;
2 1     1   1058 use Moo;
  1         2  
  1         6  
3 1     1   329 use HTTP::Tiny;
  1         2  
  1         19  
4 1     1   791 use IO::Socket::SSL;
  1         46626  
  1         8  
5 1     1   577 use Kubernetes::REST::HTTPResponse;
  1         3  
  1         35  
6 1     1   7 use Types::Standard qw/Bool/;
  1         2  
  1         5  
7              
8             has ssl_verify_server => (is => 'ro', isa => Bool, default => 1);
9             has ssl_cert_file => (is => 'ro');
10             has ssl_key_file => (is => 'ro');
11             has ssl_ca_file => (is => 'ro');
12              
13             has ua => (is => 'ro', lazy => 1, default => sub {
14             my $self = shift;
15              
16             my %options;
17             $options{ SSL_verify_mode } = SSL_VERIFY_PEER if ($self->ssl_verify_server);
18             $options{ SSL_cert_file } = $self->ssl_cert_file if (defined $self->ssl_cert_file);
19             $options{ SSL_key_file } = $self->ssl_key_file if (defined $self->ssl_key_file);
20             $options{ SSL_ca_file } = $self->ssl_ca_file if (defined $self->ssl_ca_file);
21            
22             return HTTP::Tiny->new(
23             agent => 'Kubernetes::REST Perl Client ' . $Kubernetes::REST::VERSION,
24             SSL_options => \%options,
25             );
26             });
27              
28             sub call {
29 0     0 0   my ($self, $call, $req) = @_;
30              
31 0 0         $req->authenticate if (defined $req->credentials);
32              
33 0 0         my $res = $self->ua->request(
34             $req->method,
35             $req->url,
36             {
37             headers => $req->headers,
38             (defined $req->content) ? (content => $req->content) : (),
39             }
40             );
41              
42             return Kubernetes::REST::HTTPResponse->new(
43             status => $res->{ status },
44 0 0         (defined $res->{ content })?( content => $res->{ content } ) : (),
45             );
46             }
47              
48             1;