Skip to content

Instantly share code, notes, and snippets.

@zostay
Created Aug 24, 2011
Embed
What would you like to do?
For my own sanity, what order do the around's get applied in an object that applies a role that applies a role?
package RoleBar;
use v5.10;
use Moose::Role;
around thing => sub {
my $next = shift;
my $self = shift;
say "RoleBar thing start";
$self->$next();
say "RoleBar thing stop";
};
package RoleFoo;
use v5.10;
use Moose::Role;
with 'RoleBar';
requires 'thing';
around thing => sub {
my $next = shift;
my $self = shift;
say "RoleFoo thing start";
$self->$next();
say "RoleFoo thing stop";
};
package Foo;
use v5.10;
use Moose;
with 'RoleFoo';
sub thing {
my $self = shift;
say "Foo thing";
}
package main;
my $foo = Foo->new;
$foo->thing;
# OUTPUT IS:
#
# RoleFoo thing start
# RoleBar thing start
# Foo thing
# RoleBar thing stop
# RoleFoo thing stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment