line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DNS::Oterica::App; |
2
|
|
|
|
|
|
|
# ABSTRACT: the code behind `dnsoterica` |
3
|
|
|
|
|
|
|
$DNS::Oterica::App::VERSION = '0.304'; |
4
|
1
|
|
|
1
|
|
1071
|
use Moose; |
|
1
|
|
|
|
|
323342
|
|
|
1
|
|
|
|
|
6
|
|
5
|
1
|
|
|
1
|
|
5347
|
use DNS::Oterica::Hub; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
6
|
1
|
|
|
1
|
|
657
|
use File::Find::Rule; |
|
1
|
|
|
|
|
6209
|
|
|
1
|
|
|
|
|
9
|
|
7
|
1
|
|
|
1
|
|
434
|
use YAML::XS (); |
|
1
|
|
|
|
|
2103
|
|
|
1
|
|
|
|
|
440
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#pod =attr hub |
10
|
|
|
|
|
|
|
#pod |
11
|
|
|
|
|
|
|
#pod This is the L<DNS::Oterica::Hub> into which entries will be loaded. |
12
|
|
|
|
|
|
|
#pod |
13
|
|
|
|
|
|
|
#pod =cut |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has hub => ( |
16
|
|
|
|
|
|
|
is => 'ro', |
17
|
|
|
|
|
|
|
isa => 'DNS::Oterica::Hub', |
18
|
|
|
|
|
|
|
writer => '_set_hub', |
19
|
|
|
|
|
|
|
predicate => '_has_hub', |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub BUILD { |
23
|
1
|
|
|
1
|
0
|
1034
|
my ($self, $arg) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
confess "both hub and hub_args provided" |
26
|
1
|
0
|
33
|
|
|
32
|
if $self->_has_hub and $arg->{hub_args}; |
27
|
|
|
|
|
|
|
|
28
|
1
|
50
|
|
|
|
23
|
unless ($self->_has_hub) { |
29
|
1
|
|
|
|
|
2
|
my %args = %{$arg->{hub_args}}; |
|
1
|
|
|
|
|
5
|
|
30
|
1
|
|
50
|
|
|
31
|
$self->_set_hub( DNS::Oterica::Hub->new(\%args || {}) ); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
#pod =attr root |
35
|
|
|
|
|
|
|
#pod |
36
|
|
|
|
|
|
|
#pod This is a directory in which F<dnsoterica> will look for configuration files. |
37
|
|
|
|
|
|
|
#pod |
38
|
|
|
|
|
|
|
#pod It will look in the subdirectory F<domains> for domain definitions and F<hosts> |
39
|
|
|
|
|
|
|
#pod for hosts. |
40
|
|
|
|
|
|
|
#pod |
41
|
|
|
|
|
|
|
#pod =cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has root => ( |
44
|
|
|
|
|
|
|
is => 'ro', |
45
|
|
|
|
|
|
|
required => 1, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub populate_networks { |
49
|
1
|
|
|
1
|
0
|
386
|
my ($self) = @_; |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
42
|
my $root = $self->root; |
52
|
1
|
|
|
|
|
34
|
for my $file (File::Find::Rule->file->in("$root/networks")) { |
53
|
2
|
|
|
|
|
831
|
for my $data (YAML::XS::LoadFile($file)) { |
54
|
2
|
|
|
|
|
254
|
$self->hub->add_network($data); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub populate_domains { |
60
|
1
|
|
|
1
|
0
|
8
|
my ($self) = @_; |
61
|
1
|
|
|
|
|
29
|
my $root = $self->root; |
62
|
1
|
|
|
|
|
18
|
for my $file (File::Find::Rule->file->in("$root/domains")) { |
63
|
1
|
|
|
|
|
471
|
for my $data (YAML::XS::LoadFile($file)) { |
64
|
|
|
|
|
|
|
my $node = $self->hub->domain( |
65
|
|
|
|
|
|
|
$data->{domain}, |
66
|
1
|
|
|
|
|
100
|
); |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
3
|
for my $name (@{ $data->{families} }) { |
|
1
|
|
|
|
|
3
|
|
69
|
1
|
|
|
|
|
25
|
my $family = $self->hub->node_family($name); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$node->add_to_family($family); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub populate_hosts { |
78
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
79
|
0
|
|
|
|
|
|
my $root = $self->root; |
80
|
0
|
|
|
|
|
|
my $hub = $self->hub; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
for my $file (File::Find::Rule->file->in("$root/hosts")) { |
83
|
0
|
|
|
|
|
|
for my $data (YAML::XS::LoadFile($file)) { |
84
|
0
|
|
|
|
|
|
my $interfaces; |
85
|
0
|
0
|
|
|
|
|
if (ref $data->{ip}) { |
86
|
|
|
|
|
|
|
$interfaces = [ |
87
|
|
|
|
|
|
|
map {; |
88
|
|
|
|
|
|
|
[ |
89
|
0
|
|
|
|
|
|
$data->{ip}{$_} => $hub->network($_) ] |
90
|
0
|
|
|
|
|
|
} keys %{ $data->{ip}} |
|
0
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
]; |
92
|
|
|
|
|
|
|
} else { |
93
|
|
|
|
|
|
|
$interfaces = [ |
94
|
0
|
|
|
|
|
|
[ $data->{ip} => $hub->network( $hub->all_network_name ) ] |
95
|
|
|
|
|
|
|
]; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $node = $hub->host( |
99
|
|
|
|
|
|
|
$data->{domain}, |
100
|
|
|
|
|
|
|
$data->{hostname}, |
101
|
|
|
|
|
|
|
{ |
102
|
|
|
|
|
|
|
interfaces => $interfaces, |
103
|
|
|
|
|
|
|
location => $data->{location}, |
104
|
|
|
|
|
|
|
aliases => $data->{aliases} || [], |
105
|
0
|
0
|
0
|
|
|
|
(exists $data->{ttl} ? (ttl => $data->{ttl}) : ()), |
106
|
|
|
|
|
|
|
}, |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
for my $name (@{ $data->{families} }) { |
|
0
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
my $family = $hub->node_family($name); |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
$node->add_to_family($family); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=pod |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=encoding UTF-8 |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 NAME |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
DNS::Oterica::App - the code behind `dnsoterica` |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 VERSION |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
version 0.304 |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 hub |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This is the L<DNS::Oterica::Hub> into which entries will be loaded. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 root |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This is a directory in which F<dnsoterica> will look for configuration files. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
It will look in the subdirectory F<domains> for domain definitions and F<hosts> |
145
|
|
|
|
|
|
|
for hosts. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 AUTHOR |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Ricardo SIGNES <rjbs@cpan.org> |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Ricardo SIGNES. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
156
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |