| 1 | package IO::K8s::AutoGen; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Dynamically generate IO::K8s classes from OpenAPI schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 151 | our $VERSION = '1.112'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 151 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 151 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 151 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 151 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 151 | ▶ | use Digest::SHA qw( sha1_hex ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 151 | ▶ | use Module::Runtime qw( use_module ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 151 | ▶ | use Package::Stash; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 151 | ▶ | use Scalar::Util qw(blessed reftype refaddr looks_like_number); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 151 | ▶ | use Types::Standard qw( ArrayRef Bool HashRef InstanceOf Int Num Str ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # Type::Tiny object for the [IntOrStr] array items (k167); see the array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # branch of _schema_to_type_spec for why a bareword does not do. [Time] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # items go through $GENERATED_TIME instead (k178), so Time is not imported. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # Opaque is the free map a schemaless object becomes (k191). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 151 | ▶ | use IO::K8s::Types qw( IntOrStr Opaque ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # The empty list matters: IO::K8s::APIObject's import would make this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # package a Moo class. Loaded for its subresources check (k158). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 151 | ▶ | use IO::K8s::APIObject (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 151 | our @CARP_NOT = ('IO::K8s'); # errors via an openapi_spec instance name its caller (k175) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # Cache of generated classes -- only classes whose generation run completed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # (see "Generation runs" below). generated_classes() lists exactly these. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 151 | my %_generated; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # Generation runs (k149) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # A root get_or_generate call is one small transaction, a "run". Every class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # first begun during it -- the root, each $ref'd definition generated on the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # way, each nested class -- stays pending until the whole run, identity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # methods and roles included, has succeeded; only then do they all become | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # complete together. A class is marked begun early, before its own fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # exist, because a recursive type (A.child => A, A => B => A) must be able to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # name it; a pending class is only ever handed back to that same run's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # recursion, never as a public cache hit. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # If the run dies, every class it began is recorded as failed, keyed by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # class name (so per namespace), with the run's original error -- including | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # a dependency whose own fields finished cleanly, since it may well point | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # back at the class that died. Nothing is rolled back: the packages, the Moo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # internals and the attribute registry keep whatever the run built. Any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # later request that would hand out one of those classes, directly or as a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # dependency, rethrows that original error instead. Classes that were | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # already complete before the run are untouched. The failure record is never | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # cleared, not even by clear_cache(), which would otherwise revive a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # half-built package; a repaired schema is generated into a fresh namespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # (a fresh IO::K8s instance gets one). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # class name -> the original error of the run that began it and died | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | my %_failed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # The classes begun by the generation run in progress, as a { $class => 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # hashref; undef between runs. Only _in_generation_run sets or clears it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 151 | my $_run; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # Perl's own limit on a fully qualified identifier is 251 characters. A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # path-derived nested class name (see _nested_class below) is kept while it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # fits under this, lower threshold -- the headroom accounts for a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # '::_Spec'-style segment a caller might append to an already-long name, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # for the shortened '::_<hash>' form itself, which must never in turn need | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # shortening. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 151 | my $MAX_CLASS_NAME = 200; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # Class-level schema description, keyed by generated class name. AutoGen | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # itself never reads this -- it exists for IO::K8s::CRD::Emitter, which has | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # no other way to recover a schema's `description` once the class is built | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # (the k8s DSL only records per-field descriptions, not one for the class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # as a whole). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 151 | my %_descriptions; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # Default namespace for auto-generated classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 151 | our $DEFAULT_NAMESPACE = 'IO::K8s::_AUTOGEN'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # Sanitize one or more strings into safe Perl package-name segments: every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # character outside [A-Za-z0-9_] becomes '_', and a segment that would | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # start with a digit gets a leading '_' (a bareword identifier can't start | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # with one). Each argument becomes exactly one output segment -- splitting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # a def_name or an api_version into segments is the caller's job (see | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # def_to_class and _class_name_for below); _class_segment passes a whole | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # JSON key through as a single segment on purpose, since a key containing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # '.' or '/' is one field name, not a request for sub-packages. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # A hyphenated API group ('cert-manager.io') is the case this exists for: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # left alone, 'acme.cert-manager.io' becomes the package segment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # 'cert-manager', which Perl parses as a subtraction ('cert' MINUS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # 'manager'), not an identifier -- def_to_class died building the package, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # not on anything IO::K8s::CRD did wrong. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 752 | ▶ | sub _class_segments { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_class_segments: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | return map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 752 | my $s = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1500 | $s =~ s/[^A-Za-z0-9_]/_/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1500 | ▶ | $s = "_$s" if $s =~ /^[0-9]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1500 | $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # Convert OpenAPI definition name to Perl class name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # With namespace 'MyProject::K8s': | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # helm.cattle.io.v1.HelmChart -> MyProject::K8s::helm::cattle::io::v1::HelmChart | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 220 | ▶ | sub def_to_class { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
def_to_class: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 220 | my ($def_name, $namespace) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 220 | ▶ | $namespace //= $DEFAULT_NAMESPACE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$namespace //= $IO::K8s::AutoGen::DEFAULT_NAMESPACE
MC/DC0%0/2
$namespace //= $IO::K8s::AutoGen::DEFAULT_NAMESPACE
$namespace
$IO::K8s::AutoGen::DEFAULT_NAMESPACE
Truth table66%2/3
A //= B
A= $namespaceB= $IO::K8s::AutoGen::DEFAULT_NAMESPACE
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 220 | return join('::', $namespace, _class_segments(split /\./, $def_name)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # Convert Perl class name back to OpenAPI definition name. Lossy on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # purpose: def_to_class/_class_segments sanitize each package segment (a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # hyphen becomes '_', among other substitutions), and that cannot be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # undone here. Used only for diagnostics and to build a nested class's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # synthetic def_name (_nested_class) -- never to look a definition back up | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # in $all_defs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 234 | ▶ | sub class_to_def { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class_to_def: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 234 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # Strip any _AUTOGEN namespace prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 234 | $class =~ s/^IO::K8s::_AUTOGEN_[^:]+:://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 234 | $class =~ s/^IO::K8s::_AUTOGEN:://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 234 | $class =~ s/::/./g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 234 | return $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # Check if a class was auto-generated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 8 | ▶ | sub is_autogen { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_autogen: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 8 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 8 | return $class =~ /^IO::K8s::_AUTOGEN/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # Get or generate a class from schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # Options hash can include: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # api_version => 'stable.example.com/v1' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # kind => 'StaticWebSite' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # resource_plural => 'staticwebsites' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # is_namespaced => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # subresources => { status => {}, scale => {...} } -- a CRD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # version's subresources, installed as the fixed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # identity method `subresources` on a top-level class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # (k158); checked like the IO::K8s::APIObject import | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # parameter, before the class is begun. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # reuse_core => 0|1 (default 1) -- type a nested object/items/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # additionalProperties schema as a shipped core class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # instead of a nested class when its shape matches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # one (D5); see _core_class_for. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # reuse_core_except => { 'Spec::Foo' => 1, ... } -- with reuse_core on, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # the logical nested-class paths (root-relative, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # class_path's key space) at which reuse is suppressed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # so a provider's own named type is generated even | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # though its shape matches a core class (k120). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 210 | ▶ | sub get_or_generate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_or_generate: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 210 | my ($def_name, $schema, $all_defs, $namespace, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 210 | my $class = _class_name_for($def_name, $schema, $namespace, $opts{api_version}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 210 | ▶ | return $class if _class_usable($class); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 194 | ▶ | _in_generation_run(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 194 | _generate_class($class, $def_name, $schema, $all_defs, $namespace, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 194 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 178 | return $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # Run $code as a generation run (see "Generation runs" above). A request made | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # while a run is already in progress -- a $ref reached from inside the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # property loop -- joins that run instead of opening its own, so the root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # call's run is the one unit that commits or fails. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 194 | ▶ | sub _in_generation_run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_in_generation_run: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 194 | my ($code) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 194 | ▶ | return $code->() if $_run; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 186 | $_run = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 186 | my $ok = eval { $code->(); 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 186 | ▶ | my $err = $@ || 'IO::K8s::AutoGen: class generation died without an error message'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$@ || 'IO::K8s::AutoGen: class generation died without an error message'
MC/DC100%1/1
$@ || 'IO::K8s::AutoGen: class generation died without an error message'
$@
Truth table100%2/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 186 | my @begun = keys %$_run; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 186 | undef $_run; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 186 | ▶ | if ($ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 170 | $_generated{$_} = 1 for @begun; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 170 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 16 | $_failed{$_} = $err for @begun; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 16 | die $err; # rethrow unchanged: croak would restamp it with our caller | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # Rethrow the original error of the failed run that began $class, if any. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # The first failure reaches the caller unchanged (_in_generation_run); a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # later request gets it again behind a prefix saying it is a remembered | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # failure -- otherwise a dependency asked for directly would die naming | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # another class's field and the first call's line. The original message is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # kept whole. An exception object is rethrown as it is, never stringified. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 636 | ▶ | sub _rethrow_failed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rethrow_failed: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 636 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 636 | ▶ | return unless exists $_failed{$class}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 7 | my $err = $_failed{$class}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 7 | ▶ | die $err if ref $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 7 | chomp $err; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 7 | croak 'IO::K8s::AutoGen: '.$class.' failed to generate earlier in this namespace ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | .'and stays failed; load a repaired schema into a fresh IO::K8s instance. ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | .'Original error: '.$err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # True when $class can be handed out as it is: complete, or begun earlier in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # the run in progress (recursion). Rethrows instead when its run failed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 636 | ▶ | sub _class_usable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_class_usable: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 636 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 636 | _rethrow_failed($class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 629 | ▶ | return $_generated{$class} || ($_run && $_run->{$class}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$_generated{$class} || $_run && $_run->{$class}
$_run and $_run->{$class}
MC/DC100%3/3
$_generated{$class} || $_run && $_run->{$class}
$_generated{$class}
$_run
$_run->{$class}
Truth table100%4/4
A || B and C
A= $_generated{$class}B= $_runC= $_run->{$class}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # Class identity for a definition. A definition whose | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # x-kubernetes-group-version-kind lists several entries serves more than | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # one apiVersion from one schema; requesting one of them must produce a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # package specific to that GVK, otherwise the second version would silently | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # reuse the first version's class (and its api_version method). The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # versionless generation keeps the plain def_to_class name as the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # deterministic compatibility default. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 210 | ▶ | sub _class_name_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_class_name_for: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 210 | my ($def_name, $schema, $namespace, $api_version) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 210 | my $class = def_to_class($def_name, $namespace); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 210 | ▶ | return $class unless defined $api_version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 155 | my $gvk = $schema->{'x-kubernetes-group-version-kind'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 155 | ▶ | return $class unless ref($gvk) eq 'ARRAY' && @$gvk > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $gvk eq "ARRAY" and @$gvk > 1
MC/DC100%2/2
ref $gvk eq "ARRAY" and @$gvk > 1
ref $gvk eq "ARRAY"
@$gvk > 1
Truth table100%3/3
A and B
A= ref $gvk eq "ARRAY"B= @$gvk > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # / and . are not valid in a package name, and every segment must be a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # bare identifier; map group/version to sanitized ::-separated segments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # the same way def_to_class maps def_names (see _class_segments) -- a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # hyphenated group in the api_version needs the same treatment here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 3 | my @segments = _class_segments(split m{[./]}, $api_version); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 3 | return "${class}::" . join('::', @segments); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # Wire apiVersion a GVK entry represents: group/version, or bare version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # when the group is empty (core group). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 135 | ▶ | sub _gvk_api_version { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gvk_api_version: called CC=4 SCAR=14.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 135 | my ($entry) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 135 | ▶ | my $group = $entry->{group} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$entry->{"group"} // ""
MC/DC0%0/1
$entry->{"group"} // ""
$entry->{"group"}
Truth table50%1/2
A
A= $entry->{"group"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 135 | ▶ | my $version = $entry->{version} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$entry->{"version"} // ""
MC/DC0%0/1
$entry->{"version"} // ""
$entry->{"version"}
Truth table50%1/2
A
A= $entry->{"version"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 135 | ▶ | return $group ? "$group/$version" : $version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # Deterministic ordering key for a GVK entry. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 4 | ▶ | sub _gvk_sort_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_gvk_sort_key: called CC=4 SCAR=15.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 4 | my ($entry) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | return join '/', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | ($entry->{group} // ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | ($entry->{version} // ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 4 | ▶ | ($entry->{kind} // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$entry->{"group"} // ""
$entry->{"version"} // ""
$entry->{"kind"} // ""
MC/DC0%0/1
$entry->{"group"} // ""
$entry->{"group"}
MC/DC0%0/1
$entry->{"version"} // ""
$entry->{"version"}
MC/DC0%0/1
$entry->{"kind"} // ""
$entry->{"kind"}
Truth table50%1/2
A
A= $entry->{"group"}
Truth table50%1/2
A
A= $entry->{"version"}
Truth table50%1/2
A
A= $entry->{"kind"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # Pick the GVK entry a class should be built from. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # With an $api_version the request is exact: the entry whose group/version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # matches is returned; several matches are an ambiguity error, none is a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # fail-closed error. It never silently takes the first entry. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # Without an $api_version the entries are sorted and the first is returned | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # -- deterministic regardless of array order. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 143 | ▶ | sub _select_gvk_entry { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_select_gvk_entry: called CC=5 SCAR=16.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 143 | my ($gvk, $api_version, $def_name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 143 | ▶ | return $gvk unless ref($gvk) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 143 | ▶ | if (defined $api_version) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 132 | my @matches = grep { _gvk_api_version($_) eq $api_version } @$gvk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 132 | ▶ | if (@matches > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | croak "GVK ambiguity in definition '$def_name': " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | . scalar(@matches) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | . " x-kubernetes-group-version-kind entries match api_version '$api_version'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 132 | ▶ | if (@matches == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 132 | return $matches[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | croak "No x-kubernetes-group-version-kind entry in definition '$def_name' " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | . "matches api_version '$api_version'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 11 | return (sort { _gvk_sort_key($a) cmp _gvk_sort_key($b) } @$gvk)[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # Generate a class from OpenAPI schema using IO::K8s::Resource | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 427 | ▶ | sub _generate_class { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate_class: called CC=28 SCAR=33.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 427 | my ($class, $def_name, $schema, $all_defs, $namespace, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # Determine api_version/kind from schema or explicit options. This has | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # to happen before the class is marked begun: a fail-closed error here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # (ambiguous or non-matching api_version) builds nothing, so it must not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # record the class as failed either -- a retry with a matching | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # api_version resolves to the same class name and has to work. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 427 | my ($api_ver, $kind_val, $res_plural, $is_namespaced); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 427 | ▶ | if (my $gvk = $schema->{'x-kubernetes-group-version-kind'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 143 | my $entry = _select_gvk_entry($gvk, $opts{api_version}, $def_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 143 | ▶ | my $group = $entry->{group} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$entry->{"group"} // ""
MC/DC0%0/1
$entry->{"group"} // ""
$entry->{"group"}
Truth table50%1/2
A
A= $entry->{"group"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 143 | ▶ | my $version = $entry->{version} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$entry->{"version"} // ""
MC/DC0%0/1
$entry->{"version"} // ""
$entry->{"version"}
Truth table50%1/2
A
A= $entry->{"version"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 143 | ▶ | $kind_val = $entry->{kind} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$entry->{"kind"} // ""
MC/DC0%0/1
$entry->{"kind"} // ""
$entry->{"kind"}
Truth table50%1/2
A
A= $entry->{"kind"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 143 | ▶ | $api_ver = $group ? "$group/$version" : $version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # Explicit options override schema-derived values. Hoisted above the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # property loop because whether this class ends up with GVK class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # methods decides which properties must not become attributes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 427 | ▶ | $api_ver = $opts{api_version} if exists $opts{api_version}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 427 | ▶ | $kind_val = $opts{kind} if exists $opts{kind}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 427 | ▶ | $res_plural = $opts{resource_plural} if exists $opts{resource_plural}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 427 | ▶ | $is_namespaced = $opts{is_namespaced} if exists $opts{is_namespaced}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # A CRD version's subresources (k158), checked here for the same reason | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # as the GVK selection above: a malformed section builds nothing and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # marks nothing failed, so the repaired manifest works on a retry. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 427 | my $subresources; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | $subresources = IO::K8s::APIObject::_checked_subresources($class, $opts{subresources}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 427 | ▶ | if exists $opts{subresources}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 426 | ▶ | return if _class_usable($class); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 426 | ▶ | croak "IO::K8s::AutoGen: $class generated outside a generation run" unless $_run; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 426 | $_run->{$class} = 1; # Mark begun early to allow recursion; pending until the run commits | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 426 | ▶ | $_descriptions{$class} = $schema->{description} if defined $schema->{description}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # Ensure parent packages exist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 426 | _ensure_package_exists($class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # Set up the class using IO::K8s::Resource's shared setup method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 151 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 426 | @{"${class}::ISA"} = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 426 | require IO::K8s::Resource; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 426 | IO::K8s::Resource->_setup_class($class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # Fields are declared through IO::K8s::Resource->_k8s directly, so the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # compile-time sugar (has, with, after, k8s, Str, ...) the setup just | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # gave the class is swept at once: a property may be called any of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # those names (k200). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 426 | IO::K8s::Resource->_sweep_sugar($class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 426 | ▶ | my $k8s = sub { IO::K8s::Resource->_k8s($class, @_) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | # A top-level class -- one with a GVK -- gets its identity methods and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # IO::K8s::Role::APIObject (and with it IO::K8s::Role::SpecBuilder) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | # BEFORE any property is declared: the order `use IO::K8s::APIObject` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # gives a hand-written class (k150). The other way round, Role::Tiny's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | # "class wins" let a property whose accessor has the name of a role | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | # method (label, save, is_ready, spec_get, ...) silently replace that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | # method. Now IO::K8s::Resource sees the role method when it picks the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # property's accessor and gives the property another one (_label, k200), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # keeping the JSON key as the field's json_key; the role method stays | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | # what it is. conditions keeps its k144 exception -- the role helper | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | # yields to a declared field of that name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | # The identity methods still go in before the role, so the role sees | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # them and does not install its own class-name-derived api_version, kind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | # and resource_plural -- the same reason IO::K8s::APIObject::import | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | # installs a CRD's before it composes the role. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 426 | ▶ | my $is_top = defined $api_ver && defined $kind_val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $api_ver && defined $kind_val
MC/DC50%1/2
defined $api_ver && defined $kind_val
defined $api_ver
defined $kind_val
Truth table66%2/3
A && B
A= defined $api_verB= defined $kind_val
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 426 | ▶ | if ($is_top) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 155 | my $stash = Package::Stash->new($class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # These are fixed identity methods, not writable fields. A caller | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | # passing an argument believes they retargeted the object; fail closed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # rather than swallow the write (k67, the house line of k37/k39). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 312 | ▶ | $stash->add_symbol('&api_version', sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 312 | ▶ | croak 'api_version is fixed for this class and cannot be set' if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 312 | $api_ver; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 155 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 267 | ▶ | $stash->add_symbol('&kind', sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 267 | ▶ | croak 'kind is fixed for this class and cannot be set' if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 265 | $kind_val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 155 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 46 | ▶ | $stash->add_symbol('&resource_plural', sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 46 | ▶ | croak 'resource_plural is fixed for this class and cannot be set' if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 46 | $res_plural; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 155 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | # The same identity method `use IO::K8s::APIObject subresources =>` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | # installs, so to_crd writes them back (k112 symmetry, k158). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 155 | ▶ | IO::K8s::APIObject::_install_subresources($class, $subresources) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | if $subresources; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | # Apply Role::APIObject for metadata, to_yaml, save, etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 155 | require Moo::Role; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 155 | require IO::K8s::Role::APIObject; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 155 | Moo::Role->apply_roles_to_package($class, 'IO::K8s::Role::APIObject'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | # Register the role's metadata attribute so _inflate_struct knows the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | # type -- adopted, the same way IO::K8s::APIObject::import does it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | # for hand-written classes (k144) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 155 | IO::K8s::Resource->_k8s_adopt($class, 'metadata', 'Meta::V1::ObjectMeta'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # Apply Namespaced role if requested or schema suggests it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 155 | ▶ | if ($is_namespaced) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 84 | require IO::K8s::Role::Namespaced; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 84 | Moo::Role->apply_roles_to_package($class, 'IO::K8s::Role::Namespaced'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 426 | ▶ | my $properties = $schema->{properties} // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$schema->{"properties"} // {}
MC/DC0%0/1
$schema->{"properties"} // {}
$schema->{"properties"}
Truth table50%1/2
A
A= $schema->{"properties"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # The block above gave a top-level class apiVersion, kind and metadata | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | # -- exactly the three properties IO::K8s::Role::Resource::compare_to_schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | # already excuses a top-level object for not declaring, and the line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | # k45 drew for the hand-written template classes. A schema that lists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | # them as properties as well is skipped for each of them: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | # kind: the fixed identity method is already there, so the k144 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # preflight would refuse the property as a collision. Back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # when properties came first, the identity method was | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | # installed over the generated accessor afterwards and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | # $obj->kind('Other') was a silent no-op (k60). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | # apiVersion: no method of that name, which is worse -- it would become | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | # a writable attribute and TO_JSON would emit it over the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # apiVersion the class actually is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # metadata: the role's own attribute, adopted above; declaring it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # again from the schema could only conflict with that, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | # would generate a throwaway ObjectMeta class on the way. It is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # skipped here so that a schema referencing the standard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # ObjectMeta without carrying its definition (a very common | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | # way to hand in a single CRD schema) does not trip the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | # unresolved-$ref refusal below over a field the role | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | # supplies anyway. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 426 | ▶ | my %role_supplied = $is_top ? (apiVersion => 1, kind => 1, metadata => 1) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # D5: reuse a shipped core class for a nested object/items/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # additionalProperties schema of exactly its shape, default on. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 426 | ▶ | my $reuse_core = exists $opts{reuse_core} ? ($opts{reuse_core} ? 1 : 0) : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # k120: a set of logical nested-class paths (root-relative, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # '::'-joined -- the same key space class_path/the render overlay use) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # at which core reuse is suppressed even with reuse_core on, so a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | # provider's own named type is generated where its shape happens to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | # match a core class (PrometheusOperator's Argument matches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | # Core::V1::HTTPHeader). Empty/absent -> reuse behaves exactly as before. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 426 | ▶ | my $reuse_core_except = $opts{reuse_core_except} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts{'reuse_core_except'} || {}
MC/DC100%1/1
$opts{'reuse_core_except'} || {}
$opts{'reuse_core_except'}
Truth table100%2/2
A
A= $opts{'reuse_core_except'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | # Generate attributes using k8s DSL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | # Property names with special characters ($ref, x-kubernetes-*) are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # automatically sanitized to valid Perl identifiers by _k8s(), with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | # init_arg mapping so constructors still accept the original JSON keys. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 426 | ▶ | my %required = map { $_ => 1 } @{ $schema->{required} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$schema->{"required"} // []
MC/DC100%1/1
$schema->{"required"} // []
$schema->{"required"}
Truth table100%2/2
A
A= $schema->{"required"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 426 | for my $prop (sort keys %$properties) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 890 | ▶ | next if $role_supplied{$prop}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 803 | my $prop_schema = $properties->{$prop}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 803 | my $type_spec = _schema_to_type_spec($prop_schema, $all_defs, $namespace, $prop, $class, $reuse_core, $reuse_core_except); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 785 | ▶ | next unless defined $type_spec; # Skip unsupported types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 785 | my $opts = _field_options($prop_schema, $type_spec, $required{$prop}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 785 | ▶ | $k8s->($prop, $type_spec, ($opts ? $opts : ())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 408 | return $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | # Opaque type definitions that should be the free map (Opaque), not object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | # references | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 151 | my %OPAQUE_TYPES = map { $_ => 1 } qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | io.k8s.apimachinery.pkg.apis.meta.v1.FieldsV1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | io.k8s.apimachinery.pkg.runtime.RawExtension | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | # The apiextensions union types (k152). Upstream's swagger.json describes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | # each of them with a description and nothing else, since none is a JSON | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | # object: v1.JSON is any JSON value, JSONSchemaPropsOrArray a schema or an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | # array of schemas, JSONSchemaPropsOrBool a schema or a boolean, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | # JSONSchemaPropsOrStringArray a schema or a string array. Generated from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | # such a definition, a class has no fields and no FROM_STRUCT and cannot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # hold `default: "foo"`. IO::K8s ships a hand-written class for each of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | # four, inflated through FROM_STRUCT, and a $ref to one of the names is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | # typed as that class -- by name, whether the spec carries the definition | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # or not, like the apimachinery scalars and %OPAQUE_TYPES above. reuse_core | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | # has no say: this is the type itself, not a shape that happens to match. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # IO::K8s ships no v1beta1 apiextensions classes. The v1beta1 names -- in a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | # spec from a cluster older than 1.22, which removed that API -- are carried | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | # by the v1 JSON class instead, which holds any JSON value as it came and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | # writes it back unchanged: opaque, never a field-less class that loses the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | # value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 151 | my $APIEXT_DEF = 'io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 151 | my $APIEXT_CLASS = 'IO::K8s::ApiextensionsApiserver::Pkg::Apis::Apiextensions::V1::'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | my %UNION_TYPES = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 151 | ( $APIEXT_DEF.'v1.'.$_ => $APIEXT_CLASS.$_, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | $APIEXT_DEF.'v1beta1.'.$_ => $APIEXT_CLASS.'JSON' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | } qw( JSON JSONSchemaPropsOrArray JSONSchemaPropsOrBool JSONSchemaPropsOrStringArray ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | # The shipped class a union $ref stands for, loaded, or nothing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 53 | ▶ | sub _union_class { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_union_class: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 53 | my ($ref) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 53 | ▶ | my $class = $UNION_TYPES{$ref} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 30 | return use_module($class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | # A $ref pointing at a definition the caller never supplied. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | # Refusing is the fail-closed choice (k56). The property used to be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | # skipped outright: the generated class simply had no such attribute, Moo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | # dropped the constructor argument for it without a word, and TO_JSON never | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | # emitted the data again -- an inflate/serialize round-trip that quietly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # lost whatever sat under that key. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | # The alternative considered was an opaque { Str => 1 } attribute. It was | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | # rejected for two reasons. It cannot be applied at all three call sites: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | # the k8s DSL has no array-of-hash form, so `items: { $ref: <missing> }` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | # would have to become ArrayRef[Str] and then reject the very hashrefs the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | # field carries -- the k57 failure, reintroduced. And it guesses a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | # shape: a missing definition may just as well be a string or array alias, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | # in which case the Maybe[HashRef] attribute fails its type constraint | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | # without ever naming the unresolved $ref that caused it. %OPAQUE_TYPES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | # above is a decision taken per named type, not a default for anything | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | # unresolvable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 12 | ▶ | sub _croak_unresolved_ref { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_croak_unresolved_ref: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 12 | my ($ref, $where) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 12 | croak "Cannot resolve the \$ref '$ref' for $where: no such definition in " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | . "the OpenAPI spec. Supply the definition or drop the property -- " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | . "generating the class without it would silently drop that field on " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | . "every round-trip"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | # The class segment for a nested class: the whole JSON key sanitized into | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | # one package-identifier segment (see _class_segments above), then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | # ucfirst'd. `x-extra` -> `X_extra`, `$ref` -> `_ref`, `x.y/z` -> `X_y_z` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | # -- unlike def_to_class/_class_name_for the key is never split on '.' or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | # '/' first: it is one field name, not a request for sub-packages, and a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | # key containing either used to reach package creation unsanitized and die | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | # there with a message that named neither the field nor the class. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 529 | ▶ | sub _class_segment { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_class_segment: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 529 | my ($json_key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 529 | return ucfirst((_class_segments($json_key))[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | # The field name that generated a given nested class name. Needed to fail | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | # closed on a name collision: two schema keys can sanitize + ucfirst to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | # same class segment -- an array-of-objects field `routes` (its items get | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | # an `Item` suffix) and a sibling plain-object field `routesItem` both | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | # produce `...::RoutesItem`; so would a `weights` map (`Value` suffix) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | # alongside a sibling `weightsValue`, or `x-extra` next to `x_extra`, or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | # `Foo` next to `foo`. The class name already encodes the suffix, so the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | # bare field name is enough to tell two different owners apart -- and it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | # has to be the bare name, not "$field_name$suffix", because that compound | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | # form is itself ambiguous: `routes` + the `Item` suffix and the plain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | # field `routesItem` concatenate to the identical string, which would defeat | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | # the very check meant to catch that exact pair. Without this, the `unless | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | # ($_generated{$class})` guard below would silently keep the FIRST field's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | # class for the SECOND -- the second field ends up typed as the first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | # field's class, and inflating real data for it drops the field on every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | # round-trip in the default non-strict mode. Never generate a class that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | # silently drops a field -- the same rule _croak_unresolved_ref enforces for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | # an unresolved $ref (k56), reached here from a name collision instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | # Keyed on the FULL logical name (root + the whole '::'-joined path below | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | # it), never on a class's own (possibly hash-shortened) Perl name: two | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | # different long paths must never be treated as "the same nested class" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | # just because a name collision detector happened to look at the shortened | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | # form, which -- being a 40-bit truncated hash -- is a much smaller space | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | # than the paths it stands in for. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 151 | my %_nested_origin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | # Every nested class AutoGen has generated, keyed by its actual (possibly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | # shortened) Perl class name: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | # %_root_of -> the top-level generated class (the Kind class) the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | # nesting started from. A root has no entry here; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | # class_root() falls back to the class itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | # %_class_path -> the '::'-joined path below that root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | # ('Spec::Acme::SolversItem::...'), recorded regardless of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | # whether the class name itself had to be shortened. A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | # root, or a class AutoGen did not generate as nested, has | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | # no entry; class_path() returns undef for those. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | my %_root_of; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 151 | my %_class_path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | # The Perl class name for a nested class at logical path $path below $root: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | # the path-derived name (identical to what pre-1.109 AutoGen always used) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | # while it fits under $MAX_CLASS_NAME, otherwise <root>::_<10 hex chars> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | # from a SHA-1 of the full logical name -- deterministic, so the same | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # (root, path) always yields the same class, and short enough that it can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | # never itself need shortening (root plus a fixed 13-character suffix). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 233 | ▶ | sub _class_for_path { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_class_for_path: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 233 | my ($root, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 233 | my $logical_name = "$root\::$path"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 233 | ▶ | return $logical_name if length($logical_name) <= $MAX_CLASS_NAME; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 15 | return $root . '::_' . substr(sha1_hex($logical_name), 0, 10); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | # An inline `type: object` with its own properties becomes a nested class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | # named after its place in the parent -- <Parent>::<Prop>, plus an Item / | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | # Value suffix for array items and map values -- generated in the parent's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | # namespace and cached like every other generated class. Before 1.108 such | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | # an object was an opaque hash, so a CRD's spec, which every CRD schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | # inlines, carried no typing below the top level (k94). Hash-style access on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | # the result keeps working: a Moo object is a blessed hash keyed by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | # attribute name. Property-less objects and additionalProperties-only maps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | # are not touched here; they stay opaque (k55). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | # A schema nested deep enough (cert-manager's CRDs inline a full | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | # PodTemplateSpec under a solver, itself several levels into a Challenge) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | # makes the path-derived name run past Perl's 251-character identifier | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | # limit; see $MAX_CLASS_NAME and _class_for_path above. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | # $reuse_core carries forward unchanged (D5): a schema only reaches here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | # because its own shape did NOT match a shipped core class, but its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | # properties still get the same reuse_core treatment when this new class's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | # own fields are, in turn, typed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 234 | ▶ | sub _nested_class { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_nested_class: called CC=7 SCAR=19.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 234 | my ($parent_class, $field_name, $suffix, $schema, $all_defs, $namespace, $reuse_core, $reuse_core_except) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 234 | ▶ | $reuse_core = 1 unless defined $reuse_core; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 234 | ▶ | my $root = $_root_of{$parent_class} // $parent_class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_root_of{$parent_class} // $parent_class
MC/DC0%0/2
$_root_of{$parent_class} // $parent_class
$_root_of{$parent_class}
$parent_class
Truth table66%2/3
A // B
A= $_root_of{$parent_class}B= $parent_class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 234 | my $parent_path = $_class_path{$parent_class}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 234 | ▶ | my $segment = _class_segment($field_name) . ($suffix // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$suffix // ""
MC/DC100%1/1
$suffix // ""
$suffix
Truth table100%2/2
A
A= $suffix
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 234 | ▶ | my $path = defined($parent_path) ? "$parent_path\::$segment" : $segment; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 234 | my $logical_name = "$root\::$path"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 234 | ▶ | if (exists $_nested_origin{$logical_name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 1 | my $existing = $_nested_origin{$logical_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 1 | ▶ | if ($existing ne $field_name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 1 | croak "Cannot generate a nested class for field '$field_name' of $parent_class: " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | . "its class name $logical_name is already taken by field '$existing' " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | . "-- two schema keys collapse to the same class segment; rename one of them"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | my $existing_class = _class_for_path($root, $path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | _rethrow_failed($existing_class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | return $existing_class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 233 | $_nested_origin{$logical_name} = $field_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 233 | my $class = _class_for_path($root, $path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 233 | $_root_of{$class} = $root; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 233 | $_class_path{$class} = $path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 233 | my $def_name = class_to_def($parent_class) . '.' . $segment; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 233 | _generate_class($class, $def_name, $schema, $all_defs, $namespace, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | reuse_core => $reuse_core, reuse_core_except => $reuse_core_except); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 230 | return $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | # The logical path a nested class for ($parent_class, $field_name, $suffix) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | # WOULD be generated at, computed the same way _nested_class does above -- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | # but without generating anything, so the reuse decision in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | # _schema_to_type_spec can consult reuse_core_except before it calls | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | # _core_class_for (k120). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 295 | ▶ | sub _prospective_nested_path { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prospective_nested_path: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 295 | my ($parent_class, $field_name, $suffix) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 295 | my $parent_path = $_class_path{$parent_class}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 295 | ▶ | my $segment = _class_segment($field_name) . ($suffix // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$suffix // ""
MC/DC100%1/1
$suffix // ""
$suffix
Truth table100%2/2
A
A= $suffix
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 295 | ▶ | return defined($parent_path) ? "$parent_path\::$segment" : $segment; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 925 | ▶ | sub _has_properties { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_has_properties: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 925 | my ($schema) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | return ref $schema eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | && ($schema->{type} // '') eq 'object' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | && ref $schema->{properties} eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 925 | ▶ | && %{ $schema->{properties} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition90%10/11
ref $schema eq 'HASH' && ($schema->{'type'} // '') eq 'object' && ref $schema->{'properties'} eq 'HASH' && %{$schema->{'properties'};}
ref $schema eq "HASH" and ($schema->{"type"} // "") eq "object" and ref $schema->{"properties"} eq "HASH"
ref $schema eq "HASH" and ($schema->{"type"} // "") eq "object"
$schema->{"type"} // ""
MC/DC75%3/4
ref $schema eq 'HASH' && ($schema->{'type'} // '') eq 'object' && ref $schema->{'properties'} eq 'HASH' && %{$schema->{'properties'};}
ref $schema eq "HASH"
$schema->{"type"}
ref $schema->{"properties"} eq "HASH"
%{$schema->{'properties'};}
Truth table80%4/5
A and B and C && D
A= ref $schema eq "HASH"B= $schema->{"type"}C= ref $schema->{"properties"} eq "HASH"D= %{$schema->{'properties'};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | # reuse_core (D5): a nested object whose property set is exactly the key set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | # of a shipped core / apimachinery class is typed as that class. CRD schemas | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | # inline the types they embed (a LabelSelector, a PodTemplateSpec), and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | # modeling them again would give every provider its own copy of PodSpec. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | # The index is built once from the shipped class files, keyed by JSON key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | # NAME only -- core_class_for_shape lists every candidate a key set could | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | # mean, without regard to type. _core_class_for below is the actual reuse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | # decision, and needs more than a name match to be safe: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | # 1. A schema shape under two keys is never reused. A single shared key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | # name ({value}, {name}, ...) is common enough by accident that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | # requiring at least two narrows out most of it for free. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | # 2. Every remaining candidate must be TYPE-compatible with the schema, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | # key by key (see %_TYPE_COMPAT below) -- a schema string field can't | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | # reuse a class that declares the same-named field as an array, for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | # instance. This is checked before anything else, since a name match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | # alone says nothing about the wire shape. It is coarse for arrays and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | # maps (any array, any map); step 4 settles what they hold. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | # 3. Every remaining candidate must not OVER-CONSTRAIN the schema (k136, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | # see _overrequires): a candidate that marks some shared key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | # `required` (plain Moo-enforced or registry-only `required => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | # 'schema'`) which the schema's own `required` list leaves optional is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | # dropped. Reusing it would reject or silently drop a real cluster | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | # object that (validly, per the CRD) omits that key -- the metav1. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | # Condition shape reused for a CRD condition that requires only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | # [type,status] is the case this exists for (k135/k137): message, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | # reason and lastTransitionTime are required on Condition but not on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | # the CRD, so a message-less live condition failed to inflate. Only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | # this direction is checked -- a schema requiring MORE than the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | # candidate leaves the reused class merely looser than the schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | # promises, never lossy. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | # 4. Every remaining candidate must hold the schema all the way down | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | # (k148, see _field_compatible): an array's elements, a map's values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | # and every nested object's fields, recursively. A candidate that does | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | # not -- an array of objects against a class whose same-named field is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | # an array of strings, which is what LabelSelectorRequirement was reused | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | # for before -- is dropped here. k148 first ran this as a gate on the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | # class steps 5/6 had already picked, so it could only WITHDRAW a reuse; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | # k156 moved it ahead of the tie-break, where dropping the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | # recursively-incompatible candidates can leave a single survivor and so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | # DECIDE a reuse that a name/type match alone left ambiguous: a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | # {metadata,spec} matches every *TemplateSpec by name and type, but only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | # PodTemplateSpec's spec holds a PodSpec and only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | # PersistentVolumeClaimTemplate's a PVC spec, so the mismatched | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | # candidates fall away and the one that fits is reused (AgentSandbox's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | # podTemplate and volumeClaimTemplates, PrometheusOperator's ephemeral | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | # volumeClaimTemplate). Wire-identical candidates share their verdict | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | # here (same flags, same classes per key), so they survive or fall | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | # together and step 6 still sees the same wire-identical set. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | # 5. Exactly one candidate survives every filter -> reuse it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | # 6. Several do -- reused only when they are wire-identical: the same | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | # type flags (NOT required-ness -- a field being optional on one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | # shipped class and mandatory on another doesn't change what value it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | # holds) and the same referenced class per key, where a key has one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | # {name,value} matches HTTPHeader, PodDNSConfigOption and Sysctl -- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | # three unrelated Core::V1 leaf structs, wire-identical (two required | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | # Str fields on two of them, two optional Str fields on the third, but | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | # Str either way) -- reused as the preferred one (Meta::V1, then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | # Core::V1, then alphabetical: HTTPHeader). {key,operator,values} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | # matches LabelSelectorRequirement, FieldSelectorRequirement (both | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | # Meta::V1) and NodeSelectorRequirement (Core::V1) -- also | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | # wire-identical despite spanning two API areas -- reused as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | # LabelSelectorRequirement, by a wide margin the most common shape a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | # provider CRD's inline schema turns out to match (138 LabelSelector | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | # copies, 162 of this bare triple, per the step-4 drift measurement). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | # A shape still matched by several NON-wire-identical candidates after | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | # the step-4 filter (an optional field naming a different type, a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | # different value type under the same key that both nonetheless hold the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | # schema) stays a nested class rather than guess. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | # A class's own `metadata` is part of its shape only for an embedded type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | # (PodTemplateSpec: {metadata,spec}, a real schema-visible field) -- never | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | # for a top-level Kind (Pod: {spec,status}), whose `metadata` is supplied | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | # by IO::K8s::Role::APIObject outside the schema's own properties (see | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | # _generate_class's %role_supplied) and so never appears in a CRD's own | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | # inline schema for that Kind. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 151 | my %_core_shapes; # "k1,k2,..." -> [ classes, preference-ordered ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 151 | my %_core_shape_loaded; # shape -> 1 once that shape's candidates are loaded | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 151 | my $_core_indexed = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | # The checked-in, precomputed form of %_core_shapes (k104). Building the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | # index live costs ~6.5s in a fresh process -- >99% of it Module::Runtime | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | # loading all 839 classes under the two trees, the File::Find walk and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | # registry reads being ~15ms together -- and reuse_core is default on, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | # every first add_crd / generate / CRD inflate paid it. The precomputed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | # module carries the finished shape -> classes map (no DSL semantics: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | # type-aware half of the reuse decision in _core_class_for loads the few | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | # candidate classes it actually looks at, see core_class_for_shape) and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | # loads in ~2ms. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | # It is a maint-maintained artifact in the sense of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | # maint/spec-drift-exceptions.yaml, NOT a codegen step -- nothing under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | # lib/IO/K8s/Api* is generated. maint/core-shape-index-gen.pl writes it by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | # calling _scan_core_shapes below, and t/85_core_shape_index.t fails when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | # the checked-in copy no longer matches what that same function produces, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | # which is what keeps adding, removing or renaming a class honest. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 151 | our $CORE_SHAPE_INDEX = 'IO::K8s::AutoGen::CoreShapes'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | # Preference order for core_class_for_shape's listing and for picking among | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | # several wire-identical candidates: LabelSelector / LabelSelectorRequirement | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | # first (see above), then the rest of apimachinery's Meta::V1, then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | # core/v1, then everything else alphabetically. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 151 | my @CORE_PREFERENCE = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 'IO::K8s::Apimachinery::Pkg::Apis::Meta::V1::LabelSelector', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 'IO::K8s::Apimachinery::Pkg::Apis::Meta::V1::', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 'IO::K8s::Api::Core::V1::', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 1176 | ▶ | sub _core_rank { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_core_rank: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 1176 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 1176 | for my $i (0 .. $#CORE_PREFERENCE) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 3503 | ▶ | return $i if index($class, $CORE_PREFERENCE[$i]) == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 1025 | return scalar @CORE_PREFERENCE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 123 | ▶ | sub _index_core_shapes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_index_core_shapes: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 123 | ▶ | return if $_core_indexed++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 21 | my $precomputed = eval { use_module($CORE_SHAPE_INDEX)->shapes }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | # A copy of the top level only: the arrayrefs stay shared with the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | # index module, so core_class_for_shape replaces a shape's entry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | # rather than sorting or splicing one in place. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 21 | ▶ | %_core_shapes = %{ $precomputed || _scan_core_shapes() }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$precomputed || _scan_core_shapes()
MC/DC0%0/2
$precomputed || _scan_core_shapes()
$precomputed
_scan_core_shapes()
Truth table66%2/3
A || B
A= $precomputedB= _scan_core_shapes()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | # Build the shape index by loading every shipped class under the two trees | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | # and reading its attribute registry -- the slow path the precomputed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | # index above exists to avoid. Called as the fallback when that module is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | # missing, and, deliberately, as the ONE implementation both | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | # maint/core-shape-index-gen.pl and t/85_core_shape_index.t call: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | # artifact cannot encode a different metadata rule or a different | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | # preference order than the live path produces, because it IS this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | # function's output. Returns a fresh hashref and touches no module state, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | # so the drift test can scan without disturbing a lookup already served. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 1 | ▶ | sub _scan_core_shapes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_scan_core_shapes: called CC=8 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 1 | require File::Find; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 1 | require IO::K8s::Role::Resource; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 1 | (my $lib = $INC{'IO/K8s/AutoGen.pm'}) =~ s{/IO/K8s/AutoGen\.pm\z}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 1 | my @files; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 912 | ▶ | File::Find::find(sub { push @files, $File::Find::name if /\.pm\z/ }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 1 | "$lib/IO/K8s/Api", "$lib/IO/K8s/Apimachinery"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 1 | my %shapes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 1 | for my $file (sort @files) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 839 | (my $class = $file) =~ s{^\Q$lib\E/}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 839 | $class =~ s{/}{::}g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 839 | $class =~ s/\.pm\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 839 | ▶ | eval { use_module($class); 1 } or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 839 | my $info = IO::K8s::Role::Resource::_k8s_attr_info($class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | # See the block comment above: metadata is part of the shape for an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | # embedded type, not for a top-level Kind (Role::APIObject supplies | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | # it outside the schema there). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 839 | ▶ | my @attrs = $class->can('_is_resource') ? grep { $_ ne 'metadata' } keys %$info : keys %$info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 839 | ▶ | my @keys = sort map { $info->{$_}{json_key} // $_ } @attrs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$info->{$_}{"json_key"} // $_
MC/DC0%0/2
$info->{$_}{"json_key"} // $_
$info->{$_}{"json_key"}
$_
Truth table33%1/3
A // B
A= $info->{$_}{"json_key"}B= $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 839 | ▶ | next unless @keys; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 822 | push @{ $shapes{ join ',', @keys } }, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 1 | for my $shape (keys %shapes) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 453 | ▶ | @{ $shapes{$shape} } = sort { _core_rank($a) <=> _core_rank($b) || $a cmp $b } @{ $shapes{$shape} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
_core_rank($a) <=> _core_rank($b) || $a cmp $b
MC/DC0%0/2
_core_rank($a) <=> _core_rank($b) || $a cmp $b
_core_rank($a) <=> _core_rank($b)
$a cmp $b
Truth table66%2/3
A || B
A= _core_rank($a) <=> _core_rank($b)B= $a cmp $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 1 | return \%shapes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | # Every shipped class whose key set is exactly \@json_keys, preference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | # ordered. Diagnostic / listing use as well as the reuse decision below; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | # building the class-name-only class from a plain ARRAY (JSON key names, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | # not schema fragments) keeps it usable without a schema in hand. Name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | # match only -- see _core_class_for for the type-aware reuse decision. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 123 | ▶ | sub core_class_for_shape { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
core_class_for_shape: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 123 | my ($keys) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 123 | _index_core_shapes(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 123 | my $shape = join ',', sort @$keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 123 | ▶ | my $classes = $_core_shapes{$shape} or return (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | # The precomputed index names classes without loading them, while | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | # every caller -- _core_class_for's type check first among them -- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | # reads the candidate's attribute registry, which is empty until the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | # class is loaded. Handing out an unloaded name would not raise: the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | # type filter would simply find no compatible candidate and silently | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | # stop reusing anything, which is the worst shape this optimisation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | # could fail in. So a shape's candidates are loaded the first time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | # that shape is asked for: a handful of classes per lookup instead of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | # all 839 up front. A class that will not load is dropped and stays | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | # dropped, matching the live scan, which never indexes one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 48 | ▶ | unless ($_core_shape_loaded{$shape}++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 27 | $classes = [ grep { eval { use_module($_); 1 } } @$classes ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 27 | $_core_shapes{$shape} = $classes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 48 | return @$classes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | # The JSON-schema "kind" a property's type dispatches on for reuse-safety | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | # purposes -- string / int-or-string / time / quantity / integer / number / | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | # boolean / array / object. Mirrors _schema_to_type_spec's own dispatch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | # (including its x-kubernetes-int-or-string, `format: int-or-string` and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | # `format: date-time` checks and its Str fallback for anything unmodeled) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | # without generating anything, since _core_class_for needs this for a schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | # fragment it may end up NOT typing as an object at all. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | # The string family splits into four kinds (k181, k185), not one, because a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | # reused class imposes its own wire type on the field and the wrong one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | # corrupts the value: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | # * int-or-string (k181) -- x-kubernetes-int-or-string, or `type: string` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | # with `format: int-or-string`, or a $ref to intstr.IntOrString | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | # (_scalar_ref_kind). Matches an IntOrStr field and a Quantity one: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | # controller-gen renders a resource.Quantity as x-kubernetes-int-or-string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | # with the quantity pattern (the emitter reads that back as Quantity, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | # k125), so a CRD embedding a pod template or a ResourceList still reuses | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | # the core class that holds it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | # * time -- `format: date-time`, or a $ref to meta.v1.(Micro)Time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | # (_scalar_ref_kind). Matches a Time field: the value IS an RFC 3339 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | # timestamp, which is exactly what a Time field holds and emits. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | # * quantity -- a $ref to resource.Quantity (_scalar_ref_kind). Matches a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | # Quantity field: the value IS a quantity. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | # * string -- a plain `type: string` (no format, no scalar $ref), '', and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | # anything unmodeled. Matches a Str field only (k185). It must NOT reuse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | # an IntOrStr, Quantity or Time class: an IntOrStr turns the schema's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | # "8080" into the number 8080 (a Str goes out quoted since k145), a strict | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | # Quantity rejects a "big", a strict Time rejects any non-RFC 3339 string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | # Reading a plain string as any of those was the k185 bug -- the mirror of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | # the k181 one that read int-or-string as 'string'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | # time and quantity also match a Str field: a timestamp or quantity string is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | # a lossless fit for one, the same direction the reuse check accepts elsewhere. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 620 | ▶ | sub _schema_type_kind { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_schema_type_kind: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 620 | my ($schema) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 620 | ▶ | return 'int-or-string' if eval { IO::K8s::Resource::_normalize_bool($schema->{'x-kubernetes-int-or-string'}) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 598 | ▶ | my $type = $schema->{type} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$schema->{"type"} // ""
MC/DC100%1/1
$schema->{"type"} // ""
$schema->{"type"}
Truth table100%2/2
A
A= $schema->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 598 | ▶ | return 'int-or-string' if $type eq 'string' && ($schema->{format} // '') eq 'int-or-string'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
$type eq "string" and ($schema->{"format"} // "") eq "int-or-string"
$schema->{"format"} // ""
MC/DC100%2/2
$type eq "string" and ($schema->{"format"} // "") eq "int-or-string"
$type eq "string"
$schema->{"format"}
Truth table100%3/3
A and B
A= $type eq "string"B= $schema->{"format"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 595 | ▶ | return 'time' if $type eq 'string' && ($schema->{format} // '') eq 'date-time'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
$type eq "string" and ($schema->{"format"} // "") eq "date-time"
$schema->{"format"} // ""
MC/DC100%2/2
$type eq "string" and ($schema->{"format"} // "") eq "date-time"
$type eq "string"
$schema->{"format"}
Truth table100%3/3
A and B
A= $type eq "string"B= $schema->{"format"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 561 | ▶ | return 'integer' if $type eq 'integer'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 530 | ▶ | return 'number' if $type eq 'number'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 530 | ▶ | return 'boolean' if $type eq 'boolean'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 530 | ▶ | return 'array' if $type eq 'array'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 467 | ▶ | return 'object' if $type eq 'object'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 328 | return 'string'; # 'string', '', and anything unmodeled alike (k42's own Str fallback) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | # What the items of a map of lists (additionalProperties of type array, k194) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | # are, as the generator and the reuse check read them: 'Str' for plain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | # strings, 'ref' for a $ref to an object definition or an apiextensions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | # union, 'props' for an inline object with properties, 'other' for anything | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | # the DSL has no map-of-lists form for (the map is then the free Opaque). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 1 | ▶ | sub _array_map_item_kind { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_array_map_item_kind: called CC=8 SCAR=29.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 1 | my ($items) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 1 | ▶ | if (defined(my $ref = $items->{'$ref'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 0 | $ref =~ s{^#/definitions/}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 0 | ▶ | return (_scalar_ref_type($ref) || $OPAQUE_TYPES{$ref}) ? 'other' : 'ref'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
_scalar_ref_type($ref) or $OPAQUE_TYPES{$ref}
MC/DC0%0/2
_scalar_ref_type($ref) or $OPAQUE_TYPES{$ref}
_scalar_ref_type($ref)
$OPAQUE_TYPES{$ref}
Truth table0%0/3
A or B
A= _scalar_ref_type($ref)B= $OPAQUE_TYPES{$ref}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 1 | ▶ | return 'props' if _has_properties($items); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 1 | ▶ | my $kind = ($items->{type} // '') eq 'string' ? _map_value_kind($items) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$items->{"type"} // ""
MC/DC0%0/1
$items->{"type"} // ""
$items->{"type"}
Truth table50%1/2
A
A= $items->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 1 | ▶ | return $kind eq 'Str' ? 'Str' : 'other'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | # The value type of a map whose additionalProperties is a scalar schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | # (k191) -- the DSL kind name Str, Int, Num, Bool, IntOrStr or Time -- or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | # undef when the generator types the map as the free Opaque instead: an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | # object or array value, or a value schema that names no type at all. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | # Unlike _schema_type_kind, a missing type is not read as a string here: a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | # string map stringifies every value on the wire, and `{}` promises no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | # strings. Shared by _schema_to_type_spec and the reuse check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | # (_object_compatible), so both read a map the same way. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 20 | ▶ | sub _map_value_kind { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_map_value_kind: called CC=10 SCAR=25.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 20 | my ($addl) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 20 | ▶ | return 'IntOrStr' if eval { IO::K8s::Resource::_normalize_bool($addl->{'x-kubernetes-int-or-string'}) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 15 | ▶ | my $type = $addl->{type} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$addl->{"type"} // ""
MC/DC0%0/1
$addl->{"type"} // ""
$addl->{"type"}
Truth table50%1/2
A
A= $addl->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 15 | ▶ | if ($type eq 'string') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 14 | ▶ | my $format = $addl->{format} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$addl->{"format"} // ""
MC/DC100%1/1
$addl->{"format"} // ""
$addl->{"format"}
Truth table100%2/2
A
A= $addl->{"format"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 14 | ▶ | return 'IntOrStr' if $format eq 'int-or-string'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 14 | ▶ | return 'Time' if $format eq 'date-time'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 13 | return 'Str'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 1 | ▶ | return 'Int' if $type eq 'integer'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 0 | ▶ | return 'Num' if $type eq 'number'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 0 | ▶ | return 'Bool' if $type eq 'boolean'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | # Registry type flags compatible with each schema kind (rule 2 above). The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | # string family (string / int-or-string / time / quantity) and why each is a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | # kind of its own is explained on _schema_type_kind above. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | # 'array'/'object' match by prefix/membership rather than an exhaustive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | # list -- see _flag_compatible. That coarse array/object match is only the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | # pre-selection the tie-break works on; what the array holds and what the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | # map's values are is decided by _field_compatible below (k148), which asks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | # _flag_compatible about scalar kinds only. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | my %_TYPE_COMPAT = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | string => { is_str => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 302 | quantity => { map { $_ => 1 } qw( is_quantity is_str ) }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 302 | time => { map { $_ => 1 } qw( is_time is_str ) }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 302 | 'int-or-string' => { map { $_ => 1 } qw( is_int_or_string is_quantity ) }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 302 | integer => { map { $_ => 1 } qw( is_int is_int_or_string ) }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 151 | number => { map { $_ => 1 } qw( is_num ) }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 151 | boolean => { map { $_ => 1 } qw( is_bool ) }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 533 | ▶ | sub _flag_compatible { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_flag_compatible: called CC=9 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 533 | my ($kind, $flag) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | 533 | ▶ | return 1 if $kind eq 'array' && $flag =~ /^is_array_of_/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$kind eq "array" and $flag =~ /^is_array_of_/
MC/DC50%1/2
$kind eq "array" and $flag =~ /^is_array_of_/
$kind eq "array"
$flag =~ /^is_array_of_/
Truth table66%2/3
A and B
A= $kind eq "array"B= $flag =~ /^is_array_of_/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 509 | ▶ | return 1 if $kind eq 'object' && ($flag eq 'is_object' || $flag eq 'is_inline_struct' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%8/12
$kind eq "object" and $flag eq "is_object" || $flag eq "is_inline_struct" || $flag eq "is_hash_opaque" || $flag =~ /^is_hash_of_/
$flag eq "is_object" or $flag eq "is_inline_struct" or $flag eq "is_hash_opaque" or $flag =~ /^is_hash_of_/
$flag eq "is_object" or $flag eq "is_inline_struct" or $flag eq "is_hash_opaque"
$flag eq "is_object" or $flag eq "is_inline_struct"
MC/DC20%1/5
$kind eq "object" and $flag eq "is_object" || $flag eq "is_inline_struct" || $flag eq "is_hash_opaque" || $flag =~ /^is_hash_of_/
$kind eq "object"
$flag eq "is_object"
$flag eq "is_inline_struct"
$flag eq "is_hash_opaque"
$flag =~ /^is_hash_of_/
Truth table50%3/6
A and B or C or D or E
A= $kind eq "object"B= $flag eq "is_object"C= $flag eq "is_inline_struct"D= $flag eq "is_hash_opaque"E= $flag =~ /^is_hash_of_/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | || $flag eq 'is_hash_opaque' || $flag =~ /^is_hash_of_/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 430 | ▶ | return $_TYPE_COMPAT{$kind} ? !!$_TYPE_COMPAT{$kind}{$flag} : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | # Does $registry_entry (one candidate's _k8s_attr_info entry for a key) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | # hold a type flag compatible with $kind? Every k8s()-registered attribute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | # carries exactly one "is_*" classifying flag (is_object plus | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | # is_inline_struct together for an inline struct -- either one matches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | # 'object'), so one match is enough. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 498 | ▶ | sub _entry_compatible { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_entry_compatible: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 498 | my ($entry, $kind) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 498 | ▶ | return !!grep { /^is_/ && $entry->{$_} && _flag_compatible($kind, $_) } keys %$entry; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
/^is_/ && $entry->{$_} && _flag_compatible($kind, $_)
/^is_/ and $entry->{$_}
MC/DC66%2/3
/^is_/ && $entry->{$_} && _flag_compatible($kind, $_)
/^is_/
$entry->{$_}
_flag_compatible($kind, $_)
Truth table75%3/4
A and B && C
A= /^is_/B= $entry->{$_}C= _flag_compatible($kind, $_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | # Container compatibility (k148) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | # A flag alone cannot tell whether a candidate's array or map field holds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | # what the schema says: "an array" matched every is_array_of_* and "an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | # object" every is_object / is_hash_of_*, so LabelSelectorRequirement | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | # ({key,operator,values}, values [Str]) was reused for a schema whose values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | # are an array of objects, and the schema's own valid data then failed to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | # inflate. _field_compatible instead compares the candidate's field with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | # the type _schema_to_type_spec WOULD give the schema fragment -- read off | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | # the schema the same way that function dispatches on it, without | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | # generating anything -- and recurses into element, value and nested | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | # object shapes: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | # scalar -> the scalar rules above, unchanged | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | # array -> items decide: a scalar item kind needs the matching | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | # is_array_of_<scalar> (the scalar rules one level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | # down); items with properties need is_array_of_objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | # whose class matches them (_class_compatible); bare | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | # `type: object` / `type: array` items need | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | # is_array_of_hash / is_array_of_array, what the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | # generator types them as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | # object + props -> is_object whose class matches them | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | # object + map -> additionalProperties with properties needs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | # is_hash_of_objects whose class matches it; a scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | # value kind a typed scalar map (is_hash_of_quantity, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | # ...) by the scalar rules -- the string map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | # (is_hash_of_str, labels, annotations) among them, a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | # `type: string` value needing is_hash_of_str (k191) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | # opaque object -> see below | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | # The opaque map, Opaque / is_hash_opaque (arbitrary JSON, fieldsV1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | # RawExtension), is its own case: it matches exactly the schema fragments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | # the generator itself types as Opaque -- an object with neither properties | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | # nor a scalar-valued additionalProperties (an object, array or typeless | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | # value schema, a boolean one, or none; a $ref to %OPAQUE_TYPES; see | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | # _map_value_kind). Reusing it there changes nothing about the field. It | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | # does not match a map of structured objects, a string or typed map, a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | # structured object, an array or a scalar, however permissive a plain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | # HashRef is: that would reuse a class that loses the schema's typing, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | # a match that cannot be shown is not one. Nor does an opaque schema match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | # a string map, a typed map or a structured class -- the schema allows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | # values those reject or would rewrite (a string map puts a number out as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | # a string) -- with the one exception of ObjectMeta ($OBJECT_META below). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | # Until k191 the opaque map was spelled { Str => 1 }, and is_hash_of_str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | # was matched here in its place. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | # A $ref is resolved read-only against the definitions _core_class_for was | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | # handed, the way _schema_to_type_spec resolves it: the apimachinery scalars | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | # are values -- IntOrString the int-or-string kind (k181), Quantity the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | # quantity kind and Time the time kind (k185) -- as a property, as items and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | # as map values alike (k178, see _scalar_ref_kind), %OPAQUE_TYPES is the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | # opaque map, an apiextensions union name is its shipped class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | # (%UNION_TYPES), anything else is the object its definition describes. A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | # $ref that does not resolve cannot be shown compatible. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | # Nested classes: every schema property must be declared by the class and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | # hold a compatible value (an undeclared one would end in the unknown-field | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | # bag, or die under strict), the class must not require a key the schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | # lacks, and _overrequires applies as it does one level up -- a nested | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | # class the nested decision would refuse must not come in through its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | # parent. Keys only the class declares are fine otherwise: the reused class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | # is looser than the schema there, never lossy (the same direction | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | # _overrequires accepts). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | # Recursion: a (class, schema) pair met again while it is still being | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | # checked further up (a recursive $ref'd definition against a recursive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | # class) counts as compatible at the repeat -- that pair's every other field | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | # is being checked by the frame that entered it, so nothing unchecked is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | # waved through, and any finite value of the schema is held by the class. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | # The set is path-scoped, like IO::K8s::CRD's own, so a pair that recurs as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | # an unrelated sibling is checked again rather than taken on trust. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | # The one structured class an unstructured object schema stands for. Below | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | # the root, controller-gen renders an embedded metav1.ObjectMeta as a bare | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | # `type: object` (the apiserver owns its shape) -- a PVC template's metadata | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | # inside core Volume's ephemeral source, for one -- so there the schema IS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | # ObjectMeta, not some other opaque value, and ObjectMeta holds it, with any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | # key it does not declare kept in the unknown-field bag. Refusing it would | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | # refuse the whole core Volume for every pod template a CRD embeds. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 151 | my $OBJECT_META = 'IO::K8s::Apimachinery::Pkg::Apis::Meta::V1::ObjectMeta'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 292 | ▶ | sub _field_compatible { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_field_compatible: called CC=13 SCAR=35.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 292 | my ($entry, $schema, $ctx) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 292 | ▶ | return 0 unless ref $entry eq 'HASH' && ref $schema eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $entry eq "HASH" and ref $schema eq "HASH"
MC/DC50%1/2
ref $entry eq "HASH" and ref $schema eq "HASH"
ref $entry eq "HASH"
ref $schema eq "HASH"
Truth table66%2/3
A and B
A= ref $entry eq "HASH"B= ref $schema eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | 274 | ▶ | if (defined(my $ref = $schema->{'$ref'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 7 | $ref =~ s{^#/definitions/}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | 7 | ▶ | if (my $kind = _scalar_ref_kind($ref)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 7 | return _entry_compatible($entry, $kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 0 | ▶ | return !!$entry->{is_hash_opaque} if $OPAQUE_TYPES{$ref}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | 0 | ▶ | if (my $union = _union_class($ref)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 0 | ▶ | return $entry->{is_object} && ($entry->{class} // '') eq $union; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$entry->{'is_object'} && ($entry->{'class'} // '') eq $union
$entry->{"class"} // ""
MC/DC0%0/2
$entry->{'is_object'} && ($entry->{'class'} // '') eq $union
$entry->{'is_object'}
$entry->{"class"}
Truth table0%0/3
A && B
A= $entry->{'is_object'}B= $entry->{"class"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 0 | ▶ | my $def = _ref_definition($ref, $ctx) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 0 | ▶ | return $entry->{is_object} && _class_compatible($entry->{class}, $def, $ctx); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$entry->{'is_object'} && _class_compatible($entry->{'class'}, $def, $ctx)
MC/DC0%0/2
$entry->{'is_object'} && _class_compatible($entry->{'class'}, $def, $ctx)
$entry->{'is_object'}
_class_compatible($entry->{'class'}, $def, $ctx)
Truth table0%0/3
A && B
A= $entry->{'is_object'}B= _class_compatible($entry->{'class'}, $def, $ctx)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | 267 | my $kind = _schema_type_kind($schema); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | 267 | ▶ | return _array_compatible($entry, $schema, $ctx) if $kind eq 'array'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | 231 | ▶ | return _object_compatible($entry, $schema, $ctx) if $kind eq 'object'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | 171 | return _entry_compatible($entry, $kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 36 | ▶ | sub _array_compatible { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_array_compatible: called CC=14 SCAR=35.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 36 | my ($entry, $schema, $ctx) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 36 | ▶ | my $items = $schema->{items} // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$schema->{"items"} // {}
MC/DC0%0/1
$schema->{"items"} // {}
$schema->{"items"}
Truth table50%1/2
A
A= $schema->{"items"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 36 | ▶ | return 0 unless ref $items eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | # items with a $ref: an array of the scalar an apimachinery $ref stands | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | # for, as the generator's items branch types it (k178), else an array of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | # the definition's class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 36 | ▶ | if (defined(my $ref = $items->{'$ref'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 3 | $ref =~ s{^#/definitions/}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 3 | ▶ | if (my $kind = _scalar_ref_kind($ref)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | 3 | return _element_compatible($entry, 'is_array_of_', $kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 0 | ▶ | if (my $union = _union_class($ref)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | 0 | ▶ | return $entry->{is_array_of_objects} && ($entry->{class} // '') eq $union; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$entry->{'is_array_of_objects'} && ($entry->{'class'} // '') eq $union
$entry->{"class"} // ""
MC/DC0%0/2
$entry->{'is_array_of_objects'} && ($entry->{'class'} // '') eq $union
$entry->{'is_array_of_objects'}
$entry->{"class"}
Truth table0%0/3
A && B
A= $entry->{'is_array_of_objects'}B= $entry->{"class"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | 0 | ▶ | my $def = _ref_definition($ref, $ctx) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | 0 | ▶ | return $entry->{is_array_of_objects} && _class_compatible($entry->{class}, $def, $ctx); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$entry->{'is_array_of_objects'} && _class_compatible($entry->{'class'}, $def, $ctx)
MC/DC0%0/2
$entry->{'is_array_of_objects'} && _class_compatible($entry->{'class'}, $def, $ctx)
$entry->{'is_array_of_objects'}
_class_compatible($entry->{'class'}, $def, $ctx)
Truth table0%0/3
A && B
A= $entry->{'is_array_of_objects'}B= _class_compatible($entry->{'class'}, $def, $ctx)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 33 | ▶ | return $entry->{is_array_of_objects} && _class_compatible($entry->{class}, $items, $ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$entry->{'is_array_of_objects'} && _class_compatible($entry->{'class'}, $items, $ctx)
MC/DC50%1/2
$entry->{'is_array_of_objects'} && _class_compatible($entry->{'class'}, $items, $ctx)
$entry->{'is_array_of_objects'}
_class_compatible($entry->{'class'}, $items, $ctx)
Truth table66%2/3
A && B
A= $entry->{'is_array_of_objects'}B= _class_compatible($entry->{'class'}, $items, $ctx)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | if _has_properties($items); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 25 | my $kind = _schema_type_kind($items); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 25 | ▶ | return !!$entry->{is_array_of_hash} if $kind eq 'object'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 25 | ▶ | return !!$entry->{is_array_of_array} if $kind eq 'array'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | 22 | return _element_compatible($entry, 'is_array_of_', $kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 60 | ▶ | sub _object_compatible { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_object_compatible: called CC=30 SCAR=56.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | 60 | my ($entry, $schema, $ctx) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 60 | ▶ | return $entry->{is_object} && _class_compatible($entry->{class}, $schema, $ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$entry->{'is_object'} && _class_compatible($entry->{'class'}, $schema, $ctx)
MC/DC50%1/2
$entry->{'is_object'} && _class_compatible($entry->{'class'}, $schema, $ctx)
$entry->{'is_object'}
_class_compatible($entry->{'class'}, $schema, $ctx)
Truth table66%2/3
A && B
A= $entry->{'is_object'}B= _class_compatible($entry->{'class'}, $schema, $ctx)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | if _has_properties($schema); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | 39 | my $addl = $schema->{additionalProperties}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | # a boolean additionalProperties, or none: the opaque map -- or an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | # embedded ObjectMeta (see $OBJECT_META) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | 39 | ▶ | unless (ref $addl eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 29 | ▶ | return 1 if $entry->{is_hash_opaque}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 29 | ▶ | return $entry->{is_object} && ($entry->{class} // '') eq $OBJECT_META; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition60%3/5
$entry->{'is_object'} && ($entry->{'class'} // '') eq $OBJECT_META
$entry->{"class"} // ""
MC/DC0%0/2
$entry->{'is_object'} && ($entry->{'class'} // '') eq $OBJECT_META
$entry->{'is_object'}
$entry->{"class"}
Truth table33%1/3
A && B
A= $entry->{'is_object'}B= $entry->{"class"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | 10 | ▶ | if (defined(my $ref = $addl->{'$ref'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 2 | $ref =~ s{^#/definitions/}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | # the typed map the generator makes of an apimachinery scalar (k178) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | 2 | ▶ | if (my $kind = _scalar_ref_kind($ref)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | 2 | return _element_compatible($entry, 'is_hash_of_', $kind); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 0 | ▶ | if (my $union = _union_class($ref)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | 0 | ▶ | return $entry->{is_hash_of_objects} && ($entry->{class} // '') eq $union; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$entry->{'is_hash_of_objects'} && ($entry->{'class'} // '') eq $union
$entry->{"class"} // ""
MC/DC0%0/2
$entry->{'is_hash_of_objects'} && ($entry->{'class'} // '') eq $union
$entry->{'is_hash_of_objects'}
$entry->{"class"}
Truth table0%0/3
A && B
A= $entry->{'is_hash_of_objects'}B= $entry->{"class"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | 0 | ▶ | my $def = _ref_definition($ref, $ctx) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | 0 | ▶ | return $entry->{is_hash_of_objects} && _class_compatible($entry->{class}, $def, $ctx); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$entry->{'is_hash_of_objects'} && _class_compatible($entry->{'class'}, $def, $ctx)
MC/DC0%0/2
$entry->{'is_hash_of_objects'} && _class_compatible($entry->{'class'}, $def, $ctx)
$entry->{'is_hash_of_objects'}
_class_compatible($entry->{'class'}, $def, $ctx)
Truth table0%0/3
A && B
A= $entry->{'is_hash_of_objects'}B= _class_compatible($entry->{'class'}, $def, $ctx)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | 8 | ▶ | return $entry->{is_hash_of_objects} && _class_compatible($entry->{class}, $addl, $ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$entry->{'is_hash_of_objects'} && _class_compatible($entry->{'class'}, $addl, $ctx)
MC/DC0%0/2
$entry->{'is_hash_of_objects'} && _class_compatible($entry->{'class'}, $addl, $ctx)
$entry->{'is_hash_of_objects'}
_class_compatible($entry->{'class'}, $addl, $ctx)
Truth table0%0/3
A && B
A= $entry->{'is_hash_of_objects'}B= _class_compatible($entry->{'class'}, $addl, $ctx)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | if _has_properties($addl); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | # a map of lists (k194): what the generator makes of it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | 8 | ▶ | if (($addl->{type} // '') eq 'array' && ref($addl->{items} // {}) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition42%3/7
($addl->{"type"} // "") eq "array" and ref($addl->{"items"} // {}) eq "HASH"
$addl->{"type"} // ""
$addl->{"items"} // {}
MC/DC0%0/2
($addl->{"type"} // "") eq "array" and ref($addl->{"items"} // {}) eq "HASH"
$addl->{"type"}
$addl->{"items"}
Truth table33%1/3
A and B
A= $addl->{"type"}B= $addl->{"items"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 0 | ▶ | my $items = $addl->{items} // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$addl->{"items"} // {}
MC/DC0%0/1
$addl->{"items"} // {}
$addl->{"items"}
Truth table0%0/2
A
A= $addl->{"items"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | 0 | my $item_kind = _array_map_item_kind($items); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | 0 | ▶ | return !!$entry->{is_hash_of_str_arrays} if $item_kind eq 'Str'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 0 | ▶ | if ($item_kind eq 'ref') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | 0 | ▶ | return 0 unless $entry->{is_hash_of_object_arrays}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | 0 | (my $ref = $items->{'$ref'}) =~ s{^#/definitions/}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | 0 | ▶ | if (my $union = _union_class($ref)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | 0 | ▶ | return ($entry->{class} // '') eq $union; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$entry->{"class"} // ""
MC/DC0%0/1
$entry->{"class"} // ""
$entry->{"class"}
Truth table0%0/2
A
A= $entry->{"class"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | 0 | ▶ | my $def = _ref_definition($ref, $ctx) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | 0 | return _class_compatible($entry->{class}, $def, $ctx); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | 0 | ▶ | return $entry->{is_hash_of_object_arrays} && _class_compatible($entry->{class}, $items, $ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$entry->{'is_hash_of_object_arrays'} && _class_compatible($entry->{'class'}, $items, $ctx)
MC/DC0%0/2
$entry->{'is_hash_of_object_arrays'} && _class_compatible($entry->{'class'}, $items, $ctx)
$entry->{'is_hash_of_object_arrays'}
_class_compatible($entry->{'class'}, $items, $ctx)
Truth table0%0/3
A && B
A= $entry->{'is_hash_of_object_arrays'}B= _class_compatible($entry->{'class'}, $items, $ctx)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | if $item_kind eq 'props'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 0 | return !!$entry->{is_hash_opaque}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | # a scalar value schema is the string or typed map the generator makes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | # of it, by the scalar rules; anything else it types as the opaque map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | 8 | ▶ | return !!$entry->{is_hash_opaque} unless _map_value_kind($addl); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 8 | return _element_compatible($entry, 'is_hash_of_', _schema_type_kind($addl)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | # Does $entry carry a scalar-element container flag ($prefix plus a scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | # name: is_array_of_int, is_hash_of_quantity, ...) whose scalar is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | # compatible with $kind under the scalar rules? Since k191 is_hash_of_str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | # is the string map and counts like is_array_of_str; the opaque map has a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | # flag of its own (is_hash_opaque) that never matches a prefix here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 35 | ▶ | sub _element_compatible { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_element_compatible: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | 35 | my ($entry, $prefix, $kind) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | 35 | for my $flag (grep { $entry->{$_} } keys %$entry) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | 35 | ▶ | next unless $flag =~ /^\Q$prefix\E(.+)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | 35 | ▶ | return 1 if _flag_compatible($kind, 'is_' . $1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | 8 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | # Does $class hold every value the object schema $schema describes? See | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | # the block comment above for the rules and the recursion guard. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | 128 | ▶ | sub _class_compatible { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_class_compatible: called CC=13 SCAR=26.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | 128 | my ($class, $schema, $ctx) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | 128 | ▶ | return 0 unless defined $class && _has_properties($schema); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $class and _has_properties($schema)
MC/DC0%0/2
defined $class and _has_properties($schema)
defined $class
_has_properties($schema)
Truth table33%1/3
A and B
A= defined $classB= _has_properties($schema)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | 128 | my $pair = $class . '|' . refaddr($schema); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | 128 | ▶ | return 1 if $ctx->{active}{$pair}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | 128 | ▶ | return 0 unless $class->can('_k8s_attr_info') || eval { use_module($class); 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$class->can("_k8s_attr_info") or eval {
do {
&use_module($class);
1
}
}
MC/DC0%0/2
$class->can("_k8s_attr_info") or eval {
do {
&use_module($class);
1
}
}
$class->can("_k8s_attr_info")
eval {
do {
&use_module($class);
1
}
}
Truth table66%2/3
A or B
A= $class->can("_k8s_attr_info")B= eval {
do {
&use_module($class);
1
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | 128 | local $ctx->{active}{$pair} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | 128 | my $by_json = _attrs_by_json_key($class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | 128 | my $props = $schema->{properties}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 128 | for my $key (keys %$props) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | 266 | ▶ | return 0 unless _field_compatible($by_json->{$key}, $props->{$key}, $ctx); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 65 | for my $key (keys %$by_json) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 322 | ▶ | return 0 if $by_json->{$key}{required} && !exists $props->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$by_json->{$key}{"required"} and not exists $props->{$key}
MC/DC0%0/2
$by_json->{$key}{"required"} and not exists $props->{$key}
$by_json->{$key}{"required"}
not exists $props->{$key}
Truth table66%2/3
A and not(B)
A= $by_json->{$key}{"required"}B= not exists $props->{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | 65 | ▶ | if (defined $schema->{required}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | 12 | my %schema_required = map { $_ => 1 } @{ $schema->{required} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | 12 | ▶ | return 0 if _overrequires([ keys %$props ], \%schema_required, $class); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | 65 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | # The definition a $ref names, from the definitions handed to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | # _core_class_for, or undef. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | 0 | ▶ | sub _ref_definition { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ref_definition: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | 0 | my ($ref, $ctx) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 0 | ▶ | my $def = $ctx->{defs} && $ctx->{defs}{$ref}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ctx->{'defs'} && $ctx->{'defs'}{$ref}
MC/DC0%0/2
$ctx->{'defs'} && $ctx->{'defs'}{$ref}
$ctx->{'defs'}
$ctx->{'defs'}{$ref}
Truth table0%0/3
A && B
A= $ctx->{'defs'}B= $ctx->{'defs'}{$ref}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | 0 | ▶ | return ref $def eq 'HASH' ? $def : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | # $class's registry entries keyed by JSON key rather than attribute name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | 128 | ▶ | sub _attrs_by_json_key { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_attrs_by_json_key: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | 128 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | 128 | my $info = IO::K8s::Role::Resource::_k8s_attr_info($class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | 128 | my %by_json; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | 128 | ▶ | $by_json{ $info->{$_}{json_key} // $_ } = $info->{$_} for keys %$info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$info->{$_}{"json_key"} // $_
MC/DC0%0/2
$info->{$_}{"json_key"} // $_
$info->{$_}{"json_key"}
$_
Truth table33%1/3
A // B
A= $info->{$_}{"json_key"}B= $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 128 | return \%by_json; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | # Do every one of @candidates agree, key by key, on type flags (ignoring | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | # required-ness) and on the referenced class where a key has one? Assumes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | # @candidates already share the identical JSON key set (core_class_for_shape | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | # guarantees that) -- compared by JSON key, not by each candidate's own | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | # (possibly differently-sanitized) Perl attribute name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | 11 | ▶ | sub _wire_identical { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wire_identical: called CC=10 SCAR=24.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | 11 | my ($keys, @candidates) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | 11 | ▶ | return 1 if @candidates <= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | my @by_json = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | 11 | my $info = IO::K8s::Role::Resource::_k8s_attr_info($_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | 38 | ▶ | my %j; $j{ $info->{$_}{json_key} // $_ } = $info->{$_} for keys %$info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$info->{$_}{"json_key"} // $_
MC/DC0%0/2
$info->{$_}{"json_key"} // $_
$info->{$_}{"json_key"}
$_
Truth table33%1/3
A // B
A= $info->{$_}{"json_key"}B= $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | 38 | \%j; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | } @candidates; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | 11 | for my $key (@$keys) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | 34 | my %sig; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | 34 | for my $j (@by_json) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | 129 | ▶ | my $e = $j->{$key} // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$j->{$key} // {}
MC/DC0%0/1
$j->{$key} // {}
$j->{$key}
Truth table50%1/2
A
A= $j->{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | 129 | ▶ | my @flags = sort grep { /^is_/ && $e->{$_} } keys %$e; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
/^is_/ && $e->{$_}
MC/DC50%1/2
/^is_/ && $e->{$_}
/^is_/
$e->{$_}
Truth table66%2/3
A && B
A= /^is_/B= $e->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | 129 | ▶ | $sig{ join('|', @flags) . '#' . ($e->{class} // '') } = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$e->{"class"} // ""
MC/DC0%0/1
$e->{"class"} // ""
$e->{"class"}
Truth table50%1/2
A
A= $e->{"class"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | 34 | ▶ | return 0 if keys %sig > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | 11 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | # Does $candidate mark some shared key `required` (Moo-enforced plain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | # `required => 1`, or registry-only `required => 'schema'` -- both are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | # recorded as `required => 1` in _k8s_attr_info, see IO::K8s::Resource's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | # k8s()) that $schema_required does NOT list? One direction only (k136): a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | # candidate requiring MORE than the schema is unsafe to reuse -- a real | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | # cluster object that omits that key would fail ->new() (plain required) or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | # be silently dropped on inflate (required => 'schema'), even though the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | # schema never promised the field. A schema requiring MORE than the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | # candidate is the opposite, harmless direction -- the reused class is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | # merely looser than the schema, never lossy -- and is not checked here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | # Only called (see _core_class_for) when $schema itself carries a `required` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | # key at all -- a schema fragment that omits `required` entirely is treated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | # as making no required-ness claim one way or the other, not as an explicit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | # "nothing required" (which, strictly, is what JSON Schema says an absent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | # `required` means). Every upstream CRD schema actually seen to embed one of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | # these reused shapes (LabelSelector's {key,operator,values}, {name,value}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | # ...) does carry an explicit `required` list matching the reused class, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | # this distinction changes nothing for real schemas; what it avoids is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | # treating a schema fragment that simply never bothered to state `required` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | # (as this function's own test fixtures do, and as a hand-written or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | # less careful third-party CRD might) as if it had positively declared every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | # field optional, which would fall back dozens of well-established, safe | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | # reuses (LabelSelectorRequirement, HTTPHeader, ...) to nested classes for no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | # safety gain. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | 36 | ▶ | sub _overrequires { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_overrequires: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | 36 | my ($keys, $schema_required, $candidate) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | 36 | my $info = IO::K8s::Role::Resource::_k8s_attr_info($candidate); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | 36 | ▶ | my %by_json; $by_json{ $info->{$_}{json_key} // $_ } = $info->{$_} for keys %$info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$info->{$_}{"json_key"} // $_
MC/DC0%0/2
$info->{$_}{"json_key"} // $_
$info->{$_}{"json_key"}
$_
Truth table33%1/3
A // B
A= $info->{$_}{"json_key"}B= $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | 36 | for my $key (@$keys) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | 145 | ▶ | return 1 if $by_json{$key}{required} && !$schema_required->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$by_json{$key}{"required"} and not $schema_required->{$key}
MC/DC100%2/2
$by_json{$key}{"required"} and not $schema_required->{$key}
$by_json{$key}{"required"}
not $schema_required->{$key}
Truth table100%3/3
A and not(B)
A= $by_json{$key}{"required"}B= not $schema_required->{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | 32 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | # The class to reuse for a nested object schema, or undef. $all_defs, the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | # definitions the schema's $refs resolve against, is only read (k148). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | 305 | ▶ | sub _core_class_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_core_class_for: called CC=14 SCAR=26.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | 305 | my ($schema, $all_defs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | 305 | ▶ | return undef unless _has_properties($schema); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | 255 | my @keys = sort keys %{ $schema->{properties} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | 255 | ▶ | return undef if @keys < 2; # a single shared key name is too common to trust | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | 118 | my @candidates = core_class_for_shape(\@keys); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | 118 | ▶ | return undef unless @candidates; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | # Type-compatibility filter: drop any candidate that types some key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | # incompatibly with what the schema itself says that key is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | @candidates = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | 43 | my $info = IO::K8s::Role::Resource::_k8s_attr_info($_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | 116 | ▶ | my %by_json; $by_json{ $info->{$_}{json_key} // $_ } = $info->{$_} for keys %$info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$info->{$_}{"json_key"} // $_
MC/DC0%0/2
$info->{$_}{"json_key"} // $_
$info->{$_}{"json_key"}
$_
Truth table33%1/3
A // B
A= $info->{$_}{"json_key"}B= $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | 116 | !grep { !_entry_compatible($by_json{$_}, _schema_type_kind($schema->{properties}{$_})) } @keys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | } @candidates; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | 43 | ▶ | return undef unless @candidates; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | # Required-compatibility filter (k136): drop any candidate that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | # over-constrains the schema -- see _overrequires. Only applied when the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | # schema itself declares a `required` list (see that function's comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | # for why an absent one is not treated as an explicit "nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | # required"). Checked before the single-candidate shortcut and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | # wire-identical tie-break alike, so an over-constrained candidate can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | # never be "the one" reuse picks, whether it was alone or one of several | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | # wire-identical options. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | 39 | ▶ | if (defined $schema->{required}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | 6 | my %schema_required = map { $_ => 1 } @{ $schema->{required} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | # k139: remember the shared-vocab candidates (Meta::V1 / Core::V1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | # _core_rank below @CORE_PREFERENCE) that ENTER the required filter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | # to catch the specific fallback the check just below rejects. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | 6 | my @shared_vocab_before = grep { _core_rank($_) < scalar @CORE_PREFERENCE } @candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | 6 | @candidates = grep { !_overrequires(\@keys, \%schema_required, $_) } @candidates; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | 6 | ▶ | return undef unless @candidates; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | # k139: a shared-vocab candidate matched this shape but the required | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | # filter above eliminated every one of them, leaving only a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | # domain-foreign candidate (_core_rank == @CORE_PREFERENCE) to reuse. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | # That is the k135/k137 condition case: metav1.Condition matches a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | # CRD condition's {lastTransitionTime,message,observedGeneration, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | # reason,status,type} shape but over-requires (message/reason/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | # lastTransitionTime) relative to a CRD that requires only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | # [status,type], so k136 drops it -- and reuse would otherwise fall | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | # back to an unrelated class that merely shares the shape and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | # narrower required set (Autoscaling::V2::HorizontalPodAutoscaler- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | # Condition for a cert-manager IssuerCondition). Return undef so the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | # provider's own nested class is generated instead of reusing a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | # foreign one. This fires ONLY once a shared-vocab candidate has been | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | # removed HERE: a shape whose candidates were always domain-specific | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | # (no Meta/Core member ever) is a genuine sole-family reuse of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | # one real embedded upstream type (NetworkPolicyPort, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | # CrossVersionObjectReference, ParamKind, ...) and is left untouched, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | # as is a shape where a shared-vocab candidate still survives the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | # required filter (Core::V1::NamespaceCondition for the 5-key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | # CertificateRequest condition, which requires only [status,type]). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | return undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | if @shared_vocab_before | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | 6 | ▶ | && !grep { _core_rank($_) < scalar @CORE_PREFERENCE } @candidates; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@shared_vocab_before and not grep({_core_rank($_) < scalar @CORE_PREFERENCE;} @candidates)
MC/DC50%1/2
@shared_vocab_before and not grep({_core_rank($_) < scalar @CORE_PREFERENCE;} @candidates)
@shared_vocab_before
not grep({_core_rank($_) < scalar @CORE_PREFERENCE;} @candidates)
Truth table66%2/3
A and not(B)
A= @shared_vocab_beforeB= not grep({_core_rank($_) < scalar @CORE_PREFERENCE;} @candidates)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | # Recursive-compatibility filter (k148 check, k156 placement): every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | # remaining candidate must hold what the schema describes all the way | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | # down -- array elements, map values, nested objects (see | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | # _field_compatible / _class_compatible) -- or it is dropped here, ahead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | # of the tie-break below. k148 first ran this as a gate on the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | # already-picked class (it could only WITHDRAW a reuse); k156 moves it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | # ahead of the tie-break so it can also DECIDE one: a shape several | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | # candidates match by name and type alone (a {metadata,spec} that fits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | # every *TemplateSpec) narrows to the single candidate whose deep shape | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | # holds the schema (only PodTemplateSpec's spec holds a PodSpec, only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | # PersistentVolumeClaimTemplate's a PVC spec), and that one is reused | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | # where before the non-wire-identical tie-break refused them all. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | # Wire-identical candidates share their verdict here (same flags, same | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | # classes per key), so they survive or fall together and the tie-break | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | # below still sees the same wire-identical set. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | @candidates = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | 37 | _class_compatible($_, $schema, { defs => $all_defs, active => {} }) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | } @candidates; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | 37 | ▶ | return undef unless @candidates; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | # Several type-, required- and recursively-compatible candidates: reuse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | # the preferred one only if they are wire-identical (already | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | # preference-sorted by core_class_for_shape, and every filter above | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | # preserves that order). A single survivor is reused outright. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | 30 | ▶ | return @candidates == 1 ? $candidates[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | : _wire_identical(\@keys, @candidates) ? $candidates[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | # The scalar type a $ref to one of the special apimachinery types stands for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | # (they are values, not object references), or undef -- as a property, as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | # an array's items and as a map's additionalProperties alike (k178). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | # Shared by _schema_to_type_spec and the reuse check (_field_compatible), so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | # the two read a $ref the same way. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | 88 | ▶ | sub _scalar_ref_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_scalar_ref_type: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | 88 | my ($ref) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | 88 | ▶ | return 'IntOrStr' if $ref =~ /intstr\.IntOrString$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | 79 | ▶ | return 'Quantity' if $ref =~ /resource\.Quantity$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | 63 | ▶ | return 'Time' if $ref =~ /meta\.v1\.(Micro)?Time$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | 53 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | # The reuse-check kind (see _schema_type_kind) of such a $ref, or undef: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | # IntOrString is the int-or-string kind (k181), Quantity the quantity kind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | # and Time the time kind (k185) -- each distinct from a plain string, which a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | # scalar $ref never is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | 12 | ▶ | sub _scalar_ref_kind { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_scalar_ref_kind: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | 12 | my ($ref) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | 12 | ▶ | my $scalar = _scalar_ref_type($ref) or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | 12 | ▶ | return 'int-or-string' if $scalar eq 'IntOrStr'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | 7 | ▶ | return 'quantity' if $scalar eq 'Quantity'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | 2 | return 'time'; # Time / MicroTime | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | # The element types of a generated class's scalar arrays (k178). The scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | # fields of a generated class are the barewords 'Quantity' and 'Time', which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | # the DSL builds on Str: any string, so a value the API server stores as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | # written -- a custom resource's date-time with a lowercase 't' or 'z' is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | # valid RFC 3339 -- never fails to inflate. An array element has to follow | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | # the same rule, but inside an arrayref the DSL reads a bareword as a class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | # name, and the library's Time and Quantity carry the strict regexes a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | # hand-written class keeps. So each is Str under the kind's name: the DSL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | # and _scalar_kind classify a Type::Tiny element by its name, which is what | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | # gives it the is_array_of_time / is_array_of_quantity registry flag and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | # with that its TO_JSON rule, its to_crd schema and its emitter spelling. A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | # Type::Library cannot hold a second Time, so these stay private here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | # rather than becoming an export of IO::K8s::Types. IntOrStr is Str in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | # library already. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | 151 | my $GENERATED_TIME = Str->create_child_type(name => 'Time'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | 151 | my $GENERATED_QUANTITY = Str->create_child_type(name => 'Quantity'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | 151 | my %GENERATED_ITEM_TYPE = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | IntOrStr => IntOrStr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | Quantity => $GENERATED_QUANTITY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | Time => $GENERATED_TIME, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | # The value types of a generated scalar map, HashRef[X] (k191), by the kind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | # _map_value_kind reads off additionalProperties. Time is the lenient | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | # $GENERATED_TIME for the reason the array element above is. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | 151 | my %GENERATED_MAP_VALUE_TYPE = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | Str => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | Int => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | Num => Num, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | Bool => Bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | IntOrStr => IntOrStr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | Time => $GENERATED_TIME, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | # Convert OpenAPI schema to k8s() type spec | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | # $field_name and $class are diagnostic context only: everything this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | # function refuses has to name the class being generated and the field it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1420 | # choked on, because the caller sees neither (the k42 diagnostic line). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1421 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1422 | # $reuse_core (D5, default 1) turns the object / array-items / | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1423 | # additionalProperties reuse check on or off (see _core_class_for). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1424 | 803 | ▶ | sub _schema_to_type_spec { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_schema_to_type_spec: called CC=70 SCAR=48.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1425 | 803 | my ($schema, $all_defs, $namespace, $field_name, $class, $reuse_core, $reuse_core_except) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1426 | 803 | ▶ | $reuse_core = 1 unless defined $reuse_core; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1427 | 803 | ▶ | $reuse_core_except ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$reuse_core_except ||= {}
MC/DC0%0/1
$reuse_core_except ||= {}
$reuse_core_except
Truth table50%1/2
A
A= $reuse_core_except
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | # k120: reuse core here unless this field's would-be nested class sits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | # at a path the caller marked for suppression (see reuse_core_except in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | # _generate_class). $suffix matches the _nested_class call in the same | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | # branch: 'Item' for array items, undef for a plain object, 'Value' for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | # additionalProperties. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1434 | 309 | ▶ | my $may_reuse = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1435 | 309 | my ($suffix) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1436 | 309 | ▶ | return 0 unless $reuse_core; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | 295 | return !$reuse_core_except->{ _prospective_nested_path($class, $field_name, $suffix) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | 803 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1440 | 803 | my $where = "field '" . $field_name . "' of " . $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1442 | # Handle $ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1443 | 803 | ▶ | if (my $ref = $schema->{'$ref'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1444 | 45 | $ref =~ s{^#/definitions/}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1446 | # Special apimachinery types - not object references | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | 45 | ▶ | if (my $scalar = _scalar_ref_type($ref)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | 9 | return $scalar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | # apiextensions union types: the shipped FROM_STRUCT class (k152) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | 36 | ▶ | if (my $union = _union_class($ref)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1453 | 15 | return "+$union"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1456 | # Opaque types should be the free map, not object references | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1457 | 21 | ▶ | if ($OPAQUE_TYPES{$ref}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1458 | 0 | return Opaque; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1461 | # Generate referenced class if needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1462 | 21 | ▶ | if ($all_defs && $all_defs->{$ref}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$all_defs and $all_defs->{$ref}
MC/DC50%1/2
$all_defs and $all_defs->{$ref}
$all_defs
$all_defs->{$ref}
Truth table66%2/3
A and B
A= $all_defsB= $all_defs->{$ref}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1463 | 11 | my $ref_class = get_or_generate($ref, $all_defs->{$ref}, $all_defs, $namespace); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1464 | 11 | return "+$ref_class"; # + prefix for full class name | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1465 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1466 | 10 | _croak_unresolved_ref($ref, $where); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1469 | # A structural CRD schema marks Kubernetes' IntOrString union type with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1470 | # this extension, almost always instead of `type` rather than alongside | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1471 | # it (the pruning rules for x-kubernetes-int-or-string require either no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1472 | # `type` or an `anyOf`) -- checked before the type dispatch below, which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1473 | # would otherwise read the type-less shape as "unknown type" and fall | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1474 | # back to Str. Found via IO::K8s::CRD::Emitter's stronger assertion on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1475 | # the registry type flag (t/74_crd_emitter.t): t/73_add_crd.t's own | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1476 | # same-named subtest passed regardless, since a Str-typed attribute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1477 | # holds a plain IntOrString value like '10Gi' exactly as well as an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1478 | # IntOrStr-typed one does. The swagger v2 `format: int-or-string` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1479 | # convention below still works for a schema that keeps `type: string`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1480 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1481 | # Unlike the nullable/preserve_unknown checks in _field_options (Minor 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1482 | # of the k93 review, deliberately left unwrapped: a schema property is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1483 | # always a plain scalar or JSON boolean there), this call sits ahead of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1484 | # the type dispatch below rather than after it -- a malformed value here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1485 | # must not abort class generation outright, so it is wrapped in eval and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1486 | # treated as false, falling through to the ordinary `type`-based | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1487 | # dispatch instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1488 | return 'IntOrStr' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1489 | 758 | ▶ | if eval { IO::K8s::Resource::_normalize_bool($schema->{'x-kubernetes-int-or-string'}) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1490 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1491 | 737 | ▶ | my $type = $schema->{type} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$schema->{"type"} // ""
MC/DC0%0/1
$schema->{"type"} // ""
$schema->{"type"}
Truth table50%1/2
A
A= $schema->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1493 | 737 | ▶ | if ($type eq 'string') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1494 | 227 | ▶ | my $format = $schema->{format} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$schema->{"format"} // ""
MC/DC100%1/1
$schema->{"format"} // ""
$schema->{"format"}
Truth table100%2/2
A
A= $schema->{"format"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1495 | 227 | ▶ | return 'IntOrStr' if $format eq 'int-or-string'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1496 | 225 | ▶ | return 'Time' if $format eq 'date-time'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1497 | 222 | return 'Str'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1498 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1499 | elsif ($type eq 'integer') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1500 | 87 | return 'Int'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1501 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1502 | elsif ($type eq 'number') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1503 | 3 | return 'Num'; # A genuine JSON number -- unquoted on the wire (k68) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1505 | elsif ($type eq 'boolean') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1506 | 29 | return 'Bool'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1508 | elsif ($type eq 'array') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1509 | 79 | ▶ | my $items = $schema->{items} // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$schema->{"items"} // {}
MC/DC0%0/1
$schema->{"items"} // {}
$schema->{"items"}
Truth table50%1/2
A
A= $schema->{"items"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1510 | 79 | ▶ | if (my $ref = $items->{'$ref'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1511 | 12 | $ref =~ s{^#/definitions/}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1512 | # The apimachinery scalars are values here too (k178): generated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1513 | # from their definitions -- a bare `type: string` -- they used to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1514 | # become an empty class no element could inflate into. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1515 | 12 | ▶ | if (my $scalar = _scalar_ref_type($ref)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1516 | 6 | return [ $GENERATED_ITEM_TYPE{$scalar} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1517 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1518 | 6 | ▶ | if (my $union = _union_class($ref)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1519 | 5 | return ["+$union"]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1521 | 1 | ▶ | if ($all_defs && $all_defs->{$ref}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$all_defs and $all_defs->{$ref}
MC/DC0%0/2
$all_defs and $all_defs->{$ref}
$all_defs
$all_defs->{$ref}
Truth table33%1/3
A and B
A= $all_defsB= $all_defs->{$ref}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1522 | 0 | my $ref_class = get_or_generate($ref, $all_defs->{$ref}, $all_defs, $namespace); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1523 | 0 | return ["+$ref_class"]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1524 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1525 | 1 | _croak_unresolved_ref($ref, "the items of $where"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1527 | 67 | ▶ | if ($may_reuse->('Item') and my $core = _core_class_for($items, $all_defs)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
&$may_reuse("Item") and my $core = _core_class_for($items, $all_defs)
MC/DC100%2/2
&$may_reuse("Item") and my $core = _core_class_for($items, $all_defs)
&$may_reuse("Item")
my $core = _core_class_for($items, $all_defs)
Truth table100%3/3
A and B
A= &$may_reuse("Item")B= my $core = _core_class_for($items, $all_defs)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1528 | 2 | return [ "+$core" ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1529 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1530 | 65 | ▶ | if (_has_properties($items)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1531 | 23 | return [ '+' . _nested_class($class, $field_name, 'Item', $items, $all_defs, $namespace, $reuse_core, $reuse_core_except) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1532 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1533 | # Type::Tiny objects rather than the barewords: inside an arrayref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1534 | # the DSL reads a plain string as a class name for everything except | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1535 | # 'Str' and 'Int', so ['Bool'] would ask for an array of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1536 | # IO::K8s::Api::Bool objects. [Bool] is the form that reaches the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1537 | # is_array_of_bool branch and its per-element normalization, which is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1538 | # what an array of schema-true JSON booleans needs (k57). Number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1539 | # items get [Num], the array form of the scalar number case (k68): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1540 | # they used to fall through to [ Str ] below, and a [Str] element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1541 | # goes out as a JSON string since k145 (k155). int-or-string and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1542 | # date-time items are the same gap for the scalar IntOrStr / Time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1543 | # cases above (k167), read off the items exactly as those read the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1544 | # property: the extension first, a format only with `type: string`. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1545 | # [IntOrStr] keeps an element 8080 a number on the wire; a [Time] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1546 | # element accepts what the scalar Time of a generated class accepts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1547 | # (k178, see %GENERATED_ITEM_TYPE). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1548 | return [ IntOrStr ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1549 | 42 | ▶ | if eval { IO::K8s::Resource::_normalize_bool($items->{'x-kubernetes-int-or-string'}) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1550 | 36 | ▶ | if (($items->{type} // '') eq 'string') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$items->{"type"} // ""
MC/DC100%1/1
$items->{"type"} // ""
$items->{"type"}
Truth table100%2/2
A
A= $items->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1551 | 20 | ▶ | my $format = $items->{format} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$items->{"format"} // ""
MC/DC100%1/1
$items->{"format"} // ""
$items->{"format"}
Truth table100%2/2
A
A= $items->{"format"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1552 | 20 | ▶ | return [ IntOrStr ] if $format eq 'int-or-string'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1553 | 19 | ▶ | return [ $GENERATED_TIME ] if $format eq 'date-time'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1554 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1555 | 26 | ▶ | my $item_type = $items->{type} // 'string'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$items->{"type"} // "string"
MC/DC100%1/1
$items->{"type"} // "string"
$items->{"type"}
Truth table100%2/2
A
A= $items->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1556 | 26 | ▶ | return [ Int ] if $item_type eq 'integer'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1557 | 23 | ▶ | return [ Num ] if $item_type eq 'number'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1558 | 19 | ▶ | return [ Bool ] if $item_type eq 'boolean'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1559 | # items: object / array with no further structure -> an array of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1560 | # opaque hashes / opaque arrays. Before k66 both fell through to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1561 | # [ Str ] below and rejected the very hashrefs/arrayrefs the schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1562 | # describes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1563 | 16 | ▶ | return [ {} ] if $item_type eq 'object'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1564 | 13 | ▶ | return [ [] ] if $item_type eq 'array'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1565 | 11 | return [ Str ]; # string, and the default for anything unmodelled | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1566 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1567 | elsif ($type eq 'object') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1568 | 312 | ▶ | if (_has_properties($schema)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1569 | 229 | ▶ | if ($may_reuse->(undef) and my $core = _core_class_for($schema, $all_defs)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
&$may_reuse(undef) and my $core = _core_class_for($schema, $all_defs)
MC/DC100%2/2
&$may_reuse(undef) and my $core = _core_class_for($schema, $all_defs)
&$may_reuse(undef)
my $core = _core_class_for($schema, $all_defs)
Truth table100%3/3
A and B
A= &$may_reuse(undef)B= my $core = _core_class_for($schema, $all_defs)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1570 | 19 | return "+$core"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1571 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1572 | 210 | return '+' . _nested_class($class, $field_name, undef, $schema, $all_defs, $namespace, $reuse_core, $reuse_core_except); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1573 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1574 | 83 | my $addl = $schema->{additionalProperties}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1575 | 83 | ▶ | if (ref $addl eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1576 | 32 | ▶ | if (my $ref = $addl->{'$ref'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1577 | 19 | $ref =~ s{^#/definitions/}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1578 | # The DSL's typed map of the scalar (k178), as for items | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1579 | # above: { Quantity => 1 } is what a ResourceList is. It is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1580 | # the DSL's one typed map, so its values are checked against | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1581 | # the library types -- for Quantity and Time the strict | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1582 | # form a hand-written map carries. A $ref only comes from a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1583 | # swagger definition (a CRD schema has none), and the API | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1584 | # server writes both of those scalars in canonical form. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1585 | 19 | ▶ | if (my $scalar = _scalar_ref_type($ref)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1586 | 8 | return { $scalar => 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1587 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1588 | 11 | ▶ | if (my $union = _union_class($ref)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1589 | 10 | return { "+$union" => 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1590 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1591 | 1 | ▶ | if ($all_defs && $all_defs->{$ref}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$all_defs and $all_defs->{$ref}
MC/DC0%0/2
$all_defs and $all_defs->{$ref}
$all_defs
$all_defs->{$ref}
Truth table33%1/3
A and B
A= $all_defsB= $all_defs->{$ref}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1592 | 0 | my $ref_class = get_or_generate($ref, $all_defs->{$ref}, $all_defs, $namespace); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1593 | 0 | return { "+$ref_class" => 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1594 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1595 | 1 | _croak_unresolved_ref($ref, "the additionalProperties of $where"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1596 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1597 | 13 | ▶ | if ($may_reuse->('Value') and my $core = _core_class_for($addl, $all_defs)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
&$may_reuse("Value") and my $core = _core_class_for($addl, $all_defs)
MC/DC0%0/2
&$may_reuse("Value") and my $core = _core_class_for($addl, $all_defs)
&$may_reuse("Value")
my $core = _core_class_for($addl, $all_defs)
Truth table66%2/3
A and B
A= &$may_reuse("Value")B= my $core = _core_class_for($addl, $all_defs)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1598 | 0 | return { "+$core" => 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1599 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1600 | 13 | ▶ | if (_has_properties($addl)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1601 | 1 | return { '+' . _nested_class($class, $field_name, 'Value', $addl, $all_defs, $namespace, $reuse_core, $reuse_core_except) => 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1602 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1603 | # A map of lists (k194): additionalProperties an array of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1604 | # strings -- HashRef[ArrayRef[Str]] -- or of objects, a $ref'd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1605 | # definition or an items schema with properties -- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1606 | # HashRef[ArrayRef[InstanceOf[Class]]]. Any other array value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1607 | # stays the free map. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1608 | 12 | ▶ | if (($addl->{type} // '') eq 'array' && ref($addl->{items} // {}) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition71%5/7
($addl->{"type"} // "") eq "array" and ref($addl->{"items"} // {}) eq "HASH"
$addl->{"type"} // ""
$addl->{"items"} // {}
MC/DC50%1/2
($addl->{"type"} // "") eq "array" and ref($addl->{"items"} // {}) eq "HASH"
$addl->{"type"}
$addl->{"items"}
Truth table66%2/3
A and B
A= $addl->{"type"}B= $addl->{"items"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1609 | 1 | ▶ | my $items = $addl->{items} // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$addl->{"items"} // {}
MC/DC0%0/1
$addl->{"items"} // {}
$addl->{"items"}
Truth table50%1/2
A
A= $addl->{"items"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1610 | 1 | my $item_kind = _array_map_item_kind($items); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1611 | 1 | ▶ | return HashRef[ ArrayRef[Str] ] if $item_kind eq 'Str'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1612 | 0 | ▶ | if ($item_kind eq 'ref') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1613 | 0 | (my $ref = $items->{'$ref'}) =~ s{^#/definitions/}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1614 | 0 | ▶ | if (my $union = _union_class($ref)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1615 | 0 | return HashRef[ ArrayRef[ InstanceOf[$union] ] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1616 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1617 | 0 | ▶ | if ($all_defs && $all_defs->{$ref}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$all_defs and $all_defs->{$ref}
MC/DC0%0/2
$all_defs and $all_defs->{$ref}
$all_defs
$all_defs->{$ref}
Truth table0%0/3
A and B
A= $all_defsB= $all_defs->{$ref}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1618 | 0 | my $ref_class = get_or_generate($ref, $all_defs->{$ref}, $all_defs, $namespace); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1619 | 0 | return HashRef[ ArrayRef[ InstanceOf[$ref_class] ] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1620 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1621 | 0 | _croak_unresolved_ref($ref, "the items of the additionalProperties of $where"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1622 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1623 | 0 | ▶ | if ($item_kind eq 'props') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1624 | 0 | ▶ | my $core = $may_reuse->('Item') ? _core_class_for($items, $all_defs) : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1625 | 0 | ▶ | my $item_class = $core // _nested_class($class, $field_name, 'Item', $items, $all_defs, $namespace, $reuse_core, $reuse_core_except); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$core // _nested_class($class, $field_name, "Item", $items, $all_defs, $namespace, $reuse_core, $reuse_core_except)
MC/DC0%0/2
$core // _nested_class($class, $field_name, "Item", $items, $all_defs, $namespace, $reuse_core, $reuse_core_except)
$core
_nested_class($class, $field_name, "Item", $items, $all_defs, $namespace, $reuse_core, $reuse_core_except)
Truth table0%0/3
A // B
A= $coreB= _nested_class($class, $field_name, "Item", $items, $all_defs, $namespace, $reuse_core, $reuse_core_except)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1626 | 0 | return HashRef[ ArrayRef[ InstanceOf[$item_class] ] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1627 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1628 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1629 | # A scalar value schema is the string map HashRef[Str] or the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1630 | # typed map of its kind; anything else -- object or array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1631 | # values, a value schema without a type -- the free map (k191). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1632 | # Before k191 every one of them became the then-opaque | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1633 | # { Str => 1 }. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1634 | 11 | my $value_kind = _map_value_kind($addl); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1635 | 11 | ▶ | return $value_kind ? HashRef[ $GENERATED_MAP_VALUE_TYPE{$value_kind} ] : Opaque; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1636 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1637 | # additionalProperties is allowed to be a JSON boolean instead of a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1638 | # schema -- true: any extra property, false: none. A JSON::PP::Boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1639 | # is a blessed scalar ref, so the $ref lookup above used to die "Not a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1640 | # HASH reference" naming neither class nor field (k55). Neither | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1641 | # boolean says anything about the value types, so the field stays the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1642 | # same free map (Opaque) a schemaless object gets. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1643 | 51 | ▶ | if (defined $addl) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1644 | 4 | my $reftype = reftype($addl); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1645 | 4 | ▶ | croak "additionalProperties of $where is a " . $reftype | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $reftype and $reftype ne "SCALAR"
MC/DC50%1/2
defined $reftype and $reftype ne "SCALAR"
defined $reftype
$reftype ne "SCALAR"
Truth table66%2/3
A and B
A= defined $reftypeB= $reftype ne "SCALAR"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1646 | . " reference; expected a schema object or a boolean" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1647 | if defined $reftype && $reftype ne 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1648 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1649 | 49 | return Opaque; # Generic object -> the free map (k191) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1650 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1651 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1652 | # Unknown type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1653 | 0 | return 'Str'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1654 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1655 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1656 | # The scalar type a DSL type spec is built on -- Str, Int, Num, Bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1657 | # IntOrStr, Quantity, Time -- or undef for objects, structs and the opaque | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1658 | # container forms. Value constraints (enum, minimum, maximum, pattern) only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1659 | # make sense on the former; passing one to the DSL for the latter would | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1660 | # croak at class generation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1661 | 151 | my %SCALAR_KIND = map { $_ => 1 } qw( Str Int Num Bool IntOrStr Quantity Time ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1662 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1663 | 785 | ▶ | sub _scalar_kind { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_scalar_kind: called CC=17 SCAR=28.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1664 | 785 | my ($type_spec) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1665 | 785 | ▶ | if (!ref $type_spec) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1666 | 627 | ▶ | return $SCALAR_KIND{$type_spec} ? $type_spec : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1667 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1668 | 158 | ▶ | if (ref $type_spec eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1669 | 78 | my $elem = $type_spec->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1670 | 78 | ▶ | return undef if ref $elem eq 'HASH' || ref $elem eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $elem eq "HASH" or ref $elem eq "ARRAY"
MC/DC100%2/2
ref $elem eq "HASH" or ref $elem eq "ARRAY"
ref $elem eq "HASH"
ref $elem eq "ARRAY"
Truth table100%3/3
A or B
A= ref $elem eq "HASH"B= ref $elem eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1671 | # Mirror _k8s's own array-element handling exactly (Important 4 of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1672 | # the k93 review): a Type::Tiny element is a scalar kind only when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1673 | # its name is one of the seven the DSL knows, and a bareword | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1674 | # string element is a scalar kind only for 'Str' and 'Int' -- _k8s | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1675 | # treats every other bareword (including the kind names 'Num', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1676 | # 'Bool', 'Quantity', 'Time', 'IntOrStr' spelled as plain strings) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1677 | # as a class name and hands it to _expand_class. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1678 | 73 | ▶ | if (blessed($elem) && $elem->isa('Type::Tiny')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($elem) and $elem->isa("Type::Tiny")
MC/DC50%1/2
builtin::blessed($elem) and $elem->isa("Type::Tiny")
builtin::blessed($elem)
$elem->isa("Type::Tiny")
Truth table66%2/3
A and B
A= builtin::blessed($elem)B= $elem->isa("Type::Tiny")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1679 | 43 | ▶ | return $SCALAR_KIND{$elem->name} ? $elem->name : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1680 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1681 | 30 | ▶ | return undef if ref $elem; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1682 | 30 | ▶ | return ($elem eq 'Str' || $elem eq 'Int') ? $elem : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$elem eq "Str" or $elem eq "Int"
MC/DC0%0/2
$elem eq "Str" or $elem eq "Int"
$elem eq "Str"
$elem eq "Int"
Truth table33%1/3
A or B
A= $elem eq "Str"B= $elem eq "Int"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1683 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1684 | 80 | ▶ | if (ref $type_spec eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1685 | 19 | my ($k) = keys %$type_spec; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1686 | # { Str => 1 } is the lenient string map, which takes no value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1687 | # option (IO::K8s::Resource); typed maps carry their value kind. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1688 | 19 | ▶ | return undef if $k eq 'Str'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1689 | 19 | ▶ | return $SCALAR_KIND{$k} ? $k : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1690 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1691 | # HashRef[X] (k191): the value type's kind, Str included -- the strict | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1692 | # string map takes value options; Opaque none. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1693 | 61 | ▶ | if (my $value_type = _map_value_type($type_spec)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1694 | 12 | ▶ | return $SCALAR_KIND{ $value_type->name } ? $value_type->name : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1695 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1696 | 49 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1697 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1698 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1699 | # The value type of a HashRef[X] type spec, or undef for anything else. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1700 | 478 | ▶ | sub _map_value_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_map_value_type: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1701 | 478 | my ($type_spec) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1702 | 478 | ▶ | return undef unless blessed($type_spec) && $type_spec->isa('Type::Tiny') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
builtin::blessed($type_spec) and $type_spec->isa("Type::Tiny") and $type_spec->is_parameterized and $type_spec->parameterized_from->name eq "HashRef"
builtin::blessed($type_spec) and $type_spec->isa("Type::Tiny") and $type_spec->is_parameterized
builtin::blessed($type_spec) and $type_spec->isa("Type::Tiny")
MC/DC50%2/4
builtin::blessed($type_spec) and $type_spec->isa("Type::Tiny") and $type_spec->is_parameterized and $type_spec->parameterized_from->name eq "HashRef"
builtin::blessed($type_spec)
$type_spec->isa("Type::Tiny")
$type_spec->is_parameterized
$type_spec->parameterized_from->name eq "HashRef"
Truth table60%3/5
A and B and C and D
A= builtin::blessed($type_spec)B= $type_spec->isa("Type::Tiny")C= $type_spec->is_parameterizedD= $type_spec->parameterized_from->name eq "HashRef"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1703 | && $type_spec->is_parameterized | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1704 | && $type_spec->parameterized_from->name eq 'HashRef'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1705 | 23 | return $type_spec->type_parameter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1706 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1707 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1708 | # A typed map of either spelling: { X => 1 } or HashRef[X]. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1709 | 399 | ▶ | sub _is_map_spec { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_map_spec: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1710 | 399 | my ($type_spec) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1711 | 399 | ▶ | return ref $type_spec eq 'HASH' || _map_value_type($type_spec) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $type_spec eq "HASH" or _map_value_type($type_spec)
MC/DC100%2/2
ref $type_spec eq "HASH" or _map_value_type($type_spec)
ref $type_spec eq "HASH"
_map_value_type($type_spec)
Truth table100%3/3
A or B
A= ref $type_spec eq "HASH"B= _map_value_type($type_spec)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1712 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1713 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1714 | # Field options for one property (D3). Schema-only facts (description, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1715 | # default, nullable, x-kubernetes-preserve-unknown-fields) travel for every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1716 | # field; the value constraints only where the DSL can enforce them. For an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1717 | # array the constraints sit on `items` and apply per element. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1718 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1719 | # required => 'schema' (not 1): the schema's required list is a fact for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1720 | # to_crd, not a client-side guarantee. A cluster document can validly omit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1721 | # a field the schema requires -- a server-side default, or an object still | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1722 | # short of that field (an empty status right after creation) -- and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1723 | # rejecting inflate over that would reject real cluster data. required => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1724 | # 1 would enforce it at construction; see IO::K8s::Resource/k8s (Critical | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1725 | # 1 of the k93 review). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1726 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1727 | # A pattern is an ECMA 262 regex on the wire. Perl compiles nearly all of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1728 | # them; one it cannot is dropped rather than failing the whole class -- the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1729 | # client-side check is a convenience, the API server validates regardless, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1730 | # and no data is lost (the k56 line is about data, not about checks). An | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1731 | # empty enum, a duplicate enum, or an enum containing a JSON null is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1732 | # dropped the same way; minimum/maximum are dropped (individually, if only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1733 | # one bound is bad, or both together when minimum exceeds maximum) when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1734 | # either fails to parse as a number; and a default the field cannot hold -- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1735 | # wrong type, or outside its own enum/range -- is dropped rather than | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1736 | # refused at generation time the way a hand-written k8s declaration would | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1737 | # refuse it (Important 2 of the k93 review). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1738 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1739 | # `default: null` in a schema (common on a `nullable: true` field) decodes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1740 | # to undef; that is treated as no default at all, not as a default of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1741 | # undef, since the DSL's own field-option check refuses an undef value for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1742 | # any option, and a null default carries no information for the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1743 | # client-side check anyway. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1744 | 785 | ▶ | sub _field_options { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_field_options: called CC=57 SCAR=42.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1745 | 785 | my ($prop_schema, $type_spec, $is_required) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1746 | 785 | my %opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1747 | 785 | ▶ | $opts{required} = 'schema' if $is_required; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1748 | 785 | ▶ | $opts{description} = $prop_schema->{description} if defined $prop_schema->{description}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1749 | 785 | ▶ | $opts{default} = $prop_schema->{default} if defined $prop_schema->{default}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1750 | # nullable and x-kubernetes-preserve-unknown-fields are JSON booleans on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1751 | # the wire and so need the same normalization every other Bool value in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1752 | # the distribution gets (plain Perl truthiness would treat the string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1753 | # 'false' as true). _normalize_bool only dies on a value that cannot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1754 | # mean true or false at all (a non-scalar reference); a schema property | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1755 | # is always a plain scalar or JSON boolean here, so there is nothing for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1756 | # an eval to usefully swallow (Minor 6 of the k93 review). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1757 | $opts{nullable} = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1758 | 785 | ▶ | if IO::K8s::Resource::_normalize_bool($prop_schema->{nullable}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1759 | $opts{preserve_unknown} = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1760 | 785 | ▶ | if IO::K8s::Resource::_normalize_bool($prop_schema->{'x-kubernetes-preserve-unknown-fields'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1761 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1762 | 785 | my $kind = _scalar_kind($type_spec); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1763 | # A schema decoded from JSON carries a boolean default as a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1764 | # JSON::PP::Boolean (or similar) blessed scalar ref, which fails the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1765 | # field's own Bool constraint at class-generation time (_k8s's own | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1766 | # default-vs-type check). Normalize it the one way the distribution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1767 | # normalizes every other Bool value rather than duplicating that rule | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1768 | # here (IO::K8s::Resource::_normalize_bool's own comment: "The one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1769 | # boolean normalization in the distribution"). $kind is 'Bool' for both | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1770 | # the scalar Bool field and the [Bool] array field (_scalar_kind reads | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1771 | # through the array wrapper), but the default's own shape differs: a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1772 | # [Bool] default is itself an arrayref of JSON booleans, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1773 | # _normalize_bool only accepts a scalar or scalar ref -- handing it the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1774 | # arrayref whole would die and kill class generation over an entirely | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1775 | # legal default. Normalize per element instead, and drop the default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1776 | # (rather than refuse generation) if any element cannot mean true/false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1777 | # the same "malformed default is dropped" rule every other option here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1778 | # follows (carried over from the step-2 final re-review). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1779 | 785 | ▶ | if ($kind && $kind eq 'Bool' && exists $opts{default}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$kind and $kind eq "Bool" and exists $opts{"default"}
$kind and $kind eq "Bool"
MC/DC100%3/3
$kind and $kind eq "Bool" and exists $opts{"default"}
$kind
$kind eq "Bool"
exists $opts{"default"}
Truth table100%4/4
A and B and C
A= $kindB= $kind eq "Bool"C= exists $opts{"default"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1780 | 4 | ▶ | if (_is_map_spec($type_spec)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1781 | # A map of Bool (k191): the default is a hash, normalized value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1782 | # by value and dropped when a value cannot mean true/false, as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1783 | # the array case below does per element. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1784 | 0 | my %normalized; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1785 | 0 | ▶ | if (ref $opts{default} eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1786 | 0 | for my $key (keys %{ $opts{default} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1787 | 0 | my $n = eval { IO::K8s::Resource::_normalize_bool($opts{default}{$key}) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1788 | 0 | ▶ | last if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1789 | 0 | $normalized{$key} = $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1790 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1791 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1792 | 0 | ▶ | if (ref $opts{default} eq 'HASH' && keys %normalized == keys %{ $opts{default} }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $opts{"default"} eq "HASH" and keys %normalized == keys %{$opts{"default"};}
MC/DC0%0/2
ref $opts{"default"} eq "HASH" and keys %normalized == keys %{$opts{"default"};}
ref $opts{"default"} eq "HASH"
keys %normalized == keys %{$opts{"default"};}
Truth table0%0/3
A and B
A= ref $opts{"default"} eq "HASH"B= keys %normalized == keys %{$opts{"default"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1793 | 0 | $opts{default} = \%normalized; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1794 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1795 | 0 | delete $opts{default}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1796 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1797 | } elsif (ref $type_spec eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1798 | 2 | my @normalized; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1799 | 2 | ▶ | if (ref $opts{default} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1800 | 2 | for my $elem (@{ $opts{default} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1801 | 4 | my $n = eval { IO::K8s::Resource::_normalize_bool($elem) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1802 | 4 | ▶ | last if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1803 | 3 | push @normalized, $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1804 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1805 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1806 | 2 | ▶ | if (ref $opts{default} eq 'ARRAY' && @normalized == @{ $opts{default} }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $opts{"default"} eq "ARRAY" and @normalized == @{$opts{"default"};}
MC/DC50%1/2
ref $opts{"default"} eq "ARRAY" and @normalized == @{$opts{"default"};}
ref $opts{"default"} eq "ARRAY"
@normalized == @{$opts{"default"};}
Truth table66%2/3
A and B
A= ref $opts{"default"} eq "ARRAY"B= @normalized == @{$opts{"default"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1807 | 1 | $opts{default} = \@normalized; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1808 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1809 | 1 | delete $opts{default}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1810 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1811 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1812 | 2 | $opts{default} = IO::K8s::Resource::_normalize_bool($opts{default}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1813 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1814 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1815 | 785 | ▶ | if ($kind && $kind ne 'Bool') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$kind and $kind ne "Bool"
MC/DC100%2/2
$kind and $kind ne "Bool"
$kind
$kind ne "Bool"
Truth table100%3/3
A and B
A= $kindB= $kind ne "Bool"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1816 | # A typed map (k178) constrains each value, as an array each | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1817 | # element: its constraints sit on additionalProperties. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1818 | my $src = ($prop_schema->{type} // '') eq 'array' ? ($prop_schema->{items} // {}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1819 | : _is_map_spec($type_spec) ? $prop_schema->{additionalProperties} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1820 | 406 | ▶ | : $prop_schema; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition75%3/4
$prop_schema->{"type"} // ""
$prop_schema->{"items"} // {}
MC/DC100%1/1
$prop_schema->{"type"} // ""
$prop_schema->{"type"}
MC/DC0%0/1
$prop_schema->{"items"} // {}
$prop_schema->{"items"}
Truth table100%2/2
A
A= $prop_schema->{"type"}
Truth table50%1/2
A
A= $prop_schema->{"items"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1821 | 406 | ▶ | if (ref $src->{enum} eq 'ARRAY' && @{ $src->{enum} } && !grep { !defined } @{ $src->{enum} }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
ref $src->{"enum"} eq "ARRAY" and @{$src->{"enum"};} and not grep({not defined $_;} @{$$src{"enum"};})
ref $src->{"enum"} eq "ARRAY" and @{$src->{"enum"};}
MC/DC66%2/3
ref $src->{"enum"} eq "ARRAY" and @{$src->{"enum"};} and not grep({not defined $_;} @{$$src{"enum"};})
ref $src->{"enum"} eq "ARRAY"
@{$src->{"enum"};}
not grep({not defined $_;} @{$$src{"enum"};})
Truth table75%3/4
A and B and not(C)
A= ref $src->{"enum"} eq "ARRAY"B= @{$src->{"enum"};}C= not grep({not defined $_;} @{$$src{"enum"};})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1822 | 24 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1823 | 24 | $seen{$_}++ for @{ $src->{enum} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1824 | 24 | ▶ | $opts{enum} = $src->{enum} if keys %seen == @{ $src->{enum} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1825 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1826 | 406 | ▶ | if ($kind eq 'Int' || $kind eq 'Num') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$kind eq "Int" or $kind eq "Num"
MC/DC100%2/2
$kind eq "Int" or $kind eq "Num"
$kind eq "Int"
$kind eq "Num"
Truth table100%3/3
A or B
A= $kind eq "Int"B= $kind eq "Num"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1827 | 98 | my ($min, $max) = @{$src}{qw(minimum maximum)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1828 | 98 | ▶ | $min = undef if defined $min && !looks_like_number($min); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $min and not &looks_like_number($min)
MC/DC100%2/2
defined $min and not &looks_like_number($min)
defined $min
not &looks_like_number($min)
Truth table100%3/3
A and not(B)
A= defined $minB= not &looks_like_number($min)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1829 | 98 | ▶ | $max = undef if defined $max && !looks_like_number($max); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $max and not &looks_like_number($max)
MC/DC0%0/2
defined $max and not &looks_like_number($max)
defined $max
not &looks_like_number($max)
Truth table66%2/3
A and not(B)
A= defined $maxB= not &looks_like_number($max)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1830 | 98 | ▶ | if (defined $min && defined $max && $min > $max) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $min and defined $max and $min > $max
defined $min and defined $max
MC/DC100%3/3
defined $min and defined $max and $min > $max
defined $min
defined $max
$min > $max
Truth table100%4/4
A and B and C
A= defined $minB= defined $maxC= $min > $max
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1831 | 2 | $min = $max = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1832 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1833 | 98 | ▶ | $opts{minimum} = $min if defined $min; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1834 | 98 | ▶ | $opts{maximum} = $max if defined $max; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1835 | } elsif (defined $src->{pattern}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1836 | 34 | my $re = eval { my $p = $src->{pattern}; qr/$p/ }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1837 | 34 | ▶ | $opts{pattern} = $re if $re; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1838 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1839 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1840 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1841 | # A default the field cannot hold kills class generation via _k8s's own | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1842 | # default-vs-type check unless it is dropped here first. Built from the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1843 | # same (already-filtered) enum/minimum/maximum/pattern collected above | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1844 | # so the check matches what _k8s itself would enforce. Object-bearing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1845 | # and opaque fields ($kind undef) keep the default as given -- there is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1846 | # no scalar Type::Tiny check to run there, and to_crd validates it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1847 | # against the schema instead (Important 3 of the k93 review; _k8s's own | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1848 | # default check now skips those fields too). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1849 | 785 | ▶ | if (exists $opts{default} && $kind) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $opts{"default"} and $kind
MC/DC50%1/2
exists $opts{"default"} and $kind
exists $opts{"default"}
$kind
Truth table66%2/3
A and B
A= exists $opts{"default"}B= $kind
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1850 | # An array's element type is the Type::Tiny object in the spec (k167); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1851 | # a typed map's value type is the library type of that name, the one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1852 | # IO::K8s::Resource's { X => 1 } form checks each value against -- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1853 | # the strict Quantity and Time among them (k178). A default that is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1854 | # a hash, for a map, is checked value by value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1855 | 35 | ▶ | my $base = ref $type_spec eq 'ARRAY' && blessed($type_spec->[0]) ? $type_spec->[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
ref $type_spec eq "ARRAY" and builtin::blessed($type_spec->[0])
MC/DC50%1/2
ref $type_spec eq "ARRAY" and builtin::blessed($type_spec->[0])
ref $type_spec eq "ARRAY"
builtin::blessed($type_spec->[0])
Truth table66%2/3
A and B
A= ref $type_spec eq "ARRAY"B= builtin::blessed($type_spec->[0])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1856 | : _map_value_type($type_spec) ? _map_value_type($type_spec) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1857 | : ref $type_spec eq 'HASH' ? IO::K8s::Types->get_type($kind) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1858 | : IO::K8s::Resource::_scalar_base_for($kind); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1859 | 35 | my %check_opts = map { $_ => $opts{$_} } grep { exists $opts{$_} } qw(enum minimum maximum pattern); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1860 | 35 | my $constrained = IO::K8s::Resource::_constrain($base, $kind, \%check_opts, 'AutoGen default check'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1861 | my $default_ok = ref $type_spec eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1862 | 8 | ▶ | ? (ref $opts{default} eq 'ARRAY' && !grep { !$constrained->check($_) } @{ $opts{default} }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $opts{"default"} eq "HASH" and not grep({not $constrained->check($_);} values %{$opts{"default"};})
MC/DC100%2/2
ref $opts{"default"} eq "HASH" and not grep({not $constrained->check($_);} values %{$opts{"default"};})
ref $opts{"default"} eq "HASH"
not grep({not $constrained->check($_);} values %{$opts{"default"};})
Truth table100%3/3
A and not(B)
A= ref $opts{"default"} eq "HASH"B= not grep({not $constrained->check($_);} values %{$opts{"default"};})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1863 | : _is_map_spec($type_spec) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1864 | 3 | ? (ref $opts{default} eq 'HASH' && !grep { !$constrained->check($_) } values %{ $opts{default} }) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1865 | 35 | ▶ | : $constrained->check($opts{default}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $opts{"default"} eq "ARRAY" and not grep({not $constrained->check($_);} @{$opts{"default"};})
MC/DC50%1/2
ref $opts{"default"} eq "ARRAY" and not grep({not $constrained->check($_);} @{$opts{"default"};})
ref $opts{"default"} eq "ARRAY"
not grep({not $constrained->check($_);} @{$opts{"default"};})
Truth table66%2/3
A and not(B)
A= ref $opts{"default"} eq "ARRAY"B= not grep({not $constrained->check($_);} @{$opts{"default"};})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1866 | 35 | ▶ | delete $opts{default} unless $default_ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1867 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1868 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1869 | 785 | ▶ | return %opts ? \%opts : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1870 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1871 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1872 | # Ensure parent packages exist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1873 | 426 | ▶ | sub _ensure_package_exists { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ensure_package_exists: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1874 | 426 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1875 | 426 | my @parts = split /::/, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1876 | 426 | pop @parts; # Remove the final class name | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1877 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1878 | 426 | my $current = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1879 | 426 | for my $part (@parts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1880 | 3363 | ▶ | $current .= '::' if $current; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1881 | 3363 | $current .= $part; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1882 | 151 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1883 | 3363 | ▶ | unless (%{"${current}::"}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1884 | # Create empty package | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1885 | 763 | ▶ | eval "package $current; 1;" or warn "Could not create package $current: $@"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1886 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1887 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1888 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1889 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1890 | # Clear generated class cache (mainly for testing). %_failed is left alone on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1891 | # purpose: forgetting a failure would let the next request return the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1892 | # half-built package that failed run left behind (k149). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1893 | 32 | ▶ | sub clear_cache { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_cache: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1894 | 32 | %_generated = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1895 | 32 | %_nested_origin = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1896 | 32 | %_descriptions = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1897 | 32 | %_root_of = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1898 | 32 | %_class_path = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1899 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1900 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1901 | # The schema `description` a generated class was built from, or undef when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1902 | # the schema had none. See IO::K8s::CRD::Emitter, the only consumer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1903 | 114 | ▶ | sub class_description { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class_description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1904 | 114 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1905 | 114 | return $_descriptions{$class}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1906 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1907 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1908 | # The top-level generated class (the Kind class) a nested class's naming | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1909 | # started from, or $class itself when it already is one -- a root is never | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1910 | # recorded in %_root_of, so this always falls back correctly. See | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1911 | # IO::K8s::CRD::Emitter, which needs the true root to decide whether a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1912 | # reachable class belongs to the tree it is currently rendering. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1913 | 342 | ▶ | sub class_root { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class_root: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1914 | 342 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1915 | 342 | ▶ | return $_root_of{$class} // $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_root_of{$class} // $class
MC/DC0%0/2
$_root_of{$class} // $class
$_root_of{$class}
$class
Truth table66%2/3
A // B
A= $_root_of{$class}B= $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1916 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1917 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1918 | # The '::'-joined path a nested class sits at below its root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1919 | # ('Spec::Acme::SolversItem::...'), recorded even when the class's own Perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1920 | # name had to be shortened (see $MAX_CLASS_NAME). undef for a root class, or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1921 | # for any class AutoGen did not generate through _nested_class. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1922 | 418 | ▶ | sub class_path { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class_path: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1923 | 418 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1924 | 418 | return $_class_path{$class}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1925 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1926 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1927 | # List all generated classes -- complete ones only; a class begun by a run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1928 | # that failed is never listed (k149) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1929 | 5 | ▶ | sub generated_classes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generated_classes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1930 | 5 | return keys %_generated; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1931 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1932 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1933 | 151 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1934 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1935 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||