Tie-TransactHash

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


Tie::TransactHash is a package which provides facilities for easy
editing of any hash.  It allows changes to be made without affecting
the sequence of the hash, neither losing the current position, nor
changing the order of the elements.

Included is a program which allows direct editing of any of the
standard Berkley DB file types.  This is especially useful for
debugging programs which write to DB files.

It does this by acting as an overlay (It doesn't use Tie::Overlay) for
the other hash, storing its data in a Tie::IxHash.  It then commits
when told to or at destruction time, copying its data straight over
into the IxHash.

This software is BETA.  I will accept bug reports mailed to me.
Please put TransactHash in the subject (Michael De La Rue
<miked@ed.ac.uk>).  Reports with fixes (diff -ur) will get fixed, but
please explain what you are fixing and give an example.  Problems
without fixes will have to wait till I have time.

lib/Tie/TransactHash.pm  view on Meta::CPAN

a standard perl hash or a hash indexed DBM file, one advantage is that
the original hash remains untouched during the transaction, so its
order (the order the each(), keys() or values functions give out) is
maintained - changes can be made to the transact hash whilst iterating
over it.

=head1 OVERVIEW

Editing a hash causes problems because it rearranges the hash.  If the
editing is to be done in sequence then this makes life difficult.  The
TransactHash class uses a fixed sequence hash class which overlays the
normal hash and allows editing in place.  It stores all of the changes
to the original hash in memory until it is told to apply them.

As a side effect of this design, the class also provides a
commit/rollback system.  When a commit is called, the order of the
hidden hash will be changed.  

A commit will normally be done as the TransactHash object is being
destroyed.  This could be undesirable if your program exits when it
discovers a failure.  You can change the.

t/basic.t  view on Meta::CPAN

#!./perl -w

=head1 tests for transacthash

These are the tests for standard transacthash functionality overlayed
on a normal in memory hash

=cut
print "1..3\n";

use Tie::TransactHash;

sub ok { print "ok ", shift, "\n" }
sub nok { print "not ok ", shift, "\n" }



( run in 1.128 second using v1.01-cache-2.11-cpan-49f99fa48dc )