POE::C...nt::DNS(3pm)
π POE::Component::Client::DNS β the manual, but make it make sense π
okay bestie, so this is POE::Component::Client::DNS(3pm), a User Contributed Perl Documentation page, and it's literally the non-blocking, parallel DNS client for POE. yes, that POE. let's get into it π¦
β¨ NAME β¨
POE::Component::Client::DNS β non-blocking, parallel DNS client. it's giving "ask all your DNS questions at once and never block the rest of your program", and honestly? iconic. π
πΈ VERSION πΈ
version 1.054. no cap.
π SYNOPSIS π
here's the whole vibe in code form, copy it exactly, i'm not playing:
use POE qw(Component::Client::DNS);
my $named = POE::Component::Client::DNS->spawn(
Alias => "named"
);
POE::Session->create(
inline_states => {
_start => \&start_tests,
response => \&got_response,
}
);
POE::Kernel->run();
exit;
sub start_tests {
my $response = $named->resolve(
event => "response",
host => "localhost",
context => { },
);
if ($response) {
$_[KERNEL]->yield(response => $response);
}
}
sub got_response {
my $response = $_[ARG0];
my @answers = $response->{response}->answer();
foreach my $answer (@answers) {
print(
"$response->{host} = ",
$answer->type(), " ",
$answer->rdatastr(), "\n"
);
}
}
π DESCRIPTION π
POE::Component::Client::DNS gives you non-blocking, parallel DNS requests, and it does it via Net::DNS. because it's built on POE, all your other tasks get to keep running while you're sitting there waiting for name servers to respond. multitasking queen energy, fr fr. π
okay but real talk: for simple name resolution β including smart handling of IPv6 names β please see POE::Component::Resolver instead. that's the move for the basic stuff. π«Ά
π₯ PUBLIC METHODS π₯
β spawn β
A program must spawn at least one POE::Component::Client::DNS instance before it can perform background DNS requests. Each instance represents a connection to one or more name servers. If a program only needs to request DNS requests from one server, then you only need one POE::Component::Client::DNS instance. that's it, that's the whole thing. no need to overdo it, bestie. π§
As of version 0.98 you can override the default timeout per request. From this point forward there is no need to spawn multiple instances to affect different timeouts for each request. the way that freed us from spawning a million instances... we love to see it. π
PoCo::Client::DNS's spawn method takes a few named parameters:
Aliasβ sets the component's alias. Requests will be posted to this alias. The component's alias defaults to"resolver"if one is not provided. Programs spawning more than one DNS client component must specify aliases for N-1 of them, otherwise alias collisions will occur. (N-1!! write that down. π)
Alias => $session_alias, # defaults to "resolver"
Timeoutβ sets the component's default timeout. The timeout may be overridden per request. See the"request"event, later on. If noTimeoutis set, the component will wait90seconds per request by default.
Timeouts may be set to real numbers. Timeouts are more accurate if you have Time::HiRes installed. POE (and thus this component) will use Time::HiRes automatically if it's available. β¨
Timeout => $seconds_to_wait, # defaults to 90
Nameserversβ holds a reference to a list of name servers to try. The list is passed directly toNet::DNS::Resolver'snameservers()method. By default,POE::Component::Client::DNSwill query the name servers that appear in/etc/resolv.confor its equivalent.
Nameservers => \@name_servers, # defaults to /etc/resolv.conf's
HostsFile(optional) β holds the name of a specific hosts file to use for resolving hardcoded addresses. By default, it looks for a file named/etc/hosts.
On Windows systems, it may look in the following other places:
$ENV{SystemRoot}\System32\Drivers\Etc\hosts
$ENV{SystemRoot}\System\Drivers\Etc\hosts
$ENV{SystemRoot}\hosts
β resolve β
resolve() requests the component to resolve a host name. It will return a hash reference (described in RESPONSE MESSAGES, below) if it can honor the request immediately (perhaps from a cache). Otherwise it returns undef if a resolver must be consulted asynchronously. so either you get your answer instantly or you get undef and have to be patient. growth. π±
Requests are passed as a list of named fields.
$resolver->resolve(
class => $dns_record_class, # defaults to "IN"
type => $dns_record_type, # defaults to "A"
host => $request_host, # required
context => $request_context, # required
event => $response_event, # required
timeout => $request_timeout, # defaults to spawn()'s Timeout
nameservers => $nameservers, # defaults to $resolver's Nameservers
);
The "class" and "type" fields specify what kind of information to return about a host. Most of the time internet addresses are requested for host names, so the class and type default to "IN" (internet) and "A" (address), respectively. classic defaults, they ate. π
The "host" field designates the host to look up. It is required.
The "event" field tells the component which event to send back when a response is available. It is required, but it will not be used if resolve() can immediately return a cached response. (so don't come for it if it doesn't fire, it just already had the tea β)
"timeout" tells the component how long to wait for a response to this request. It defaults to the "Timeout" given at spawn() time.
"context" includes some external data that links responses back to their requests. The context data is provided by the program that uses POE::Component::Client::DNS. The component will pass the context back to the program without modification. The "context" parameter is required, and may contain anything that fits in a scalar. it's literally your little note-to-self that comes back to you untouched. π
β shutdown β
shutdown() causes the component to terminate gracefully. It will finish serving pending requests then close down. no chaos, no half-finished requests, just a graceful exit. main character departure. πͺβ¨
β get_resolver β
POE::Component::Client::DNS uses a Net::DNS::Resolver object internally. get_resolver() returns that object so it may be interrogated or modified. See Net::DNS::Resolver for options. peak "here, hold my internals" behavior, we love transparency. π«Ά
Set the resolver to check on nonstandard port 1153:
$poco_client_dns->get_resolver()->port(1153);
π RESPONSE MESSAGES π
POE::Component::Client::DNS responds in one of two ways. Its resolve() method will return a response immediately if it can be found in the component's cache. Otherwise the component posts the response back in $_[ARG0]. In either case, the response is a hash reference containing the same fields:
host => $request_host,
type => $request_type,
class => $request_class,
context => $request_context,
response => $net_dns_packet,
error => $net_dns_error,
The "host", "type", "class", and "context" response fields are identical to those given in the request message. what you sent is what you get back, periodt. π
"response" contains a Net::DNS::Packet object on success or undef if the lookup failed. The Net::DNS::Packet object describes the response to the program's request. It may contain several DNS records. Please consult Net::DNS and Net::DNS::Packet for more information.
"error" contains a description of any error that has occurred. It is only valid if "response" is undefined. (so if response is defined, don't go reading error, bestie, it's not the moment π)
π SEE ALSO π
POEβPOE::Component::Client::DNSbuilds heavily on POE.POE::Component::Resolverβ A system name resolver, including IPv6 support and whatever else your system supports.Net::DNSβ This module usesNet::DNSinternally.Net::DNS::Packetβ Responses are returned asNet::DNS::Packetobjects.
π DEPRECATIONS π
okay so, heavy stuff, listen up:
The older, list-based interfaces are no longer documented as of version 0.98. They are being phased out. The method-based interface, first implemented in version 0.98, will replace the deprecated interfaces after a six-month phase-out period.
Version 0.98 was released in October of 2004. The deprecated interfaces will continue to work without warnings until January 2005.
As of January 2005, programs that use the deprecated interfaces will continue to work, but they will generate mandatory warnings. Those warnings will persist until April 2005.
As of April 2005 the mandatory warnings will be upgraded to mandatory errors. Support for the deprecated interfaces will be removed entirely.
As of late January 2011, POE::Component::Resolver provides basic system resolver support, including IPv6 and mDNS if your resolver's configured to use it. The use of POE::Component::Client::DNS for basic resolution is deprecated, however it's still the best option for actual DNS server requests.
π¨ so basically: deprecated means deprecated. it warns, then it errors, then it's gone. if you're still on the old list-based interface, this is your sign to migrate. i'm not being mean, i'm being honest. π
π BUG TRACKER π
https://rt.cpan.org/Dist/Display.html?Queue=POE-Component-Client-DNS
found a bug? take it there, bestie, they'll handle it. π«Ά
π¦ REPOSITORY π¦
http://github.com/rcaputo/poe-component-client-dns
π OTHER RESOURCES π
http://search.cpan.org/dist/POE-Component-Client-DNS/
π AUTHOR & COPYRIGHTS π
POE::Component::Client::DNS is Copyright 1999-2009 by Rocco Caputo. All rights are reserved. POE::Component::Client::DNS is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
Postback arguments were contributed by tag. shoutout. π«Άβ¨
and that's the whole page, babes. this shipped as part of perl v5.36.0, dated 2023-10-29 β so yeah, that's the version and the date, and honestly? it still slays. now go resolve something non-blocking. ππ
π¦ where this page comes from
- debian trixie: libpoe-component-client-dns-perl 1:1.054-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libpoe-component-client-dns-perl 1:1.054-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libpoe-component-client-dns-perl 1:1.054-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libpoe-component-client-dns-perl 1:1.054-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms