<?xml version="1.0" encoding="windows-1252"?>
<node id="89188" title="Re: Undoable Objects" created="2001-06-17 19:10:52" updated="2005-07-21 01:27:21">
<type id="11">
note</type>
<author id="83012">
bikeNomad</author>
<data>
<field name="doctext">
It would also be a good idea to add a DESTROY method in that same scope so that the history gets cleaned up when objects go away:&lt;p&gt;&lt;code&gt;
{
        my %history;

        sub _log {
                my $self = shift;
                my $attrib = shift;
                my $value = $self-&gt;{$attrib};
                push @{ $history{$self} }, [ $attrib, $value ];
        }

        sub undo {
                my $self = shift;
                return unless (scalar @{ $history{$self} });
                my ($attrib, $value) = @{ pop @{ $history{$self} } };
                $self-&gt;{$attrib} = $value;
        }

 sub DESTROY {
  my $self = shift;
  delete $history{$self};
 }
}
&lt;/code&gt;</field>
<field name="root_node">
29813</field>
<field name="parent_node">
29813</field>
</data>
</node>
