Parse bind config file.
use BIND::Config::Parser; # Create the parser my $parser = new BIND::Config::Parser; my $indent = 0; # Set up callback handlers $parser->set_open_block_handler( sub { print "\t" x $indent, join( " ", @_ ), " {\n"; $indent++; } ); $parser->set_close_block_handler( sub { $indent--; print "\t" x $indent, "};\n"; } ); $parser->set_statement_handler( sub { print "\t" x $indent, join( " ", @_ ), ";\n"; } ); # Parse the file $parser->parse_file( "named.conf" );
BIND::Config::Parser provides a lightweight parser to the configuration file syntax of \s-1BIND\s0 v8 and v9 using a \*(C`Parse::RecDescent\*(C' grammar.
It is in a similar vein to \*(C`BIND::Conf_Parser\*(C'. However, as it has no knowledge of the directives, it doesn't need to be kept updated as new directives are added, it simply knows how to carve up a \s-1BIND\s0 configuration file into logical chunks.
Create a new \*(C`BIND::Config::Parser\*(C' object.
Set the code to be called when a configuration block is opened. At least one argument will be passed; the name of that block, for example \*(C`options\*(C' or \*(C`zone\*(C', etc. as well as any additional items up to but not including the opening curly brace.
Set the code to be called when a configuration block is closed. No arguments are passed.
Set the code to be called on a single line configuration element. At least one argument will be passed; the name of that element, as well as any additional items up to but not including the ending semi-colon.
Parse \s-1FILENAME\s0, triggering the above defined handlers on the relevant sections.
Probably the odd one or two things. I'm fairly sure the grammar is correct.
Copyright (c) 2005 Matt Dainty.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Matt Dainty <[email protected]>.
perl, Parse::RecDescent, BIND::Conf_Parser.