man Data::Grove::Parent () - provide parent properties to Data::Grove objects


Data::Grove::Parent - provide parent properties to Data::Grove objects


 use Data::Grove::Parent;

 $root = $object->root;
 $rootpath = $object->rootpath;
 $tied = $object->add_magic([ $parent ]);

 $node = Data::Grove::Parent->new($hash [, $parent]);
 $node_list = Data::Grove::ParentList->new($array [, $parent]);


Data::Grove::Parent is an extension to Data::Grove that adds `CWParent' and `CWRaw' properties to Data::Grove objects and methods for returning the root node of a grove, a list of nodes between and including the root node and the current node, and a method that creates parented nodes.

Data::Grove::Parent works by creating a Perl ``tied'' object that contains a parent reference (`CWParent') and a reference to the original Data::Grove object (`CWRaw'). Tying-magic is used so that every time you reference the Data::Grove::Parent object it actually references the underlying raw object.

When you retrieve a list or a property of the Raw object, Data::Grove::Parent automatically adds magic to the returned list or node. This means you only call `add_magic()' once to create the first Data::Grove::Parent object and then use the grove objects like you normally would.

The most obvious use of this is so you don't have to call a `CWdelete' method when you want to release a grove or part of a grove; since Data::Grove and Data::Grove::Parent objects have no cyclic references, Perl can garbage collect them normally.

A secondary use is to allow you to reuse grove or property set fragments in multiple trees. WARNING: Data::Grove currently does not protect you from creating your own cyclic references! This could lead to infinite loops if you don't take care to avoid them.


`CWroot()' returns the root node if `CW$object' is a `CWData::Grove::Parent' object. `CWrootpath()' returns an array of all the nodes between and including the root node and `CW$object'. `CWadd_magic()' returns a CWData::Grove::Parent object with `CW$object' as it's `CWRaw' object. If `CW$parent' is given, that becomes the tied object's parent object.


Ken MacLeod,