blib/lib/Kubernetes/Comb/CRD/Comb.pm

filter: Statementstmt 100% 37 / 37 Branchbran 100% 10 / 10 Conditioncond 83.3% 5 / 6 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 96.7% 59 / 61 CC 10 SCAR 20.1
CC
10
Cov
98%
__ANON__
10.0
BEGIN
1.0
BEGIN
1.0
CRAP 7.4
« blib/lib/Kubernetes/Comb.pm ↑ Summary blib/lib/Kubernetes/Comb/CRD/CombSpec.pm »
1 package Kubernetes::Comb::CRD::Comb;
2 # ABSTRACT: The Comb custom resource
3 27 our $VERSION = '0.001';
4  
5 use IO::K8s::APIObject
6 27 ▶ api_version => 'comb.internal/v1',
Subroutine BEGIN: called CC=1 SCAR=0.0
7 27 resource_plural => 'combs';
8 27 with 'IO::K8s::Role::Namespaced';
9  
10 27 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 27 ▶use Kubernetes::Comb::CRD::CombSpec;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 27 ▶use Kubernetes::Comb::CRD::CombStatus;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 27 k8s spec => '+Kubernetes::Comb::CRD::CombSpec';
16  
17  
18 27 k8s status => '+Kubernetes::Comb::CRD::CombStatus';
19  
20  
21 6 ▶around to_crd => sub {
Subroutine __ANON__: called CC=10 SCAR=23.0
22 6 my ( $orig, $self, %args ) = @_;
23 6 my @unknown = sort grep { !/\A(?:group|kind|plural)\z/ } keys %args;
24 6 ▶ croak __PACKAGE__.'->to_crd: unknown argument(s) '.join( ', ', @unknown )
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 1 5 6
25 .' (known: group, kind, plural)' if @unknown;
26 5 for my $arg (qw( group kind plural )) {
27 croak __PACKAGE__.'->to_crd: '.$arg.' must be a non-empty string'
28 13 ▶ if exists $args{$arg} && !( defined $args{$arg} && length $args{$arg} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$arg} and not defined $args{$arg} && length $args{$arg} 1 12 13
Condition83%5/6
exists $args{$arg} and not defined $args{$arg} && length $args{$arg}
!ll&&!rl&&r
931
defined $args{$arg} && length $args{$arg}
!ll&&!rl&&r
013
MC/DC66%2/3
exists $args{$arg} and not defined $args{$arg} && length $args{$arg}
exists $args{$arg} defined $args{$arg} length $args{$arg}
Truth table75%3/4
A and not(B && C)
A= exists $args{$arg}B= defined $args{$arg}C= length $args{$arg}
ABCresult
0XX0
1110
10X1
1101
29 }
30  
31 4 my $crd = $self->$orig;
32 4 my $spec = $crd->spec;
33 4 my $names = $spec->names;
34 4 ▶ $spec->group( $args{group} ) if exists $args{group};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"group"} 1 3 4
35 4 ▶ if ( exists $args{kind} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"kind"}) 1 3 4
36 1 $names->kind( $args{kind} );
37 1 $names->singular( lc $args{kind} );
38 1 $names->listKind( $args{kind}.'List' );
39 }
40 4 ▶ $names->plural( $args{plural} ) if exists $args{plural};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"plural"} 1 3 4
41 4 $crd->metadata->name( $names->plural.'.'.$spec->group );
42 4 $_->subresources({ status => {} }) for @{ $spec->versions };
43 4 return $crd;
44 27 };
45  
46  
47 27 1;
48  
49 __END__
50  
51 =pod
52  
53 =encoding UTF-8
54  
55 =head1 NAME
56  
57 Kubernetes::Comb::CRD::Comb - The Comb custom resource
58  
59 =head1 VERSION
60  
61 version 0.001
62  
63 =head1 SYNOPSIS
64  
65 use Kubernetes::Comb::CRD::Comb;
66  
67 my $cr = Kubernetes::Comb::CRD::Comb->new(
68 metadata => { name => 'nats', namespace => 'platform' },
69 spec => { class => 'MyApp::Comb::NATS', dependsOn => [ 'db' ] }
70 );
71 print $cr->to_yaml;
72  
73 # the CustomResourceDefinition, as an IO::K8s object
74 my $crd = Kubernetes::Comb::CRD::Comb->to_crd;
75 $rest->ensure_crd('Kubernetes::Comb::CRD::Comb'); # Kubernetes::REST
76  
77 # another API group: a three-line subclass, passed as crd_class
78 package MyApp::CRD::Comb;
79 use Moo; extends 'Kubernetes::Comb::CRD::Comb';
80 sub api_version { 'comb.example.com/v1' }
81  
82 =head1 DESCRIPTION
83  
84 The C<Comb> custom resource: default group C<comb.internal/v1> (C<.internal>
85 is reserved for private use and never collides with a real domain), kind
86 C<Comb>, plural C<combs>, namespaced, with the status subresource. Whoever
87 manages Combs watches these and builds a live Comb instance from each; the
88 instance writes its own status back.
89  
90 L<IO::K8s> fixes C<api_version> when the class is loaded, so another API group
91 is a subclass, not a runtime switch: the subclass overrides C<api_version>,
92 and everything else -- C<kind> and C<resource_plural>, the schema, L</to_crd>
93 -- follows it. Keep C<Comb> as the last segment of the subclass's package
94 name: IO::K8s derives C<kind> from it. Pass the subclass wherever a
95 C<crd_class> is taken, for example to L<Kubernetes::Comb::CRD> and to the
96 Comb itself.
97  
98 =head2 spec
99  
100 L<Kubernetes::Comb::CRD::CombSpec>; a hashref is inflated.
101  
102 =head2 status
103  
104 L<Kubernetes::Comb::CRD::CombStatus>; a hashref is inflated. Written through
105 the status subresource only.
106  
107 =head2 to_crd
108  
109 my $crd = Kubernetes::Comb::CRD::Comb->to_crd;
110 my $crd = Kubernetes::Comb::CRD::Comb->to_crd(
111 group => 'comb.example.com',
112 kind => 'Comb',
113 plural => 'combs'
114 );
115  
116 Returns the C<CustomResourceDefinition> as an L<IO::K8s> object, with the
117 C<openAPIV3Schema> generated from these classes and the status subresource
118 enabled. C<group>, C<kind> and C<plural> default to what the class says;
119 each may be overridden. An overridden value only describes the definition --
120 a CR class that talks to that group, kind or plural is still a subclass (see
121 L</DESCRIPTION>), so pass the overrides only to publish a definition for such
122 a subclass without loading it. Croaks on unknown arguments and on an empty
123 value.
124  
125 This extends L<IO::K8s::Role::APIObject/to_crd>, so
126 L<Kubernetes::REST/ensure_crd> installs the same definition, status
127 subresource included.
128  
129 =head1 SEE ALSO
130  
131 =over
132  
133 =item * L<Kubernetes::Comb::CRD> -- resource map provider for this class
134  
135 =item * L<Kubernetes::Comb::CRD::CombSpec>
136  
137 =item * L<Kubernetes::Comb::CRD::CombStatus>
138  
139 =back
140  
141 =head1 SUPPORT
142  
143 =head2 Issues
144  
145 Please report bugs and feature requests on GitHub at
146 L<https://github.com/Getty/p5-kubernetes-comb/issues>.
147  
148 =head2 IRC
149  
150 Join C<#kubernetes> on C<irc.perl.org> or message Getty directly.
151  
152 =head1 CONTRIBUTING
153  
154 Contributions are welcome! Please fork the repository and submit a pull request.
155  
156 =head1 AUTHOR
157  
158 Torsten Raudssus <getty@cpan.org>
159  
160 =head1 COPYRIGHT AND LICENSE
161  
162 This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>.
163  
164 This is free software; you can redistribute it and/or modify it under
165 the same terms as the Perl 5 programming language system itself.
166  
167 =cut
« blib/lib/Kubernetes/Comb.pm ↑ Summary blib/lib/Kubernetes/Comb/CRD/CombSpec.pm »