Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Perl 6 OOP: before and after methods "CLOS style"

by raiph (Deacon)
on Feb 19, 2017 at 22:31 UTC ( [id://1182321]=note: print w/replies, xml ) Need Help??


in reply to Perl 6 OOP: before and after methods "CLOS style"

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....

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

    Excellent pointers, Method::Modifiers is very interesting.

    The authors hints to this Perl 5 module:

    Moose::Manual::MethodModifiers

    as his ispiration. So now I know that not only Perl 6 can have before/around/after methods but also Perl 5 has them! I never had the chance to use OOP in Perl 5 (I use it for all my personal scripts when they are not trivial or they have to be cross platform, no big programs so far) but now I'm going to study Moose.

      Fyi, there's some really great sounding new stuff in the pipeline from the guy who started Moose and who is now focused on p5-MOP. Here's a recent presentation on p5-MOP. The audio's poor and it's probably way too low level but Stevan's so manic it'll probably be fun to watch a few minutes of it...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1182321]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-16 09:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found