|Think about Loose Coupling|
Tree::DAG_Nodeby bm (Hermit)
|on Sep 02, 2003 at 15:13 UTC||Need Help??|
Item Description: Represents nodes in a tree, and their relationships
I work in release management, and am constantly dealing with tree's of many different types, such as projects, file system, releases, versions of a file, class diagrams,etc. I have grown used to managing these through a variety of different ways, such as hashes, or rolling my own "tree structure" by adding parent/child or predecessor/successor properties and methods to my classes.
But Perl being Perl, well, CPAN being CPAN, you can always take advantage of other's experience. A few searches later, I found Tree::DAG_Node.
This class represents tree structures in OO Perl. Specifically, this class manages the relationships between a set of "nodes". There is only one type of relationship you can create: the mother node and the daughter node. The daughter list of a node is ordered, but this is of course ignoreable.
While a node can contain whatever data you would like it to (through the 'attributes' property), not every relationship can be created - for example, a node may only have one mother.
The author, prolific CPAN contributor Sean M. Burke, encourages inheriting off Tree::DAG_Node. This exposes a seriously large number of tree related methods to your class, such as:
And that is just the summary! To quote the doco In fact, I'd be very surprised if any one user ever had use for more that even a third of the methods in this class. And remember: an atomic sledgehammer will kill that fly. , this is a very large class. Perhaps too over the top for some solutions (hence the atomic sledgehammer analogy!). Autoloader is not implemented, so some might find this a little slow for their needs, and there lies the biggest problem with this class.
The other thing I don't get is where he gets the DAG in DAG_Node from!
In summary though, and excellent class that provides a vast array of sophistication to a tree structure. Adding:
to the top of your class can open many doors that would not of otherwise existed (just look at the walk_down method alone). I highly recommend this class for implementing tree structures.