IO::Lambda::DNS(3)

πŸ“¦ version 1.34, in alpine 3.24

πŸ’… IO::Lambda::DNS β€” DNS queries lambda style

Hi bestie! So this page is IO::Lambda::DNS(3) from the User Contributed Perl Documentation, and it's literally the glow-up your DNS lookups have been waiting for πŸ¦‹


✨ NAME ✨

IO::Lambda::DNS β€” DNS queries, but lambda style. Iconic. No cap.


🌸 DESCRIPTION 🌸

Okay so listen: this module gives you access to asynchronous DNS queries through Net::DNS. That's the whole vibe.

And because the author loves you, there are two functions that do the exact same operation β€” a constructor called new and a condition called dns. Pick whichever one matches your main character energy πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

Here's the code, copy-pasted exactly because I would never do you dirty like that:

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

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

# parallel async queries
lambda {
   for my $site ( map { "www.$_.com" } qw(google yahoo perl)) {
      context $site, 'MX', timeout => 0.25;
      dns { print shift-> string if ref($_[0]) }
   }
}-> wait;

⭐ OPTIONS ⭐

The options that are specific to this module are:

  • timeout or deadline β€” in seconds ⏱️
  • retry β€” in times πŸ”

Everything else β€” like nameservers, dnssec, etc etc (yes, the manpage literally says "etc etc", love that for us) β€” gets passed as is straight to the Net::DNS::Resolver constructor. So go read its man page for the details, bestie 🫢


πŸ‘‘ USAGE πŸ‘‘

πŸ’– new β€” the constructor

Constructor new accepts Net::DNS-specific options (peep OPTIONS above, I got you) plus a query, and returns a lambda. That lambda takes no parameters, and gives you back either an IP address or a response object (depends on which call syntax you use, see below), or an error string.

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

In the simple case, it takes a $HOSTNAME string and returns a string too β€” either an IP address or an error. To tell them apart, use the " /^\d/ " regexp. Why? Because it is guaranteed that no error message will begin with a digit, and no IP address will begin with anything other than a digit. Slay, honestly πŸ”₯

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

In the complex case, it takes either a Net::DNS::Packet object, or a $HOSTNAME and $TYPE string β€” where that $TYPE can be one of A, MX, etc DNS query type. For the exact syntax, see "bgsend" in Net::DNS::Resolver.

It returns either a Net::DNS::RR object or an error string ✨

πŸ¦‹ dns β€” condition wrapper over new

That's it. That's the whole thing. It's a condition wrapper over new:

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

🌈 SEE ALSO 🌈

Go check out:

  • IO::Lambda
  • Net::DNS::Resolver

Both linked, both worth your time. Periodt πŸ’œ


🌸 AUTHOR 🌸

Dmitry Karasik, <dmitry@karasik.eu.org>. Give him his flowers, he earned them πŸ’


That's the whole page bestie, you're officially a DNS lambda girlie now 🧚

Ok bye ily, this was perl v5.42.2 and the page itself is dated 2026-02-15 β€” the header up top says IO::Lambda::DNS(3), but you already knew that πŸ’–

πŸ“¦ where this page comes from