Net::DNS::ZoneFile(3)
π Net::DNS::ZoneFile(3) π
okay bestie, listen up β this is the User Contributed Perl Documentation page for Net::DNS::ZoneFile(3), like, the whole manual, and we're gonna get through it together. grab a strawberry drink π and let's go.
β¨ NAME β¨
Net::DNS::ZoneFile β it's a DNS zone file. that's the vibe. π
πΈ SYNOPSIS πΈ
here's the whole thing in action, no cap:
use Net::DNS::ZoneFile;
$zonefile = Net::DNS::ZoneFile->new( 'named.example' );
while ( $rr = $zonefile->read ) {
$rr->print;
}
@zone = $zonefile->read;
literally that's it, that's the whole flow π
π¦ DESCRIPTION π¦
so every single Net::DNS::ZoneFile object instance? it represents a zone file plus any subordinate files that get pulled in by the $INCLUDE directive. like a whole little found family of files π«Ά. and the zone file syntax itself is defined by RFC1035 β that's the icon, that's the blueprint.
a program can totally have multiple zone file objects, and each one keeps its own independent parser state information. no sharing, no drama, each one has its own main character energy β¨.
the parser is out here supporting both the $TTL directive defined by RFC2308 and the BIND $GENERATE syntax extension. versatile queen π.
β important: all RRs in a zone file must have the same class. it can be specified for the first RR you encounter, and then it's propagated automatically to all subsequent records. automatic. slay.
π METHODS π
π new
$zonefile = Net::DNS::ZoneFile->new( 'filename', ['example.com'] );
$handle = IO::File->new( 'filename', '<:encoding(ISO8859-7)' );
$zonefile = Net::DNS::ZoneFile->new( $handle, ['example.com'] );
the new() constructor hands you back a Net::DNS::ZoneFile object that represents the zone file you named in the argument list. π¦
the file or file handle you specified gets opened for reading, and it gets closed either when it's exhausted or when all references to the ZoneFile object cease to exist. it's giving closure, literally π
the optional second argument specifies $ORIGIN for the zone file. cute.
zone files are presumed to be UTF-8 encoded where that is supported β default assumption, bestie.
alternative character encodings? you can specify those indirectly by creating a file handle with the desired encoding layer, which you then pass as an argument to new(). and the specified encoding is propagated to files introduced by $INCLUDE directives β it follows them in, obsessed π.
π₯ read
$rr = $zonefile->read;
@rr = $zonefile->read;
in scalar context, read() returns a Net::DNS::RR object representing the next resource record encountered in the zone file β or undefined if end of data has been reached. that's the end, periodt.
in list context, read() returns the list of Net::DNS::RR objects in the order that they appear in the zone file. in order. respectful. π
comments and blank lines are silently disregarded β they simply do not exist to us π.
and the $INCLUDE, $ORIGIN, $TTL and $GENERATE directives are processed transparently. you don't even have to think about them, they just work, iconic.
β name
$filename = $zonefile->name;
returns the name of the current zone file. and heads up: embedded $INCLUDE directives will cause this to differ from the filename argument you supplied when the object was created. plot twist π
πΈ line
$line = $zonefile->line;
returns the number of the last line read from the current zone file. for when you need to know exactly where you are, iykyk.
π§ origin
$origin = $zonefile->origin;
returns the fully qualified name of the current origin within the zone file. fully qualified, as she should be π
π ttl
$ttl = $zonefile->ttl;
returns the default TTL as specified by the $TTL directive. the default. the baseline. the standard. β¨
π COMPATIBILITY WITH Net::DNS::ZoneFile 1.04 π
okay so this part is for the legacy girlies. applications that depended on the defunct Net::DNS::ZoneFile 1.04 CPAN distribution will continue to operate with minimal change using the compatibility interface described below. but listen β new application code should use the object-oriented interface. no cap, that's the way forward π₯.
use Net::DNS::ZoneFile;
$listref = Net::DNS::ZoneFile->read( $filename );
$listref = Net::DNS::ZoneFile->read( $filename, $include_dir );
$listref = Net::DNS::ZoneFile->readfh( $filehandle );
$listref = Net::DNS::ZoneFile->readfh( $filehandle, $include_dir );
$listref = Net::DNS::ZoneFile->parse( $string );
$listref = Net::DNS::ZoneFile->parse( $string, $include_dir );
$listref = Net::DNS::ZoneFile->parse( \$string );
$listref = Net::DNS::ZoneFile->parse( \$string, $include_dir );
$_->print for @$listref;
the optional second argument specifies the default path for filenames. the current working directory is used by default β home base π .
although it wasn't available in the original implementation, you can also get the RR list directly by calling any of these methods in list context. upgrade unlocked β:
@rr = Net::DNS::ZoneFile->read( $filename, $include_dir );
π careful bestie: the partial result is returned if an error is encountered by the parser.
π read
$listref = Net::DNS::ZoneFile->read( $filename );
$listref = Net::DNS::ZoneFile->read( $filename, $include_dir );
read() parses the contents of the specified file and returns a reference to the list of Net::DNS::RR objects. and if an error is encountered by the parser, the return value is undefined. sad but true π.
π readfh
$listref = Net::DNS::ZoneFile->readfh( $filehandle );
$listref = Net::DNS::ZoneFile->readfh( $filehandle, $include_dir );
readfh() parses data from the specified file handle and returns a reference to the list of Net::DNS::RR objects. same deal: return value is undefined if an error is encountered by the parser. π
π¦ parse
$listref = Net::DNS::ZoneFile->parse( $string );
$listref = Net::DNS::ZoneFile->parse( $string, $include_dir );
$listref = Net::DNS::ZoneFile->parse( \$string );
$listref = Net::DNS::ZoneFile->parse( \$string, $include_dir );
parse() interprets the text in the argument string and returns a reference to the list of Net::DNS::RR objects. and yes β return value is undefined if an error is encountered by the parser. consistency queen π.
π«Ά ACKNOWLEDGEMENTS π«Ά
this package is designed as an improved and compatible replacement for Net::DNS::ZoneFile 1.04, which was created by Luis Munoz in 2002 as a separate CPAN module. history!! π
the present implementation is the result of an agreement to merge our two different approaches into one package integrated into Net::DNS. and the contribution of Luis Munoz is gratefully acknowledged. we love a collab π€π
thanks are also due to Willem Toorop for his constructive criticism of the initial version and invaluable assistance during testing. real ones fr fr π
π COPYRIGHT π
Copyright (c)2011-2012 Dick Franks.
All rights reserved.
β¨ LICENSE β¨
permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted β provided that the original copyright notices appear in all copies and that both copyright notice and this permission notice appear in supporting documentation, and that the name of the author not be used in advertising or publicity pertaining to distribution of the software without specific prior written permission. read it, know it, respect it ππ
β οΈ and then the loud part: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. like, genuinely no warranty bestie, don't come for them π
π SEE ALSO π
perlNet::DNSNet::DNS::RRRFC1035(5.1)<https://iana.org/go/rfc1035/section-5.1>RFC2308(4)<https://iana.org/go/rfc2308/section-4>- BIND Administrator Reference Manual <https://bind9.readthedocs.io/en/latest/>
that's the whole page, bestie, you ate that πβ¨ and one last cute lil sign-off: this was perl v5.42.0, dated 2026-09-02, and it's the Net::DNS::ZoneFile(3) page β go read some zone files, ily ππ¦
π¦ where this page comes from
- opensuse-leap 16.0: perl-Net-DNS 1.570.0-bp160.1.1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms