Tree::Base - a base class for trees
package MyTree; use base 'Tree::Base'; sub blah {shift->{blah}} use MyTree; my $tree = MyTree->new(blah => ...); my $child = $tree->create_child(blah => ...); $child->create_child(blah => ...);
my $tree = Tree::Base->new(%data);
my $child = $tree->create_child(%data);
$tree->add_child($child);
undef if the node is the root.
my $parent = $tree->parent;
my @children = $tree->children;
Get the child with index $i.
my $child = $toc->child($i);
The root node ($tree if $tree is the root.)
my $root = $tree->root;
True if this is the root node.
$tree->is_root;
Recursive children.
my @descendants = $toc->descendants;
Nodes before this, at the same level.
my @nodes = $tree->older_siblings;
Nodes after this, at the same level.
my @nodes = $tree->younger_siblings;
Returns the next sibling or undef.
$younger = $toc->next_sibling;
Returns the previous sibling or undef.
$older = $tree->prev_sibling;
Returns all of the node's ancestors (from parent upward.)
my @ancestors = $tree->ancestors;
my @ans = $tree->rmap(sub {...});
You may prefer the JavaStyleAccessors of Tree::Simple or one of the other tree modules mentioned in its fine manual. I wanted a tree with lower-cased accessors, fewer methods, a root() which returned undef, and no need to worry about circular references.
This module was partially based on the tree functionality of dotReader's dtRdr::TOC object.
Eric Wilhelm @ <ewilhelm at cpan dot org>
http://scratchcomputing.com/
If you found this module on CPAN, please report any bugs or feature requests through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
If you pulled this development version from my /svn/, please contact me directly.
Copyright (C) 2006-2009 Eric L. Wilhelm, All Rights Reserved.
Absolutely, positively NO WARRANTY, neither express or implied, is offered with this software. You use this software at your own risk. In case of loss, no person or entity owes you anything whatsoever. You have been warned.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Tree::Base, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tree::Base
CPAN shell
perl -MCPAN -e shell install Tree::Base
For more information on module installation, please visit the detailed CPAN module installation guide.