Kubernetes/Role/ResourceLister.pm

filter: Statementstmt 57.8% 63 / 109 Branchbran 40.0% 16 / 40 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod n/a totaltotal 54.1% 85 / 157 CC 26 SCAR 33.0
CC
26
Cov
53%
list_services
56.0
list_secrets
56.0
list_pods
7.1
CRAP 27.0
↑ Summary Kubernetes/Role/ResourceCreator.pm »
1 package Net::Kubernetes::Role::ResourceLister;
2 2 $Net::Kubernetes::Role::ResourceLister::VERSION = '0.05';
3 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use MooseX::Aliases;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 require Net::Kubernetes::Resource::Service;
6 2 require Net::Kubernetes::Resource::Pod;
7 2 require Net::Kubernetes::Resource::ReplicationController;
8 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 Net::Kubernetes::Role::ResourceLister
13  
14 =head1 VERSION
15  
16 version 0.05
17  
18 =cut
19  
20 2 with 'Net::Kubernetes::Role::ResourceFactory';
21  
22 2 requires 'ua';
23 2 requires 'create_request';
24 2 requires 'json';
25  
26  
27 sub list_pods {
28 5 ▶ my $self = shift;
Subroutine list_pods: called CC=7 SCAR=19.6
29 5 my(%options);
30 5 ▶ if (ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 5 5
31 0 %options = %{ $_[0] };
32 }else{
33 5 %options = @_;
34 }
35  
36 5 my $uri = URI->new($self->path.'/pods');
37 5 my(%form) = ();
38 5 ▶ $form{labelSelector}=$self->_build_selector_from_hash($options{labels}) if (exists $options{labels});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"labels"} 1 4 5
39 5 ▶ $form{fieldSelector}=$self->_build_selector_from_hash($options{fields}) if (exists $options{fields});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"fields"} 1 4 5
40 5 $uri->query_form(%form);
41  
42 5 my $res = $self->ua->request($self->create_request(GET => $uri));
43 5 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 4 1 5
44 4 my $pod_list = $self->json->decode($res->content);
45 4 my(@pods)=();
46 4 foreach my $pod (@{ $pod_list->{items}}){
47 3 $pod->{apiVersion} = $pod_list->{apiVersion};
48 3 push @pods, $self->create_resource_object($pod, 'Pod');
49 }
50 4 ▶ return wantarray ? @pods : \@pods;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 4 4
51 }else{
52 1 Net::Kubernetes::Exception->throw(code=>$res->code, message=>$res->message);
53 }
54 }
55  
56 sub list_replication_controllers {
57 5 ▶ my $self = shift;
Subroutine list_replication_controllers: called CC=7 SCAR=19.6
58 5 my(%options);
59 5 ▶ if (ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 5 5
60 0 %options = %{ $_[0] };
61 }else{
62 5 %options = @_;
63 }
64  
65 5 my $uri = URI->new($self->path.'/replicationcontrollers');
66 5 my(%form) = ();
67 5 ▶ $form{labelSelector}=$self->_build_selector_from_hash($options{labels}) if (exists $options{labels});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"labels"} 1 4 5
68 5 ▶ $form{fieldSelector}=$self->_build_selector_from_hash($options{fields}) if (exists $options{fields});
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"fields"} 1 4 5
69 5 $uri->query_form(%form);
70  
71 5 my $res = $self->ua->request($self->create_request(GET => $uri));
72 5 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 4 1 5
73 4 my $pod_list = $self->json->decode($res->content);
74 4 my(@rcs)=();
75 4 foreach my $rc (@{ $pod_list->{items}}){
76 3 $rc->{apiVersion} = $pod_list->{apiVersion};
77 3 push @rcs, $self->create_resource_object($rc, 'ReplicationController');;
78 }
79 4 ▶ return wantarray ? @rcs : \@rcs;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 4 4
80 }else{
81 1 Net::Kubernetes::Exception->throw(code=>$res->code, message=>$res->message);
82 }
83 }
84  
85 2 alias list_rc => 'list_replication_controllers';
86  
87 sub list_services {
88 0 ▶ my $self = shift;
Subroutine list_services: not called CC=7 SCAR=40.3
89 0 my(%options);
90 0 ▶ if (ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
91 0 %options = %{ $_[0] };
92 }else{
93 0 %options = @_;
94 }
95  
96 0 my $uri = URI->new($self->path.'/services');
97 0 my(%form) = ();
98 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
99 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
100 0 $uri->query_form(%form);
101  
102 0 my $res = $self->ua->request($self->create_request(GET => $uri));
103 0 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 0 0 0
104 0 my $pod_list = $self->json->decode($res->content);
105 0 my(@services)=();
106 0 foreach my $service (@{ $pod_list->{items}}){
107 0 $service->{apiVersion} = $pod_list->{apiVersion};
108 0 push @services, $self->create_resource_object($service, 'Service');
109 }
110 0 ▶ return wantarray ? @services : \@services;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
111 }else{
112 0 Net::Kubernetes::Exception->throw(code=>$res->code, message=>$res->message);
113 }
114 }
115  
116 sub list_secrets {
117 0 ▶ my $self = shift;
Subroutine list_secrets: not called CC=7 SCAR=40.3
118 0 my(%options);
119 0 ▶ if (ref($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0]) { } 0 0 0
120 0 %options = %{ $_[0] };
121 }else{
122 0 %options = @_;
123 }
124  
125 0 my $uri = URI->new($self->path.'/secrets');
126 0 my(%form) = ();
127 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
128 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
129 0 $uri->query_form(%form);
130  
131 0 my $res = $self->ua->request($self->create_request(GET => $uri));
132 0 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 0 0 0
133 0 my $pod_list = $self->json->decode($res->content);
134 0 my(@secrets)=();
135 0 foreach my $secret (@{ $pod_list->{items}}){
136 0 $secret->{apiVersion} = $pod_list->{apiVersion};
137 0 push @secrets, $self->create_resource_object($secret, 'Secret');
138 }
139 0 ▶ return wantarray ? @secrets : \@secrets;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
140 }else{
141 0 Net::Kubernetes::Exception->throw(code=>$res->code, message=>$res->message);
142 }
143 }
144  
145 sub _build_selector_from_hash {
146 4 ▶ my($self, $select_hash) = @_;
Subroutine _build_selector_from_hash: called CC=2 SCAR=6.9
147 4 my(@selectors);
148 4 foreach my $label (keys %{ $select_hash }){
149 4 push @selectors, $label.'='.$select_hash->{$label};
150 }
151 4 return \@selectors;
152 }
153  
154 2 return 42;
↑ Summary Kubernetes/Role/ResourceCreator.pm »