lib/WWW/Hetzner/CLI/Cmd/Record/Cmd/List.pm

filter: Statementstmt 87.1% 34 / 39 Branchbran 50.0% 4 / 8 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 78.5% 44 / 56 CC 7 SCAR 17.5
CC
7
Cov
80%
execute
8.5
BEGIN
1.0
BEGIN
1.0
CRAP 5.8
« lib/WWW/Hetzner/Cloud/API/Networks.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/Server/Cmd/Rescue.pm »
1 package WWW::Hetzner::CLI::Cmd::Record::Cmd::List;
2 # ABSTRACT: List DNS records
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 list --zone <zone-id> [--type <type>] [--name <name>]';
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 type => (
20 is => 'ro',
21 format => 's',
22 short => 't',
23 doc => 'Filter by record type (A, AAAA, CNAME, MX, TXT, etc.)',
24 );
25  
26 1 option name => (
27 is => 'ro',
28 format => 's',
29 short => 'n',
30 doc => 'Filter by record name',
31 );
32  
33 1 ▶sub execute {
Subroutine execute: called CC=7 SCAR=21.4
Pod undocumented
34 1 my ($self, $args, $chain) = @_;
35  
36 1 my $main = $chain->[0];
37 1 my $cloud = $main->cloud;
38  
39 1 my %params;
40 1 ▶ $params{type} = $self->type if $self->type;
Branch: 1 branch
BranchTrueFalseTotal
if $self->type 0 1 1
41 1 ▶ $params{name} = $self->name if $self->name;
Branch: 1 branch
BranchTrueFalseTotal
if $self->name 0 1 1
42  
43 1 my $rrsets = $cloud->zones->rrsets($self->zone);
44 1 my $records = $rrsets->list_all(%params);
45  
46 1 ▶ if ($main->output eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($main->output eq "json") 0 1 1
47 0 print encode_json([map { $_->data } @$records]), "\n";
48 0 return;
49 }
50  
51 1 ▶ if (!@$records) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$records) 0 1 1
52 0 print "No records found.\n";
53 0 return;
54 }
55  
56 1 printf "%-25s %-8s %-8s %s\n",
57 'NAME', 'TYPE', 'TTL', 'VALUES';
58 1 print "-" x 80, "\n";
59  
60 1 for my $r (@$records) {
61 5 my $values = join(', ', map { $_->{value} } @{$r->records});
62 5 ▶ printf "%-25s %-8s %-8s %s\n",
Condition50%1/2
$r->ttl // "-"
l!l
50
MC/DC0%0/1
$r->ttl // "-"
$r->ttl
Truth table50%1/2
A
A= $r->ttl
Aresult
11
00
63 $r->name,
64 $r->type,
65 $r->ttl // '-',
66 $values;
67 }
68 }
69  
70 1 1;
71  
72 __END__
« lib/WWW/Hetzner/Cloud/API/Networks.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/Server/Cmd/Rescue.pm »