Tree::Simple::Manager::Index - A class for quick-access indexing for Tree::Simple hierarchies
use Tree::Simple::Manager::Index; my $index = Tree::Simple::Manager::Index->new($tree_hierarchy); my $node_deep_in_the_tree = $index->getTreeByID(100134);
This module will index a Tree::Simple hierarchy so that node's can be quickly accessed without needing to search the entire heirarchy. It currently will index the Tree::Simple nodes by their UID property. Plans for allowing other means of indexing are in the future.
Given a $tree it will index all it's nodes by their UID values.
$tree
This will take the root tree (the $tree arguments in new) and index it. This method can be overridden by a subclass to provide custom indexing functionality. See the SUBCLASSING section below.
new
This will return a list of all the index keys.
This will return the root of the indexed tree.
Given an $id this will return the tree associated with it. If no tree is associated with it, an exeception will be thrown.
$id
Returns a boolean if there is a tree associated with that $id.
This module will index a Tree::Simple hierarchy using the UID property of each tree node (fetched with the getUID method of Tree::Simple). This works well with the Tree::Simple::Manager's default tree file parser filter, which expects a tree file format which supplies an id field. It is obvious that this approach may not be useful in all cases, so I have built this module too easily allow for subclassing and customization of the indexing process.
getUID
You will need to override the indexTree method. The root tree is accessible by the getRootTree method, and the index is a hash reference available as a public field $self->{index}. How you choose to construct the index from here is up to you. Here are a couple of things to keep in mind though.
indexTree
getRootTree
$self->{index}
We throw an exception in the default indexer if we notice a duplicate key being created. It is the responsibility of the subclass author to check.
None that I am aware of. Of course, if you find a bug, let me know, and I will be sure to fix it.
I use Devel::Cover to test the code coverage of my tests, see the Tree::Simple::Manager documentation for more details.
stevan little, <stevan@iinteractive.com>
Copyright 2004-2007 by Infinity Interactive, Inc.
http://www.iinteractive.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
Expected text after =item, not a bullet
To install Tree::Simple::Manager, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tree::Simple::Manager
CPAN shell
perl -MCPAN -e shell install Tree::Simple::Manager
For more information on module installation, please visit the detailed CPAN module installation guide.