NAME
Zonemaster::Engine::NameserverSet - a set supporting DNS name/IP pairs and plain DNS names
SYNOPSIS
use Zonemaster::Engine::NameserverSet;
my $set = Zonemaster::Engine::NameserverSet->new();
my $ns1 = Zonemaster::Engine::Nameserver->new({ name => 'ns.nic.example', address => '2001:db8::8:53' });
my $ns2 = Zonemaster::Engine::Nameserver->new({ name => 'ns.nic.example', address => '2001:db8::9:53' });
$set->push( $ns1, $ns2 );
my $name = Zonemaster::Engine::DNSName->new( 'ns2.nic.example' );
$set->push( $name );
$set->get( 'ns.nic.example' ); # returns $ns1 and $ns2 in list context
$set->get( 'ns2.nic.example' ); # returns $name in list context
# Retrieve items
my @items = $set->items; # or $set->sorted_items
DESCRIPTION
Zonemaster::Engine::NameserverSet implements a collection type that is specialized for holding a mix of name/IP pairs (represented as Zonemaster::Engine::Nameserver objects) and bare domain names (represented as Zonemaster::Engine::DNSName objects).
In other words, it is a collection type that stores mappings of name server names to zero, one or more IP addresses.
METHODS
- new()
-
Constructs a new empty name server set.
- push( $name_or_ns )
-
Adds an item to the set. Objects of type Zonemaster::Engine::DNSName or Zonemaster::Engine::Nameserver are accepted. Other types are converted to strings, then turned into Zonemaster::Engine::DNSName objects before being added to the set.
This method obeys the following rules:
If
$name_or_nsis a Zonemaster::Engine::DNSName (or automatically converted to an object of that type), it is added to the set if and only if the set contains no Zonemaster::Engine::DNSName object with the same name nor any Zonemaster::Engine::Nameserver objects with the same name.If
$name_or_nsis a Zonemaster::Engine::Nameserver, it is added to the set if and only if the set contains no other Zonemaster::Engine::Nameserver with the same name and address.If
$name_or_nsis a Zonemaster::Engine::Nameserver and the set already contains a Zonemaster::Engine::DNSName object with the same name, the nameserver object replaces the plain DNS name in the set.
- get( $name )
-
Returns a list of all items whose name is equivalent to
$name, or an empty list if no match.If only a Zonemaster::Engine::DNSName is stored in the set, that name as a single return value (or a singleton list in list context).
If one or more Zonemaster::Engine::Nameserver objects with matching
$nameare stored in the set, returns a list comprising of those objects. - get_ips( $name )
-
Returns a list of all Zonemaster::Engine::Nameserver objects with matching
$namethat are stored in the set.If only a Zonemaster::Engine::DNSName of the same
$nameis stored in the set, this function returns undef. - items()
-
Returns the entire contents of the set as a list, in an unspecified order.
- names()
-
Returns the unique list of names associated with the objects stored in the set, both plain Zonemaster::Engine::DNSName objects or the names of Zonemaster::Engine::Nameserver objects.
All names are returned as Zonemaster::Engine::DNSName objects.
- sorted_items()
-
Returns the entire contents of the set as a list, in a deterministic order.
Items are sorted lexicographically based on their names, and if multiple Zonemaster::Engine::Nameserver objects have the same name, these are sorted on IP addresses such that IPv4 addresses are sorted before IPv6 addresses, and within an address family, each address is sorted based on their integer values.
- is_empty()
-
Returns true if and only if the set contains no items.
- difference( $other_set )
-
Computes the difference between two sets. Returns a pair of sets: the first one contains the items only occurring in the left set (i.e. left minus right), the second one the items only in the right set (i.e. right minus left).
- equals( $other_set )
-
Returns true if and only if the set is equal to
$other_set.