Skip to content

Commit

Permalink
Merge pull request #27 from gfx/issue-17
Browse files Browse the repository at this point in the history
Disable metaclass cache in M::M::Role::Application to fix #17
  • Loading branch information
gfx committed May 25, 2014
2 parents 0d568b7 + 596942c commit 6422ae1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/Mouse/Meta/Role/Application.pm
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ sub apply {
$self->{_to} = 'instance';
$instance = $consumer;

$consumer = (Mouse::Util::class_of($instance) || 'Mouse::Meta::Class')
my $meta = Mouse::Util::class_of($instance);
$consumer = ($meta || 'Mouse::Meta::Class')
->create_anon_class(
superclasses => [ref $instance],
roles => [$role],
cache => 1,
cache => 0,

in_application_to_instance => 1, # suppress to apply roles
);
Expand Down
6 changes: 4 additions & 2 deletions t/030_roles/010_run_time_role_composition.t
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ isa_ok($obj2, 'My::Class');
Bark->meta->apply($obj2);

ok($obj2->does('Bark'), '... we now do the Bark role');
{ local $TODO = '#17';
is(blessed($obj), blessed($obj2), '... they share the same anon-class/role thing');
}
}

{
is($obj->sleep, 'nite-nite', '... the original method responds as expected');

Expand Down Expand Up @@ -97,7 +98,8 @@ isa_ok($obj2, 'My::Class');
Sleeper->meta->apply($obj2);

ok($obj2->does('Sleeper'), '... we now do the Bark role');
{ local $TODO = '#17';
is(blessed($obj), blessed($obj2), '... they share the same anon-class/role thing again');
}
}

done_testing;
33 changes: 33 additions & 0 deletions t/900_mouse_bugs/016_issue17_memleak.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use strict;
use warnings;

use Test::More;
use Test::LeakTrace;

{
package Iyan;
use Mouse;
}

{
package Role1;
use Mouse::Role;
}

{
package Role2;
use Mouse::Role;
}

no_leaks_ok {
foo();
} 'apply_all_roles';

note 'after no_leaks_ok';

done_testing;

sub foo {
my $self = bless {}, 'Iyan';
Mouse::Util::apply_all_roles($self, 'Role1', 'Role2');
}

0 comments on commit 6422ae1

Please sign in to comment.