in reply to Perl 6 OOP: before and after methods "CLOS style"
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....
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl 6 OOP: before and after methods "CLOS style"
by adhrain (Sexton) on Feb 20, 2017 at 23:08 UTC | |
by raiph (Deacon) on Feb 22, 2017 at 05:33 UTC |