| 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
Condition100%5/5
ref $status eq "HASH" and ($status->{"kind"} // "") eq "Status"
$status->{"kind"} // ""
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"}
| |||||||||||||||||||||||||||||||||
| 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 // {}
MC/DC100%1/1
$_[0]->_status // {}
$_[0]->_status
Truth table100%2/2
A
A= $_[0]->_status
| |||||||||||||||||||||||||||||||||
| 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 // {}
MC/DC100%1/1
$_[0]->_status // {}
$_[0]->_status
Truth table100%2/2
A
A= $_[0]->_status
| |||||||||||||||||||||||||||||||||
| 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 // {}
MC/DC100%1/1
$_[0]->_status // {}
$_[0]->_status
Truth table100%2/2
A
A= $_[0]->_status
| |||||||||||||||||||||||||||||||||
| 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 // ""
MC/DC100%1/1
$self->context // ""
$self->context
Truth table100%2/2
A
A= $self->context
| |||||||||||||||||||||||||||||||||
| 81 | . $self->code . ' ' . $self->body . $self->_location; | ||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 91 | 1; | |||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||||||||||||||||