NAME
Bio::Root::Storable - Safely store/retrieve objects from disk
SYNOPSIS
my $storable = Bio::Root::Storable->new();# Store/retrieve using class retrievermy $token = $storable->store();my $storable2 = Bio::Root::Storable->retrieve( $token );# Store/retrieve using object retrievermy $storable2 = $storable->new_retrievable();$storable2->retrieve();
DESCRIPTION
Generic module that allows objects to be safely stored/retrieved from disk. Can be inhereted by any BioPerl object. As it will not usually be the first class in the inheretence list, _initialise_storable() should be called during object instantiation.
Object storage is recursive; If the object being stored contains other storable objects, these will be stored separately, and replaced by a skeleton object in the parent hierarchy. When the parent is later retrieved, its children remain in the skeleton state until explicitly retrieved by the parent. This lazy-retrieve approach has obvious memory efficiency benefits for certain applications.
By default, objects are stored in binary format (using the Perl Storable module). Earlier versions of Perl5 do not include Storable as a core module. If this is the case, ASCII object storage (using the Perl Data::Dumper module) is used instead.
ASCII storage can be enabled by default by setting the value of $Bio::Root::Storable::BINARY to false.
AUTHOR Will Spooner
new
Arg [1] : -workdir => filesystem path,-template => tmpfile template,-suffix => tmpfile suffix,Function : Builds a new Bio::Root::Storable inhereting objectReturntype: Bio::Root::Storable inhereting objectExceptions:Caller :Example : $storable = Bio::Root::Storable->new()
_initialise_storable
Arg [1] : See 'new' methodFunction : Initialises storable-specific attributesReturntype: booleanExceptions:Caller :Example :
statefile
Arg [1] : string (optional)Function : Accessor for the file to write state into.Should not normally use as a setter - let Root::IOdo this for you.Returntype: stringExceptions:Caller : Bio::Root::Storable->storeExample : my $statefile = $obj->statefile();
workdir
Arg [1] : string (optional) (TODO - convert to array for x-platform)Function : Accessor for the statefile directory. Defaults to File::Spec->tmpdirReturntype: stringExceptions:Caller :Example : $obj->workdir('/tmp/foo');
template
Arg [1] : string (optional)Function : Accessor for the statefile template. Defaults to XXXXXXXXReturntype: stringExceptions:Caller :Example : $obj->workdir('RES_XXXXXXXX');
suffix
Arg [1] : string (optional)Function : Accessor for the statefile template.Returntype: stringExceptions:Caller :Example : $obj->suffix('.state');
new_retrievable
Arg [1] : Same as for 'new'Function : Similar to store, except returns a 'skeleton' of the callingobject, rather than the statefile.The skeleton can be repopulated by calling 'retrieve'. Thiswill be a clone of the original object.Returntype: Bio::Root::Storable inhereting objectExceptions:Caller :Example : my $skel = $obj->new_retrievable(); # skeleton$skel->retrieve(); # clone
retrievable
Arg [1] : noneFunction : Reports whether the object is in 'skeleton' state, and the'retrieve' method can be called.Returntype: booleanExceptions:Caller :Example : if( $obj->retrievable ){ $obj->retrieve }
token
Arg [1] : NoneFunction : Accessor for token attributeReturntype: string. Whatever retrieve needs to retrieve.This base implementation returns the statefileExceptions:Caller :Example : my $token = $obj->token();
store
Arg [1] : noneFunction : Saves a serialised representation of the object structureto disk. Returns the name of the file that the object wassaved to.Returntype: stringExceptions:Caller :Example : my $token = $obj->store();
serialise
Arg [1] : noneFunction : Prepares the the serialised representation of the object.Object attribute names starting with '__' are skipped.This is useful for those that do not serialise too well(e.g. filehandles).Attributes are examined for other storable objects. If theseare found they are serialised separately using 'new_retrievable'Returntype: stringExceptions:Caller :Example : my $serialised = $obj->serialise();
retrieve
Arg [1] : string; filesystem location of the state file to be retrievedFunction : Retrieves a stored object from disk.Note that the retrieved object will be blessed into its originalclass, and not theReturntype: Bio::Root::Storable inhereting objectExceptions:Caller :Example : my $obj = Bio::Root::Storable->retrieve( $token );
clone
Arg [1] : noneFunction : Returns a clone of the calling objectReturntype: Bio::Root::Storable inhereting objectExceptions:Caller :Example : my $clone = $obj->clone();
remove
Arg [1] : noneFunction : Clears the stored object from diskReturntype: booleanExceptions:Caller :Example : $obj->remove();
_freeze
Arg [1] : variableFunction : Converts whatever is in the the arg into a string.Uses either Storable::freeze or Data::Dumper::Dumpdepending on the value of $Bio::Root::BINARYReturntype:Exceptions:Caller :Example :
_thaw
Arg [1] : stringFunction : Converts the string into a perl 'whatever'.Uses either Storable::thaw or eval depending on thevalue of $Bio::Root::BINARY.Note; the string arg should have been created withthe _freeze method, or strange things may occur!Returntype: variableExceptions:Caller :Example :