VERSION

SYNOPSIS

DESCRIPTION

Tie::HashHistory interposes itself between your program and another tied hash. Fetching and storing to the hash looks completely normal, but Tie::HashHistory is keeping a record of all the changes to the each key, and can Tie::HashHistory will give you a list of all the values the key has ever had, in chronological order.

The arguments to the tie call should be Tie::HashHistory, and then the arguments that you would have given to tie to tie the hash without the history feature. For example, suppose you wanted to store your hash data in an NDBM file named database. Normally, you would say:

tie %hash => NDBM_File, 'database', $flags, $mode;

to get this history feature, just add Tie::HashHistory before NDBM_File:

The data will still be stored in database, and it will still be an NDBM file. All the fetching and storing will look the same, but the change history of each key will be available.

The tie call will return an object; to find out the history of a key, use the history method on this object. It takes one argument, which is a key string. It will return a list of all the values that have ever been associated with the key, in chronological order, starting with the most recent. For example:

This is not as efficient as it could be because fetches and stores on %hash still go through two layers of tieing. I may fix this in a future release.

Bugs and Caveats

You cannot use delete on a Tie::HashHistory hash, because it is not clear yet what it should do. It could revert the value to the previous version (this would be easy to implement) or it could record in the history that the key was deleted. (This is more difficult.) A future version of this package may provide subclasses with one or the other functionality.

This module needs some more test files.

Author

Mark-Jason Dominus, Plover Systems

Please send questions and other remarks about this software to mjd-perl-hashhistory@pobox.com

For updates, visit http://www.plover.com/~mjd/perl/HashHistory/.

Thanks to Randal Schwartz and Chris Nandor for their assistance with the **!!** line.