| 1 | package Kubernetes::Comb::Client::Async; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Asynchronous Comb client on Net::Async::Kubernetes | ||||||||||||||||||||||||||||
| 3 | our $VERSION = '0.002'; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | with 'Kubernetes::Comb::Role::Client'; | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use Future; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use IO::K8s; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use Module::Runtime qw( module_notional_filename require_module ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use Types::Standard qw( InstanceOf Str ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 8 | ▶ | use Kubernetes::Comb::CRD; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 8 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # Optional dependencies (recommends): loaded here, not with `use`, so the | ||||||||||||||||||||||||||||
| 17 | # rest of the distribution never needs them, and a missing or too old one is | ||||||||||||||||||||||||||||
| 18 | # named. Each is a module and, where one is needed, its minimum version -- | ||||||||||||||||||||||||||||
| 19 | # the only place in the code that states it. | ||||||||||||||||||||||||||||
| 20 | for my $optional ( [ 'IO::Async::Loop' ], [ 'Net::Async::Kubernetes', '0.009' ] ) { | ||||||||||||||||||||||||||||
| 21 | my ( $module, $minimum ) = @$optional; | ||||||||||||||||||||||||||||
| 22 | croak __PACKAGE__.' needs '.$module.', an optional dependency of' | ||||||||||||||||||||||||||||
| 23 | .' Kubernetes::Comb that is not available: '.$@ | ||||||||||||||||||||||||||||
| 24 | unless eval { require_module($module); 1 }; | ||||||||||||||||||||||||||||
| 25 | next unless defined $minimum; | ||||||||||||||||||||||||||||
| 26 | next if eval { $module->VERSION($minimum); 1 }; | ||||||||||||||||||||||||||||
| 27 | my $found = $module->VERSION; | ||||||||||||||||||||||||||||
| 28 | croak __PACKAGE__.' needs '.$module.' '.$minimum.' or newer, an optional' | ||||||||||||||||||||||||||||
| 29 | .' dependency of Kubernetes::Comb, and found ' | ||||||||||||||||||||||||||||
| 30 | .( defined $found ? $found : 'one without a version' ) | ||||||||||||||||||||||||||||
| 31 | .' in '.$INC{ module_notional_filename($module) }; | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | has kubeconfig => ( is => 'ro', isa => Str, predicate => 1 ); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | has context => ( is => 'ro', isa => Str, predicate => 1 ); | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | has kube => ( | ||||||||||||||||||||||||||||
| 42 | is => 'lazy', | ||||||||||||||||||||||||||||
| 43 | isa => InstanceOf['Net::Async::Kubernetes'], | ||||||||||||||||||||||||||||
| 44 | predicate => '_has_kube' | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 5 | ▶ | sub _build_kube { | ||||||||||||||||||||||||||
|
Subroutine
_build_kube: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 48 | 5 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 49 | my $kube = Net::Async::Kubernetes->new( | ||||||||||||||||||||||||||||
| 50 | ( $self->has_kubeconfig ? ( kubeconfig => $self->kubeconfig ) : () ), | ||||||||||||||||||||||||||||
| 51 | ( $self->has_context ? ( context => $self->context ) : () ), | ||||||||||||||||||||||||||||
| 52 | resource_map => { | ||||||||||||||||||||||||||||
| 53 | 5 | %{ IO::K8s->default_resource_map }, | |||||||||||||||||||||||||||
| 54 | 5 | ▶ | %{ Kubernetes::Comb::CRD->new->resource_map } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | 4 | $self->loop->add($kube); | |||||||||||||||||||||||||||
| 58 | 4 | return $kube; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | has loop => ( is => 'lazy', isa => InstanceOf['IO::Async::Loop'] ); | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 1 | ▶ | sub _build_loop { | ||||||||||||||||||||||||||
|
Subroutine
_build_loop: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||
| 65 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 66 | 1 | ▶ | return $self->kube->loop if $self->_has_kube && $self->kube->loop; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->_has_kube and $self->kube->loop
MC/DC0%0/2
$self->_has_kube and $self->kube->loop
$self->_has_kube
$self->kube->loop
Truth table33%1/3
A and B
A= $self->_has_kubeB= $self->kube->loop
| |||||||||||||||||||||||||||||
| 67 | 0 | return IO::Async::Loop->new; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 2 | ▶ | sub get { shift->_call( get => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub list { shift->_call( list => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
list: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 73 | 1 | ▶ | sub ensure { shift->_call( ensure => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
ensure: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 74 | 2 | ▶ | sub delete { shift->_call( delete => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
delete: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 75 | 1 | ▶ | sub update { shift->_call( update => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
update: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub patch { shift->_call( patch => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
patch: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub update_status { shift->_call( update_status => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
update_status: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub patch_status { shift->_call( patch_status => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
patch_status: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub log { shift->_call( log => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
log: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 6 | ▶ | sub _call { | ||||||||||||||||||||||||||
|
Subroutine
_call: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 82 | 6 | my ( $self, $method, @args ) = @_; | |||||||||||||||||||||||||||
| 83 | 6 | ▶ | return Future->call( sub { $self->kube->$method(@args) } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 3 | ▶ | sub server_url { shift->kube->server->endpoint } | ||||||||||||||||||||||||||
|
Subroutine
server_url: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 12 | ▶ | has _for_context => ( is => 'ro', init_arg => undef, default => sub { {} } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 3 | ▶ | sub for_context { | ||||||||||||||||||||||||||
|
Subroutine
for_context: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||
| 93 | 3 | my ( $self, $context ) = @_; | |||||||||||||||||||||||||||
| 94 | 3 | ▶ | return $self->_for_context->{$context} //= ref($self)->new( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->_for_context->{$context} //= ref($self)->new("loop", $self->loop, $self->has_kubeconfig ? ("kubeconfig", $self->kubeconfig) : (), "context", $context)
MC/DC0%0/2
$self->_for_context->{$context} //= ref($self)->new("loop", $self->loop, $self->has_kubeconfig ? ("kubeconfig", $self->kubeconfig) : (), "context", $context)
$self->_for_context->{$context}
ref($self)->new("loop", $self->loop, $self->has_kubeconfig ? ("kubeconfig", $self->kubeconfig) : (), "context", $context)
Truth table66%2/3
A //= B
A= $self->_for_context->{$context}B= ref($self)->new("loop", $self->loop, $self->has_kubeconfig ? ("kubeconfig", $self->kubeconfig) : (), "context", $context)
| |||||||||||||||||||||||||||||
| 95 | loop => $self->loop, | ||||||||||||||||||||||||||||
| 96 | ( $self->has_kubeconfig ? ( kubeconfig => $self->kubeconfig ) : () ), | ||||||||||||||||||||||||||||
| 97 | context => $context | ||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 1; | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | __END__ | ||||||||||||||||||||||||||||