| 1 | package Webservice::OVH::Email::Domain; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | =encoding utf-8 | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | Webservice::OVH::Email::Domain | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | use Webservice::OVH; | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | my $ovh = Webservice::OVH->new_from_json("credentials.json"); | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | my $email_domains = $ovh->email->domain->domains; | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | foreach $email_domain (@$email_domains) { | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | $email_domain->name; | ||||||||||||||||||||
| 20 | } | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | Provides access to email domain objects. | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | =head1 METHODS | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 36 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | 36 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | 36 | ▶ | use Carp qw{ carp croak }; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 36 | our $VERSION = 0.48; | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 36 | ▶ | use Webservice::OVH::Email::Domain::Domain; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =head2 _new | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | Internal Method to create the domain object. | ||||||||||||||||||||
| 41 | This method is not ment to be called external. | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | =over | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | =item * Parameter: $api_wrapper - ovh api wrapper object, $module - root object | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | =item * Return: L<Webservice::OVH::Email::Domain> | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | =item * Synopsis: Webservice::OVH::Email::Domain->_new($ovh_api_wrapper, $zone_name, $module); | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | =back | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | =cut | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | ▶ | sub _new { | ||||||||||||||||||
|
Subroutine
_new: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | my ( $class, %params ) = @_; | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | ▶ | die "Missing module" unless $params{module}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 0 | ▶ | die "Missing wrapper" unless $params{wrapper}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 0 | my $module = $params{module}; | |||||||||||||||||||
| 63 | 0 | my $api_wrapper = $params{wrapper}; | |||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 0 | my $self = bless { _module => $module, _api_wrapper => $api_wrapper, _domains => {}, _aviable_domains => [] }, $class; | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 0 | my $api = $self->{_api_wrapper}; | |||||||||||||||||||
| 68 | 0 | my $response = $api->rawCall( method => 'get', path => "/email/domain/", noSignature => 0 ); | |||||||||||||||||||
| 69 | 0 | ▶ | croak $response->error if $response->error; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | $self->{_aviable_domains} = $response->content; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 0 | return $self; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | =head2 domain_exists | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | Returns 1 if email-domain is available for the connected account, 0 if not. | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | =over | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | =item * Parameter: $domain - (required)Domain name, $no_recheck - (optional)only for internal usage | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | =item * Return: VALUE | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | =item * Synopsis: print "mydomain.com exists" if $ovh->email->domain->domain_exists("mydomain.com"); | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | =back | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | =cut | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 0 | ▶ | sub domain_exists { | ||||||||||||||||||
|
Subroutine
domain_exists: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 0 | my ( $self, $domain, $no_recheck ) = @_; | |||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 0 | ▶ | if ( !$no_recheck ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 0 | my $api = $self->{_api_wrapper}; | |||||||||||||||||||
| 99 | 0 | my $response = $api->rawCall( method => 'get', path => "/email/domain/", noSignature => 0 ); | |||||||||||||||||||
| 100 | 0 | ▶ | croak $response->error if $response->error; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 0 | $self->{_aviable_domains} = $response->content; | |||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 0 | my $list = $response->content; | |||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 0 | ▶ | return ( grep { $_ eq $domain } @$list ) ? 1 : 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | } else { | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 0 | my $list = $self->{_aviable_domains}; | |||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 0 | ▶ | return ( grep { $_ eq $domain } @$list ) ? 1 : 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | } | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | =head2 domains | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | Produces an array of all available email-domains that are connected to the used account. | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | =over | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | =item * Return: L<ARRAY> | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | =item * Synopsis: my $domains = $ovh->email->domain->domains(); | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =back | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | =cut | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | 0 | ▶ | sub domains { | ||||||||||||||||||
|
Subroutine
domains: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 0 | my ($self) = @_; | |||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | 0 | my $api = $self->{_api_wrapper}; | |||||||||||||||||||
| 135 | 0 | my $response = $api->rawCall( method => 'get', path => "/email/domain/", noSignature => 0 ); | |||||||||||||||||||
| 136 | 0 | ▶ | croak $response->error if $response->error; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 0 | my $domain_array = $response->content; | |||||||||||||||||||
| 139 | 0 | my $domains = []; | |||||||||||||||||||
| 140 | 0 | $self->{_aviable_domains} = $domain_array; | |||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | 0 | foreach my $domain (@$domain_array) { | |||||||||||||||||||
| 143 | 0 | ▶ | if ( $self->domain_exists( $domain, 1 ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 144 | 0 | ▶ | my $domain = $self->{_domains}{$domain} = $self->{_domains}{$domain} || Webservice::OVH::Email::Domain::Domain->_new( wrapper => $api, id => $domain, module => $self->{_module} ); | ||||||||||||||||||
|
Condition0%0/3
$self->{'_domains'}{$domain} || 'Webservice::OVH::Email::Domain::Domain'->_new('wrapper', $api, 'id', $domain, 'module', $self->{'_module'})
MC/DC0%0/2
$self->{'_domains'}{$domain} || 'Webservice::OVH::Email::Domain::Domain'->_new('wrapper', $api, 'id', $domain, 'module', $self->{'_module'})
$self->{'_domains'}{$domain}
'Webservice::OVH::Email::Domain::Domain'->_new('wrapper', $api, 'id', $domain, 'module', $self->{'_module'})
Truth table0%0/3
A || B
A= $self->{'_domains'}{$domain}B= 'Webservice::OVH::Email::Domain::Domain'->_new('wrapper', $api, 'id', $domain, 'module', $self->{'_module'})
| |||||||||||||||||||||
| 145 | 0 | push @$domains, $domain; | |||||||||||||||||||
| 146 | } | ||||||||||||||||||||
| 147 | } | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | 0 | return $domains; | |||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | } | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | =head2 domain | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | Returns a single email-domains by name | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | =over | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | =item * Parameter: $domain - domain name | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | =item * Return: L<Webservice::OVH::Email::Domains::Domain> | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | =item * Synopsis: my $email_domain = $ovh->email->domain->domain("mydomain.com"); | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | =back | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | =cut | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | 0 | ▶ | sub domain { | ||||||||||||||||||
|
Subroutine
domain: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | 0 | my ( $self, $domain ) = @_; | |||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | 0 | ▶ | if ( $self->domain_exists($domain) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | 0 | my $api = $self->{_api_wrapper}; | |||||||||||||||||||
| 176 | 0 | ▶ | my $domain = $self->{_domains}{$domain} = $self->{_domains}{$domain} || Webservice::OVH::Email::Domain::Domain->_new( wrapper => $api, id => $domain, module => $self->{_module} ); | ||||||||||||||||||
|
Condition0%0/3
$self->{'_domains'}{$domain} || 'Webservice::OVH::Email::Domain::Domain'->_new('wrapper', $api, 'id', $domain, 'module', $self->{'_module'})
MC/DC0%0/2
$self->{'_domains'}{$domain} || 'Webservice::OVH::Email::Domain::Domain'->_new('wrapper', $api, 'id', $domain, 'module', $self->{'_module'})
$self->{'_domains'}{$domain}
'Webservice::OVH::Email::Domain::Domain'->_new('wrapper', $api, 'id', $domain, 'module', $self->{'_module'})
Truth table0%0/3
A || B
A= $self->{'_domains'}{$domain}B= 'Webservice::OVH::Email::Domain::Domain'->_new('wrapper', $api, 'id', $domain, 'module', $self->{'_module'})
| |||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | 0 | return $domain; | |||||||||||||||||||
| 179 | } else { | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | 0 | carp "Domain $domain doesn't exists"; | |||||||||||||||||||
| 182 | 0 | return undef; | |||||||||||||||||||
| 183 | } | ||||||||||||||||||||
| 184 | } | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | 36 | 1; | |||||||||||||||||||