Tie::History - Perl extension giving scalars, arrays and hashes a history.
use Tie::History; my $scalartobj = tie($scalar, 'Tie::History'); $scalar = "Blah blah blah"; $tiedobject->commit; # If you don't have $tiedobject, you can use tied(). tied($scalar)->commit; # Commit the change $scalar = "More more more"; $tiedobject->commit; # Commit the change my $arraytobj = tie(@array, 'Tie::History'); @array = qw/one two three/; $arraytobj->commit; my $hashtobj = tie(%hash, 'Tie::History'); $hash{key} = "value"; $hashtobj->commit;
$scalartobj->commit; $arraytobj->commit; $hashtobj->commit; # Or if you don't have an object created tied($scalar)->commit; tied(@array)->commit; tied(%hash)->commit;
Commit the current value into the history.
$previous = $scalartobj->previous; @previous = $arraytob->previous; %previous = $hashobj->previous; # Or if you don't have an object created $previous = tied($scalar)->previous; @previous = tied(@array)->previous; %previous = tied(%hash)->previous;
Return the previous committed copy.
$current = $scalartobj->current; @current = $arraytobj->current; %current = $hashtobj->current; # Or if you don't have an object created $current = tied($scalar)->current; @current = tied(@array)->current; %current = tied(%hash)->current;
Return the current copy, even if uncommitted.
$first = $scalartobj->get(0); @first = $arraytobj->get(0); %first = $hashtobj->get(0); # Or if you don't have an object created $first = tied($scalar)->get(0); @first = tied(@array)->get(0); %first = tied(%hash)->get(0);
Return the copy in the position passed, starting with 0 as the first, and -1 as the last.
@all = $scalartobj->getall; @all = $arraytobj->getall; @all = $hashtobj->getall; # Or if you don't have an object created @all = tied($scalar)->getall; @all = tied(@array)->getall; @all = tied(%hash)->getall;
Return an array with all previous versions committed.
$scalartobj->revert(1); $arraytobj->revert(1); $hashtobj->revert(1); # Or if you don't have an object created tied($scalar)->revert(1); tied(@array)->revert(1); tied(%hash)->revert(1);
Will revert the tied variable back to what position passed. If nothing is passed, it will revert to the last committed item. If the last item committed item is the same as the current, it will revert to the previous item. This may change in the future.
Tie::History will allow you to keep a history of previous versions of a variable, by means of committed the changes. As this is all stored in memory, it is not for use in a production system, but best kept for debugging.
None by default.
Tie::HashHistory
Tie::RDBM
Larry Shatzer, Jr., <larrysh@cpan.org>
Copyright 2004 by Larry Shatzer, Jr.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Tie::History, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tie::History
CPAN shell
perl -MCPAN -e shell install Tie::History
For more information on module installation, please visit the detailed CPAN module installation guide.