Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 48324
Status: resolved
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: BrigJ [...] IntoText.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



In the 'OVERRIDE AND SUPER' section of http://search.cpan.org/~drolsky/Moose-0.87/lib/Moose/Manual/MethodModifiers.pod I have a question about the example. It says: package Employee; use Moose; extends 'Person'; has 'job_title' => ( is => 'rw' ); override 'display_name' => sub { my $self = shift; return super() . q{, } . $self->title(); }; But should that last line read as: return super() . q{, } . $self->job_title(); (Which leads to: if not, then what is 'title()'?) As an aside, when I read the original example about 'around', which showed: around 'foo' => sub { my $orig = shift; my $self = shift; print "I'm around foo\n"; $self->$orig(@_); print "I'm still around foo\n"; }; I was confused. Later you point out that: "An around modifier receives the original method as its first argument, then the object, and finally any arguments passed to the method." Ah, now it makes sense. But perhaps the example can be changed to read: around 'foo' => sub { my $orig = shift; # the original method my $self = shift; # the object print "I'm around foo\n"; $self->$orig(@_); # optional to even invoke the original method print "I'm still around foo\n"; };
Just so that I understand, method modifiers run as separate methods from the intended method so that effectively what's happening is an invocation of: $object->method(1, 2); would be treated as: $object->before(1, 2); $object->method(1, 2); so that 'before' receives a ref to the object as its first parameter, such that my $self = shift; works for the 'before' part and then 'method' receives a ref to the same object so that its my $self = shift; also knows about the object at hand. Suppose the 'before' sub alters '@_' via 'shift', that won't change what 'method' sees when it starts processing '@_', correct, since they each receive a set of the original parameters (1, 2) for use via their own @_? Or do 'before' and 'method' each work off of the same "@_" array so that changes by 'before' affect what 'method' sees in @_?
This is actually fairly well detailed in Class::MOP::Class here => http://search.cpan.org/~drolsky/Class-MOP- 0.91/lib/Class/MOP/Class.pm#Method_Modifiers On Thu Jul 30 10:39:50 2009, BrigJ@IntoText.com wrote: Show quoted text
> Just so that I understand, method modifiers run as separate methods from > the intended method so that effectively what's happening is an > invocation of: > > $object->method(1, 2); > > would be treated as: > $object->before(1, 2); > $object->method(1, 2); > > so that 'before' receives a ref to the object as its first parameter, > such that > my $self = shift; > works for the 'before' part > > and then 'method' receives a ref to the same object so that its > my $self = shift; > also knows about the object at hand. > > > Suppose the 'before' sub alters '@_' via 'shift', that won't change what > 'method' sees when it starts processing '@_', correct, since they each > receive a set of the original parameters (1, 2) for use via their own > @_? Or do 'before' and 'method' each work off of the same "@_" array so > that changes by 'before' affect what 'method' sees in @_?
Another question arising from reading about Roles involves the order of processing any 'before' modifiers. The method-modifier documentation describes the order of processing as: before 2 before 1 around 2 around 1 primary around 1 around 2 after 1 after 2 but then the Roles documentation says something normal for 'after' but leaves the 'before' order vague. That is, in the following example do all the 'before' sections of 'Breakable' run before the 'before' sections of 'ExplodeOnBreakage' or do the 'before' sections of 'ExplodeOnBreakage' run first? package MovieCar; use Moose; extends 'Car'; with 'Breakable', 'ExplodesOnBreakage'; Assuming that the new ExplodesOnBreakage method also has an after modifier on break, the after modifiers will run one after the other. The modifier from Breakable will run first, then the one from ExplodesOnBreakage.
The bug tracker is not a good place to have a discussion. Please come to the Moose IRC channel (#moose on irc.perl.org) or send email to the moose@perl.org list. I'm closing this ticket, so please don't reply to it directly, or it will be re-opened.