File Coverage

blib/lib/IO/K8s/APIObject.pm
Criterion Covered Total %
statement 32 32 100.0
branch 6 6 100.0
condition n/a
subroutine 8 8 100.0
pod n/a
total 46 46 100.0


line stmt bran cond sub pod time code
1             package IO::K8s::APIObject;
2             # ABSTRACT: Base class for top-level Kubernetes API objects
3             our $VERSION = '1.009';
4 26     26   6250 use v5.10;
  26         125  
5 26     26   11834 use IO::K8s::Resource ();
  26         99  
  26         940  
6 26     26   183 use Import::Into;
  26         87  
  26         753  
7 26     26   169 use Package::Stash;
  26         47  
  26         529  
8 26     26   101 use Moo::Role ();
  26         62  
  26         5607  
9              
10              
11             sub import {
12 318     318   1171 my $class = shift;
13 318         1387 my %params = @_;
14 318         1590 my $caller = caller;
15              
16             # First, do everything IO::K8s::Resource does
17 318         7007 IO::K8s::Resource->import::into($caller);
18              
19             # Install CRD overrides *before* applying the role
20             # This way the role sees these methods and doesn't install its defaults
21 318         5354 my $is_crd = 0;
22 318 100       2187 if (my $api_ver = $params{api_version}) {
23 114         933 my $stash = Package::Stash->new($caller);
24 114     386   1347 $stash->add_symbol('&api_version', sub { $api_ver });
  386         80265  
25 114         432 $is_crd = 1;
26             }
27 318 100       1440 if (my $plural = $params{resource_plural}) {
28 114         708 my $stash = Package::Stash->new($caller);
29 114     48   1087 $stash->add_symbol('&resource_plural', sub { $plural });
  48         325  
30             }
31              
32             # Apply the APIObject role (provides metadata, labels, conditions, owners)
33 318         1853 Moo::Role->apply_roles_to_package($caller, 'IO::K8s::Role::APIObject');
34              
35             # CRDs get SpecBuilder automatically (deep-path spec manipulation)
36 318 100       976320 if ($is_crd) {
37 114         596 Moo::Role->apply_roles_to_package($caller, 'IO::K8s::Role::SpecBuilder');
38             }
39              
40             # Register metadata attribute using the k8s DSL
41             # This allows _inflate_struct to properly inflate metadata as ObjectMeta
42             # The k8s function skips attribute creation if it already exists (from the role)
43 318         382490 $caller->can('k8s')->('metadata', 'Meta::V1::ObjectMeta');
44             }
45              
46             1;
47              
48             __END__