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

NAME

Config::AST::Node::Section - Configuration section node.

DESCRIPTION

Nodes of this class represent configuration sections in the AST.

METHODS

new(ROOT, ARG => VAL, ...)

Creates new section object. ROOT is the root object of the tree or the Config::AST object. The ARG => VAL pairs are passed to the parent class constructor (see Config::AST::Node).

$t = $node->subtree

Returns tree containing all subordinate nodes of this node.

$t = $node->subtree($key)

Returns the subnode at $key or undef if there is no such subnode.

$t = $node->subtree($key => $value)

Creates new subnode with the given $key and $value. Returns the created node.

@a = $node->keys;

Returns a list of names of all subordinate statements in this section.

$bool = $node->has_key($str)

Returns true if statement with name $str is present in the section described by $node.

$node->delete($name)

Deletes the node with name $name. Returns the removed node, or undef if not found.

$node->merge($other)

Merges the section $other (a Config::AST::Node::Section) to $node.

$h = $cfg->as_hash

$h = $cfg->as_hash($map)

Returns parse tree converted to a hash reference. If $map is supplied, it must be a reference to a function. For each $key/$value pair, this function will be called as:

    ($newkey, $newvalue) = &{$map}($what, $key, $value)

where $what is section or value, depending on the type of the hash entry being processed. Upon successful return, $newvalue will be inserted in the hash slot for the key $newkey.

If $what is section, $value is always a reference to an empty hash (since the parse tree is traversed in pre-order fashion). In that case, the $map function is supposed to do whatever initialization that is necessary for the new subtree and return as $newvalue either $value itself, or a reference to a hash available inside the $value. For example:

    sub map {
        my ($what, $name, $val) = @_;
        if ($name eq 'section') {
            $val->{section} = {};
            $val = $val->{section};
        }
        ($name, $val);
    }
    

$s = $node->as_string

Returns the string "(section)".

SEE ALSO

Config::AST, Config::AST::Node.