| DNS-Oterica documentation | Contained in the DNS-Oterica distribution. |
DNS::Oterica::App - the code behind `dnsoterica`
version 0.100001
This is the DNS::Oterica::Hub into which entries will be loaded.
This is a directory in which dnsoterica will look for configuration files.
It will look in the subdirectory domains for domain definitions and hosts for hosts.
Ricardo SIGNES <rjbs@cpan.org>
This software is copyright (c) 2011 by Ricardo SIGNES.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
| DNS-Oterica documentation | Contained in the DNS-Oterica distribution. |
package DNS::Oterica::App; BEGIN { $DNS::Oterica::App::VERSION = '0.100001'; } # ABSTRACT: the code behind `dnsoterica` use Moose; use DNS::Oterica::Hub; use File::Find::Rule; use YAML::XS (); has hub => ( is => 'ro', isa => 'DNS::Oterica::Hub', writer => '_set_hub', predicate => '_has_hub', ); sub BUILD { my ($self, $arg) = @_; confess "both hub and hub_args provided" if $self->_has_hub and $arg->{hub_args}; unless ($self->_has_hub) { my %args = %{$arg->{hub_args}}; $self->_set_hub( DNS::Oterica::Hub->new(\%args || {}) ); } } has root => ( is => 'ro', required => 1, ); sub populate_locations { my ($self) = @_; my $root = $self->root; for my $file (File::Find::Rule->file->in("$root/locations")) { for my $data (YAML::XS::LoadFile($file)) { $self->hub->add_location($data); } } } sub populate_domains { my ($self) = @_; my $root = $self->root; for my $file (File::Find::Rule->file->in("$root/domains")) { for my $data (YAML::XS::LoadFile($file)) { my $node = $self->hub->domain( $data->{domain}, ); for my $name (@{ $data->{families} }) { my $family = $self->hub->node_family($name); $node->add_to_family($family); } } } } sub populate_hosts { my ($self) = @_; my $root = $self->root; for my $file (File::Find::Rule->file->in("$root/hosts")) { for my $data (YAML::XS::LoadFile($file)) { my $location = $self->hub->location($data->{location}); my $interfaces; if (ref $data->{ip}) { $interfaces = [ map {; [ $data->{ip}{$_} => $self->hub->location($_) ] } keys %{ $data->{ip}} ]; } else { $interfaces = [ [ $data->{ip} => $self->hub->location('world') ] ]; } my $node = $self->hub->host( $data->{domain}, $data->{hostname}, { interfaces => $interfaces, location => $data->{location}, aliases => $data->{aliases} || [], (exists $data->{ttl} ? (ttl => $data->{ttl}) : ()), }, ); for my $name (@{ $data->{families} }) { my $family = $self->hub->node_family($name); $node->add_to_family($family); } } } } 1; __END__