Mongol::Model - Everything is a model
package Models::Person { use Moose; extends 'Mongol::Model'; has 'first_name' => ( is => 'ro', isa => 'Str', required => 1, ); has 'last_name' => ( is => 'ro', isa => 'Str', required => 1, ); __PACKAGE__->meta()->make_immutable(); } package main { use strict; use warnings; use Model::Person; my $person => Model::Person->new( { first_name => 'Peter', last_name => 'Parker', } ); my $hashref = $person->pack(); my $clone = Model::Person->unpack( $hashref ); my $nice_hashref = $person->serialize(); }
In Mongol there's no need to defined your model classes as document or subdocument it knows automatically to diferentiate between them. Everything should be a model, if you're planning to store that information in the database then make sure your class inherits from this package. Right now all it does it takes care of the data serialization for you and it makes sure that some of the datatypes are converted correctly.
my $hashref = $model->pack();
Inherited from MooseX::Storage.
my $model = Model::Class->unpack( $hashref );
my $hashref = $model->serialize();
Just like pack except it drops the __CLASS__ field from the resulting hash reference.
MooseX::Storage
To install Mongol, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mongol
CPAN shell
perl -MCPAN -e shell install Mongol
For more information on module installation, please visit the detailed CPAN module installation guide.