File Coverage

blib/lib/DNS/Oterica/Node/Host.pm
Criterion Covered Total %
statement 6 23 26.0
branch n/a
condition n/a
subroutine 2 5 40.0
pod 2 2 100.0
total 10 30 33.3


line stmt bran cond sub pod time code
1             package DNS::Oterica::Node::Host;
2             # ABSTRACT: a host node
3             $DNS::Oterica::Node::Host::VERSION = '0.304';
4 1     1   4 use Moose;
  1         1  
  1         6  
5             extends 'DNS::Oterica::Node';
6              
7             #pod =head1 OVERVIEW
8             #pod
9             #pod C<DNS::Oterica::Node::Host> represents an individual machine in DNS::Oterica.
10             #pod A node has interfaces (which have IP addresses) and is part of a named domain.
11             #pod
12             #pod =attr hostname
13             #pod
14             #pod This is the name of the host. B<It does not include the domain name.>
15             #pod
16             #pod =cut
17              
18             has hostname => (is => 'ro', isa => 'Str', required => 1);
19              
20             #pod =attr aliases
21             #pod
22             #pod This is an arrayref of other fully-qualified names that refer to this host.
23             #pod
24             #pod The accessor returns a list.
25             #pod
26             #pod =cut
27              
28             has aliases => (
29             isa => 'ArrayRef',
30             required => 1,
31             default => sub { [] },
32             traits => [ 'Array' ],
33             handles => {
34             aliases => 'elements',
35             },
36             );
37              
38             #pod =attr interfaces
39             #pod
40             #pod This is an arrayref of pairs, each one an IP address and a network.
41             #pod
42             #pod This attribute is pretty likely to change later.
43             #pod
44             #pod =cut
45              
46             has interfaces => (
47             isa => 'ArrayRef',
48             required => 1,
49             traits => [ 'Array' ],
50             handles => {
51             interfaces => 'elements',
52             },
53             );
54              
55             #pod =attr location
56             #pod
57             #pod The name of the network location of this host
58             #pod
59             #pod =cut
60              
61             has location => (is => 'ro', isa => 'Str', required => 1);
62              
63             #pod =attr ttl
64             #pod
65             #pod This is the default TTL for the host's A records -- it doesn't affect the TTL
66             #pod for records created by families to which the host belongs. If not provided,
67             #pod it will be unset, and the default TTL is used.
68             #pod
69             #pod =cut
70              
71             has ttl => (is => 'ro', isa => 'Int');
72              
73             #pod =method fqdn
74             #pod
75             #pod This is the fully-qualified domain name of this host.
76             #pod
77             #pod =cut
78              
79             sub fqdn {
80 0     0 1   my ($self) = @_;
81 0           sprintf '%s.%s', $self->hostname, $self->domain;
82             }
83              
84             sub _family_names {
85 0     0     my ($self) = @_;
86 0           my @all_families = $self->hub->node_families;
87 0           my @has_self = grep { grep { $_ == $self } $_->nodes } @all_families;
  0            
  0            
88              
89 0           return map { $_->name } @has_self;
  0            
90             }
91              
92             sub as_data_lines {
93 0     0 1   my ($self) = @_;
94              
95 0           my @lines = $self->rec->comment("begin host ". $self->fqdn);
96              
97 0           push @lines, $self->rec->comment(
98             " families: " . join(q{, }, $self->_family_names)
99             );
100              
101 0           push @lines, $self->rec->a_and_ptr({
102             name => $self->fqdn,
103             node => $self,
104             ttl => scalar $self->ttl,
105             });
106              
107 0           for ($self->aliases) {
108 0           push @lines, $self->rec->a({
109             name => $_,
110             node => $self,
111             ttl => scalar $self->ttl,
112             });
113             }
114              
115 0           push @lines, $self->rec->comment("end host ". $self->fqdn . "\n");
116              
117 0           return @lines;
118             }
119              
120             __PACKAGE__->meta->make_immutable;
121 1     1   5093 no Moose;
  1         2  
  1         4  
122             1;
123              
124             __END__
125              
126             =pod
127              
128             =encoding UTF-8
129              
130             =head1 NAME
131              
132             DNS::Oterica::Node::Host - a host node
133              
134             =head1 VERSION
135              
136             version 0.304
137              
138             =head1 OVERVIEW
139              
140             C<DNS::Oterica::Node::Host> represents an individual machine in DNS::Oterica.
141             A node has interfaces (which have IP addresses) and is part of a named domain.
142              
143             =head1 ATTRIBUTES
144              
145             =head2 hostname
146              
147             This is the name of the host. B<It does not include the domain name.>
148              
149             =head2 aliases
150              
151             This is an arrayref of other fully-qualified names that refer to this host.
152              
153             The accessor returns a list.
154              
155             =head2 interfaces
156              
157             This is an arrayref of pairs, each one an IP address and a network.
158              
159             This attribute is pretty likely to change later.
160              
161             =head2 location
162              
163             The name of the network location of this host
164              
165             =head2 ttl
166              
167             This is the default TTL for the host's A records -- it doesn't affect the TTL
168             for records created by families to which the host belongs. If not provided,
169             it will be unset, and the default TTL is used.
170              
171             =head1 METHODS
172              
173             =head2 fqdn
174              
175             This is the fully-qualified domain name of this host.
176              
177             =head1 AUTHOR
178              
179             Ricardo SIGNES <rjbs@cpan.org>
180              
181             =head1 COPYRIGHT AND LICENSE
182              
183             This software is copyright (c) 2016 by Ricardo SIGNES.
184              
185             This is free software; you can redistribute it and/or modify it under
186             the same terms as the Perl 5 programming language system itself.
187              
188             =cut