Benjamin Tietz > Net-DNS-ZoneParse-0.103 > Net::DNS::ZoneParse

Download:
Net-DNS-ZoneParse-0.103.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  1
View/Report Bugs
Module Version: 0.103   Source  

NAME ^

Net::DNS::ZoneParse - Perl extension for Parsing and Writing BIND8/9 (and RFC1035) compatible zone-files.

SYNOPSIS ^

Plain interface

  use Net::DNS::ZoneParse qw(parse, writezone);

  my $rr = parse("db.example.com");
  my $zonetext = writezone($rr);

Object oriented interface - supporting cached parsing

  use Net::DNS::ZoneParse;

  my $parser = Net::DNS::ZoneParse->new;
  my $zone = $parser->zone("example.com");
  $zone->rr->[0]->newserial if($zone->rr->[0]->{type} eq "SOA");
  $zone->save;

DESCRIPTION ^

This module is yet another caching parser/generator for RFC1035 compatible zone-files. It aims to have a fast interface for parsing and support all RRs known to Net::DNS::RR.

In some circumstances the parsing of an entry is too complicated for the default _from_string-logic of the corresponding RR. For this cases, N::D::ZoneParse extends the Interface of N::D::RR with the function new_from_filestring. Per default this will call the responding new_from_string, but may be implemented differently for a given RR.

When dealing not just with one Zonefile, the Object-oriented Interface even becomes more handy. It provides an interface loading only the zonefiles needed and those only once. Each Zone is then represented by a Net::DNS::ZoneParse::Zone object.

METHODS

new

        $parser = Net::DNS::ZoneParse->new( [ $config ] )

Creating a new Net::DNS::ZoneParse object with the given configuration for file-autoloading. The following parameters are currently supported:

path

Path to the directory where all of the ZoneFiles can be found. The default is the current working directory.

prefix

The prefix to the generate the filename out of the zonename. The default is "db.". Thus using the default, loading "example.com" will search for the file "db.example.com"

suffix

Similar to prefix, the default is the empty string.

dontload

If set to true, the zone() wont parsed the corresponding file automaticly

nocache

If set to true, loaded files won't be cached within this object automaticly. In this case, extent has to be used.

parser

The parsers to use when reading files. These must be given within a arrayreference. All of the given parsers must be found within Net::DNS::ZoneParse::Parser. The default is [ "Native" ]. All Parsers in the list will be used consecutively unless one has returned contents of the file to read.

parser_args

A hashref with parser-names as keys. Some parser may allow further options; these can be accessed using this argument.

generator

The generators to use when generating a new zonefile. The use is corresponding to parsers. Generators must be found within Net::DNS::ZoneParse::Generator

zone

        $zone = $parser->zone("example.com" [, $param])

Returns the Net::DNS::ZoneParse::Zone object for the given domain. If there where no corresponding zonefile found, an empty Object will be returned. If the zone was loaded for the first time the corresponding file will be loaded, otherwise the cached object will be returned.

$param is a hash-reference which can be used to adjust the behaviour. If a parameter is not given here, it's value used at the time of the objects generation will be used. Supported parameters are:

path
filename

This will take precedence above prefix/suffix

prefix
suffix
dontload

extent

        $parser->extent("example.com", $rrs);

Extent the cached entries for the given origin - "example.com" in the example by the RRs given in $rrs. These might be an array or a reference to an array of Net::DNS::RR-Objects.

uncache

        $parser->uncache("example.com");

Uncaching removes a zone from the zonecache. The exported instances of this zone will stay alive, but the next call to zone() will generate a new object.

EXPORT

writezone

        $zonetext = writezone($rr);
        # or
        $zonetext = $parser->writezone($zone);

$rr might be either an array of Net::DNS::RR object, or a reference to them. If using the object-oriented interface, this can be used to by just using the name of the zone to write. In that case, correct directives for $ORIGIN and $TTL will be created, too.

writezone will then return a string with the contents of a corresponding zone-file.

As last parameter, a additional Hash-ref can be used to tweak some of the behavior. The following parameters are supported:

origin

This may contain the zone-name, unless used in the object-oriented interface

ttl

The default TTL to be used in the generated file.

rr

The Resource-records to write

generator

the same as in new

parse

        $rr = parse($file);
        # or
        $rr = $parser->parse($file [, $param [, $rrin]]);

parse a specific zonefile and returns a reference to an array of Net::DNS::RR objects.

If the function-oriented interface is used and Net::DNS::ZoneFile::Fast is installed, that parser is used instead.

$file might be either a filename or a open filehandle to be read.

$param is a HASH-ref, with the following entries. If given, those may change to reflect the contents of the parsed file.

origin

The current domains name

ttl

The default TTL for all RRs

fh

An already opened filehandle, $file can be ommitted, if this is given.

file

The name of the file to read, $file can be ommitted, if this is given

rrs

Resource Records, which will be added to these found in the file

nocache

if given, the parsed file will not be cached in the object.

parser
parser_args

Same as in the call of new().

$rrin is a ARRAY-ref of Net::DNS::RR objects. If given, this list will be extended.

SEE ALSO ^

Net::DNS

AUTHOR ^

Benjamin Tietz <benjamin@micronet24.de>

COPYRIGHT ^

Copyright (C) 2010 by Benjamin Tietz

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: