NAME

IO::Lambda::DNS - DNS queries lambda style

DESCRIPTION

The module provides access to asynchronous DNS queries through Net::DNS. Two names doing the same function are exported: predicate-style dns_query and lambda-style dns_lambda.

SYNOPSIS

use strict;
use IO::Lambda::DNS qw(:all);
use IO::Lambda qw(:all);

# simple async query
my $reply = dns_lambda( "www.site.com" )-> wait;
print (($reply =~ /^\d/) ? "Resolved to $reply\n" : "Error: $reply\n");

# parallel async queries -- create many lambdas, wait with tails() for them all
my @replies = lambda {
    context map { 
        dns_lambda( $_, timeout => 1, retry => 3);
    } @hostnames;
    \&tails;
}-> wait;

# again parallel async queries -- within single lambda, fire-and-forget
for my $site ( map { "www.$_.com" } qw(google yahoo perl)) {
     context $site, 'MX', nameservers => ['127.0.0.1'], timeout => 0.25;
	dns_query { print shift-> string if ref($_[0]) }
}

OPTIONS

Accepted options specific to the module are timeout (in seconds) and retry (in times). All other options, such as nameservers, dnssec etc etc are passed as is to the Net::DNS::Resolver constructor. See its man page for details.

USAGE

dns_lambda

dns_lambda accepts Net::DNS-specific options (see OPTIONS above) and query, and returns a lambda. The lambda accepts no parameters, return either IP address or response object, depending on the call, or an error string.

dns_lambda (%OPTIONS, $HOSTNAME) :: () -> $IP_ADDRESS|$ERROR

In simple case, accepts $HOSTNAME string, and returns a string, either IP address or an error. To distinguish between these use /^\d/ regexp, because it is guaranteed that no error message will begin with digit, and no IP address will begin with anything other than digit.

dns_lambda (%OPTIONS, ($PACKET | $HOSTNAME $TYPE)) :: () -> $RESPONSE|$ERROR

In complex case, accepts either $HOSTNAME string and $TYPE string, where the latter is A, MX, etc DNS query type. See "new" in Net::DNS::Resolver. Returns either Net::DNS::RR object or error string.

dns_query

Predicate wrapper over dns_lambda.

dns_query (%OPTIONS, $HOSTNAME) -> $IP_ADDRESS|$ERROR
dns_query (%OPTIONS, ($PACKET | $HOSTNAME $TYPE)) -> $RESPONSE|$ERROR

SEE ALSO

IO::Lambda, Net::DNS::Resolver.

AUTHOR

Dmitry Karasik, <dmitry@karasik.eu.org>.