ObjStore::HV::Database - a generic hash-oriented database


ObjStore documentation Contained in the ObjStore distribution.

Index


Code Index:

NAME

Top

    ObjStore::HV::Database - a generic hash-oriented database

SYNOPSIS

Top

  package MyDatabase;
  use base 'ObjStore::HV::Database';

  my $db = MyDatabase->new("/path/to/my/database", 'update', 0666);

DESCRIPTION

Top

Often you want to treat a database as a hash of related information. Roots could be used, but there are a number of reasons to use this class instead of roots:

* PERFORMANCE

You have no control over the implementation of roots. Performance is unknown and cannot be improved or degraded. (The "do it yourself" principle.)

* FLEXIBILITY

If you want to move the top-level hash down to a deeper level, you cannot easily do this with roots. (Principle of consistany.)

* NON-STANDARD

The standard way to create hash-oriented databases is with ObjStore::HV::Database. (Proof by paradox.)

SEE ALSO

Top

ObjStore::ServerDB


ObjStore documentation Contained in the ObjStore distribution.

use strict;
package ObjStore::HV::Database;
use ObjStore;
use Carp;
use base 'ObjStore::Database';
use vars qw($VERSION);
$VERSION = '1.00';

sub ROOT() { carp "ROOT is depreciated, sorry"; 'hv' }
sub hash {
    use attrs 'method';
    $_[0]->root('hv', sub { ObjStore::HV->new($_[0], 25) });
}

sub STORE {
    my ($o, $k, $v) = @_;
    my $t = $o->hash();
    $t->{$k} = $v;
    $o->gc_segments;
    defined wantarray? ($v) : ();
}

sub FETCH {
    my ($o, $k) = @_;
    my $t = $o->hash();
    $t->{$k};
}

sub DELETE {
    my ($o, $k) = @_;
    delete $o->hash()->{$k};
    $o->gc_segments;
}

sub POSH_ENTER { shift->hash; }

1;