Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jjn1056/460580 to your computer and use it in GitHub Desktop.
Save jjn1056/460580 to your computer and use it in GitHub Desktop.
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