Skip to content

Instantly share code, notes, and snippets.

@xenoterracide
Created May 29, 2012 01:53
Show Gist options
  • Select an option

  • Save xenoterracide/2822109 to your computer and use it in GitHub Desktop.

Select an option

Save xenoterracide/2822109 to your computer and use it in GitHub Desktop.
MooseX::RemoteHelper Example
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