Skip to content

Instantly share code, notes, and snippets.

@benvanstaveren
Created June 3, 2011 20:41
Show Gist options
  • Save benvanstaveren/1007128 to your computer and use it in GitHub Desktop.
Save benvanstaveren/1007128 to your computer and use it in GitHub Desktop.
deflating Moose class to something suitable for using in MongoDB
use Data::Dumper;
sub deflate {
my $self = shift;
my $doc = {};
foreach my $attribute ($self->meta->get_all_attributes) {
# here be dragons, type checks, trait checks, and more
$doc->{$attribute->name} = $attribute->get_value($self);
}
return
Data::Dumper->new([$doc])
->Indent(0)
->Purity(1)
->Useqq(1)
->Terse(1)
->Deepcopy(1)
->Dump;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment