| 1 | package IO::K8s::ApiextensionsApiserver::Pkg::Apis::Apiextensions::V1::JSONSchemaPropsOrBool; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: JSONSchemaPropsOrBool represents JSONSchemaProps or a boolean value. Defaults to true for the boolean property. | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 17 | our $VERSION = '1.112'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use Types::Standard qw( Bool ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use JSON::MaybeXS (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | # Carp treats IO::K8s as part of this class (k175), as IO::K8s::List does | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # (k170): a schema arm is inflated through IO::K8s, and a shape croak raised | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # there -- a plain scalar where a schema belongs -- names the line that called | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # FROM_STRUCT, or IO::K8s itself on the way in, not the inflation call below. | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # A caller in any other package still sees its own line. | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 17 | our @CARP_NOT = ('IO::K8s'); | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 17 | my $PROPS = 'IO::K8s::ApiextensionsApiserver::Pkg::Apis::Apiextensions::V1::JSONSchemaProps'; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 17 | has schema => ( | |||||||||||||||||||||||||||||||||||||||||
| 21 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 22 | isa => Types::Standard::Maybe[ Types::Standard::InstanceOf[$PROPS] ], | ||||||||||||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 17 | has allows => ( | |||||||||||||||||||||||||||||||||||||||||
| 27 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | default => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub _build__json_encoder { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__json_encoder: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | return JSON::MaybeXS->new(utf8 => 1, canonical => 1, allow_nonref => 1); | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 7 | ▶ | sub is_schema { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_schema: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 7 | ▶ | return defined $self->schema ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 1522 | ▶ | sub FROM_STRUCT { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FROM_STRUCT: called CC=9 SCAR=22.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 1522 | my ($class, $struct, $k8s) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 1522 | ▶ | if (ref $struct eq 'HASH' || (Scalar::Util::blessed($struct) && $struct->isa($PROPS))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $struct eq "HASH" or builtin::blessed($struct) and $struct->isa($PROPS)
builtin::blessed($struct) and $struct->isa($PROPS)
MC/DC33%1/3
ref $struct eq "HASH" or builtin::blessed($struct) and $struct->isa($PROPS)
ref $struct eq "HASH"
builtin::blessed($struct)
$struct->isa($PROPS)
Truth table75%3/4
A or B and C
A= ref $struct eq "HASH"B= builtin::blessed($struct)C= $struct->isa($PROPS)
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 1226 | ▶ | $k8s //= do { require IO::K8s; IO::K8s->new }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/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 table66%2/3
A //= B
A= $k8sB= do {
require IO::K8s;
"IO::K8s"->new
}
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1226 | return $class->new(schema => $k8s->_struct_to_object_expanded($PROPS, $struct)); | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | # Booleans arrive as JSON::PP::Boolean, \1 / \0, or plain scalars. | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 296 | my $bool = $struct; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 296 | ▶ | $bool = $$bool if ref($bool) && (Scalar::Util::reftype($bool) // '') eq 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
ref $bool and (builtin::reftype($bool) // "") eq "SCALAR"
builtin::reftype($bool) // ""
MC/DC50%1/2
ref $bool and (builtin::reftype($bool) // "") eq "SCALAR"
ref $bool
builtin::reftype($bool)
Truth table66%2/3
A and B
A= ref $boolB= builtin::reftype($bool)
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 296 | ▶ | return $class->new(allows => $bool ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 590 | ▶ | sub TO_JSON { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TO_JSON: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 590 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 590 | my $schema = $self->schema; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 590 | ▶ | return $schema->TO_JSON if defined $schema; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 420 | ▶ | return $self->allows ? JSON::MaybeXS::true() : JSON::MaybeXS::false(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | # The node a spec path walks into (IO::K8s::Role::SpecBuilder, k172): the | ||||||||||||||||||||||||||||||||||||||||||
| 68 | # schema, or the boolean -- a scalar, which a path cannot descend through. | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 5 | ▶ | sub _spec_path_node { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_spec_path_node: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 5 | my $schema = $self->schema; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 5 | ▶ | return defined $schema ? ($schema) : ($self->allows); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 17 | with 'IO::K8s::Role::Resource'; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||||||||||||||||