NAME

Mongol::Model - Everything is a model

SYNOPSIS

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();
}

DESCRIPTION

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.

METHODS

pack

my $hashref = $model->pack();

Inherited from MooseX::Storage.

unpack

my $model = Model::Class->unpack( $hashref );

Inherited from MooseX::Storage.

serialize

my $hashref = $model->serialize();

Just like pack except it drops the __CLASS__ field from the resulting hash reference.

SEE ALSO