Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

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

People
Owner: Nobody in particular
Requestors: ANDK [...] cpan.org
Cc: GRAF [...] cpan.org
AdminCc:

Bug Information
Severity: (no value)
Broken in: 2.1302-TRIAL
Fixed in: 2.1403



CC: GRAF [...] cpan.org
Subject: The missing manual: Execution order of method modifiers with regard to inheritance
The documentation on method modifiers leaves out the (imho) important concept of the ordering in the case when both parent and child have method modifiers. The rest of this ticket is a tentative first stab at documenting what goes on. Feel free to improve on it:), but please do not drop the ball as I'm sure quite a few Moose users would not know about this. Enjoy, =head2 Execution order of method modifiers with regard to inheritance When both a superclass and an inheriting class have the same method modifiers, the method modifiers of the inheriting class are wrapped around the method modifiers of the superclass, as the following examples illustrate: Parent.pm: package Parent; use Moose; sub rant { printf "rant Parent\n" } before 'rant' => sub { printf "In %s before\n", __PACKAGE__ }; after 'rant' => sub { printf "In %s after\n", __PACKAGE__ }; around 'rant' => sub { my $orig = shift; my $self = shift; printf "In %s around-before\n", __PACKAGE__; $self->$orig; printf "In %s around-after\n", __PACKAGE__; }; 1; Child.pm: use Parent; package Child; use Moose; extends 'Parent'; before 'rant' => sub { printf "In %s before\n", __PACKAGE__ }; after 'rant' => sub { printf "In %s after\n", __PACKAGE__ }; around 'rant' => sub { my $orig = shift; my $self = shift; printf "In %s around-before\n", __PACKAGE__; $self->$orig; printf "In %s around-after\n", __PACKAGE__; }; Program and output: % perl -e ' use Child; package main; Child->new->rant; ' In Child before In Child around-before In Parent before In Parent around-before rant Parent In Parent around-after In Parent after In Child around-after In Child after
The relevant doc updates are in master.
CC: ANDK [...] cpan.org, GRAF [...] cpan.org
Subject: Re: [rt.cpan.org #98940] The missing manual: Execution order of method modifiers with regard to inheritance
Date: Thu, 27 Nov 2014 21:28:06 +0100
To: bug-Moose [...] rt.cpan.org
From: Andreas Koenig <andreas.koenig.7os6VVqR [...] franz.ak.mind.de>
Show quoted text
>>>>> On Thu, 27 Nov 2014 15:00:46 -0500, "Dave Rolsky via RT" <bug-Moose@rt.cpan.org> said:
Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=98940 > > The relevant doc updates are in master.
Cool, thanks! -- andreas