Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose collection attribute from Document role #8

Open
jmmills opened this issue Dec 26, 2014 · 0 comments
Open

Expose collection attribute from Document role #8

jmmills opened this issue Dec 26, 2014 · 0 comments

Comments

@jmmills
Copy link

jmmills commented Dec 26, 2014

Make Meerkat::Role::Document::_collection attribute non-private so that objects can be "clone aware".
For example:

package My::Template;
use Moose;
with 'Meerkat::Role::Document;

has latest => (...boolean..);
has version => (...number..);
has content => (...string...);

sub as_hash { ... }

sub update_content {
    my ($self, $content) = @_;
    my $clone = $self->as_hash;

    $self->update_set( content => $content );
    $self->update_inc( version => 1 );
    $self->sync;

    $clone->{latest} => 0;
    $self->collection->create( %{ $clone } ); # as $self->_collection

    return $self;
} 

package main;
say $meerkat->collection('Template')
            ->find_one({latest => 1})
            ->update_content('I like fluffy bunnies')
            ->version;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant