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 = '1.03';
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 10 ▶sub list_pods {
Subroutine list_pods: called CC=7 SCAR=19.6
18 10 my $self = shift;
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 10 ▶sub list_replication_controllers {
Subroutine list_replication_controllers: called CC=7 SCAR=19.6
48 10 my $self = shift;
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 12 ▶sub list_services {
Subroutine list_services: called CC=7 SCAR=19.6
80 12 my $self = shift;
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 0 ▶sub list_events {
Subroutine list_events: not called CC=7 SCAR=40.3
110 0 my $self = shift;
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 8 ▶sub list_secrets {
Subroutine list_secrets: called CC=7 SCAR=20.0
140 8 my $self = shift;
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 10 ▶sub list_endpoints {
Subroutine list_endpoints: called CC=7 SCAR=19.6
170 10 my $self = shift;
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 24 ▶sub _build_selector_from_hash {
Subroutine _build_selector_from_hash: called CC=2 SCAR=6.9
199 24 my($self, $select_hash) = @_;
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__
« Kubernetes/Role/SecretBuilder.pm ↑ Summary Kubernetes/Resource/ReplicationController.pm »