POE::Stage::Resolver - a simple non-blocking DNS resolver
# Note, this is not a complete program.
# See the distribution's examples directory.
sub some_handler :Handler {
my $req_resolver = POE::Stage::Resolver->new(
method => "resolve",
on_success => "handle_host",
on_error => "handle_error",
args => {
input => "thirdlobe.com",
type => "A", # A is default
class => "IN", # IN is default
},
);
}
sub handle_host :Handler {
my ($arg_input, $arg_packet);
my @answers = $arg_packet->answer();
foreach my $answer (@answers) {
print(
"Resolved: $arg_input = type(", $answer->type(), ") data(",
$answer->rdatastr, ")\n"
);
}
# Cancel the resolver by destroying it.
my $req_resolver = undef;
}
POE::Stage::Resolver is a simple non-blocking DNS resolver. For now it uses
Net::DNS::Resolver for the bulk of its work. It returns Net::DNS::Packet
objects in its "success" responses. Please see the documentation for
Net::DNS.
Commands are invoked with POE::Request objects.
Creates a POE::Stage::Resolver instance and asks it to resolve some INPUT into
records of a given CLASS and TYPE. CLASS and TYPE default to "IN"
and "A", respectively.
When complete, the stage will respond with either a
"success" or an "error" message.
Responses are returned by POE::Request->return() or emit().
Net::DNS::Resolver successfully resolved a request. The original input is passed
back in the "input" parameter. The resulting Net::DNS::Packet object
is returned in "packet".
Net::DNS::Resolver, or something else, failed to resolve the input to a
response. The original input is passed back in the "input"
parameter. Net::DNS::Resolver's error message comes back as "error".
See <http://thirdlobe.com/projects/poe-stage/report/1> for known issues.
See <http://thirdlobe.com/projects/poe-stage/newticket> to report one.
POE::Stage is too young for production use. For example, its
syntax is still changing. You probably know what you don't like, or what you
need that isn't included, so consider fixing or adding that, or at least
discussing it with the people on POE's mailing list or IRC channel. Your
feedback and contributions will bring POE::Stage closer to usability. We
appreciate it.
POE::Stage and POE::Request. The examples/log-resolver.perl program in
POE::Stage's distribution. Net::DNS::Packet for an explanation of returned
packets. POE::Component::Client::DNS for the original inspiration and a much
more complete asynchronous DNS implementation.
Rocco Caputo <rcaputo@cpan.org>.
POE::Stage::Resolver is Copyright 2005-2006 by Rocco Caputo. All rights are
reserved. You may use, modify, and/or distribute this module under the same
terms as Perl itself.