DNS-Oterica

 view release on metacpan or  search on metacpan

lib/DNS/Oterica/Node.pm  view on Meta::CPAN

package DNS::Oterica::Node;
# ABSTRACT: DNSO node. belongs to families. 
$DNS::Oterica::Node::VERSION = '0.314';
use Moose;

use DNS::Oterica::Role::RecordMaker;

#pod =head1 OVERVIEW
#pod
#pod A node is any part of a network, either a domain or a node.  It is a member of
#pod zero or more families.
#pod
#pod Like other DNS::Oterica objects, they should be created through the hub.
#pod
#pod =attr domain
#pod
#pod This is a string representing the domain's domain name, for example
#pod F<example.com>.
#pod
#pod =cut

has domain   => (is => 'ro', isa => 'Str', required => 1);

#pod =attr families
#pod
#pod This is an arrayref of the families in which the node has been placed.
#pod
#pod =cut

has families => (is => 'ro', isa => 'ArrayRef', default => sub { [] });

#pod =method add_to_family
#pod
#pod   $node->add_to_family($family);
#pod
#pod This method adds the node to the given family, which may be given either as an
#pod object or as a name.
#pod
#pod If the node is already in the family, nothing happens.
#pod
#pod =cut

sub add_to_family {
  my ($self, $family) = @_;
  $family = $self->hub->node_family($family) unless ref $family;
  return if $self->in_node_family($family);
  $family->add_node($self);
  push @{ $self->families }, $family;
}

#pod =method in_node_family
#pod
#pod   if ($node->in_node_family($family)) { ... }
#pod
#pod This method returns true if the node is a member of the named (or passed)
#pod family and false otherwise.
#pod
#pod =cut

sub in_node_family {
  my ($self, $family) = @_;
  $family = $self->hub->node_family($family) unless ref $family;

  for my $node_family (@{ $self->families }) {
    return 1 if $family == $node_family;
  }

  return;
}

#pod =method as_data_lines
#pod
#pod This method returns a list of lines of configuration output.
#pod
#pod By default, it returns nothing.
#pod
#pod =cut

sub as_data_lines {
  confess 'do not call ->as_data_lines in non-list context' unless wantarray;
  return;
}

with 'DNS::Oterica::Role::HasHub';

__PACKAGE__->meta->make_immutable;
no Moose;
1;

__END__



( run in 1.111 second using v1.01-cache-2.11-cpan-140bd7fdf52 )