| 1 | package WWW::Hetzner::Cloud::PrimaryIP; | ||||||||||||
| 2 | # ABSTRACT: Hetzner Cloud Primary IP object | ||||||||||||
| 3 | |||||||||||||
| 4 | 56 | our $VERSION = '0.101'; | |||||||||||
| 5 | |||||||||||||
| 6 | 56 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 56 | with 'WWW::Hetzner::Role::HasAction'; | |||||||||||
| 8 | 56 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 56 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | |||||||||||||
| 12 | 56 | has _client => ( | |||||||||||
| 13 | is => 'ro', | ||||||||||||
| 14 | required => 1, | ||||||||||||
| 15 | weak_ref => 1, | ||||||||||||
| 16 | init_arg => 'client', | ||||||||||||
| 17 | ); | ||||||||||||
| 18 | |||||||||||||
| 19 | 56 | has id => ( is => 'ro' ); | |||||||||||
| 20 | |||||||||||||
| 21 | |||||||||||||
| 22 | 56 | has name => ( is => 'rw' ); | |||||||||||
| 23 | |||||||||||||
| 24 | |||||||||||||
| 25 | 56 | has ip => ( is => 'ro' ); | |||||||||||
| 26 | |||||||||||||
| 27 | |||||||||||||
| 28 | 56 | has type => ( is => 'ro' ); | |||||||||||
| 29 | |||||||||||||
| 30 | |||||||||||||
| 31 | 56 | has assignee_id => ( is => 'ro' ); | |||||||||||
| 32 | |||||||||||||
| 33 | |||||||||||||
| 34 | 56 | has assignee_type => ( is => 'ro' ); | |||||||||||
| 35 | |||||||||||||
| 36 | |||||||||||||
| 37 | 0 | ▶ | has datacenter => ( is => 'ro', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 38 | |||||||||||||
| 39 | |||||||||||||
| 40 | 0 | ▶ | has dns_ptr => ( is => 'ro', default => sub { [] } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 41 | |||||||||||||
| 42 | |||||||||||||
| 43 | 56 | has auto_delete => ( is => 'rw' ); | |||||||||||
| 44 | |||||||||||||
| 45 | |||||||||||||
| 46 | 56 | has blocked => ( is => 'ro' ); | |||||||||||
| 47 | |||||||||||||
| 48 | |||||||||||||
| 49 | 0 | ▶ | has labels => ( is => 'rw', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 50 | |||||||||||||
| 51 | |||||||||||||
| 52 | 0 | ▶ | has protection => ( is => 'ro', default => sub { {} } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 53 | |||||||||||||
| 54 | |||||||||||||
| 55 | 56 | has created => ( is => 'ro' ); | |||||||||||
| 56 | |||||||||||||
| 57 | |||||||||||||
| 58 | # Convenience | ||||||||||||
| 59 | 2 | ▶ | sub is_assigned { defined shift->assignee_id } | ||||||||||
|
Subroutine
is_assigned: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 60 | |||||||||||||
| 61 | |||||||||||||
| 62 | 3 | ▶ | sub datacenter_name { shift->datacenter->{name} } | ||||||||||
|
Subroutine
datacenter_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 63 | |||||||||||||
| 64 | |||||||||||||
| 65 | # Actions | ||||||||||||
| 66 | 0 | ▶ | sub update { | ||||||||||
|
Subroutine
update: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 67 | 0 | my ($self) = @_; | |||||||||||
| 68 | 0 | ▶ | croak "Cannot update primary IP without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 69 | |||||||||||||
| 70 | 0 | my $result = $self->_client->put("/primary_ips/" . $self->id, { | |||||||||||
| 71 | name => $self->name, | ||||||||||||
| 72 | auto_delete => $self->auto_delete, | ||||||||||||
| 73 | labels => $self->labels, | ||||||||||||
| 74 | }); | ||||||||||||
| 75 | 0 | return $self; | |||||||||||
| 76 | } | ||||||||||||
| 77 | |||||||||||||
| 78 | |||||||||||||
| 79 | 0 | ▶ | sub delete { | ||||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 80 | 0 | my ($self) = @_; | |||||||||||
| 81 | 0 | ▶ | croak "Cannot delete primary IP without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | |||||||||||||
| 83 | 0 | $self->_client->delete("/primary_ips/" . $self->id); | |||||||||||
| 84 | 0 | return 1; | |||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | |||||||||||||
| 88 | 1 | ▶ | sub assign { | ||||||||||
|
Subroutine
assign: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||
| 89 | 1 | my ($self, $assignee_id, $assignee_type) = @_; | |||||||||||
| 90 | 1 | ▶ | croak "Cannot assign primary IP without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 91 | 1 | ▶ | croak "Assignee ID required" unless $assignee_id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 92 | 1 | ▶ | $assignee_type //= 'server'; | ||||||||||
|
Condition50%1/2
$assignee_type //= "server"
MC/DC0%0/1
$assignee_type //= "server"
$assignee_type
Truth table50%1/2
A
A= $assignee_type
| |||||||||||||
| 93 | |||||||||||||
| 94 | 1 | return $self->_client->primary_ips->assign($self->id, $assignee_id, $assignee_type); | |||||||||||
| 95 | } | ||||||||||||
| 96 | |||||||||||||
| 97 | |||||||||||||
| 98 | 1 | ▶ | sub unassign { | ||||||||||
|
Subroutine
unassign: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 99 | 1 | my ($self) = @_; | |||||||||||
| 100 | 1 | ▶ | croak "Cannot unassign primary IP without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 101 | |||||||||||||
| 102 | 1 | return $self->_client->primary_ips->unassign($self->id); | |||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | |||||||||||||
| 106 | 1 | ▶ | sub change_dns_ptr { | ||||||||||
|
Subroutine
change_dns_ptr: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||
| 107 | 1 | my ($self, $ip, $dns_ptr) = @_; | |||||||||||
| 108 | 1 | ▶ | croak "Cannot modify primary IP without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 109 | 1 | ▶ | croak "IP required" unless $ip; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 110 | 1 | ▶ | croak "dns_ptr required" unless defined $dns_ptr; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 111 | |||||||||||||
| 112 | 1 | return $self->_client->primary_ips->change_dns_ptr($self->id, $ip, $dns_ptr); | |||||||||||
| 113 | } | ||||||||||||
| 114 | |||||||||||||
| 115 | |||||||||||||
| 116 | 0 | ▶ | sub refresh { | ||||||||||
|
Subroutine
refresh: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 117 | 0 | my ($self) = @_; | |||||||||||
| 118 | 0 | ▶ | croak "Cannot refresh primary IP without ID" unless $self->id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 119 | |||||||||||||
| 120 | 0 | my $result = $self->_client->get("/primary_ips/" . $self->id); | |||||||||||
| 121 | 0 | my $data = $result->{primary_ip}; | |||||||||||
| 122 | |||||||||||||
| 123 | 0 | $self->name($data->{name}); | |||||||||||
| 124 | 0 | $self->auto_delete($data->{auto_delete}); | |||||||||||
| 125 | 0 | ▶ | $self->labels($data->{labels} // {}); | ||||||||||
|
Condition0%0/2
$data->{"labels"} // {}
MC/DC0%0/1
$data->{"labels"} // {}
$data->{"labels"}
Truth table0%0/2
A
A= $data->{"labels"}
| |||||||||||||
| 126 | |||||||||||||
| 127 | 0 | return $self; | |||||||||||
| 128 | } | ||||||||||||
| 129 | |||||||||||||
| 130 | |||||||||||||
| 131 | 1 | ▶ | sub data { | ||||||||||
|
Subroutine
data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 132 | 1 | my ($self) = @_; | |||||||||||
| 133 | return { | ||||||||||||
| 134 | 1 | id => $self->id, | |||||||||||
| 135 | name => $self->name, | ||||||||||||
| 136 | ip => $self->ip, | ||||||||||||
| 137 | type => $self->type, | ||||||||||||
| 138 | assignee_id => $self->assignee_id, | ||||||||||||
| 139 | assignee_type => $self->assignee_type, | ||||||||||||
| 140 | datacenter => $self->datacenter, | ||||||||||||
| 141 | dns_ptr => $self->dns_ptr, | ||||||||||||
| 142 | auto_delete => $self->auto_delete, | ||||||||||||
| 143 | blocked => $self->blocked, | ||||||||||||
| 144 | labels => $self->labels, | ||||||||||||
| 145 | protection => $self->protection, | ||||||||||||
| 146 | created => $self->created, | ||||||||||||
| 147 | }; | ||||||||||||
| 148 | } | ||||||||||||
| 149 | |||||||||||||
| 150 | |||||||||||||
| 151 | |||||||||||||
| 152 | 56 | 1. | |||||||||||
| 153 | |||||||||||||
| 154 | __END__ | ||||||||||||