lib/Kubernetes/REST/APIError.pm

filter: Statementstmt 95.8% 46 / 48 Branchbran 100% 2 / 2 Conditioncond 100% 13 / 13 MC/DCmcdc 100% 6 / 6 Subroutinesub 88.2% 15 / 17 Podpod 100% 3 / 3 totaltotal 95.5% 85 / 89 CC 8 SCAR 6.1
CC
8
Cov
97%
_build__status
4.0
_build_reason
2.0
_build_message
2.0
CRAP 1.8
« lib/Kubernetes/REST/AuthTokenFile.pm ↑ Summary lib/Kubernetes/REST/HTTPRequest.pm »
1 package Kubernetes::REST::APIError;
2 91 our $VERSION = '1.110';
3 # ABSTRACT: An HTTP error status answered by the Kubernetes API
4 91 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 91 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 91 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 91 ▶use Types::Standard qw(Int Maybe Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 91 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 use overload
11 91 ▶ '""' => '_as_string',
Subroutine BEGIN: called CC=1 SCAR=0.0
12 17 ▶ bool => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
13 91 fallback => 1;
14  
15  
16 91 has code => (is => 'ro', isa => Int, required => 1);
17  
18  
19 0 ▶has body => (is => 'ro', isa => Str, default => sub { '' });
Subroutine __ANON__: not called CC=1 SCAR=1.2
20  
21  
22 # Maybe: check_response may be called without a context, and the message
23 # then reads "Kubernetes API error (): ...", as it always did.
24 91 has context => (is => 'ro', isa => Maybe[Str]);
25  
26  
27 91 has response => (is => 'ro');
28  
29  
30 # The Kubernetes Status object the body holds, or undef when it holds none:
31 # a proxy's HTML page, plain text, JSON of another shape, no body at all.
32 91 has _status => (is => 'lazy');
33  
34 10 ▶sub _build__status {
Subroutine _build__status: called CC=4 SCAR=13.9
35 10 my ($self) = @_;
36 # body is characters already, so the decoder must not expect bytes.
37 10 my $status = eval { JSON::MaybeXS->new->decode($self->body) };
38 10 ▶ return unless ref $status eq 'HASH' && ($status->{kind} // '') eq 'Status';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $status eq "HASH" and ($status->{"kind"} // "") eq "Status" 4 6 10
Condition100%5/5
ref $status eq "HASH" and ($status->{"kind"} // "") eq "Status"
!ll&&!rl&&r
316
$status->{"kind"} // ""
l!l
61
MC/DC100%2/2
ref $status eq "HASH" and ($status->{"kind"} // "") eq "Status"
ref $status eq "HASH" $status->{"kind"}
Truth table100%3/3
A and B
A= ref $status eq "HASH"B= $status->{"kind"}
ABresult
0X0
100
111
39 6 return $status;
40 }
41  
42 91 has reason => (is => 'lazy');
43  
44 9 ▶sub _build_reason { ($_[0]->_status // {})->{reason} }
Subroutine _build_reason: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]->_status // {}
l!l
54
MC/DC100%1/1
$_[0]->_status // {}
$_[0]->_status
Truth table100%2/2
A
A= $_[0]->_status
Aresult
11
00
45  
46  
47 91 has message => (is => 'lazy');
48  
49 7 ▶sub _build_message { ($_[0]->_status // {})->{message} }
Subroutine _build_message: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]->_status // {}
l!l
43
MC/DC100%1/1
$_[0]->_status // {}
$_[0]->_status
Truth table100%2/2
A
A= $_[0]->_status
Aresult
11
00
50  
51  
52 91 has details => (is => 'lazy');
53  
54 4 ▶sub _build_details { ($_[0]->_status // {})->{details} }
Subroutine _build_details: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]->_status // {}
l!l
13
MC/DC100%1/1
$_[0]->_status // {}
$_[0]->_status
Truth table100%2/2
A
A= $_[0]->_status
Aresult
11
00
55  
56  
57 # ' at FILE line N.' plus newline, as croak appends it; set by throw.
58 0 ▶has _location => (is => 'ro', default => sub { '' });
Subroutine __ANON__: not called CC=1 SCAR=1.2
59  
60 6 ▶sub is_not_found { $_[0]->code == 404 }
Subroutine is_not_found: called CC=1 SCAR=0.0
Pod documented
61  
62  
63 5 ▶sub is_conflict { $_[0]->code == 409 }
Subroutine is_conflict: called CC=1 SCAR=0.0
Pod documented
64  
65  
66 91 our @CARP_NOT;
67  
68 75 ▶sub throw {
Subroutine throw: called CC=1 SCAR=0.0
Pod documented
69 75 my ($class, %args) = @_;
70 # Trust the package that throws, so Carp skips its frames exactly as a
71 # croak from there would: the location names the caller line the string
72 # croak named before this was an object.
73 75 local @CARP_NOT = (scalar caller);
74 75 die $class->new(%args, _location => Carp::shortmess(''));
75 }
76  
77  
78 76 ▶sub _as_string {
Subroutine _as_string: called CC=2 SCAR=6.9
79 76 my ($self) = @_;
80 76 ▶ return 'Kubernetes API error (' . ($self->context // '') . '): '
Condition100%2/2
$self->context // ""
l!l
751
MC/DC100%1/1
$self->context // ""
$self->context
Truth table100%2/2
A
A= $self->context
Aresult
11
00
81 . $self->code . ' ' . $self->body . $self->_location;
82 }
83  
84 91 1;
85  
86 __END__
« lib/Kubernetes/REST/AuthTokenFile.pm ↑ Summary lib/Kubernetes/REST/HTTPRequest.pm »