The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mongol::Base - Base class for Mongol entities

SYNOPSIS

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

DESCRIPTION

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.

METHODS

pack

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

Inherited from MooseX::Storage.

unpack

$model->unpack( $hash );

Inherited from MooseX::Storage.

serialize

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

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

SEE ALSO