| 1 | package Kubernetes::Comb::CRD::CombSpec; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Spec of the Comb custom resource | ||||||||||||||||||||||||||||
| 3 | 28 | our $VERSION = '0.002'; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 28 | ▶ | use IO::K8s::Resource; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 28 | ▶ | use IO::K8s::Types qw( Opaque ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 28 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 28 | k8s class => Str, { | |||||||||||||||||||||||||||
| 11 | required => 1, | ||||||||||||||||||||||||||||
| 12 | description => 'Perl class of the Comb; a stub is just another class' | ||||||||||||||||||||||||||||
| 13 | }; | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 28 | k8s dependsOn => [Str], { | |||||||||||||||||||||||||||
| 17 | description => 'Combs this one needs, as "name" or "namespace/name"' | ||||||||||||||||||||||||||||
| 18 | }; | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 28 | k8s config => Opaque, { | |||||||||||||||||||||||||||
| 22 | preserve_unknown => 1, | ||||||||||||||||||||||||||||
| 23 | description => 'Free-form configuration for the class' | ||||||||||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 28 | k8s enabled => Bool, { | |||||||||||||||||||||||||||
| 28 | description => 'Unset: automatic, false: off, true: on' | ||||||||||||||||||||||||||||
| 29 | }; | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 28 | k8s upstream => Opaque, { | |||||||||||||||||||||||||||
| 33 | nullable => 1, | ||||||||||||||||||||||||||||
| 34 | preserve_unknown => 1, | ||||||||||||||||||||||||||||
| 35 | description => 'Where the Comb borrows its service from: class plus' | ||||||||||||||||||||||||||||
| 36 | .' upstream-specific keys; null means local' | ||||||||||||||||||||||||||||
| 37 | }; | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 28 | has '+upstream' => ( predicate => 1 ); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 723 | ▶ | sub FROM_STRUCT { | ||||||||||||||||||||||||||
|
Subroutine
FROM_STRUCT: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 723 | my ( $class, $struct ) = @_; | |||||||||||||||||||||||||||
| 44 | 723 | ▶ | croak $class.'->FROM_STRUCT needs a hashref, got '.( ref $struct || 'a plain scalar' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $struct || 'a plain scalar'
MC/DC0%0/1
ref $struct || 'a plain scalar'
ref $struct
Truth table50%1/2
A
A= ref $struct
| |||||||||||||||||||||||||||||
| 45 | unless ref $struct eq 'HASH'; | ||||||||||||||||||||||||||||
| 46 | 722 | my %args; | |||||||||||||||||||||||||||
| 47 | 722 | for my $key ( keys %$struct ) { | |||||||||||||||||||||||||||
| 48 | 1153 | my $value = $struct->{$key}; | |||||||||||||||||||||||||||
| 49 | 1153 | ▶ | next unless defined $value || $key eq 'upstream'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $value or $key eq "upstream"
MC/DC100%2/2
defined $value or $key eq "upstream"
defined $value
$key eq "upstream"
Truth table100%3/3
A or B
A= defined $valueB= $key eq "upstream"
| |||||||||||||||||||||||||||||
| 50 | 1151 | ▶ | $args{$key} = ref $value eq 'HASH' ? { %$value } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 51 | : ref $value eq 'ARRAY' ? [ @$value ] | ||||||||||||||||||||||||||||
| 52 | : $value; | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 722 | return $class->new(%args); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 625 | ▶ | around TO_JSON => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 59 | 625 | my ( $orig, $self, @args ) = @_; | |||||||||||||||||||||||||||
| 60 | 625 | my $data = $self->$orig(@args); | |||||||||||||||||||||||||||
| 61 | 625 | ▶ | $data->{upstream} = undef if $self->has_upstream && !defined $self->upstream; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->has_upstream and not defined $self->upstream
MC/DC100%2/2
$self->has_upstream and not defined $self->upstream
$self->has_upstream
not defined $self->upstream
Truth table100%3/3
A and not(B)
A= $self->has_upstreamB= not defined $self->upstream
| |||||||||||||||||||||||||||||
| 62 | 625 | return $data; | |||||||||||||||||||||||||||
| 63 | 28 | }; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 28 | 1; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||||||||||