| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Webservice::OVH::Hosting::Web; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | =encoding utf-8 | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | =head1 NAME | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | Webservice::OVH::Hosting::Web | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | Gives access to services and zones connected to the uses account. | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =head1 METHODS | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | =cut | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 36 |  |  | 36 |  | 259 | use strict; | 
|  | 36 |  |  |  |  | 129 |  | 
|  | 36 |  |  |  |  | 1074 |  | 
| 20 | 36 |  |  | 36 |  | 209 | use warnings; | 
|  | 36 |  |  |  |  | 97 |  | 
|  | 36 |  |  |  |  | 1484 |  | 
| 21 | 36 |  |  | 36 |  | 300 | use Carp qw{ carp croak }; | 
|  | 36 |  |  |  |  | 127 |  | 
|  | 36 |  |  |  |  | 2676 |  | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | our $VERSION = 0.48; | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 36 |  |  | 36 |  | 15801 | use Webservice::OVH::Hosting::Web::Service; | 
|  | 36 |  |  |  |  | 129 |  | 
|  | 36 |  |  |  |  | 18902 |  | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | =head2 _new | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | Internal Method to create the Web object. | 
| 30 |  |  |  |  |  |  | This method is not ment to be called external. | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =over | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =item * Parameter: $api_wrapper - ovh api wrapper object, $module - root object | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | =item * Return: L<Webservice::OVH::Order> | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =item * Synopsis: Webservice::OVH::Order->_new($ovh_api_wrapper, $self); | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | =back | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =cut | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | sub _new { | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 0 |  |  | 0 |  |  | my ( $class, %params ) = @_; | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 0 | 0 |  |  |  |  | die "Missing module"  unless $params{module}; | 
| 49 | 0 | 0 |  |  |  |  | die "Missing wrapper" unless $params{wrapper}; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 0 |  |  |  |  |  | my $module      = $params{module}; | 
| 52 | 0 |  |  |  |  |  | my $api_wrapper = $params{wrapper}; | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 0 |  |  |  |  |  | my $self = bless { _module => $module, _api_wrapper => $api_wrapper, _services => {}, _aviable_services => [], }, $class; | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 0 |  |  |  |  |  | return $self; | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =head2 service_exists | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | Returns 1 if service is available for the connected account, 0 if not. | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | =over | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =item * Parameter: $service_name - service name, $no_recheck - (optional)only for internal usage | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | =item * Return: VALUE | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | =item * Synopsis: print "mydomain.com exists" if $ovh->hosting->web->service_exists("mydomain.com"); | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =back | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =cut | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | sub service_exists { | 
| 76 |  |  |  |  |  |  |  | 
| 77 | 0 |  |  | 0 | 1 |  | my ( $self, $service_name, $no_recheck ) = @_; | 
| 78 |  |  |  |  |  |  |  | 
| 79 | 0 | 0 |  |  |  |  | if ( !$no_recheck ) { | 
| 80 |  |  |  |  |  |  |  | 
| 81 | 0 |  |  |  |  |  | my $api = $self->{_api_wrapper}; | 
| 82 | 0 |  |  |  |  |  | my $response = $api->rawCall( method => 'get', path => "/hosting/web", noSignature => 0 ); | 
| 83 | 0 | 0 |  |  |  |  | croak $response->error if $response->error; | 
| 84 |  |  |  |  |  |  |  | 
| 85 | 0 |  |  |  |  |  | my $list = $response->content; | 
| 86 |  |  |  |  |  |  |  | 
| 87 | 0 | 0 |  |  |  |  | return ( grep { $_ eq $service_name } @$list ) ? 1 : 0; | 
|  | 0 |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | } else { | 
| 90 |  |  |  |  |  |  |  | 
| 91 | 0 |  |  |  |  |  | my $list = $self->{_aviable_services}; | 
| 92 |  |  |  |  |  |  |  | 
| 93 | 0 | 0 |  |  |  |  | return ( grep { $_ eq $service_name } @$list ) ? 1 : 0; | 
|  | 0 |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | } | 
| 95 |  |  |  |  |  |  | } | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | =head2 services | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | Produces an array of all available services that are connected to the used account. | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | =over | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | =item * Return: ARRAY | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | =item * Synopsis: my $services = $ovh->order->services(); | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | =back | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | =cut | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | sub services { | 
| 112 |  |  |  |  |  |  |  | 
| 113 | 0 |  |  | 0 | 1 |  | my ($self) = @_; | 
| 114 |  |  |  |  |  |  |  | 
| 115 | 0 |  |  |  |  |  | my $api = $self->{_api_wrapper}; | 
| 116 | 0 |  |  |  |  |  | my $response = $api->rawCall( method => 'get', path => "/hosting/web", noSignature => 0 ); | 
| 117 | 0 | 0 |  |  |  |  | croak $response->error if $response->error; | 
| 118 |  |  |  |  |  |  |  | 
| 119 | 0 |  |  |  |  |  | my $service_array = $response->content; | 
| 120 | 0 |  |  |  |  |  | my $services      = []; | 
| 121 | 0 |  |  |  |  |  | $self->{_aviable_services} = $service_array; | 
| 122 |  |  |  |  |  |  |  | 
| 123 | 0 |  |  |  |  |  | foreach my $service_name (@$service_array) { | 
| 124 | 0 | 0 |  |  |  |  | if ( $self->service_exists( $service_name, 1 ) ) { | 
| 125 | 0 |  | 0 |  |  |  | my $service = $self->{_services}{$service_name} = $self->{_services}{$service_name} || Webservice::OVH::Hosting::Web::Service->_new( wrapper => $api, id => $service_name, module => $self->{_module} ); | 
| 126 | 0 |  |  |  |  |  | push @$services, $service; | 
| 127 |  |  |  |  |  |  | } | 
| 128 |  |  |  |  |  |  | } | 
| 129 |  |  |  |  |  |  |  | 
| 130 | 0 |  |  |  |  |  | return $services; | 
| 131 |  |  |  |  |  |  | } | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | =head2 service | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | Returns a single service by name | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | =over | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | =item * Parameter: $service_name - service name | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | =item * Return: L<Webservice::OVH::Hosting::Web::Service> | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | =item * Synopsis: my $service = $ovh->hosting->web->service("mydomain.com"); | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | =back | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | =cut | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | sub service { | 
| 150 |  |  |  |  |  |  |  | 
| 151 | 0 |  |  | 0 | 1 |  | my ( $self, $service_name ) = @_; | 
| 152 |  |  |  |  |  |  |  | 
| 153 | 0 | 0 |  |  |  |  | if ( $self->service_exists($service_name) ) { | 
| 154 |  |  |  |  |  |  |  | 
| 155 | 0 |  |  |  |  |  | my $api = $self->{_api_wrapper}; | 
| 156 | 0 |  | 0 |  |  |  | my $service = $self->{_services}{$service_name} = $self->{_services}{$service_name} || Webservice::OVH::Hosting::Web::Service->_new( wrapper => $api, id => $service_name, module => $self->{_module} ); | 
| 157 |  |  |  |  |  |  |  | 
| 158 | 0 |  |  |  |  |  | return $service; | 
| 159 |  |  |  |  |  |  | } else { | 
| 160 |  |  |  |  |  |  |  | 
| 161 | 0 |  |  |  |  |  | carp "Service $service_name doesn't exists"; | 
| 162 | 0 |  |  |  |  |  | return undef; | 
| 163 |  |  |  |  |  |  | } | 
| 164 |  |  |  |  |  |  | } | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | 1; |