lib/WWW/Hetzner/CLI/Cmd/Record/Cmd/Create.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 52 CC 3 SCAR 18.4
CC
3
Cov
0%
execute
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 6.3
1 package WWW::Hetzner::CLI::Cmd::Record::Cmd::Create;
2 # ABSTRACT: Create a DNS record
3  
4 our $VERSION = '0.100';
5  
6 use Moo;
7 use MooX::Cmd;
8 use MooX::Options usage_string => 'USAGE: hcloud.pl record create --zone <zone-id> --name <name> --type <type> --value <value>';
9 use JSON::MaybeXS qw(encode_json);
10  
11 option zone => (
12 is => 'ro',
13 format => 's',
14 short => 'z',
15 required => 1,
16 doc => 'Zone ID',
17 );
18  
19 option name => (
20 is => 'ro',
21 format => 's',
22 short => 'n',
23 required => 1,
24 doc => 'Record name (e.g., www, @, mail)',
25 );
26  
27 option type => (
28 is => 'ro',
29 format => 's',
30 short => 't',
31 required => 1,
32 doc => 'Record type (A, AAAA, CNAME, MX, TXT, etc.)',
33 );
34  
35 option value => (
36 is => 'ro',
37 format => 's@',
38 short => 'v',
39 required => 1,
40 autosplit => ',',
41 doc => 'Record value(s), comma-separated for multiple',
42 );
43  
44 option ttl => (
45 is => 'ro',
46 format => 'i',
47 doc => 'TTL in seconds',
48 );
49  
50 sub execute {
51 my ($self, $args, $chain) = @_;
52  
53 my $main = $chain->[0];
54 my $cloud = $main->cloud;
55  
56 my @records = map { { value => $_ } } @{$self->value};
57  
58 my %params = (
59 name => $self->name,
60 type => uc($self->type),
61 records => \@records,
62 );
63 $params{ttl} = $self->ttl if $self->ttl;
64  
65 my $rrsets = $cloud->zones->rrsets($self->zone);
66 my $record = $rrsets->create(%params);
67  
68 if ($main->output eq 'json') {
69 print encode_json($record->data), "\n";
70 return;
71 }
72  
73 print "Record created:\n";
74 printf " Name: %s\n", $record->name;
75 printf " Type: %s\n", $record->type;
76 printf " TTL: %s\n", $record->ttl // '-';
77 print " Values:\n";
78 for my $v (@{$record->records}) {
79 print " - $v->{value}\n";
80 }
81 }
82  
83 1;
84  
85 __END__