NAME

Zing::Store - Storage Interface

ABSTRACT

Data Storage Interface

SYNOPSIS

use Zing::Store;

my $store = Zing::Store->new;

# $store->drop;

DESCRIPTION

This package provides a data persistence interface to be implemented by data storage abstractions.

LIBRARIES

This package uses type constraints from:

Zing::Types

METHODS

This package implements the following methods:

args

args(Str $env) : (Any)

The args method parses strings with key/value data (typically from an environment variable) meant to be used in object construction.

args example #1
# given: synopsis

[$store->args('port=0001,debug=0')]
args example #2
# given: synopsis

[$store->args('ports=0001|0002,debug=0')]

drop

drop(Str $key) : Int

The drop method should remove items from the datastore by key.

drop example #1
# given: synopsis

$store->drop('model');

dump

dump(HashRef $data) : Str

The dump method should encode and return the data provided in a format suitable for the underlying storage mechanism.

dump example #1
# given: synopsis

$store->dump({ status => 'ok' });

keys

keys(Str @keys) : ArrayRef[Str]

The keys method should return a list of keys under the namespace provided including itself.

keys example #1
# given: synopsis

my $keys = $store->keys('nodel');
keys example #2
# given: synopsis

# $store->send('model', { status => 'ok' });

my $keys = $store->keys('model');

load

load(Str $data) : HashRef

The load method should decode the data provided and returns the data as a hashref.

load example #1
# given: synopsis

$store->load('{"status":"ok"}');

pop

pop(Str $key) : Maybe[HashRef]

The pop method should pop data off of the bottom of a list in the datastore.

pop example #1
# given: synopsis

$store->pop('collection');
pop example #2
# given: synopsis

# $store->push('collection', { status => 1 });
# $store->push('collection', { status => 2 });

$store->pop('collection');

pull

pull(Str $key) : Maybe[HashRef]

The pull method should pop data off of the top of a list in the datastore.

pull example #1
# given: synopsis

$store->pull('collection');
pull example #2
# given: synopsis

# $store->push('collection', { status => 'ok' });

$store->pull('collection');

push

push(Str $key, HashRef $val) : Int

The push method should push data onto the bottom of a list in the datastore.

push example #1
# given: synopsis

$store->push('collection', { status => 'ok' });

recv

recv(Str $key) : Maybe[HashRef]

The recv method should fetch and return data from the datastore by its key.

recv example #1
# given: synopsis

$store->recv('model');
recv example #2
# given: synopsis

# $store->send('model', { status => 'ok' });

$store->recv('model');

send

send(Str $key, HashRef $val) : Str

The send method should commit data to the datastore with its key and return truthy (or falsy if not).

send example #1
# given: synopsis

$store->send('model', { status => 'ok' });

size

size(Str $key) : Int

The size method should return the size of a list in the datastore.

size example #1
# given: synopsis

my $size = $store->size('collection');
size example #2
# given: synopsis

# $store->push('collection', { status => 'ok' });

my $size = $store->size('collection');

slot

slot(Str $key, Int $pos) : Maybe[HashRef]

The slot method should return the data from a list in the datastore by its position in the list.

slot example #1
# given: synopsis

my $model = $store->slot('collection', 0);
slot example #2
# given: synopsis

# $store->push('collection', { status => 'ok' });

my $model = $store->slot('collection', 0);

term

term(Str @keys) : Str

The term method generates a term (safe string) for the datastore. This method doesn't need to be implemented.

term example #1
# given: synopsis

$store->term('model');

test

test(Str $key) : Int

The test method should return truthy if the specific key exists in the datastore.

test example #1
# given: synopsis

# $store->push('collection', { status => 'ok' });

$store->test('collection');
test example #2
# given: synopsis

# $store->drop('collection');

$store->test('collection');

AUTHOR

Al Newkirk, awncorp@cpan.org

LICENSE

Copyright (C) 2011-2019, Al Newkirk, et al.

This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file".

PROJECT

Wiki

Project

Initiatives

Milestones

Contributing

Issues