Created
September 18, 2009 07:28
-
-
Save lestrrat/188924 to your computer and use it in GitHub Desktop.
This file contains 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
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