Mongol::Base - Base class for Mongol entities
package My::Model::Person { use Moose; extends 'Mongol::Base'; has 'name' => ( is => 'ro', isa => 'Str', required => 1, ); has 'age' => ( is => 'ro', isa => 'Int', required => 1, ); __PACKAGE__->meta()->make_immutable(); } ... my $person = Person->new( { name => 'John Doe', age => 30 } ); my $data = $person->pack(); my $other_person = Person->unpack( $data );
ALl Mongol entitities should inherit from this class since this takes care of the serializiation/deserialization of the objects. The serialization is provided by MooseX::Storage together with MooseX::Storage::Base::SerializedClass, this way we don't have to worry about coercions and defining custom subtypes.
But this comes with a price since MooseX::Storage adds an additional field for each object which contains the class name.
my $hash = $model->pack();
Inherited from MooseX::Storage.
$model->unpack( $hash );
my $hash = $model->serialize();
Just like pack except it drops the __CLASS__ field from the resulting hash reference.
Moose
MooseX::Storage
MooseX::Storage::Engine
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.