NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
And with Moose in Perl 5 (Score:1)
package POC::TestAnnouncer;
use Moose::Role;
before test => sub {
my $project = $_[1];
announce-start-of('test', $project{name});
};
after test => sub {
my $project = $_[1];
announce-end-of('test', $project{name});
};
And then there's the more powerful around:
package POC::TestAnnouncer;
use Moose::Role;
around test => sub {
my $fn = shift;
my $self = shift;
my $project = $_[0];
announce-start-of('test', $project{name});
--fREW
http://blog.afoolishmanifesto.com
Re: (Score:1)
Thanks. I was only aware of how Moose did it to the extent that people come into the #perl6 channel sometimes and ask "what's the equivalent to Moose's before/after/around in Perl 6?" and we answer "[call|next][same|with]".
(The "call-" methods are returning calls, and the "next-" methods are tailcalls. "-same" sends along the original arguments, and "-with" allows you to send new ones.)
What's really neat, and what I still haven't quite gotten my head wrapped around, is that these four routines are used in t
Re: (Score:1)
Oh, huh, and I should probably add that mixins may look like they do a variant of wrapping in Perl 6, but they really work by creating an anonymous subclass to the class of the object, and re-blessing the object to that subclass. So, they work by inheritance, not wrapping.
The fact that both of these use "callsame;" to delegate to the original routine means that I can use mixins and think they are wrappers, and they'll still behave as I expect. That's why I like the above unification.
Re: (Score:1)
Also playing about some I came up with something nearly identical using MooseX::Declare's syntax.
role POC::TestAnnouncer {
use mro;
method test ($project) {
announce-start-of('test', $project{name});
my $result = $self->maybe::next::method($project); # callsame
announce-end-of('test', $result);
Re: (Score:1)
I mean
$.callsamerather than.callsame. Thanks to TimToady and TiMBuS for clarifying things at least enough that I understand that much.Re:And with Moose in Perl 5 (Score:1)
Yes, it's
$.callsame. See this post [perl.org] for a slightly deeper "why" answer.Reply to This
Parent