The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tree::Persist

SYNOPSIS

  my $persist = Tree::Persist->new({
      ...
  });

  my $tree = $persist->tree.

  $persist->autocommit( 0 );

  $tree->set_value( 'foo' );

DESCRIPTION

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.

PLUGINS

The plugins that have been written are:

Please refer to their documentation for the appropriate options for connect() and create_datastore().

METHODS

Class Methods

  • 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().

Behaviors

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.

    This is a no-op if autocommit is true.

    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().

CODE COVERAGE

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
  ---------------------------- ------ ------ ------ ------ ------ ------ ------

SUPPORT

The mailing list is at TreeCPAN@googlegroups.com. I also read http://www.perlmonks.com on a daily basis.

AUTHORS

Rob Kinyon <rob.kinyon@iinteractive.com>

Stevan Little <stevan.little@iinteractive.com>

Thanks to Infinity Interactive for generously donating our time.

COPYRIGHT AND LICENSE

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.