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

Add to_json support from Document Role #9

Open
jmmills opened this issue Dec 31, 2014 · 1 comment
Open

Add to_json support from Document Role #9

jmmills opened this issue Dec 31, 2014 · 1 comment

Comments

@jmmills
Copy link

jmmills commented Dec 31, 2014

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" };
   }->();
}
@dagolden
Copy link
Collaborator

dagolden commented Jan 1, 2015

Interesting idea. I'll consider this more when I'm back to work in the new year. :-)

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