Hi monks!
I just started to play with Perl6, and encountered some problem. Consider such kind of modular codes implemented using Moose:
################################################## # toHash() in base class provides an empty hashref ################################################## { package Base; use Moose; sub toHash { return {} } } ############################################# # In a role, specific attributes are going to # be stored in hashref provided by base class ############################################# { package FooRole; use Moose::Role; has foo => (is=>'rw', isa=>'Str'); has bar => (is=>'rw', isa=>'Str'); around toHash => sub { my($orig,$self) = @_; my $hash = $self->$orig(); # I only want store foo, but not bar $hash->{foo} = $self->foo; return $hash; }; } ################################################### # We may have many other roles that provide further # modifications to the function. # And those roles may be assembled in arbitrary # pattern, which provides flexibility. ################################################### { package Foo; use Moose; extends 'Base'; with 'FooRole'; } my $foo = Foo->new( foo => 'foo_value', bar => 'bar_value' ); my $data = $foo->toHash # produces { foo => 'foo_value' }
Through this way, I can add role-spicific modifications to a method. How can I implement that on Perl6? Somebody told me to use function wrapping, but I don't really understand that...
In reply to Moose method modifier equivalent on Perl 6 by llancet
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |