Created
May 29, 2012 01:53
-
-
Save xenoterracide/2822109 to your computer and use it in GitHub Desktop.
MooseX::RemoteHelper Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use 5.014; | |
| use warnings; | |
| use Data::Dumper; | |
| package MessagePart { | |
| use Moose; | |
| 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; | |
| 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 ) ] }), | |
| }); | |
| say Dumper $message->serialize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment