NAME
MooseX::RemoteHelper::CompositeSerialization - Serialize object recursively
VERSION
version 0.001014
SYNOPSIS
{
package MessagePart;
use Moose 2;
use MooseX::RemoteHelper;
with 'MooseX::RemoteHelper::CompositeSerialization';
has array => (
remote_name => 'SomeColonDelimitedArray',
isa => 'ArrayRef',
is => 'ro',
serializer => sub {
my ( $attr, $instance ) = @_;
return join( ':', @{ $attr->get_value( $instance ) } );
},
);
__PACKAGE__->meta->make_immutable;
}
{
package Message;
use Moose 2;
use MooseX::RemoteHelper;
with 'MooseX::RemoteHelper::CompositeSerialization';
has bool => (
remote_name => 'Boolean',
isa => 'Bool',
is => 'ro',
serializer => sub {
my ( $attr, $instance ) = @_;
return $attr->get_value( $instance ) ? 'Y' : 'N';
},
);
has foo_bar => (
remote_name => 'FooBar',
isa => 'Str',
is => 'ro',
);
has part => (
isa => 'MessagePart',
remote_name => 'MyMessagePart',
is => 'ro',
);
__PACKAGE__->meta->make_immutable;
}
my $message
= Message->new({
bool => 0,
foo_bar => 'Baz',
part => MessagePart->new({ array => [ qw( 1 2 3 4 ) ] }),
});
$message->serialize;
# {
# Boolean => "N",
# FooBar => "Baz",
# MyMessagePart => { SomeColonDelimitedArray => "1:2:3:4" }
# }
DESCRIPTION
Recursively serialize to hashref based on the Composite Pattern. It's intended to allow easy passing of a plain old perl data structure to a serialization module like JSON or YAML.
METHODS
serialize
serialize to a perl hashref
BUGS
Please report any bugs or feature requests on the bugtracker website https://github.com/xenoterracide/moosex-remotehelper/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
SEE ALSO
Please see those modules/websites for more information related to this module.
AUTHOR
Caleb Cushing <xenoterracide@gmail.com>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2013 by Caleb Cushing.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)