Hi AM,

Thanks for looking into Perl and visiting the monastery. :)

something similar to CLOS before/around/after methods.

The v6.c version of the Perl 6 language is supposed to have a similar feature called `wrap` such that, given this code:

sub foo { say 42 } &foo.wrap: { say 'before'; callsame; say 'after' } foo;

The `foo` call in the last line displays:

before 42 after

The above is equivalent to a CLOS `:around`.

Be aware that, compared with Perl 5, Perl 6 is an immature upstart, and that's an understatement. I've tested that my v6.c compatible Rakudo (all Rakudos released in 2016 or later support v6.c) does the above correctly and I can see that a lot of simple cases are tested in S06-advanced/wrap.t but I also see lots of bugs in the bug queue with 'wrap' in their title, at least some of which are about this particular feature.

A search of modules.perl6.org for 'before' yielded Method::Modifiers. I see recent commits by the author. The project's modules are tiny examples of MOP programming. They're probably worth a look over even if you don't actually `use Method::Modifiers;`.

I see others have answered your other questions. Have The Appropriate Amount Of Fun....


In reply to Re: Perl 6 OOP: before and after methods "CLOS style" by raiph
in thread Perl 6 OOP: before and after methods "CLOS style" by Anonymous Monk

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.