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.
This is called each time the object is loaded from the data store. This is meant to be overridden.
Yote - Persistant Perl container objects in a directed graph of lazilly loaded nodes.
This is for anyone who wants to store arbitrary structured state data and doesn't have the time or inclination to write a schema or configure some framework. This can be used orthagonally to any other storage system.
Yote only loads data as it needs too. It does not load all stored containers at once. Data is stored in a data directory and is stored using the Data::RecordStore module. A Yote container is a key/value store where the values can be strings, numbers, arrays, hashes or other Yote containers.
The entry point for all Yote data stores is the root node. All objects in the store are unreachable if they cannot trace a reference path back to this node. If they cannot, running compress_store will remove them.
There are lots of potential uses for Yote, and a few come to mind :
* configuration data * data modeling * user preference data * user account data * game data * shopping carts * product information
use Yote; my $store = Yote::open_store( '/path/to/data-directory' ); my $root_node = $store->fetch_root; $root_node->add_to_myList( $store->newobj( { someval => 123.53, somehash => { A => 1 }, someobj => $store->newobj( { foo => "Bar" }, 'yote - class' ); } ); # the root node now has a list 'myList' attached to it with the single # value of a yote object that yote object has two fields, # one of which is an other yote object. $root_node->add_to_myList( 42 ); # # New Yote container objects are created with $store->newobj. Note that # they must find a reference path to the root to be protected from # being deleted from the record store upon compression. # my $newObj = $store->newobj; $root_node->set_field( "Value" ); my $val = $root_node->get_value( "default" ); # $val eq 'default' $val = $root_node->get_value( "Somethign Else" ); # $val eq 'default' (old value not overridden by a new default value) my $otherval = $root_node->get( 'ot3rv@l', 'other default' ); # $otherval eq 'other default' $root_node->set( 'ot3rv@l', 'newy valuye' ); $otherval2 = $root_node->get( 'ot3rv@l', 'yet other default' ); # $otherval2 eq 'newy valuye' $root_node->set_value( "Something Else" ); my $val = $root_node->get_value( "default" ); # $val eq 'Something Else' my $myList = $root_node->get_myList; for my $example (@$myList) { print ">$example\n"; } # # Each object gets a unique ID which can be used to fetch that # object directly from the store. # my $someid = $root_node->get_someobj->{ID}; my $someref = $store->fetch( $someid ); # # Even hashes and array have unique yote IDS. These can be # determined by calling the _get_id method of the store. # my $hash = $root_node->set_ahash( { zoo => "Zar" } ); my $hash_id = $store->_get_id( $hash ); my $other_ref_to_hash = $store->fetch( $hash_id ); # # Anything that cannot trace a reference path to the root # is eligable for being removed upon compression. #
Starts up a persistance engine and returns it.
Yote::ObjStore - manages Yote::Obj objects in a graph.
The Yote::ObjStore does the following things :
* fetches the root object * creates new objects * fetches existing objects by id * saves all new or changed objects * finds objects that cannot connect to the root node and removes them
Returns the root node of the graph. All things that can be trace a reference path back to the root node are considered active and are not removed when the object store is compressed.
Creates a container object initialized with the incoming hash ref data. The class of the object must be either Yote::Obj or a subclass of it. Yote::Obj is the default. Once created, the object will be saved in the data store when $store->stow_all has been called. If the object is not attached to the root or an object that can be reached by the root, it will be remove when Yote::ObjStore::Compress is called.
This takes an object that belongs to a seperate store and makes a deep copy of it.
This turns on caching for the store. Any objects loaded will remain cached until clear_cache is called. Normally, they would be DESTROYed once their last reference was removed unless they are in a state that needs stowing.
This removes the object from the cache if it was in the cache
When called, no new objects will be added to the cache until cache_all is called.
When called, this dumps the object cache. Objects that references or have changes that need to be stowed will not be cleared.
Returns the object with the given id.
Copyright (c) 2017 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.
To install Yote, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Yote
CPAN shell
perl -MCPAN -e shell install Yote
For more information on module installation, please visit the detailed CPAN module installation guide.