Created
July 25, 2010 22:39
-
-
Save jjn1056/489956 to your computer and use it in GitHub Desktop.
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 MooseX::Declare; | |
role MyParameterizableRole(Str :$prefix = "test") | |
{ | |
requires 'mymethod'; | |
around mymethod($aaa) { | |
return $prefix .":". $self->$orig($aaa); | |
} | |
} | |
role MyMethodTrait { | |
has repeat => (is=>'ro', isa=>'Int', required=>1, default=>2); | |
around wrap(ClassName $class: $code, %options) { | |
my $method_obj; | |
$method_obj = $class->$orig( | |
sub { | |
my ($self, $arg) = @_; | |
$self->$code("$arg:" x $method_obj->repeat ); | |
}, %options, | |
); | |
return $method_obj | |
} | |
} | |
class MyClass { | |
method mymethod(Str $message) | |
does MyMethodTrait(repeat=>5) { | |
return $message; | |
} | |
with 'MyParameterizableRole' => {prefix=>'hello'}; | |
} | |
my $aaa = MyClass->new; | |
warn $aaa->mymethod('world'); | |
## output is "hello:world:world:world:world:world:" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment