Created
August 24, 2011 04:05
-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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