DNS-Unbound

 view release on metacpan or  search on metacpan

lib/DNS/Unbound.pm  view on Meta::CPAN

# Load the default async query implementation.
# This may change when non-default implementations
# leave experimental status.
use DNS::Unbound::AsyncQuery::PromiseES6 ();

# Retain this to avoid having to load Net::DNS::Parameters
# except in unusual cases.
use constant _COMMON_RR => {
    A          => 1,
    AAAA       => 28,
    AFSDB      => 18,
    ANY        => 255,
    APL        => 42,
    CAA        => 257,
    CDNSKEY    => 60,
    CDS        => 59,
    CERT       => 37,
    CNAME      => 5,
    DHCID      => 49,
    DLV        => 32769,
    DNAME      => 39,
    DNSKEY     => 48,
    DS         => 43,
    HIP        => 55,
    HINFO      => 13,
    IPSECKEY   => 45,
    KEY        => 25,
    KX         => 36,
    LOC        => 29,
    MX         => 15,
    NAPTR      => 35,
    NS         => 2,
    NSEC       => 47,
    NSEC3      => 50,
    NSEC3PARAM => 51,
    OPENPGPKEY => 61,
    PTR        => 12,
    RRSIG      => 46,
    RP         => 17,
    SIG        => 24,
    SMIMEA     => 53,
    SOA        => 6,
    SRV        => 33,
    SSHFP      => 44,
    TA         => 32768,
    TKEY       => 249,
    TLSA       => 52,
    TSIG       => 250,
    TXT        => 16,
    URI        => 256,
};

use constant {
    _DEFAULT_PROMISE_ENGINE => 'Promise::ES6',
};

use constant _ctx_err => {
    (
        map { $_ => _ub_strerror($_) }
        map { __PACKAGE__->can($_)->() }
        split m<\s+>, _ERROR_NAMES_STR()
    )
};

#----------------------------------------------------------------------

=head1 CONSTANTS

The following from F<libunbound/context.h> are defined here:
C<UB_NOERROR>, C<UB_SOCKET>, C<UB_NOMEM>, C<UB_SYNTAX>, C<UB_SERVFAIL>,
C<UB_FORKFAIL>, C<UB_AFTERFINAL>, C<UB_INITFAIL>, C<UB_PIPE>,
C<UB_READFILE>, C<UB_NOID>

=head1 METHODS

=head2 I<CLASS>->new()

Instantiates this class.

=cut

sub new {
    return bless {
        _ub  => DNS::Unbound::Context::create(),
        _pid => $$,
      },
      shift();
}

=head2 $result_obj = I<OBJ>->resolve( $NAME, $TYPE [, $CLASS ] )

Runs a synchronous query for a given $NAME and $TYPE. $TYPE may be
expressed numerically or, for convenience, as a string. $CLASS is
optional and defaults to 1 (C<IN>), which is probably what you want.

Returns a L<DNS::Unbound::Result> instance.

B<NOTE:> libunbound doesn’t seem to offer effective controls for
timing out a synchronous query.
If timeouts are relevant for you, you probably need
to use C<resolve_async()> instead.

=cut

sub resolve {
    my ($self, $name, $type, $class) = @_;

    die 'Need type!' if !$type;

    $type = _normalize_type_to_number($type);

    my $result = $self->{'_ub'}->_resolve( $name, $type, $class || () );

    if ( !ref($result) ) {
        die _create_resolve_error($result);
    }

    return DNS::Unbound::Result->new(%$result);
}

sub _normalize_type_to_number {



( run in 1.176 second using v1.01-cache-2.11-cpan-71847e10f99 )