Stevan Little > Tree-Simple-Manager > Tree::Simple::Manager::Index

Download:
Tree-Simple-Manager-0.07.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.04   Source  

NAME ^

Tree::Simple::Manager::Index - A class for quick-access indexing for Tree::Simple hierarchies

SYNOPSIS ^

  use Tree::Simple::Manager::Index;
  
  my $index = Tree::Simple::Manager::Index->new($tree_hierarchy);  
  my $node_deep_in_the_tree = $index->getTreeByID(100134);

DESCRIPTION ^

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.

METHODS ^

new ($tree)

Given a $tree it will index all it's nodes by their UID values.

indexTree

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.

getIndexKeys

This will return a list of all the index keys.

getRootTree

This will return the root of the indexed tree.

getTreeByID ($id)

Given an $id this will return the tree associated with it. If no tree is associated with it, an exeception will be thrown.

hasTreeAtID ($id)

Returns a boolean if there is a tree associated with that $id.

SUBCLASSING ^

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.

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.

Duplicate index keys

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.

BUGS ^

None that I am aware of. Of course, if you find a bug, let me know, and I will be sure to fix it.

CODE COVERAGE ^

I use Devel::Cover to test the code coverage of my tests, see the Tree::Simple::Manager documentation for more details.

AUTHOR ^

stevan little, <stevan@iinteractive.com>

COPYRIGHT AND LICENSE ^

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.

syntax highlighting: