| 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 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 36 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | 36 | ▶ | use Carp qw{ carp croak }; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 36 | our $VERSION = 0.48; | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 36 | ▶ | use Webservice::OVH::Hosting::Web::Service; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 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 | 0 | ▶ | sub _new { | ||||||||||||||||||
|
Subroutine
_new: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 0 | my ( $class, %params ) = @_; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | ▶ | die "Missing module" unless $params{module}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 0 | ▶ | die "Missing wrapper" unless $params{wrapper}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | 0 | ▶ | sub service_exists { | ||||||||||||||||||
|
Subroutine
service_exists: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 0 | my ( $self, $service_name, $no_recheck ) = @_; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | ▶ | if ( !$no_recheck ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 0 | my $api = $self->{_api_wrapper}; | |||||||||||||||||||
| 82 | 0 | my $response = $api->rawCall( method => 'get', path => "/hosting/web", noSignature => 0 ); | |||||||||||||||||||
| 83 | 0 | ▶ | croak $response->error if $response->error; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | my $list = $response->content; | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 0 | ▶ | return ( grep { $_ eq $service_name } @$list ) ? 1 : 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | } else { | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | my $list = $self->{_aviable_services}; | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | ▶ | return ( grep { $_ eq $service_name } @$list ) ? 1 : 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | 0 | ▶ | sub services { | ||||||||||||||||||
|
Subroutine
services: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 0 | 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 | ▶ | croak $response->error if $response->error; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | ▶ | if ( $self->service_exists( $service_name, 1 ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 125 | 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} ); | ||||||||||||||||||
|
Condition0%0/3
$self->{'_services'}{$service_name} || 'Webservice::OVH::Hosting::Web::Service'->_new('wrapper', $api, 'id', $service_name, 'module', $self->{'_module'})
MC/DC0%0/2
$self->{'_services'}{$service_name} || 'Webservice::OVH::Hosting::Web::Service'->_new('wrapper', $api, 'id', $service_name, 'module', $self->{'_module'})
$self->{'_services'}{$service_name}
'Webservice::OVH::Hosting::Web::Service'->_new('wrapper', $api, 'id', $service_name, 'module', $self->{'_module'})
Truth table0%0/3
A || B
A= $self->{'_services'}{$service_name}B= '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 | 0 | ▶ | sub service { | ||||||||||||||||||
|
Subroutine
service: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | 0 | my ( $self, $service_name ) = @_; | |||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 0 | ▶ | if ( $self->service_exists($service_name) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | 0 | my $api = $self->{_api_wrapper}; | |||||||||||||||||||
| 156 | 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} ); | ||||||||||||||||||
|
Condition0%0/3
$self->{'_services'}{$service_name} || 'Webservice::OVH::Hosting::Web::Service'->_new('wrapper', $api, 'id', $service_name, 'module', $self->{'_module'})
MC/DC0%0/2
$self->{'_services'}{$service_name} || 'Webservice::OVH::Hosting::Web::Service'->_new('wrapper', $api, 'id', $service_name, 'module', $self->{'_module'})
$self->{'_services'}{$service_name}
'Webservice::OVH::Hosting::Web::Service'->_new('wrapper', $api, 'id', $service_name, 'module', $self->{'_module'})
Truth table0%0/3
A || B
A= $self->{'_services'}{$service_name}B= '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 | 36 | 1; | |||||||||||||||||||