Kubernetes/Role/ResourceLister.pm

filter: Statementstmt 77.7% 115 / 148 Branchbran 66.6% 40 / 60 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod n/a totaltotal 75.1% 163 / 217 CC 38 SCAR 26.5
CC
38
Cov
75%
list_events
56.0
list_secrets
7.4
list_pods
7.1
CRAP 14.1
« Kubernetes/Role/SecretBuilder.pm ↑ Summary Kubernetes/Resource/ReplicationController.pm »
1 package Net::Kubernetes::Role::ResourceLister;
2 # ABSTRACT: Role to give access to list_* methods.
3 4 $Net::Kubernetes::Role::ResourceLister::VERSION = '0.19';
4 4 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use MooseX::Aliases;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 require Net::Kubernetes::Resource::Service;
7 4 require Net::Kubernetes::Resource::Pod;
8 4 require Net::Kubernetes::Resource::ReplicationController;
9  
10 4 with 'Net::Kubernetes::Role::ResourceFactory';
11  
12 4 requires 'ua';
13 4 requires 'create_request';
14 4 requires 'json';
15  
16  
17 sub list_pods {
18 10 ▶ my $self = shift;
Subroutine list_pods: called CC=7 SCAR=19.6
19 10 my(%options);
20 10 ▶ if (ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 10 10
21 0 %options = %{ $_[0] };
22 }else{
23 10 %options = @_;
24 }
25  
26 10 my $uri = URI->new($self->path.'/pods');
27 10 my(%form) = ();
28 10 ▶ $form{labelSelector}=$self->_build_selector_from_hash($options{labels}) if (exists $options{labels});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"labels"} 2 8 10
29 10 ▶ $form{fieldSelector}=$self->_build_selector_from_hash($options{fields}) if (exists $options{fields});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"fields"} 2 8 10
30 10 $uri->query_form(%form);
31  
32 10 my $res = $self->ua->request($self->create_request(GET => $uri));
33 10 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 8 2 10
34 8 my $pod_list = $self->json->decode($res->content);
35 8 my(@pods)=();
36 8 foreach my $pod (@{ $pod_list->{items}}){
37 2 $pod->{apiVersion} = $pod_list->{apiVersion};
38 2 push @pods, $self->create_resource_object($pod, 'Pod');
39 }
40 8 ▶ return wantarray ? @pods : \@pods;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 8 8
41 }else{
42 2 Net::Kubernetes::Exception->throw(code=>$res->code, message=>$res->message);
43 }
44 }
45  
46  
47 sub list_replication_controllers {
48 10 ▶ my $self = shift;
Subroutine list_replication_controllers: called CC=7 SCAR=19.6
49 10 my(%options);
50 10 ▶ if (ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 10 10
51 0 %options = %{ $_[0] };
52 }else{
53 10 %options = @_;
54 }
55  
56 10 my $uri = URI->new($self->path.'/replicationcontrollers');
57 10 my(%form) = ();
58 10 ▶ $form{labelSelector}=$self->_build_selector_from_hash($options{labels}) if (exists $options{labels});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"labels"} 2 8 10
59 10 ▶ $form{fieldSelector}=$self->_build_selector_from_hash($options{fields}) if (exists $options{fields});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"fields"} 2 8 10
60 10 $uri->query_form(%form);
61  
62 10 my $res = $self->ua->request($self->create_request(GET => $uri));
63 10 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 8 2 10
64 8 my $pod_list = $self->json->decode($res->content);
65 8 my(@rcs)=();
66 8 foreach my $rc (@{ $pod_list->{items}}){
67 2 $rc->{apiVersion} = $pod_list->{apiVersion};
68 2 push @rcs, $self->create_resource_object($rc, 'ReplicationController');;
69 }
70 8 ▶ return wantarray ? @rcs : \@rcs;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 8 8
71 }else{
72 2 Net::Kubernetes::Exception->throw(code=>$res->code, message=>$res->message);
73 }
74 }
75  
76 4 alias list_rc => 'list_replication_controllers';
77  
78  
79 sub list_services {
80 12 ▶ my $self = shift;
Subroutine list_services: called CC=7 SCAR=19.6
81 12 my(%options);
82 12 ▶ if (ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 12 12
83 0 %options = %{ $_[0] };
84 }else{
85 12 %options = @_;
86 }
87  
88 12 my $uri = URI->new($self->path.'/services');
89 12 my(%form) = ();
90 12 ▶ $form{labelSelector}=$self->_build_selector_from_hash($options{labels}) if (exists $options{labels});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"labels"} 2 10 12
91 12 ▶ $form{fieldSelector}=$self->_build_selector_from_hash($options{fields}) if (exists $options{fields});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"fields"} 2 10 12
92 12 $uri->query_form(%form);
93  
94 12 my $res = $self->ua->request($self->create_request(GET => $uri));
95 12 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 10 2 12
96 10 my $pod_list = $self->json->decode($res->content);
97 10 my(@services)=();
98 10 foreach my $service (@{ $pod_list->{items}}){
99 4 $service->{apiVersion} = $pod_list->{apiVersion};
100 4 push @services, $self->create_resource_object($service, 'Service');
101 }
102 10 ▶ return wantarray ? @services : \@services;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 10 10
103 }else{
104 2 Net::Kubernetes::Exception->throw(code=>$res->code, message=>$res->message);
105 }
106 }
107  
108  
109 sub list_events {
110 0 ▶ my $self = shift;
Subroutine list_events: not called CC=7 SCAR=40.3
111 0 my(%options);
112 0 ▶ if (ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
113 0 %options = %{ $_[0] };
114 }else{
115 0 %options = @_;
116 }
117  
118 0 my $uri = URI->new($self->path.'/events');
119 0 my(%form) = ();
120 0 ▶ $form{labelSelector}=$self->_build_selector_from_hash($options{labels}) if (exists $options{labels});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"labels"} 0 0 0
121 0 ▶ $form{fieldSelector}=$self->_build_selector_from_hash($options{fields}) if (exists $options{fields});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"fields"} 0 0 0
122 0 $uri->query_form(%form);
123  
124 0 my $res = $self->ua->request($self->create_request(GET => $uri));
125 0 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 0 0 0
126 0 my $event_list = $self->json->decode($res->content);
127 0 my(@events)=();
128 0 foreach my $service (@{ $event_list->{items}}){
129 0 $service->{apiVersion} = $event_list->{apiVersion};
130 0 push @events, $self->create_resource_object($service, 'Event');
131 }
132 0 ▶ return wantarray ? @events : \@events;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
133 }else{
134 0 Net::Kubernetes::Exception->throw(code=>$res->code, message=>$res->message);
135 }
136 }
137  
138  
139 sub list_secrets {
140 8 ▶ my $self = shift;
Subroutine list_secrets: called CC=7 SCAR=20.0
141 8 my(%options);
142 8 ▶ if (ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 8 8
143 0 %options = %{ $_[0] };
144 }else{
145 8 %options = @_;
146 }
147  
148 8 my $uri = URI->new($self->path.'/secrets');
149 8 my(%form) = ();
150 8 ▶ $form{labelSelector}=$self->_build_selector_from_hash($options{labels}) if (exists $options{labels});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"labels"} 2 6 8
151 8 ▶ $form{fieldSelector}=$self->_build_selector_from_hash($options{fields}) if (exists $options{fields});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"fields"} 2 6 8
152 8 $uri->query_form(%form);
153  
154 8 my $res = $self->ua->request($self->create_request(GET => $uri));
155 8 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 6 2 8
156 6 my $pod_list = $self->json->decode($res->content);
157 6 my(@secrets)=();
158 6 foreach my $secret (@{ $pod_list->{items}}){
159 0 $secret->{apiVersion} = $pod_list->{apiVersion};
160 0 push @secrets, $self->create_resource_object($secret, 'Secret');
161 }
162 6 ▶ return wantarray ? @secrets : \@secrets;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 6 6
163 }else{
164 2 Net::Kubernetes::Exception->throw(code=>$res->code, message=>$res->message);
165 }
166 }
167  
168  
169 sub list_endpoints {
170 10 ▶ my $self = shift;
Subroutine list_endpoints: called CC=7 SCAR=19.6
171 10 my(%options);
172 10 ▶ if (ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 10 10
173 0 %options = %{ $_[0] };
174 }else{
175 10 %options = @_;
176 }
177  
178 10 my $uri = URI->new($self->path.'/endpoints');
179 10 my(%form) = ();
180 10 ▶ $form{labelSelector}=$self->_build_selector_from_hash($options{labels}) if (exists $options{labels});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"labels"} 2 8 10
181 10 ▶ $form{fieldSelector}=$self->_build_selector_from_hash($options{fields}) if (exists $options{fields});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"fields"} 2 8 10
182 10 $uri->query_form(%form);
183  
184 10 my $res = $self->ua->request($self->create_request(GET => $uri));
185 10 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 8 2 10
186 8 my $point_list = $self->json->decode($res->content);
187 8 my(@points)=();
188 8 foreach my $point (@{ $point_list->{items} }){
189 2 $point->{apiVersion} = $point_list->{apiVersion};
190 2 push @points, $self->create_resource_object($point, 'Endpoint');
191 }
192 8 ▶ return wantarray ? @points : \@points;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 8 8
193 }else{
194 2 Net::Kubernetes::Exception->throw(code=>$res->code, message=>$res->message);
195 }
196 }
197  
198 sub _build_selector_from_hash {
199 24 ▶ my($self, $select_hash) = @_;
Subroutine _build_selector_from_hash: called CC=2 SCAR=6.9
200 24 my(@selectors);
201 24 foreach my $label (keys %{ $select_hash }){
202 24 push @selectors, $label.'='.$select_hash->{$label};
203 }
204 24 return \@selectors;
205 }
206  
207 4 return 42;
208  
209 __END__
210  
211 =pod
212  
213 =encoding UTF-8
214  
215 =head1 NAME
216  
217 Net::Kubernetes::Role::ResourceLister - Role to give access to list_* methods.
218  
219 =head1 VERSION
220  
221 version 0.19
222  
223 =head1 METHODS
224  
225 =head2 list_pods([label=>{label=>value}], [fields=>{field=>value}])
226  
227 returns a list of L<Net::Kubernetes::Resource::Pod>s
228  
229 =head2 list_rc([label=>{label=>value}], [fields=>{field=>value}])
230  
231 returns a list of L<Net::Kubernetes::Resource::ReplicationController>s
232  
233 =head2 list_replication_controllers([label=>{label=>value}], [fields=>{field=>value}])
234  
235 returns a list of L<Net::Kubernetes::Resource::ReplicationController>s
236  
237 =head2 list_services([label=>{label=>value}], [fields=>{field=>value}])
238  
239 returns a list of L<Net::Kubernetes::Resource::Service>s
240  
241 =head2 list_events([label=>{label=>value}], [fields=>{field=>value}])
242  
243 returns a list of L<Net::Kubernetes::Resource::Event>s
244  
245 =head2 list_secrets([label=>{label=>value}], [fields=>{field=>value}])
246  
247 returns a list of L<Net::Kubernetes::Resource::Secret>s
248  
249 =head2 list_endpoints([label=>{label=>value}], [fields=>{field=>value}])
250  
251 returns a list of L<Net::Kubernetes::Resource::Endpoint>s
252  
253 =head1 AUTHOR
254  
255 Dave Mueller <dave@perljedi.com>
256  
257 =head1 COPYRIGHT AND LICENSE
258  
259 This software is Copyright (c) 2015 by Dave Mueller.
260  
261 This is free software, licensed under:
262  
263 The MIT (X11) License
264  
265 =head1 SEE ALSO
266  
267 Please see those modules/websites for more information related to this module.
268  
269 =over 4
270  
271 =item *
272  
273 L<Net::Kubernetes|Net::Kubernetes>
274  
275 =back
276  
277 =head1 CONSUMES
278  
279 =over 4
280  
281 =item * L<Net::Kubernetes::Role::ResourceFactory>
282  
283 =back
284  
285 =cut
« Kubernetes/Role/SecretBuilder.pm ↑ Summary Kubernetes/Resource/ReplicationController.pm »