Tree::Nary::Extended - Tree::Nary with substantial load/save from/to sql/hash
use Tree::Nary::Extended; Tree::Nary->to_hash( $ntree ) Tree::Nary->from_dbi_to_hash( $dbh, $table_name ) Tree::Nary->from_dbi_to_tree( $dbh, $table_name ) Tree::Nary->to_dbi( $tree, $dbh, $table_name ) Tree::Nary->bread_crumb_trail( $node ) Tree::Nary->depth( $node ) Tree::Nary->type( $node ) my $href_nodes = Tree::Nary->from_dbi( $dbh, $table_name ); my $nary = Tree::Nary->from_hash( $href_nodes ); Tree::Nary->depth( $nary->{children} ); my $found = Tree::Nary->find( $nary, $Tree::Nary::IN_ORDER, $Tree::Nary::TRAVERSE_ALL, 'foobar' ); my $aref_trail = Tree::Nary->bread_crumb_trail( $found ); Tree::Nary->append( $found, new Tree::Nary( 'Dummy' ) ); Tree::Nary->traverse( $nary, $Tree::Nary::PRE_ORDER, $Tree::Nary::TRAVERSE_ALL, -1, \&Tree::Nary::Extended::_callback_textout ); my $href_nodes = Tree::Nary->to_hash( $nary ); Tree::Nary->to_dbi( $href_nodes, $dbh, $table_name );
This module is not inheriting from Tree::Nary, but adds service methods to the namespace. So it an be seen as an "extended", but a bit "fishy" replacement for Tree::Nary. It loads Tree::Nary in the background and relies on some private innerts, which risks future compability. But noteworthy it works very well and does a good job for its author so far.
Tree::Nary
You should understand Tree::Nary (from CPAN) concepts first, before you proceed with this module.
Creates a Nary Tree from a hash. The keys must be id, parent_id and data.
Produces a hash from Nary Tree. Returns a reference to it.
Reads a table from a DBI $dbh and produces a hash and returns the hashref to it.
Produces a Tree::Nary::Extended tree out of a DBI table.
Note: Read the DESCRIPTION from DBIx::Tree for the format of the sql table. The columns names must be "id", "parent_id" and "data"
DESCRIPTION
DBIx::Tree
Write a Tree::Nary::Extended tree to a DBI table. See Note of from_dbi_to_tree for the format. Only the three node attributes id, parent_id, data are saved.
Tree::Nary::Extended
from_dbi_to_tree
Note: The written sql table can be read with from_dbi_to_tree method.
Traverses the anchestrol tree (partent->to->parent) upwards and collects all parents to an array. A reference to it is returned. This can be used for building a "bread crumb trail" in website navigation.
Returns the depth of a node, which is the distance to the root parent as an integer value.
Returns the node "type". 'root' if it is the root node. 'leaf' if it is a leaf node.
Tree::Nary heavily uses callbacks for doing something. Tree::Nary::Extended ships with some preconfectioned callbacks usefull for various things.
Fills the scalarref with the highest node id number of the tree.
Overwrite the node ids with primary key ids (linear (+1) unique id).
Internal use. Cannot remember what is was.
Returns the first node with a given id. $aref_args[1] will contain the resulting node.
Dumps a textual printout of the node structure. Helps debugging.
Returns a hash of tablenames from a DBI $dbh. Values are 1.
Because Tree::Nary isnt that clean OO, i had to use some dirty tricks on the innerts of the private hash objects. Thats why this module relies somehow on Tree::Nary Version 1.21 and may be broken on future updates of Tree::Nary.
None by default.
M. Ünalan, muenalan@cpan.org
Tree::Nary, DBIx::Tree
2 POD Errors
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
Non-ASCII character seen before =encoding in 'Ünalan,'. Assuming CP1252
To install Tree::Nary::Extended, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tree::Nary::Extended
CPAN shell
perl -MCPAN -e shell install Tree::Nary::Extended
For more information on module installation, please visit the detailed CPAN module installation guide.