Hui Zhou


OGDL::Graph - a class for manipulating a OGDL graph object


  use OGDL::Graph;

  #the following prints:
  #    subnode1
  #    subnode1

  #the following prints:

  $s=$g->getname("node1.[0]"); #$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("node2","subnode1"); #Recreates the above graph
  @nodes=$g->glist("*.subnode1"); #@nodes contains the two subnodes

  #it prints
  #    subnode1


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:

$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.