Applying roles after the fact changes the flow of method modifiers. It
seems that application order takes precidance over the actual modifier
type.
#!/usr/bin/perl
use strict;
use warnings;
use Test::Most qw{no_plan};
#-----------------------------------------------------------------
BEGIN {
package My::Test;
use Mouse;
has stack => (
is => 'rw',
isa => 'ArrayRef',
lazy => 1,
default => sub{[]},
clearer => 'clear_stack',
);
sub add {
my $self = shift;
push @{$self->stack}, 3
};
package My::Test::Around;
use Mouse::Role;
around add => sub{
my $next = shift;
my $self = shift;
push @{$self->stack}, 2 ;
$self->$next();
};
package My::Test::Before;
use Mouse::Role;
before add => sub{ push @{ shift->stack }, 1 };
package My::Test::Whole;
use Mouse;
extends qw{My::Test};
with qw{My::Test::Before My::Test::Around};
};
#-----------------------------------------------------------------
{ my $T = My::Test::Whole->new;
$T->add;
eq_or_diff $T->stack, [1,2,3]
}
{ my $T = My::Test->new ;
$T->add ;
eq_or_diff( $T->stack, [3] );
$T->clear_stack;
My::Test::Before->meta->apply($T);
$T->add;
eq_or_diff( $T->stack, [1,3] );
$T->clear_stack;
My::Test::Around->meta->apply($T);
$T->add;
eq_or_diff( $T->stack, [1,2,3] );
}
__END__
ok 1
ok 2
ok 3
not ok 4
# Failed test at /tmp/mouse_method_modify.t line 68.
# +----+-----+----+----------+
# | Elt|Got | Elt|Expected |
# +----+-----+----+----------+
# * 0|2 * | |
# | 1|1 | 0|1 |
# | | * 1|2 *
# | 2|3 | 2|3 |
# +----+-----+----+----------+
1..4
# Looks like you failed 1 test of 4.
--
benh~