NAME
Konstrukt::Parser::Node - A node in the parse tree
SYNOPSIS
#create root node
my $root_node = Konstrukt::Parser::Node->new({ type => "root" });
#create text node
my $text_node = Konstrukt::Parser::Node->new({ type => "plaintext", content => "text" });
#create tag node
my $tag_node = Konstrukt::Parser::Node->new({ type => "tag", handler_type => "&", tag => { type => "upcase" } });
#create tree
$root_node->add_child($tag_node);
$tag_node->add_child($text_node);
#print out the tree
print $root_node->tree_to_string();
DESCRIPTION
Class for the nodes of the parse tree.
Each node has a type and a content. The type will usually be "root" for the root node, "plaintext" for a text node, "comment" for a comment node or "tag" for a tag node (which usually has some child nodes).
Generally you will create a root node first and then add child nodes (plaintext or tags).
This class provides some handy methods for the work with the tree and its nodes.
METHODS
new
Constructor of this class
Parameters:
$hash - Optional: Hashref that contains the initial data
add_child
Adds a child to this node behind the last child node
Parameters:
$child - The child node (a Konstrukt::Parser::Node object) to add
delete
Deletes this child from the tree
append
Appends a child behind this one
Parameters:
$node - The node to append
prepend
Prepends a child before this one
Parameters:
$node - The node to prepend
replace_by_node
Replaces this node by a specified other node. The new node should not come from an other position in a tree as the pointers of the new node will be modified to fit into the position of the replaced node. The replacement node will be torn out of its old position.
Parameters:
$node - The new node
replace_by_children
Replaces this node by its children.
move_children
Moves all children of one node to another node. The child nodes will be deleted from the source node (the node on which the method is called) and added to the destination node.
Parameters:
$destination - The destination node
children_to_string
Will join all plaintext- and comment child nodes to a string. All other nodes will be ignored. Will not recurse into deeper levels.
tree_to_string
Creates a human readable tree string from the specified node. Mainly used for debugging.
Undocumented debug methods
remove_cross_references
Removes all cross references that fuck up the data dump.
restore_cross_references
Add some not really neccessary but handy cross references.
AUTHOR
Copyright 2006 Thomas Wittek (mail at gedankenkonstrukt dot de). All rights reserved.
This document is free software. It is distributed under the same terms as Perl itself.