Konstrukt::Parser::Node - A node in the parse tree
#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();
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.
Constructor of this class
Parameters:
$hash - Optional: Hashref that contains the initial data
Adds a child to this node behind the last child node
$child - The child node (a Konstrukt::Parser::Node object) to add
Deletes this child from the tree
Appends a child behind this one
$node - The node to append
Prepends a child before this one
$node - The node to prepend
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.
$node - The new node
Replaces this node by its 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.
$destination - The destination node
Will join all plaintext- and comment child nodes to a string. All other nodes will be ignored. Will not recurse into deeper levels.
Creates a human readable tree string from the specified node. Mainly used for debugging.
Removes all cross references that fuck up the data dump.
Add some not really neccessary but handy cross references.
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.
Konstrukt::Parser
To install Konstrukt, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Konstrukt
CPAN shell
perl -MCPAN -e shell install Konstrukt
For more information on module installation, please visit the detailed CPAN module installation guide.