| line | stmt | bran | cond | sub | pod | time | code | 
| 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 |  |  | 36 |  | 261 | use strict; | 
|  | 36 |  |  |  |  | 73 |  | 
|  | 36 |  |  |  |  | 1067 |  | 
| 39 | 36 |  |  | 36 |  | 185 | use warnings; | 
|  | 36 |  |  |  |  | 100 |  | 
|  | 36 |  |  |  |  | 1049 |  | 
| 40 | 36 |  |  | 36 |  | 187 | use Carp qw{ carp croak }; | 
|  | 36 |  |  |  |  | 69 |  | 
|  | 36 |  |  |  |  | 2668 |  | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | our $VERSION = 0.48; | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 36 |  |  | 36 |  | 16903 | use Webservice::OVH::Domain::Service; | 
|  | 36 |  |  |  |  | 134 |  | 
|  | 36 |  |  |  |  | 1543 |  | 
| 45 | 36 |  |  | 36 |  | 16874 | use Webservice::OVH::Domain::Zone; | 
|  | 36 |  |  |  |  | 110 |  | 
|  | 36 |  |  |  |  | 34284 |  | 
| 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 |  |  |  |  |  |  | sub _new { | 
| 65 |  |  |  |  |  |  |  | 
| 66 | 0 |  |  | 0 |  |  | my ( $class, %params ) = @_; | 
| 67 |  |  |  |  |  |  |  | 
| 68 | 0 | 0 |  |  |  |  | die "Missing module"  unless $params{module}; | 
| 69 | 0 | 0 |  |  |  |  | die "Missing wrapper" unless $params{wrapper}; | 
| 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 |  |  |  |  |  |  | sub service_exists { | 
| 96 |  |  |  |  |  |  |  | 
| 97 | 0 |  |  | 0 | 1 |  | my ( $self, $service_name, $no_recheck ) = @_; | 
| 98 |  |  |  |  |  |  |  | 
| 99 | 0 | 0 |  |  |  |  | if ( !$no_recheck ) { | 
| 100 |  |  |  |  |  |  |  | 
| 101 | 0 |  |  |  |  |  | my $api = $self->{_api_wrapper}; | 
| 102 | 0 |  |  |  |  |  | my $response = $api->rawCall( method => 'get', path => "/domain", noSignature => 0 ); | 
| 103 | 0 | 0 |  |  |  |  | croak $response->error if $response->error; | 
| 104 |  |  |  |  |  |  |  | 
| 105 | 0 |  |  |  |  |  | my $list = $response->content; | 
| 106 |  |  |  |  |  |  |  | 
| 107 | 0 | 0 |  |  |  |  | return ( grep { $_ eq $service_name } @$list ) ? 1 : 0; | 
|  | 0 |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | } else { | 
| 110 |  |  |  |  |  |  |  | 
| 111 | 0 |  |  |  |  |  | my $list = $self->{_aviable_services}; | 
| 112 |  |  |  |  |  |  |  | 
| 113 | 0 | 0 |  |  |  |  | return ( grep { $_ eq $service_name } @$list ) ? 1 : 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 |  |  |  |  |  |  | sub zone_exists { | 
| 134 |  |  |  |  |  |  |  | 
| 135 | 0 |  |  | 0 | 1 |  | my ( $self, $zone_name, $no_recheck ) = @_; | 
| 136 |  |  |  |  |  |  |  | 
| 137 | 0 | 0 |  |  |  |  | if ( !$no_recheck ) { | 
| 138 |  |  |  |  |  |  |  | 
| 139 | 0 |  |  |  |  |  | my $api = $self->{_api_wrapper}; | 
| 140 | 0 |  |  |  |  |  | my $response = $api->rawCall( method => 'get', path => "/domain/zone", noSignature => 0 ); | 
| 141 | 0 | 0 |  |  |  |  | croak $response->error if $response->error; | 
| 142 |  |  |  |  |  |  |  | 
| 143 | 0 |  |  |  |  |  | my $list = $response->content; | 
| 144 |  |  |  |  |  |  |  | 
| 145 | 0 | 0 |  |  |  |  | return ( grep { $_ eq $zone_name } @$list ) ? 1 : 0; | 
|  | 0 |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | } else { | 
| 148 |  |  |  |  |  |  |  | 
| 149 | 0 |  |  |  |  |  | my $list = $self->{_aviable_zones}; | 
| 150 |  |  |  |  |  |  |  | 
| 151 | 0 | 0 |  |  |  |  | return ( grep { $_ eq $zone_name } @$list ) ? 1 : 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 |  |  |  |  |  |  | sub services { | 
| 170 |  |  |  |  |  |  |  | 
| 171 | 0 |  |  | 0 | 1 |  | my ($self) = @_; | 
| 172 |  |  |  |  |  |  |  | 
| 173 | 0 |  |  |  |  |  | my $api = $self->{_api_wrapper}; | 
| 174 | 0 |  |  |  |  |  | my $response = $api->rawCall( method => 'get', path => "/domain", noSignature => 0 ); | 
| 175 | 0 | 0 |  |  |  |  | croak $response->error if $response->error; | 
| 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 | 0 |  |  |  |  | if ( $self->service_exists( $service_name, 1 ) ) { | 
| 183 | 0 |  | 0 |  |  |  | my $service = $self->{_services}{$service_name} = $self->{_services}{$service_name} || Webservice::OVH::Domain::Service->_new( wrapper => $api, id => $service_name, module => $self->{_module} ); | 
| 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 |  |  |  |  |  |  | sub zones { | 
| 206 |  |  |  |  |  |  |  | 
| 207 | 0 |  |  | 0 | 1 |  | 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 | 0 |  |  |  |  | croak $response->error if $response->error; | 
| 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 | 0 |  |  |  |  | if ( $self->zone_exists( $zone_name, 1 ) ) { | 
| 220 | 0 |  | 0 |  |  |  | my $zone = $self->{_zones}{$zone_name} = $self->{_zones}{$zone_name} || Webservice::OVH::Domain::Zone->_new( wrapper => $api, id => $zone_name, module => $self->{_module} ); | 
| 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 |  |  |  |  |  |  | sub service { | 
| 245 |  |  |  |  |  |  |  | 
| 246 | 0 |  |  | 0 | 1 |  | my ( $self, $service_name ) = @_; | 
| 247 |  |  |  |  |  |  |  | 
| 248 | 0 | 0 |  |  |  |  | if ( $self->service_exists($service_name) ) { | 
| 249 |  |  |  |  |  |  |  | 
| 250 | 0 |  |  |  |  |  | my $api = $self->{_api_wrapper}; | 
| 251 | 0 |  | 0 |  |  |  | my $service = $self->{_services}{$service_name} = $self->{_services}{$service_name} || Webservice::OVH::Domain::Service->_new( wrapper => $api, id => $service_name, module => $self->{_module} ); | 
| 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 |  |  |  |  |  |  | sub zone { | 
| 278 |  |  |  |  |  |  |  | 
| 279 | 0 |  |  | 0 | 1 |  | my ( $self, $zone_name ) = @_; | 
| 280 |  |  |  |  |  |  |  | 
| 281 | 0 | 0 |  |  |  |  | if ( $self->zone_exists($zone_name) ) { | 
| 282 | 0 |  |  |  |  |  | my $api = $self->{_api_wrapper}; | 
| 283 | 0 |  | 0 |  |  |  | my $zone = $self->{_zones}{$zone_name} = $self->{_zones}{$zone_name} || Webservice::OVH::Domain::Zone->_new( wrapper => $api, id => $zone_name, module => $self->{_module} ); | 
| 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 |  |  |  |  |  |  | 1; |