From: Dave Rolsky Date: Sun, 19 Feb 2012 19:47:36 +0000 (-0600) Subject: When applying roles, don't apply the exact same role object more than once. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bf46ee52709c38edc600f24ceb3a334d2c90965e;p=gitmo%2FMoose.git When applying roles, don't apply the exact same role object more than once. This fixes one of the memory leaks. --- diff --git a/lib/Moose/Meta/Role/Application/ToClass.pm b/lib/Moose/Meta/Role/Application/ToClass.pm index 822d1e5..3a5a650 100644 --- a/lib/Moose/Meta/Role/Application/ToClass.pm +++ b/lib/Moose/Meta/Role/Application/ToClass.pm @@ -23,6 +23,10 @@ __PACKAGE__->meta->add_attribute('class' => ( sub apply { my ($self, $role, $class) = @_; + # We're not checking for role names to support multiple instances of the + # same Parameterized role. + return if grep { $role == $_ } @{ $class->roles() }; + # We need weak_ref in CMOP :( weaken($self->{role} = $role); weaken($self->{class} = $class); diff --git a/lib/Moose/Meta/Role/Application/ToRole.pm b/lib/Moose/Meta/Role/Application/ToRole.pm index e8ab886..54979f5 100644 --- a/lib/Moose/Meta/Role/Application/ToRole.pm +++ b/lib/Moose/Meta/Role/Application/ToRole.pm @@ -10,7 +10,13 @@ use base 'Moose::Meta::Role::Application'; sub apply { my ($self, $role1, $role2) = @_; + + # We're not checking for role names to support multiple instances of the + # same Parameterized role. + return if grep { $role1 == $_ } @{ $role2->get_roles() }; + $self->SUPER::apply($role1, $role2); + $role2->add_role($role1); }