Webservice/OVH/Domain.pm

filter: Statementstmt 20.2% 17 / 84 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 41.6% 5 / 12 Podpod 100% 6 / 6 totaltotal 18.1% 28 / 154 CC 23 SCAR 30.4
CC
23
Cov
13%
service_exists
30.0
zone_exists
30.0
services
30.0
CRAP 21.0
« Webservice/OVH/Cloud/Project.pm ↑ Summary Webservice/OVH/Email/Domain.pm »
1 package Webservice::OVH::Domain;
2  
3 =encoding utf-8
4  
5 =head1 NAME
6  
7 Webservice::OVH::Domain
8  
9 =head1 SYNOPSIS
10  
11 use Webservice::OVH;
12
13 my $ovh = Webservice::OVH->new_from_json("credentials.json");
14
15 my $services = $ovh->domain->services;
16 foreach my $service (@$services) {
17
18 print $service->name;
19 }
20
21 my $ = $ovh->domain->zones;
22 foreach my $zone (@$zones) {
23
24 print $zone->name;
25 }
26
27 print "I have a zone" if $ovh->domain->zone_exists("myaddress.de");
28 print "I have a service" if $ovh->domain->service_exists("myaddress.de");
29  
30 =head1 DESCRIPTION
31  
32 Gives access to services and zones connected to the uses account.
33  
34 =head1 METHODS
35  
36 =cut
37  
38 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 36 ▶use Carp qw{ carp croak };
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 36 our $VERSION = 0.48;
43  
44 36 ▶use Webservice::OVH::Domain::Service;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 36 ▶use Webservice::OVH::Domain::Zone;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 =head2 _new
48  
49 Internal Method to create the domain object.
50 This method is not ment to be called external.
51  
52 =over
53  
54 =item * Parameter: $api_wrapper - ovh api wrapper object, $module - root object
55  
56 =item * Return: L<Webservice::OVH::Order>
57  
58 =item * Synopsis: Webservice::OVH::Order->_new($ovh_api_wrapper, $self);
59  
60 =back
61  
62 =cut
63  
64 0 ▶sub _new {
Subroutine _new: not called CC=3 SCAR=24.8
65  
66 0 my ( $class, %params ) = @_;
67  
68 0 ▶ die "Missing module" unless $params{module};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"module"} 0 0 0
69 0 ▶ die "Missing wrapper" unless $params{wrapper};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"wrapper"} 0 0 0
70  
71 0 my $module = $params{module};
72 0 my $api_wrapper = $params{wrapper};
73  
74 0 my $self = bless { _module => $module, _api_wrapper => $api_wrapper, _services => {}, _zones => {}, _aviable_services => [], _aviable_zones => [] }, $class;
75  
76 0 return $self;
77 }
78  
79 =head2 service_exists
80  
81 Returns 1 if service is available for the connected account, 0 if not.
82  
83 =over
84  
85 =item * Parameter: $service_name - Domain name, $no_recheck - (optional)only for internal usage
86  
87 =item * Return: VALUE
88  
89 =item * Synopsis: print "mydomain.com exists" if $ovh->domain->service_exists("mydomain.com");
90  
91 =back
92  
93 =cut
94  
95 0 ▶sub service_exists {
Subroutine service_exists: not called CC=5 SCAR=34.0
Pod documented
96  
97 0 my ( $self, $service_name, $no_recheck ) = @_;
98  
99 0 ▶ if ( !$no_recheck ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $no_recheck) { } 0 0 0
100  
101 0 my $api = $self->{_api_wrapper};
102 0 my $response = $api->rawCall( method => 'get', path => "/domain", noSignature => 0 );
103 0 ▶ croak $response->error if $response->error;
Branch: 1 branch
BranchTrueFalseTotal
if $response->error 0 0 0
104  
105 0 my $list = $response->content;
106  
107 0 ▶ return ( grep { $_ eq $service_name } @$list ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({$_ eq $service_name;} @$list) ? : 0 0 0
108  
109 } else {
110  
111 0 my $list = $self->{_aviable_services};
112  
113 0 ▶ return ( grep { $_ eq $service_name } @$list ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({$_ eq $service_name;} @$list) ? : 0 0 0
114 }
115 }
116  
117 =head2 zone_exists
118  
119 Returns 1 if zone is available for the connected account, 0 if not.
120  
121 =over
122  
123 =item * Parameter: $zone_name - Domain name, $no_recheck - (optional)only for internal usage
124  
125 =item * Return: VALUE
126  
127 =item * Synopsis: print "zone mydomain.com exists" if $ovh->domain->zone_exists("mydomain.com");
128  
129 =back
130  
131 =cut
132  
133 0 ▶sub zone_exists {
Subroutine zone_exists: not called CC=5 SCAR=34.0
Pod documented
134  
135 0 my ( $self, $zone_name, $no_recheck ) = @_;
136  
137 0 ▶ if ( !$no_recheck ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $no_recheck) { } 0 0 0
138  
139 0 my $api = $self->{_api_wrapper};
140 0 my $response = $api->rawCall( method => 'get', path => "/domain/zone", noSignature => 0 );
141 0 ▶ croak $response->error if $response->error;
Branch: 1 branch
BranchTrueFalseTotal
if $response->error 0 0 0
142  
143 0 my $list = $response->content;
144  
145 0 ▶ return ( grep { $_ eq $zone_name } @$list ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({$_ eq $zone_name;} @$list) ? : 0 0 0
146  
147 } else {
148  
149 0 my $list = $self->{_aviable_zones};
150  
151 0 ▶ return ( grep { $_ eq $zone_name } @$list ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({$_ eq $zone_name;} @$list) ? : 0 0 0
152 }
153 }
154  
155 =head2 services
156  
157 Produces an array of all available services that are connected to the used account.
158  
159 =over
160  
161 =item * Return: ARRAY
162  
163 =item * Synopsis: my $services = $ovh->order->services();
164  
165 =back
166  
167 =cut
168  
169 0 ▶sub services {
Subroutine services: not called CC=5 SCAR=34.0
Pod documented
170  
171 0 my ($self) = @_;
172  
173 0 my $api = $self->{_api_wrapper};
174 0 my $response = $api->rawCall( method => 'get', path => "/domain", noSignature => 0 );
175 0 ▶ croak $response->error if $response->error;
Branch: 1 branch
BranchTrueFalseTotal
if $response->error 0 0 0
176  
177 0 my $service_array = $response->content;
178 0 my $services = [];
179 0 $self->{_aviable_services} = $service_array;
180  
181 0 foreach my $service_name (@$service_array) {
182 0 ▶ if ( $self->service_exists( $service_name, 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->service_exists($service_name, 1)) 0 0 0
183 0 ▶ my $service = $self->{_services}{$service_name} = $self->{_services}{$service_name} || Webservice::OVH::Domain::Service->_new( wrapper => $api, id => $service_name, module => $self->{_module} );
Condition0%0/3
$self->{'_services'}{$service_name} || 'Webservice::OVH::Domain::Service'->_new('wrapper', $api, 'id', $service_name, 'module', $self->{'_module'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_services'}{$service_name} || 'Webservice::OVH::Domain::Service'->_new('wrapper', $api, 'id', $service_name, 'module', $self->{'_module'})
$self->{'_services'}{$service_name} 'Webservice::OVH::Domain::Service'->_new('wrapper', $api, 'id', $service_name, 'module', $self->{'_module'})
Truth table0%0/3
A || B
A= $self->{'_services'}{$service_name}B= 'Webservice::OVH::Domain::Service'->_new('wrapper', $api, 'id', $service_name, 'module', $self->{'_module'})
ABresult
1X1
011
000
184 0 push @$services, $service;
185 }
186 }
187  
188 0 return $services;
189 }
190  
191 =head2 zones
192  
193 Produces an array of all available zones that are connected to the used account.
194  
195 =over
196  
197 =item * Return: ARRAY
198  
199 =item * Synopsis: my $zones = $ovh->order->zones();
200  
201 =back
202  
203 =cut
204  
205 0 ▶sub zones {
Subroutine zones: not called CC=5 SCAR=34.0
Pod documented
206  
207 0 my ($self) = @_;
208  
209 0 my $api = $self->{_api_wrapper};
210 0 my $response = $api->rawCall( method => 'get', path => "/domain/zone", noSignature => 0 );
211 0 ▶ croak $response->error if $response->error;
Branch: 1 branch
BranchTrueFalseTotal
if $response->error 0 0 0
212  
213 0 my $zone_names = $response->content;
214 0 my $zones = [];
215 0 $self->{_aviable_zones} = $zone_names;
216  
217 0 foreach my $zone_name (@$zone_names) {
218  
219 0 ▶ if ( $self->zone_exists( $zone_name, 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->zone_exists($zone_name, 1)) 0 0 0
220 0 ▶ my $zone = $self->{_zones}{$zone_name} = $self->{_zones}{$zone_name} || Webservice::OVH::Domain::Zone->_new( wrapper => $api, id => $zone_name, module => $self->{_module} );
Condition0%0/3
$self->{'_zones'}{$zone_name} || 'Webservice::OVH::Domain::Zone'->_new('wrapper', $api, 'id', $zone_name, 'module', $self->{'_module'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_zones'}{$zone_name} || 'Webservice::OVH::Domain::Zone'->_new('wrapper', $api, 'id', $zone_name, 'module', $self->{'_module'})
$self->{'_zones'}{$zone_name} 'Webservice::OVH::Domain::Zone'->_new('wrapper', $api, 'id', $zone_name, 'module', $self->{'_module'})
Truth table0%0/3
A || B
A= $self->{'_zones'}{$zone_name}B= 'Webservice::OVH::Domain::Zone'->_new('wrapper', $api, 'id', $zone_name, 'module', $self->{'_module'})
ABresult
1X1
011
000
221 0 push @$zones, $zone;
222 }
223 }
224  
225 0 return $zones;
226 }
227  
228 =head2 service
229  
230 Returns a single service by name
231  
232 =over
233  
234 =item * Parameter: $service_name - domain name
235  
236 =item * Return: L<Webservice::OVH::Domain::Service>
237  
238 =item * Synopsis: my $service = $ovh->domain->service("mydomain.com");
239  
240 =back
241  
242 =cut
243  
244 0 ▶sub service {
Subroutine service: not called CC=3 SCAR=24.8
Pod documented
245  
246 0 my ( $self, $service_name ) = @_;
247  
248 0 ▶ if ( $self->service_exists($service_name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->service_exists($service_name)) { } 0 0 0
249  
250 0 my $api = $self->{_api_wrapper};
251 0 ▶ my $service = $self->{_services}{$service_name} = $self->{_services}{$service_name} || Webservice::OVH::Domain::Service->_new( wrapper => $api, id => $service_name, module => $self->{_module} );
Condition0%0/3
$self->{'_services'}{$service_name} || 'Webservice::OVH::Domain::Service'->_new('wrapper', $api, 'id', $service_name, 'module', $self->{'_module'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_services'}{$service_name} || 'Webservice::OVH::Domain::Service'->_new('wrapper', $api, 'id', $service_name, 'module', $self->{'_module'})
$self->{'_services'}{$service_name} 'Webservice::OVH::Domain::Service'->_new('wrapper', $api, 'id', $service_name, 'module', $self->{'_module'})
Truth table0%0/3
A || B
A= $self->{'_services'}{$service_name}B= 'Webservice::OVH::Domain::Service'->_new('wrapper', $api, 'id', $service_name, 'module', $self->{'_module'})
ABresult
1X1
011
000
252  
253 0 return $service;
254 } else {
255  
256 0 carp "Service $service_name doesn't exists";
257 0 return undef;
258 }
259 }
260  
261 =head2 zone
262  
263 Returns a single zone by name
264  
265 =over
266  
267 =item * Parameter: $zone_name - domain name
268  
269 =item * Return: L<Webservice::OVH::Domain::Zone>
270  
271 =item * Synopsis: my $zone = $ovh->domain->zone("mydomain.com");
272  
273 =back
274  
275 =cut
276  
277 0 ▶sub zone {
Subroutine zone: not called CC=3 SCAR=24.8
Pod documented
278  
279 0 my ( $self, $zone_name ) = @_;
280  
281 0 ▶ if ( $self->zone_exists($zone_name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->zone_exists($zone_name)) { } 0 0 0
282 0 my $api = $self->{_api_wrapper};
283 0 ▶ my $zone = $self->{_zones}{$zone_name} = $self->{_zones}{$zone_name} || Webservice::OVH::Domain::Zone->_new( wrapper => $api, id => $zone_name, module => $self->{_module} );
Condition0%0/3
$self->{'_zones'}{$zone_name} || 'Webservice::OVH::Domain::Zone'->_new('wrapper', $api, 'id', $zone_name, 'module', $self->{'_module'})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'_zones'}{$zone_name} || 'Webservice::OVH::Domain::Zone'->_new('wrapper', $api, 'id', $zone_name, 'module', $self->{'_module'})
$self->{'_zones'}{$zone_name} 'Webservice::OVH::Domain::Zone'->_new('wrapper', $api, 'id', $zone_name, 'module', $self->{'_module'})
Truth table0%0/3
A || B
A= $self->{'_zones'}{$zone_name}B= 'Webservice::OVH::Domain::Zone'->_new('wrapper', $api, 'id', $zone_name, 'module', $self->{'_module'})
ABresult
1X1
011
000
284  
285 0 return $zone;
286  
287 } else {
288  
289 0 carp "Zone $zone_name doesn't exists";
290 0 return undef;
291 }
292  
293 }
294  
295 36 1;
« Webservice/OVH/Cloud/Project.pm ↑ Summary Webservice/OVH/Email/Domain.pm »