Created
July 1, 2010 21:17
-
-
Save jjn1056/460580 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 MyRole(Str :$prefix = "test") { | |
around mymethod($aaa) { | |
return $prefix .":". $self->$orig($aaa); | |
} | |
} | |
use MooseX::Declare; | |
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 | |
} | |
} | |
use MooseX::Declare; | |
class MyClass { | |
method mymethod(Str $aaa) | |
does MyMethodTrait(repeat=>5) { | |
return $aaa; | |
} | |
with 'MyRole' => {prefix=>'hello'}; | |
} | |
my $aaa = MyClass->new; | |
warn $aaa->mymethod('aaa'); | |
## Try to use it | |
perl -e "use MyClass" | |
hello:aaa:aaa:aaa:aaa:aaa: at MyClass.pm line 11. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment