# # Copyright (C) 1999 Ken MacLeod # Data::Grove is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # # $Id: Grove.pm,v 1.6 1999/12/22 21:15:00 kmacleod Exp $ # ### ### For a similar package, see also: ### ### Graph::Element -- elements for a directed graph ### Neil Bowers (NIELB) ### package Data::Grove; use vars qw{ $VERSION }; # will be substituted by make-rel script $VERSION = "0.07"; sub new { my $type = shift; my $self = ($#_ == 0) ? { %{ (shift) } } : { @_ }; if (defined $self->{Raw}) { # clone the raw object $self = { %{ $self->{Raw} } }; } return bless $self, $type; } package Data::Grove::Characters; use vars qw{ @ISA $type_name }; @ISA = qw{Data::Grove}; $type_name = 'characters'; 1; __END__ =head1 NAME Data::Grove -- support for deeply nested structures =head1 SYNOPSIS use Data::Grove; $object = MyPackage->new; package MyPackage; @ISA = qw{Data::Grove}; =head1 DESCRIPTION C provides support for deeply nested tree or graph structures. C is intended primarily for Perl module authors writing modules with many types or classes of objects that need to be manipulated and extended in a consistent and flexible way. C is best used by creating a core set of ``data'' classes and then incrementally adding functionality to the core data classes by using ``extension'' modules. One reason for this design is so that the data classes can be swapped out and the extension modules can work with new data sources. For example, these other data sources could be disk-based, network-based or built on top of a relational database. Two extension modules that come with C are C and C. C adds a `C' property to grove objects and implements a `C' method to grove objects to return the root node of the tree from anywhere in the tree and a `C' method to return a list of nodes between the root node and ``this'' node. C adds callback methods `C' and `C' that call your handler or receiver module back by object type name or the object's name. C objects do not contain parent references, Perl garbage collection will delete them when no longer referenced and sub-structures can be shared among several structures. C is used to create temporary objects with parent pointers. Properties of data classes are accessed directly using Perl's hash functions (i.e. `C<$object-E{Property}>'). Extension modules may also define properties that they support or use, for example Data::Grove::Parent adds `C' and `C' properties and Visitor depends on `C' and `C' properties. See the module C for an example implementation of C. =head1 METHODS =over 4 =item new( PROPERTIES ) Return a new object blessed into the SubClass, with the given properties. PROPERTIES may either be a list of key/value pairs, a single hash containing key/value pairs, or an existing C object. If an existing C is passed to `C', a shallow copy of that object will be returned. A shallow copy means that you are returned a new object, but all of the objects underneath still refer to the original objects. =back =head1 AUTHOR Ken MacLeod, ken@bitsko.slc.ut.us =head1 SEE ALSO perl(1) =cut