| 1 | package IO::K8s::ApiextensionsApiserver::Pkg::Apis::Apiextensions::V1::JSONSchemaPropsOrStringArray; | ||||||||||||||||||||
| 2 | # ABSTRACT: JSONSchemaPropsOrStringArray represents a JSONSchemaProps or a string array. | ||||||||||||||||||||
| 3 | 7 | our $VERSION = '1.112'; | |||||||||||||||||||
| 4 | 7 | ▶ | use v5.10; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 7 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 7 | ▶ | use Types::Standard qw( Str ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 7 | ▶ | use JSON::MaybeXS (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | # Carp treats IO::K8s as part of this class (k175), as IO::K8s::List does | ||||||||||||||||||||
| 10 | # (k170): a schema arm is inflated through IO::K8s, and a shape croak raised | ||||||||||||||||||||
| 11 | # there -- a plain scalar where a schema belongs -- names the line that called | ||||||||||||||||||||
| 12 | # FROM_STRUCT, or IO::K8s itself on the way in, not the inflation call below. | ||||||||||||||||||||
| 13 | # A caller in any other package still sees its own line. | ||||||||||||||||||||
| 14 | 7 | our @CARP_NOT = ('IO::K8s'); | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 7 | my $PROPS = 'IO::K8s::ApiextensionsApiserver::Pkg::Apis::Apiextensions::V1::JSONSchemaProps'; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 7 | has schema => ( | |||||||||||||||||||
| 20 | is => 'rw', | ||||||||||||||||||||
| 21 | isa => Types::Standard::Maybe[ Types::Standard::InstanceOf[$PROPS] ], | ||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 7 | has property => ( | |||||||||||||||||||
| 26 | is => 'rw', | ||||||||||||||||||||
| 27 | isa => Types::Standard::Maybe[ Types::Standard::ArrayRef[Str] ], | ||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | ▶ | sub _build__json_encoder { | ||||||||||||||||||
|
Subroutine
_build__json_encoder: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 32 | 0 | return JSON::MaybeXS->new(utf8 => 1, canonical => 1, allow_nonref => 1); | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 5 | ▶ | sub is_schema { | ||||||||||||||||||
|
Subroutine
is_schema: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 37 | 5 | my ($self) = @_; | |||||||||||||||||||
| 38 | 5 | ▶ | return defined $self->property ? 0 : 1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 154 | ▶ | sub FROM_STRUCT { | ||||||||||||||||||
|
Subroutine
FROM_STRUCT: called CC=4 SCAR=15.5
Pod
documented
| |||||||||||||||||||||
| 43 | 154 | my ($class, $struct, $k8s) = @_; | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | # Stringify so the arm always serializes as JSON strings; undef is left | ||||||||||||||||||||
| 46 | # alone so the ArrayRef[Str] constraint reports it instead of quietly | ||||||||||||||||||||
| 47 | # turning it into an empty string. | ||||||||||||||||||||
| 48 | 154 | ▶ | return $class->new(property => [ map { defined($_) ? "$_" : undef } @$struct ]) | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 49 | if ref $struct eq 'ARRAY'; | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 0 | ▶ | $k8s //= do { require IO::K8s; IO::K8s->new }; | ||||||||||||||||||
|
Condition33%1/3
$k8s //= do {
require IO::K8s;
"IO::K8s"->new
}
MC/DC0%0/2
$k8s //= do {
require IO::K8s;
"IO::K8s"->new
}
$k8s
do {
require IO::K8s;
"IO::K8s"->new
}
Truth table33%1/3
A //= B
A= $k8sB= do {
require IO::K8s;
"IO::K8s"->new
}
| |||||||||||||||||||||
| 52 | 11 | return $class->new(schema => $k8s->_struct_to_object_expanded($PROPS, $struct)); | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 226 | ▶ | sub TO_JSON { | ||||||||||||||||||
|
Subroutine
TO_JSON: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 57 | 226 | my ($self) = @_; | |||||||||||||||||||
| 58 | 226 | my $property = $self->property; | |||||||||||||||||||
| 59 | 226 | ▶ | return [ @$property ] if defined $property; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 13 | my $schema = $self->schema; | |||||||||||||||||||
| 61 | 13 | ▶ | return defined $schema ? $schema->TO_JSON : undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | # The node a spec path walks into (IO::K8s::Role::SpecBuilder, k172): the | ||||||||||||||||||||
| 65 | # arm in use -- the property array, named so an element written into it is | ||||||||||||||||||||
| 66 | # checked against that attribute, or the schema. | ||||||||||||||||||||
| 67 | 5 | ▶ | sub _spec_path_node { | ||||||||||||||||||
|
Subroutine
_spec_path_node: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 68 | 5 | my ($self) = @_; | |||||||||||||||||||
| 69 | 5 | my $property = $self->property; | |||||||||||||||||||
| 70 | 5 | ▶ | return defined $property ? ($property, 'property') : ($self->schema); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 7 | with 'IO::K8s::Role::Resource'; | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 7 | 1; | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||