Data-ObjectStore
view release on metacpan or search on metacpan
lib/Data/ObjectStore.pm view on Meta::CPAN
that have been changed since the last time save was
called. Note that this deletes the objects that are not
connected to root.
=head2 existing_id( obj )
If the object already has an id in the store, this returns
that id. If it does not, it returns undef.
=head2 quick_purge
This is a memory intensive version of vaccuuming the store.
It maintains a hash of all the items to not purge in memory as it runs.
This shouldn't be run if the store is really really big.
=head2 upgrade_store( '/path/to/directory' )
This updagrades the object store to the current version. Back up the store
before applying.
=head2 info()
Returns a hash of info about this opened data store.
Updating the hash has no effect.
* db_version
* ObjectStore_version
* created_time
* last_update_time
=head2 get_db_version
Returns the version of Data::RecordStore that this was created under.
=head2 get_store_version
Returns the version of Data::ObjectStore that this was created under.
=head2 get_created_time
Returns when the store was created.
=head2 get_last_update_time
=head2 last_updated( obj )
Returns the timestamp the given object was last updated
=head2 created( obj )
Returns the timestamp the given object was created.
Returns the last time this store was updated.
=head2 lock( @names )
Adds an advisory (flock) lock for each of the unique names given.
=head2 unlock()
Unlocks all names locked by this thread
=head2 sync()
Asks the data provider to sync to persistance.
=head1 SUBCLASSING
Blessed objects must be a subclass of Data::ObjectStore::Container
in order to be able to be stored in the object store. _init and _load
can be useful to override.
package Mad::Science::User;
use Data::ObjectStore;
use base 'Data::ObjectStore::Container';
# called when an object is newly created
sub _init {
my $self = shift;
$self->set_status( "NEWLY CREATED" );
$self->set_experiments([]);
}
# called when the object is loaded from the store
sub _load {
my $self = shift;
print "Loaded " . $self->get_name . " from store";
if( @{$self->get_experiments} > 0 ) {
$self->set_status( "DOING EXPERIMENTS" );
}
}
sub evacuate {
my $self = shift;
$self->set_status( "HEADING FOR THE HILLS" );
}
=head1 Data::ObjectStore::Container
Persistant Perl container object.
=head2 SYNOPSIS
$obj_A = $store->create_container;
$obj_B = $store->create_container( {
myfoo => "This foo is mine",
mylist => [ "A", "B", "C" ],
myhash => { peanut => "Butter" }
} );
$obj_C = $store->create_container( 'My::Subclass' );
$obj_D = $store->create_container( 'My::Othersubclass', { initial => "DATA" } );
#
# get operations
#
print $obj_B->get_myfoo; # prints "this foo is mine"
lib/Data/ObjectStore.pm view on Meta::CPAN
# yes, the $newlist reference is changed when the object is operated on with list operations
=head2 DESCRIPTION
This is a container object that can be used to store key value data
where the keys are strings and the values can be hashes, arrays or
Data::ObjectStore::Container objects. Any instances that can trace a
reference path to the store's root node are reachable upon reload.
This class is designed to be overridden. Two methods are provided
for convenience. _init is run the first time the object is created.
_load is run each time the object is loaded from the data store.
These methods are no-ops in the base class.
=head2 METHODS
=head2 set( field, value )
Sets the field to the given value and returns the value.
The value may be a Data::ObjectStore::Container or subclass, or
a hash or array reference.
=head2 get( field, default_value )
Returns the value associated with the given field.
If the value is not defined and a default value is given,
this sets the value to the given default value and returns
it.
The value may be a Data::ObjectStore::Container or subclass, or
a hash or array reference.
=head2 fields
Returns a list reference of all the field names of the object.
=head2 remove_field( field )
Removes the field from the object.
=head2 vol( key, value )
This sets or gets a temporary (volatile) value attached to the object.
=head2 clearvol( key )
This unsets a temporary (volatile) value attached to the object.
=head2 store
Returns the Data::ObjectStore that created this object.
=head2 lock( @names )
Adds an advisory (flock) lock for each of the unique names given.
This may not be called twice in a row without an unlock in between.
=head2 unlock
Unlocks all names locked by this thread
=head2 _init
This is called the first time an object is created. It is not
called when the object is loaded from storage. This can be used
to set up defaults. This is meant to be overridden.
=cut
=head2 _load
This is called each time the object is loaded from the data store.
This is meant to be overridden.
=head1 AUTHOR
Eric Wolf coyocanid@gmail.com
=head1 COPYRIGHT AND LICENSE
Copyright (c) 2012 - 2020 Eric Wolf. All rights reserved. This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=head1 VERSION
Version 2.13 (Feb, 2020))
=cut
( run in 1.815 second using v1.01-cache-2.11-cpan-140bd7fdf52 )