| 1 | package WWW::Hetzner::CLI::Cmd::Record::Cmd::Create; | ||||||||||||
| 2 | # ABSTRACT: Create a DNS record | ||||||||||||
| 3 | |||||||||||||
| 4 | 1 | our $VERSION = '0.102'; | |||||||||||
| 5 | |||||||||||||
| 6 | 1 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use MooX::Cmd; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 1 | ▶ | use MooX::Options usage_string => 'USAGE: hcloud.pl record create --zone <zone-id> --name <name> --type <type> --value <value>'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 1 | ▶ | use JSON::MaybeXS qw(encode_json); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 1 | option zone => ( | |||||||||||
| 12 | is => 'ro', | ||||||||||||
| 13 | format => 's', | ||||||||||||
| 14 | short => 'z', | ||||||||||||
| 15 | required => 1, | ||||||||||||
| 16 | doc => 'Zone ID', | ||||||||||||
| 17 | ); | ||||||||||||
| 18 | |||||||||||||
| 19 | 1 | 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 | 1 | 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 | 1 | 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 | 1 | option ttl => ( | |||||||||||
| 45 | is => 'ro', | ||||||||||||
| 46 | format => 'i', | ||||||||||||
| 47 | doc => 'TTL in seconds', | ||||||||||||
| 48 | ); | ||||||||||||
| 49 | |||||||||||||
| 50 | 1 | ▶ | sub execute { | ||||||||||
|
Subroutine
execute: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||
| 51 | 1 | my ($self, $args, $chain) = @_; | |||||||||||
| 52 | |||||||||||||
| 53 | 1 | my $main = $chain->[0]; | |||||||||||
| 54 | 1 | my $cloud = $main->cloud; | |||||||||||
| 55 | |||||||||||||
| 56 | 1 | my @records = map { { value => $_ } } @{$self->value}; | |||||||||||
| 57 | |||||||||||||
| 58 | 1 | my %params = ( | |||||||||||
| 59 | name => $self->name, | ||||||||||||
| 60 | type => uc($self->type), | ||||||||||||
| 61 | records => \@records, | ||||||||||||
| 62 | ); | ||||||||||||
| 63 | 1 | ▶ | $params{ttl} = $self->ttl if $self->ttl; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 64 | |||||||||||||
| 65 | 1 | my $rrsets = $cloud->zones->rrsets($self->zone); | |||||||||||
| 66 | 1 | my $record = $rrsets->create(%params); | |||||||||||
| 67 | |||||||||||||
| 68 | 1 | ▶ | if ($main->output eq 'json') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 69 | 0 | print encode_json($record->data), "\n"; | |||||||||||
| 70 | 0 | return; | |||||||||||
| 71 | } | ||||||||||||
| 72 | |||||||||||||
| 73 | 1 | print "Record created:\n"; | |||||||||||
| 74 | 1 | printf " Name: %s\n", $record->name; | |||||||||||
| 75 | 1 | printf " Type: %s\n", $record->type; | |||||||||||
| 76 | 1 | ▶ | printf " TTL: %s\n", $record->ttl // '-'; | ||||||||||
|
Condition50%1/2
$record->ttl // "-"
MC/DC0%0/1
$record->ttl // "-"
$record->ttl
Truth table50%1/2
A
A= $record->ttl
| |||||||||||||
| 77 | 1 | print " Values:\n"; | |||||||||||
| 78 | 1 | for my $v (@{$record->records}) { | |||||||||||
| 79 | 1 | print " - $v->{value}\n"; | |||||||||||
| 80 | } | ||||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | 1 | 1; | |||||||||||
| 84 | |||||||||||||
| 85 | __END__ | ||||||||||||