require Class::Eroot;
my $some_obj;
my $eroot = new EROOT ( 'Name' => "persist.file",
'Key' => "myAppObjects" );
if( $eroot->Continue ){
# No existing objects. Start from scratch.
$some_obj = new SomeObj;
$eroot->Keep( "Some_obj" => $some_obj );
}
else{
$some_obj = $eroot->Root("some_obj");
}
$eroot->List;
$eroot->Keep( "MyObj" => $myobj );
$eroot->Lose( "Old_Obj" );
$eroot->Lose( $this_obj );
The eroot will attempt to send a suspend message to the object prior to storing the object's state. The object's class is not required to have a suspend method defined.
When the eroot restores an object it will bless the object reference in the object's class (package) and will attempt to send a resume message to the object. The object's class is not required to have a resume method defined.
An object should not propagate suspend and resume messages. The eroot will send suspend messages to the objects in the order in which they were stored in the eroot (breadth-first, root-to-leaves). The eroot will send resume messages by starting with the classes of the objects at the leaves of the object hierarchy and moving toward the root of the object hierarchy.
Note that Perl will call the destructors of the persistent objects. The programmer should be prepared to deal with this.
It is necessary to Keep an object only once. The object will remain persistent until the eroot is told to Lose it.
Embedded single quotes in the value will be preserved. This is currently the only place where single quotes are handled.
o Storing the eroot.
o Storing references to tie()'d variables and objects.
o Storing references to CODE objects.
o Storing the same object in two different eroots.
Unless you think you know what you're doing, of course.
o Using two eroots to store each other :)
o Storing named arrays and hashes. These will be restored as
anonymous arrays and hashes.
o Storing an object while it has an open stream.
o Storing an object which has an %OVERLOAD somewhere in
it's class hierarchy.
Know your object hierarchy. Be sure that everything in the hierarchy can handle persistence.
Class::Eroot.pm - Eternal Root class.
persist.file - User-defined file where objects are stored.
Class::Template.pm - Struct/member template builder.