-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathApiFactory.pm
130 lines (82 loc) · 2.71 KB
/
ApiFactory.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
=begin comment
Kubernetes
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
The version of the OpenAPI document: v1.13.7
Generated by: https://openapi-generator.tech
=end comment
=cut
#
# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
# Do not edit the class manually.
# Ref: https://openapi-generator.tech
#
package Kubernetes::ApiFactory;
use strict;
use warnings;
use utf8;
use Carp;
use Module::Find;
usesub Kubernetes::Object;
use Kubernetes::ApiClient;
=head1 Name
Kubernetes::ApiFactory - constructs APIs to retrieve Kubernetes objects
=head1 Synopsis
package My::Petstore::App;
use Kubernetes::ApiFactory;
my $api_factory = Kubernetes::ApiFactory->new( ... ); # any args for ApiClient constructor
# later...
my $pet_api = $api_factory->get_api('Pet');
# $pet_api isa Kubernetes::PetApi
my $pet = $pet_api->get_pet_by_id(pet_id => $pet_id);
# object attributes have proper accessors:
printf "Pet's name is %s", $pet->name;
# change the value stored on the object:
$pet->name('Dave');
=cut
# Load all the API classes and construct a lookup table at startup time
my %_apis = map { $_ =~ /^Kubernetes::(.*)$/; $1 => $_ }
grep { $_ =~ /Api$/ } usesub 'Kubernetes';
=head1 new($api_client)
create a new Kubernetes::ApiFactory instance with the given Kubernetes::ApiClient instance.
=head1 new(%parameters)
Any parameters are optional, and are passed to and stored on the api_client object.
See L<Kubernetes::ApiClient> and L<Kubernetes::Configuration> for valid parameters
=cut
sub new {
my ($class) = shift;
my $api_client;
if ( $_[0] && ref $_[0] && ref $_[0] eq 'Kubernetes::ApiClient' ) {
$api_client = $_[0];
}
else {
$api_client = Kubernetes::ApiClient->new(@_);
}
bless { api_client => $api_client }, $class;
}
=head1 get_api($which)
Returns an API object of the requested type.
$which is a nickname for the class:
FooBarClient::BazApi has nickname 'Baz'
=cut
sub get_api {
my ( $self, $which ) = @_;
croak "API not specified" unless $which;
my $api_class = $_apis{"${which}Api"} || croak "No known API for '$which'";
return $api_class->new( $self->api_client );
}
=head1 api_client()
Returns the api_client object, should you ever need it.
=cut
sub api_client { $_[0]->{api_client} }
=head1 apis_available()
=cut
sub apis_available {
return map { $_ =~ s/Api$//; $_ } sort keys %_apis;
}
=head1 classname_for()
=cut
sub classname_for {
my ( $self, $api_name ) = @_;
return $_apis{"${api_name}Api"};
}
1;