Created
June 3, 2011 20:41
-
-
Save benvanstaveren/1007128 to your computer and use it in GitHub Desktop.
deflating Moose class to something suitable for using in MongoDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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