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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.