lib/IO/K8s/ApiextensionsApiserver/Pkg/Apis/Apiextensions/V1/JSONSchemaPropsOrBool.pm

filter: Statementstmt 97.5% 39 / 40 Branchbran 100% 14 / 14 Conditioncond 71.4% 10 / 14 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 90.0% 9 / 10 Podpod 100% 3 / 3 totaltotal 87.5% 77 / 88 CC 13 SCAR 15.8
CC
13
Cov
93%
FROM_STRUCT
9.2
TO_JSON
3.0
_build__json_encoder
2.0
CRAP 4.9
« blib/lib/IO/K8s/Role/SpecBuilder.pm ↑ Summary lib/IO/K8s/Role/CertManaged.pm »
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
BranchTrueFalseTotal
defined $self->schema ? : 2 5 7
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
BranchTrueFalseTotal
if (ref $struct eq "HASH" or builtin::blessed($struct) and $struct->isa($PROPS)) 1226 296 1522
Condition66%4/6
ref $struct eq "HASH" or builtin::blessed($struct) and $struct->isa($PROPS)
l!l&&r!l&&!r
12260296
builtin::blessed($struct) and $struct->isa($PROPS)
!ll&&!rl&&r
82880
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)
ABCresult
1XX1
0111
00X0
0100
48 1226 ▶ $k8s //= do { require IO::K8s; IO::K8s->new };
Condition66%2/3
$k8s //= do { require IO::K8s; "IO::K8s"->new }
l!l&&r!l&&!r
122510
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 }
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ref $bool and (builtin::reftype($bool) // "") eq "SCALAR" 291 5 296
Condition80%4/5
ref $bool and (builtin::reftype($bool) // "") eq "SCALAR"
!ll&&!rl&&r
41291
builtin::reftype($bool) // ""
l!l
2920
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)
ABresult
0X0
100
111
55  
56 296 ▶ return $class->new(allows => $bool ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$bool ? : 276 20 296
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
BranchTrueFalseTotal
if defined $schema 170 420 590
64 420 ▶ return $self->allows ? JSON::MaybeXS::true() : JSON::MaybeXS::false();
Branch: 1 branch
BranchTrueFalseTotal
$self->allows ? : 403 17 420
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
BranchTrueFalseTotal
defined $schema ? : 2 3 5
73 }
74  
75 17 with 'IO::K8s::Role::Resource';
76  
77 17 1;
78  
79 __END__
« blib/lib/IO/K8s/Role/SpecBuilder.pm ↑ Summary lib/IO/K8s/Role/CertManaged.pm »