Package: libnet-dns-perl
Version: 0.66-2+b2
There doesn't seem to be an easy way to create a Net::DNS::RR
instance given a “pre-parsed” resource record serialization
(such as one read from a XML or CSV file, or an SQL database.)
Consider, e. g.:
## as read, e. g., from a CSV file
my @rrs
= (["foo.example.org", "AAAA", "2001:db8:1337::cafe"],
["bar.example.org", "CNAME", "foo.example.org"]);
foreach my $rr (@rrs) {
## FIXME: this switch shouldn't be necessary
my $key
= ($rr->[1] eq "AAAA" ? "address"
: $rr->[1] eq "CNAME" ? "cname"
: ...);
my $rr
= Net::DNS::RR->new ("name" => $rr->[0], "type" => $rr->[1],
$key => $rr->[2]);
}
Obviously, this is further complicated by the fact that certain
RR's include more than one payload value (MX, SRV, etc.)
A possible work-around function is MIME'd (based on the the
Net::DNS::RR->new_from_string () constructor's code), which, I
believe, should be possible to adapt into a proper Net::DNS::RR
constructor.
TIA.
--
FSF associate member #7257 rp. The Evil That Men Do — Iron Maiden
require Net::DNS;
sub rr_new_mixed {
my ($rdatastr, @rest) = @_;
my $rr1
= Net::DNS::RR->new (@rest)
or die ();
## NB: accessing the internals directly
my $rr_class
= Net::DNS::RR->_get_subclass ($rr1->type ())
or die ();
my $rr
= $rr_class->new_from_string ($rr1, $rdatastr)
or die ();
## .
$rr;
}
# require Data::Dump;
# my $rr_1
# = rr_new_mixed ("2001:db8:1337::cafe",
# "name" => "foo.example.org",
# "type" => "AAAA");
# print ($rr_1->string (), "\n",
# Data::Dump::dump ($rr_1), "\n");
# my $rr_2
# = rr_new_mixed ("foo.example.org",
# "name" => "bar.example.org",
# "type" => "CNAME");
# print ($rr_2->string (), "\n",
# Data::Dump::dump ($rr_2), "\n");