Skip to content

Add to_json support from Document Role #9

Open

Description

@jmmills

Add a default but sub-classable serializing method to Meerkat::Role::Document... perhaps just expose the storage serializer?
I'm already defining the structure of the object in Mongo via Moose attributes, why should I have to do the same for a hash? This would make developing REST interfaces around Meerkat objects super simple:

For example:

package My::Model::Foo;
use Moose;
with 'Meerkat::Role::Document';

has somekey => (is => 'ro', isa => 'String');
has otherkey => (is => 'ro, isa => 'Bool');

__PACKAGE__->meta->make_immutable;

package Inside::Some::Dancer::Like::REST::Framework;

get 'things' => sub {
   my $obj = meerkat->collection('foo')->find_one({somekey => 'doodad'});
   return $obj? $obj->to_hash : sub {
      status 404;
      { errormsg => "Can't find this thing" };
   }->();
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions