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