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