NAME

DBIx::NoSQL::Store::Manager::Model - Role for classes to be handled by DBIx::NoSQL::Store::Manager

VERSION

version 1.0.0

SYNOPSIS

package MyComics::Model::Comic;

use strict;
use warnings;

use Moose;

with 'DBIx::NoSQL::Store::Manager::Model';

has series => (
    traits => [ 'StoreKey' ],
    is => 'ro',
);

has issue =>  (
    traits => [ 'StoreKey' ],
    is => 'ro',
    isa => 'Int',
);

has penciller => (
    traits => [ 'StoreIndex' ],
    is => 'ro',
);

has writer => (
    is => 'ro',
);

__PACKAGE__->meta->make_immutable;

1;

DESCRIPTION

Role for classes to be stashed in a DBIx::NoSQL::Store::Manager store.

The only hard-requirement for a class consuming this role is to define a key to be used as the unique id of the object in the store. This can be done by applying the DBIx::NoSQL::Store::Manager::StoreIndex trait to one or more attributes (the key will be the concatenation of those attributes). Or, if the generation of the key is more complicated, it can be done by playing with the store_key attribute directly:

has '+store_key' => (
    default => sub {
        my $self = shift;

        return $self->generate_arcane_key;
    },
);

Attributes of the class can be marked for indexed by giving them the DBIx::NoSQL::Store::Manager::StoreIndex trait.

ATTRIBUTES

store_db

The DBIx::NoSQL::Store::Manager store to which the object belongs to.

store_model

Class-level attribute holding the model name of the class. If not given, defaults to the class name with everything up to a *::Model:: truncated (e.g., MyStore::Model::Thingy would become Thingy).

Not that as it's a class-level attribute, it can't be passed to new(), but has to be set via class_has:

class_has '+store_model' => (
    default => 'SomethingElse',
);

store_key

The store id of the object. Defaults to the concatenation of the value of all attributes having the DBIx::NoSQL::Store::Manager::StoreKey trait.

METHODS

store_db

Returns the DBIx::NoSQL::Store::Manager store to which the object belongs to.

store()

DEPRECATED - use save() instead.

Serializes the object into the store.

delete()

Deletes the object from the store.

save( $store )

Saves the object in the store. The $store object can be given as an argument if the object was not created via a master DBIx::NoSQL::Store::Manager object and store_db was not already provided via the constructor.

AUTHOR

Yanick Champoux <yanick@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2018, 2013, 2012 by Yanick Champoux.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.