Take me over?
NAME
Tree::Base - a base class for trees
SYNOPSIS
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 => ...);
new
my $tree = Tree::Base->new(%data);
create_child
my $child = $tree->create_child(%data);
add_child
$tree->add_child($child);
parent
undef if the node is the root.
my $parent = $tree->parent;
children
my @children = $tree->children;
child
Get the child with index $i.
my $child = $toc->child($i);
root
The root node ($tree if $tree is the root.)
my $root = $tree->root;
is_root
True if this is the root node.
$tree->is_root;
descendants
Recursive children.
my @descendants = $toc->descendants;
older_siblings
Nodes before this, at the same level.
my @nodes = $tree->older_siblings;
younger_siblings
Nodes after this, at the same level.
my @nodes = $tree->younger_siblings;
next_sibling
Returns the next sibling or undef.
$younger = $toc->next_sibling;
prev_sibling
Returns the previous sibling or undef.
$older = $tree->prev_sibling;
ancestors
Returns all of the node's ancestors (from parent upward.)
my @ancestors = $tree->ancestors;
rmap
my @ans = $tree->rmap(sub {...});
See Also
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.
AUTHOR
Eric Wilhelm @ <ewilhelm at cpan dot org>
http://scratchcomputing.com/
BUGS
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
Copyright (C) 2006-2009 Eric L. Wilhelm, All Rights Reserved.
NO WARRANTY
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.
LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.