Tree::Persist
my $persist = Tree::Persist->new({ ... }); my $tree = $persist->tree. $persist->autocommit( 0 ); $tree->set_value( 'foo' );
This is a transparent persistence layer for Tree and its children. It's fully pluggable and will allow either loading, storing, and/or association with between a datastore and a tree.
NOTE: If you load a subtree, you will have access to the parent's id, but the node will be considered the root for the tree you are working with.
The plugins that have been written are:
Tree::Persist::DB::SelfReferential
Tree::Persist::File::XML
Please refer to their documentation for the appropriate options for connect() and create_datastore().
connect()
create_datastore()
connect({ %opts })
This will return an object that will provide persistence. It will not be an object that inherits from Tree::Persist.
create_datastore({ %opts })
This will create a new datastore for a tree. It will then return the object used to create that datastore, as if you had called connect().
These behaviors apply to the object returned from connect() or create_datastore().
autocommit()
This is a boolean option that determines whether or not changes to the tree will committed to the datastore immediately or not. The default is true. This will return the current setting.
tree()
This returns the tree.
commit()
This will save all changes made to the tree associated with this Tree::Persist object.
This is a no-op if autocommit is true.
rollback()
This will undo all changes made to the tree since the last commit. If there were any changes, it will reload the tree from the datastore.
NOTE: Any references to any of the nodes in the tree as it was before rollback() is called will not refer to the same node of $persist>tree after rollback().
$persist>tree
We use Devel::Cover to test the code coverage of our tests. Below is the Devel::Cover report on this module's test suite.
---------------------------- ------ ------ ------ ------ ------ ------ ------ File stmt bran cond sub pod time total ---------------------------- ------ ------ ------ ------ ------ ------ ------ blib/lib/Tree/Persist.pm 100.0 83.3 n/a 100.0 100.0 17.7 97.6 .../lib/Tree/Persist/Base.pm 100.0 88.9 100.0 100.0 100.0 20.0 98.3 blib/lib/Tree/Persist/DB.pm 100.0 n/a n/a 100.0 n/a 3.1 100.0 ...ist/DB/SelfReferential.pm 100.0 93.8 n/a 100.0 n/a 36.3 99.2 .../lib/Tree/Persist/File.pm 100.0 50.0 n/a 100.0 n/a 7.7 96.7 .../Tree/Persist/File/XML.pm 100.0 100.0 100.0 100.0 n/a 15.1 100.0 Total 100.0 89.1 100.0 100.0 100.0 100.0 98.7 ---------------------------- ------ ------ ------ ------ ------ ------ ------
The mailing list is at TreeCPAN@googlegroups.com. I also read http://www.perlmonks.com on a daily basis.
Rob Kinyon <rob.kinyon@iinteractive.com>
Stevan Little <stevan.little@iinteractive.com>
Thanks to Infinity Interactive for generously donating our time.
Copyright 2004, 2005 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.
To install Tree::Persist, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tree::Persist
CPAN shell
perl -MCPAN -e shell install Tree::Persist
For more information on module installation, please visit the detailed CPAN module installation guide.