Skip to content

Instantly share code, notes, and snippets.

@lestrrat
Created September 18, 2009 07:28
Show Gist options
  • Save lestrrat/188924 to your computer and use it in GitHub Desktop.
Save lestrrat/188924 to your computer and use it in GitHub Desktop.
package Encodable;
use Moose::Role;
has encoder => (
is => 'rw',
isa => 'CodeRef'
);
sub encode {
my $self = shift;
my $thing = shift;
return $self->encoder->encode($self, $thing);
}
package MyObject;
use Moose;
with 'Encodable';
package main;
my $object = MyObject->new(encoder => sub { .... });
$object->encode("foo");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment