forked from rafl/moosex-methodattributes
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with role composition onto subclasses.
Metaclass re-initialization was happening too late - i.e. after the methods from the roles were composed, but before the method modifiers from the roles. This resulted in the metaclass reinitialization losing the methods from the roles, and then trying to apply the modifiers wrapping the lost methods which, of course, entirely failed. The solution is that we don't actaully need to perform force reinitialization at this point, and so removing that line fixes everything.
- Loading branch information
Showing
3 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use Test::Exception; | ||
|
||
use Moose::Util qw/apply_all_roles/; | ||
|
||
{ | ||
package BaseClass; | ||
use Moose; | ||
use MooseX::MethodAttributes; | ||
no Moose; | ||
} | ||
|
||
{ | ||
package AClass; | ||
use Moose; | ||
BEGIN { extends 'BaseClass' } | ||
sub foo : Bar {} | ||
|
||
no Moose; | ||
} | ||
|
||
{ | ||
package Role1; | ||
use Moose::Role; | ||
our $called = 0; | ||
sub pack { $called++ } | ||
no Moose::Role; | ||
} | ||
|
||
{ | ||
package Role2; | ||
use Moose::Role; | ||
|
||
our $called = 0; | ||
around pack => sub { | ||
my ($orig, $self, @rest) = @_; | ||
$called++; | ||
$self->$orig(@rest); | ||
}; | ||
no Moose::Role; | ||
} | ||
|
||
{ | ||
package BClass; | ||
use Moose; | ||
BEGIN { extends 'AClass' }; | ||
|
||
sub moo : Quux {} | ||
|
||
::lives_ok { with qw/Role1 Role2/ }; | ||
no Moose; | ||
} | ||
|
||
{ | ||
package CClass; | ||
use Moose; | ||
BEGIN { extends 'AClass' }; | ||
|
||
sub moo : Quux {} | ||
no Moose; | ||
} | ||
|
||
my $c = CClass->new; | ||
lives_ok { apply_all_roles($c, qw/Role1 Role2/) }; | ||
|
||
foreach my $i (BClass->new, $c) { | ||
$Role1::called = $Role2::called = 0; | ||
can_ok $i, 'pack' and $i->pack; | ||
is $Role1::called, 1; | ||
is $Role2::called, 1; | ||
is_deeply( | ||
$i->meta->find_method_by_name('foo')->attributes, | ||
[(q{Bar})], | ||
); | ||
is_deeply( | ||
$i->meta->find_method_by_name('moo')->attributes, | ||
[(q{Quux})], | ||
); | ||
} | ||
|
||
done_testing; |