Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Tree::DAG_Node

by bm (Hermit)
on Sep 02, 2003 at 15:13 UTC ( #288332=modulereview: print w/ replies, xml ) Need Help??

Item Description: Represents nodes in a tree, and their relationships

Review Synopsis:

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:

  • $node->daughters or $node->mother
  • $node->add_daughter or $node->add_daughter_left
  • $node->attributes->{'version'} = '1.1.3.4' (defines the attribute 'version' in the node)
  • $node->ancestors (returns a list of nodes)
  • $node->walk_down ({ callback => \&foo, callbackback => \&foo, ... }) (a depth first traversal of the tree, executes the passed callback)
  • various list of list to tree conversion methods
  • $node->draw_ascii_tree (ASCII pretty print of the tree)

    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:

    use Tree::DAG_Node; @ISA = qw(Tree::DAG_Node);
    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.

    Comment on Tree::DAG_Node
    Download Code
    Re: Tree::DAG_Node
    by Anonymous Monk on Sep 02, 2003 at 15:58 UTC
      The DAG comes from Directed Acyclic Graph. All the arcs have direction (you can only travel from parent to child, for instance), and the entire graph has no cycles (it isn't possible to travel from a node back to itself without having to retrace the outgoing path). All DAGs can be viewed as trees (or forests, depending on how many connected components you have).
    Re: Tree::DAG_Node
    by cchampion (Curate) on Sep 02, 2003 at 18:18 UTC

    Back to Reviews

  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Node Status?
    node history
    Node Type: modulereview [id://288332]
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (13)
    As of 2014-08-21 16:30 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (137 votes), past polls