The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::DNS::ZoneFile - DNS zone file

SYNOPSIS

    use Net::DNS;

    $zonefile = new Net::DNS::ZoneFile( 'db.example' );

    while ( $rr = $zonefile->read ) {
        $rr->print;
    }

    @zone = $zonefile->read;

DESCRIPTION

Each Net::DNS::ZoneFile object instance represents a zone file together with any subordinate files nominated using $INCLUDE directives. Zone file syntax is defined by RFC1035.

A program can have multiple zone file objects, each maintaining its own independent parser state information.

The parser supports both the $TTL directive defined by RFC2308 and the BIND $GENERATE syntax extension.

All RRs in a zone file must have the same class, which may be specified for the first RR encountered and is then propagated automatically to all subsequent records.

METHODS

new

    $zonefile = new Net::DNS::ZoneFile( 'db.example', ['example.com'] );

Returns a Net::DNS::ZoneFile object which represents the zone file specified in the argument list.

The file is opened for reading and remains open until exhausted or all references to the ZoneFile object cease to exist.

The optional second argument specifies $ORIGIN for the zone file.

read

    $rr = $zonefile->read;

When invoked in scalar context, returns the next RR encountered in the zone file, or undefined if end of data has been reached.

Comments and blank lines are silently disregarded.

$INCLUDE, $ORIGIN, $TTL and $GENERATE directives are processed transparently.

    @rr = $zonefile->read;

When invoked in list context, returns the list of all RR objects in the zone file.

name

    $filename = $zonefile->name;

Returns the name of the zone file from which RRs will be read. $INCLUDE directives will cause this to differ from the filename argument supplied when the object was created.

line

    $line = $zonefile->line;

Returns the line number of the last non-continuation line encountered in the current zone file.

origin

    $origin = $zonefile->origin;

Returns the fully qualified name of the current origin within the zone file.

ttl

    $ttl = $zonefile->ttl;

Returns the default TTL as specified by the $TTL directive.

COMPATIBILITY WITH Net::DNS::ZoneFile 1.04

Applications which depended on the Net::DNS::ZoneFile 1.04 package will continue to operate with minimal change using compatibility interface described below.

    use Net::DNS::ZoneFile;

    $rrset = Net::DNS::ZoneFile->read( $filename [, $include_dir] );

    $rrset = Net::DNS::ZoneFile->readfh( $fh [, $include_dir] );

    $rrset = Net::DNS::ZoneFile->parse( \$zone_text [, $include_dir] );

    print $_->string, "\n" for @$rrset;

read

    $rrset = Net::DNS::ZoneFile->read( $filename [, $include_dir] );

read() parses the specified zone file and returns a reference to an array of Net::DNS::RR objects representing the RRs in the file. The return value is undefined if the zone data can not be parsed.

readfh

    $rrset = Net::DNS::ZoneFile->readfh( $fh [, $include_dir] );

read() parses data from the specified file handle and returns a reference to an array of Net::DNS::RR objects representing the RRs in the file. The return value is undefined if the zone data can not be parsed.

parse

    $rrset = Net::DNS::ZoneFile->parse( \$zone_text [, $include_dir] );

ACKNOWLEDGEMENT

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.

The present implementation is the result of an agreement to merge our two different approaches into one package integrated into Net::DNS. The contribution of Luis Munoz is gratefully acknowledged.

COPYRIGHT

Copyright (c)2011-2012 Dick Franks

All rights reserved.

This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

perl, Net::DNS, Net::DNS::Domain, Net::DNS::RR, RFC1035 Section 5.1, RFC2308, BIND 9 Administrator Reference Manual