MooseX::RememberHistory - Add the ability for attributes to remember their history
package MyClass; use Moose; use MooseX::RememberHistory; has 'some_attr' => ( traits => [ 'RememberHistory' ], isa => 'Num', is => 'rw', default => 0 ); package main; my $obj = MyClass->new; $obj->some_attr(1); my $hist = $obj->some_attr_history; # [ 0, 1 ]
MooseX::RememberHisory provides an attribute trait (RememberHistory) which will automagically store the values of that attribute in a related ArrayRef on each write to the trait.
RememberHistory
When the trait is applied, a history attribute is created. By default, the name of this attribute is the name of the original attribute with the extension _history (e.g. an attribute named x would get an additional x_history attribute).
_history
x
x_history
This name may be specified manually by the use of the history_name attribute option. In this case the "SYNOPSIS" example would become:
history_name
package MyClass; use Moose; use MooseX::RememberHistory; has 'some_attr' => ( traits => [ 'RememberHistory' ], history_name => 'history_of_some_attr', isa => 'Num', is => 'rw', default => 0 ); package main; my $obj = MyClass->new; $obj->some_attr(1); my $hist = $obj->history_of_some_attr; # [ 0, 1 ]
The author wrote this module to ease the writing of object-oriented differential equation solver framework. When the objects store the history of their own evolution it eases the burden of writing the solver. The solver object only needs to evolve the constituent objects and it need not worry about storing the results; those objects can now do this themselves!
Moose - A postmodern object system for Perl 5
"Attribute-traits-and-metaclasses" in Moose::Manual::Attributes
http://github.com/jberger/MooseX-RememberHistory
Joel Berger, <joel.a.berger@gmail.com>
Copyright (C) 2012 by Joel Berger
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install MooseX::RememberHistory, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::RememberHistory
CPAN shell
perl -MCPAN -e shell install MooseX::RememberHistory
For more information on module installation, please visit the detailed CPAN module installation guide.