lib/Kubernetes/REST/HTTPTinyIO.pm

filter: Statementstmt 92.0% 58 / 63 Branchbran 81.2% 26 / 32 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 90.0% 100 / 111 CC 19 SCAR 18.2
CC
19
Cov
89%
__ANON__
13.1
_headers
4.0
__ANON__
3.0
CRAP 6.2
« lib/Kubernetes/REST/AuthExec.pm ↑ Summary lib/Kubernetes/REST/CLI/Crd2Class.pm »
1 package Kubernetes::REST::HTTPTinyIO;
2 4 our $VERSION = '1.113';
3 # ABSTRACT: HTTP client using HTTP::Tiny
4 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use IO::Socket::SSL;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Kubernetes::REST::HTTPResponse;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Types::Standard qw/Bool/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 with 'Kubernetes::REST::Role::IO';
11  
12  
13 4 has ssl_verify_server => (is => 'ro', isa => Bool, default => 1);
14  
15  
16 4 has ssl_cert_file => (is => 'ro');
17  
18  
19 4 has ssl_cert_pem => (is => 'ro');
20  
21  
22 4 has ssl_key_file => (is => 'ro');
23  
24  
25 4 has ssl_key_pem => (is => 'ro');
26  
27  
28 4 has ssl_ca_file => (is => 'ro');
29  
30  
31 4 has ssl_ca_pem => (is => 'ro');
32  
33  
34 17 ▶has timeout => (is => 'ro', default => sub { 310 });
Subroutine __ANON__: called CC=1 SCAR=0.0
35  
36  
37 4 ▶has ua => (is => 'ro', lazy => 1, default => sub {
Subroutine __ANON__: called CC=10 SCAR=25.7
38 4 my $self = shift;
39 4 require IO::Socket::SSL::Utils;
40  
41 4 my %options;
42 4 ▶ $options{ SSL_verify_mode } = $self->ssl_verify_server ? SSL_VERIFY_PEER : SSL_VERIFY_NONE;
Branch: 1 branch
BranchTrueFalseTotal
$self->ssl_verify_server ? : 3 1 4
43  
44 4 ▶ if (defined $self->ssl_cert_pem) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->ssl_cert_pem) { } 0 4 4
elsif (defined $self->ssl_cert_file) { } 0 4 4
45 0 $options{ SSL_cert } = [ IO::Socket::SSL::Utils::PEM_string2cert($self->ssl_cert_pem) ];
46 } elsif (defined $self->ssl_cert_file) {
47 0 $options{ SSL_cert_file } = $self->ssl_cert_file;
48 }
49  
50 4 ▶ if (defined $self->ssl_key_pem) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->ssl_key_pem) { } 0 4 4
elsif (defined $self->ssl_key_file) { } 0 4 4
51 0 $options{ SSL_key } = IO::Socket::SSL::Utils::PEM_string2key($self->ssl_key_pem);
52 } elsif (defined $self->ssl_key_file) {
53 0 $options{ SSL_key_file } = $self->ssl_key_file;
54 }
55  
56 4 ▶ if (defined $self->ssl_ca_pem) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->ssl_ca_pem) { } 0 4 4
elsif (defined $self->ssl_ca_file) { } 1 3 4
57 0 $options{ SSL_ca } = [ IO::Socket::SSL::Utils::PEM_string2cert($self->ssl_ca_pem) ];
58 } elsif (defined $self->ssl_ca_file) {
59 1 $options{ SSL_ca_file } = $self->ssl_ca_file;
60 }
61  
62 4 ▶ return HTTP::Tiny->new(
Branch: 1 branch
BranchTrueFalseTotal
$self->ssl_verify_server ? : 3 1 4
Condition100%2/2
$Kubernetes::REST::VERSION // "dev"
l!l
13
MC/DC100%1/1
$Kubernetes::REST::VERSION // "dev"
$Kubernetes::REST::VERSION
Truth table100%2/2
A
A= $Kubernetes::REST::VERSION
Aresult
11
00
63 agent => 'Kubernetes::REST Perl Client ' . ($Kubernetes::REST::VERSION // 'dev'),
64 timeout => $self->timeout,
65 verify_SSL => $self->ssl_verify_server ? 1 : 0,
66 SSL_options => \%options,
67 );
68 4 });
69  
70  
71 13 ▶sub call {
Subroutine call: called CC=3 SCAR=11.0
Pod documented
72 13 my ($self, $req) = @_;
73  
74  
75 13 ▶ my $res = $self->ua->request(
Branch: 1 branch
BranchTrueFalseTotal
defined $req->content ? : 1 12 13
76 $req->method,
77 $req->url,
78 {
79 headers => $req->headers,
80 (defined $req->content) ? (content => $req->content) : (),
81 }
82 );
83  
84 return Kubernetes::REST::HTTPResponse->new(
85 status => $res->{ status },
86 (defined $res->{ content })?( content => $res->{ content } ) : (),
87 13 ▶ headers => $self->_headers($res->{ headers }),
Branch: 1 branch
BranchTrueFalseTotal
defined $res->{'content'} ? : 12 1 13
88 );
89 }
90  
91 8 ▶sub call_streaming {
Subroutine call_streaming: called CC=3 SCAR=11.0
Pod documented
92 8 my ($self, $req, $data_callback) = @_;
93  
94  
95 # HTTP::Tiny turns a die in data_callback into a 599; keep the original
96 # exception and rethrow it unchanged after the request.
97 8 my ( $failed, $error );
98 my $res = $self->ua->request(
99 $req->method,
100 $req->url,
101 {
102 headers => $req->headers,
103 6 ▶ data_callback => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
104 6 ▶ return if $failed;
Branch: 1 branch
BranchTrueFalseTotal
if $failed 0 6 6
105 6 ▶ unless ( eval { $data_callback->(@_); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { &$data_callback(@_); 1 } }) 2 4 6
106 2 ( $failed, $error ) = ( 1, $@ );
107 2 die $error;
108 }
109 },
110 }
111 8 );
112  
113 8 ▶ die $error if $failed;
Branch: 1 branch
BranchTrueFalseTotal
if $failed 2 6 8
114  
115 return Kubernetes::REST::HTTPResponse->new(
116 status => $res->{ status },
117 (defined $res->{ content })?( content => $res->{ content } ) : (),
118 6 ▶ headers => $self->_headers($res->{ headers }),
Branch: 1 branch
BranchTrueFalseTotal
defined $res->{'content'} ? : 4 2 6
119 );
120 }
121  
122 # HTTP::Tiny's headers - lowercased names, a string for a header that came
123 # once and an arrayref for a repeated one - as an arrayref of values each, in
124 # the order they came (karr k79). A response without headers has none.
125 19 ▶sub _headers {
Subroutine _headers: called CC=4 SCAR=13.9
126 19 my ($self, $headers) = @_;
127 19 ▶ return {} unless ref $headers eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $headers eq "HASH" 10 9 19
128 9 my %headers;
129 9 for my $name (keys %$headers) {
130 17 my $value = $headers->{$name};
131 17 ▶ $headers{ lc $name } = [ ref $value eq 'ARRAY' ? @$value : $value ];
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 1 16 17
132 }
133 9 return \%headers;
134 }
135  
136 4 1;
137  
138 __END__
« lib/Kubernetes/REST/AuthExec.pm ↑ Summary lib/Kubernetes/REST/CLI/Crd2Class.pm »