NAME

Config::AST::Node - generic configuration syntax tree node

SYNOPSIS

use parent 'Config::AST::Node';

DESCRIPTION

This is an abstract class representing a node in the configuration parse tree. A node can be either a non-leaf node, representing a section, or a leaf node, representing a simple statement.

METHODS

new(ARG => VAL, ...)

Creates new object. Recognized arguments are:

clone => OBJ

Clone object OBJ, which must be an instance of Config::AST::Node or its derived class.

default => VAL

Sets default value.

locus => LOC

Sets the locus - an object of class Text::Locus, which see.

file => NAME

Sets the file name.

order => N

Sets ordinal number.

$x = $node->locus;

Returns a locus associated with the node.

$node->locus($LOC)

$node->locus($FILE, $LINE)

Associates a locus with the node. In the second form, a new locus object is created for location $FILE:$LINE.

$x = $node->order

$node->order($N)

Returns or sets and returns ordinal number for the node.

$x = $node->default

$node->default($N)

Returns or sets and returns default value for the node.

$node->is_leaf

Returns true if node is a leaf node

$node->is_null

Returns true if node is a null node

$node->is_section

Returns true if node represents a section.

$node->is_value

Returns true if node represents a value (or statement).

@array = $cfg->flatten()

@array = $cfg->flatten(sort => $sort)

Returns a flattened representation of the configuration, as a list of pairs [ $path, $value ], where $path is a reference to the variable pathname, and $value is a Config::AST::Node::Value object.

The $sort argument controls the ordering of the entries in the returned @array. It is either a code reference suitable to pass to the Perl sort function, or one of the following constants:

NO_SORT

Don't sort the array. Statements will be placed in an apparently random order.

SORT_NATURAL

Preserve relative positions of the statements. Entries in the array will be in the same order as they appeared in the configuration file. This is the default.

SORT_PATH

Sort by pathname.

These constants are not exported by default. You can either import the ones you need, or use the :sort keyword to import them all, e.g.:

use Config::AST::Node qw(:sort);
@array = $node->flatten(sort => SORT_PATH);

$cfg->canonical(%args)

Returns the canonical string representation of the configuration node. For value nodes, canonical representation is:

QVAR=VALUE

where QVAR is fully qualified variable name, and VALUE is the corresponding value.

For sections, canonical representation is a list of canonical representations of the underlying nodes, delimited by newlines (or another character - see the description of the delim argument, below). The list is sorted by QVAR in ascending lexicographical order.

%args are zero or more of the following keywords:

delim => STR

Use STR to delimit statements, instead of the newline.

locus => 1

Prefix each statement with its location.

SEE ALSO

Config::AST, Config::AST::Node::Null, Config::AST::Node::Value, Config::AST::Node::Section.