MooseX::RemoteHelper::CompositeSerialization - Serialize object recursively
version 0.001020
{ 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" } # }
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.
serialize to a perl hashref
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.
Please see those modules/websites for more information related to this module.
MooseX::RemoteHelper
Caleb Cushing <xenoterracide@gmail.com>
This software is Copyright (c) 2013 by Caleb Cushing.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install MooseX::RemoteHelper, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::RemoteHelper
CPAN shell
perl -MCPAN -e shell install MooseX::RemoteHelper
For more information on module installation, please visit the detailed CPAN module installation guide.