lib/WWW/Hetzner/Cloud/API/RRSets.pm

filter: Statementstmt 100% 75 / 75 Branchbran 95.4% 42 / 44 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 17 / 17 Podpod 100% 10 / 10 totaltotal 96.0% 146 / 152 CC 25 SCAR 11.6
CC
25
Cov
97%
update
5.0
create
5.0
add_mx
4.0
CRAP 3.2
« lib/WWW/Hetzner/Cloud/SSHKey.pm ↑ Summary lib/WWW/Hetzner/Cloud/PlacementGroup.pm »
1 package WWW::Hetzner::Cloud::API::RRSets;
2 # ABSTRACT: Hetzner Cloud DNS RRSets (Records) API
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 WWW::Hetzner::Cloud::RRSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 25 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 25 has client => (
13 is => 'ro',
14 required => 1,
15 weak_ref => 1,
16 );
17  
18 25 has zone_id => (
19 is => 'ro',
20 required => 1,
21 );
22  
23 sub _wrap {
24 25 ▶ my ($self, $data) = @_;
Subroutine _wrap: called CC=1 SCAR=0.0
25 25 return WWW::Hetzner::Cloud::RRSet->new(
26 client => $self->client,
27 zone_id => $self->zone_id,
28 %$data,
29 );
30 }
31  
32 sub _wrap_list {
33 3 ▶ my ($self, $list) = @_;
Subroutine _wrap_list: called CC=1 SCAR=0.0
34 3 return [ map { $self->_wrap($_) } @$list ];
35 }
36  
37 sub _base_path {
38 14 ▶ my ($self) = @_;
Subroutine _base_path: called CC=1 SCAR=0.0
39 14 return "/zones/" . $self->zone_id . "/rrsets";
40 }
41  
42  
43 sub list {
44 3 ▶ my ($self, %params) = @_;
Subroutine list: called CC=2 SCAR=7.1
Pod documented
45  
46 3 my $result = $self->client->get($self->_base_path, params => \%params);
47 3 ▶ return $self->_wrap_list($result->{rrsets} // []);
Condition50%1/2
$result->{"rrsets"} // []
l!l
30
MC/DC0%0/1
$result->{"rrsets"} // []
$result->{"rrsets"}
Truth table50%1/2
A
A= $result->{"rrsets"}
Aresult
11
00
48 }
49  
50  
51 sub get {
52 3 ▶ my ($self, $name, $type) = @_;
Subroutine get: called CC=3 SCAR=11.0
Pod documented
53 3 ▶ croak "Record name required" unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 2 3
54 2 ▶ croak "Record type required" unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 1 1 2
55  
56 1 my $path = $self->_base_path . "/$name/$type";
57 1 my $result = $self->client->get($path);
58 1 return $self->_wrap($result->{rrset});
59 }
60  
61  
62 sub create {
63 11 ▶ my ($self, %params) = @_;
Subroutine create: called CC=5 SCAR=16.1
Pod documented
64  
65 11 ▶ croak "name required" unless $params{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"name"} 1 10 11
66 10 ▶ croak "type required" unless $params{type};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"type"} 1 9 10
67 9 ▶ croak "records required" unless $params{records};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"records"} 1 8 9
68  
69 my $body = {
70 name => $params{name},
71 type => $params{type},
72 records => $params{records},
73 8 };
74  
75 8 ▶ $body->{ttl} = $params{ttl} if $params{ttl};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"ttl"} 2 6 8
76  
77 8 my $result = $self->client->post($self->_base_path, $body);
78 8 return $self->_wrap($result->{rrset});
79 }
80  
81  
82 sub update {
83 3 ▶ my ($self, $name, $type, %params) = @_;
Subroutine update: called CC=5 SCAR=16.2
Pod documented
84 3 ▶ croak "Record name required" unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 2 3
85 2 ▶ croak "Record type required" unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 1 1 2
86  
87 1 my $body = {};
88 1 ▶ $body->{ttl} = $params{ttl} if exists $params{ttl};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"ttl"} 1 0 1
89 1 ▶ $body->{records} = $params{records} if exists $params{records};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"records"} 1 0 1
90  
91 1 my $path = $self->_base_path . "/$name/$type";
92 1 my $result = $self->client->put($path, $body);
93 1 return $self->_wrap($result->{rrset});
94 }
95  
96  
97 sub delete {
98 3 ▶ my ($self, $name, $type) = @_;
Subroutine delete: called CC=3 SCAR=11.0
Pod documented
99 3 ▶ croak "Record name required" unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 2 3
100 2 ▶ croak "Record type required" unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 1 1 2
101  
102 1 my $path = $self->_base_path . "/$name/$type";
103 1 return $self->client->delete($path);
104 }
105  
106  
107 sub add_a {
108 4 ▶ my ($self, $name, $ip, %opts) = @_;
Subroutine add_a: called CC=3 SCAR=11.0
Pod documented
109 4 ▶ croak "name required" unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 3 4
110 3 ▶ croak "IP address required" unless $ip;
Branch: 1 branch
BranchTrueFalseTotal
unless $ip 1 2 3
111  
112 2 return $self->create(
113 name => $name,
114 type => 'A',
115 records => [{ value => $ip }],
116 %opts,
117 );
118 }
119  
120  
121 sub add_aaaa {
122 3 ▶ my ($self, $name, $ip, %opts) = @_;
Subroutine add_aaaa: called CC=3 SCAR=11.0
Pod documented
123 3 ▶ croak "name required" unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 2 3
124 2 ▶ croak "IPv6 address required" unless $ip;
Branch: 1 branch
BranchTrueFalseTotal
unless $ip 1 1 2
125  
126 1 return $self->create(
127 name => $name,
128 type => 'AAAA',
129 records => [{ value => $ip }],
130 %opts,
131 );
132 }
133  
134  
135 sub add_cname {
136 3 ▶ my ($self, $name, $target, %opts) = @_;
Subroutine add_cname: called CC=3 SCAR=11.0
Pod documented
137 3 ▶ croak "name required" unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 2 3
138 2 ▶ croak "target required" unless $target;
Branch: 1 branch
BranchTrueFalseTotal
unless $target 1 1 2
139  
140 1 return $self->create(
141 name => $name,
142 type => 'CNAME',
143 records => [{ value => $target }],
144 %opts,
145 );
146 }
147  
148  
149 sub add_mx {
150 3 ▶ my ($self, $name, $mailserver, $priority, %opts) = @_;
Subroutine add_mx: called CC=4 SCAR=13.9
Pod documented
151 3 ▶ croak "name required" unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 2 3
152 2 ▶ croak "mailserver required" unless $mailserver;
Branch: 1 branch
BranchTrueFalseTotal
unless $mailserver 1 1 2
153 1 ▶ $priority //= 10;
Condition50%1/2
$priority //= 10
l!l
10
MC/DC0%0/1
$priority //= 10
$priority
Truth table50%1/2
A
A= $priority
Aresult
11
00
154  
155 1 return $self->create(
156 name => $name,
157 type => 'MX',
158 records => [{ value => "$priority $mailserver" }],
159 %opts,
160 );
161 }
162  
163  
164 sub add_txt {
165 3 ▶ my ($self, $name, $value, %opts) = @_;
Subroutine add_txt: called CC=3 SCAR=11.0
Pod documented
166 3 ▶ croak "name required" unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 2 3
167 2 ▶ croak "value required" unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 1 1 2
168  
169 1 return $self->create(
170 name => $name,
171 type => 'TXT',
172 records => [{ value => $value }],
173 %opts,
174 );
175 }
176  
177  
178 25 1;
179  
180 __END__
« lib/WWW/Hetzner/Cloud/SSHKey.pm ↑ Summary lib/WWW/Hetzner/Cloud/PlacementGroup.pm »