Skip to content

Instantly share code, notes, and snippets.

@zostay
Created August 24, 2011 04:05
Show Gist options
  • Save zostay/1167283 to your computer and use it in GitHub Desktop.
Save zostay/1167283 to your computer and use it in GitHub Desktop.
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