Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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'} = '' (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.

    In reply to Tree::DAG_Node by bm

    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (3)
    As of 2019-05-20 20:56 GMT
    Find Nodes?
      Voting Booth?
      Do you enjoy 3D movies?

      Results (129 votes). Check out past polls.