OGDL::Graph - a class for manipulating a OGDL graph object
use OGDL::Graph; $g=OGDL::Graph->new("rootname"); $g1=$g->addGraph("node1"); $g2=$g->addGraph("node2"); $g11=$g1->addGraph("subnode1"); $g2->addNode($g11) #the following prints: #node1 # subnode1 #node2 # subnode1 $g->print; $q=$g->get("node1"); #the following prints: #subnode1 $q->print; $s=$g->getname("node1."); #$s eq "subnode1" @c=$g->getChildren; #@c now is ($g1, $g2) ## Editing the graph with paths $g->clear # unlinks all the children nodes $g->gadd("node1.subnode1"); $g->gadd("node2","subnode1"); #Recreates the above graph @nodes=$g->glist("*.subnode1"); #@nodes contains the two subnodes $g->remove("*2.*"); $g->print; #it prints #node1 # subnode1 #node2
OGDL is a human editable alternative to XML. It embeds information in the form of graphs, where the nodes are strings and the arcs or edges are spaces or indentations. This class facilitates the manipulation of ogdl graph.
$g=OGDL::Graph->new($rootname) This method creates an empty graph with root node name $rootname.
$child=$g->addGraph($name) This method adds a subnode with name $name to $g as its last children node. It returns the new subnode that is added.
$node=$g->get($path) This method returns the node specified by $path. For the OGDL PATH specification, see: http://ogdl.sourceforge.net.
$str=$g->getname($path) This method returns the name of the node matches $path.
$n=$g->childrencount It returns the number of children nodes of $g.
@nodes=$g->getChildren It returns all the children nodes of $g as an array.
$node->unlink unlinks $node from the graph
$g->glist($path) Returns a list of nodes that matches $path
$g->gremove($path) Unlinks the nodes specified by $path from the graph
$g->gadd($path) Adds nodes to the graph that qualified by $path
$g->print(%print_options) It prints $g into a text stream. It accepts following options: "indentwidth" sets the indent width for each level, defaut is 4; "singlequote" sets whether to put quote around the text if the output only contains a single node, default is not to put quote; "filehandle" sets the filehandle the output goes to. The default goes to STDOUT; "depth" sets how many level of subnodes to print. The default is -1, which prints all subnodes. "group"=>n prints all nodes below level n into one line. The default prints each node in a single line. "noblockquote"=>1 prints all nodes that require quoting with doulble quotes. The default prints it in a '\' block.