From: Jesse Luehrs Date: Fri, 4 Mar 2011 17:49:01 +0000 (-0600) Subject: yes, this is necessary for us X-Git-Tag: 1.25~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8d3bb22c39392fe041e520ae3f5259d4c85aaf90;p=gitmo%2FMoose.git yes, this is necessary for us (cherry picked from commit 082256d07987c60f4352681b9d1eeb06eb52a79b) --- diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index 8edaca4..f9fea21 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -625,16 +625,13 @@ sub consumers { no warnings 'uninitialized'; return unless $self->name =~ /^$ANON_ROLE_PREFIX/; - # XXX: is this necessary for us? I don't understand what it's doing - # -sartak - # Moose does a weird thing where it replaces the metaclass for # class when fixing metaclass incompatibility. In that case, # we don't want to clean out the namespace now. We can detect # that because Moose will explicitly update the singleton # cache in Class::MOP. - #my $current_meta = Class::MOP::get_metaclass_by_name($self->name); - #return if $current_meta ne $self; + my $current_meta = Class::MOP::get_metaclass_by_name($self->name); + return if $current_meta ne $self; my ($serial_id) = ($self->name =~ /^$ANON_ROLE_PREFIX(\d+)/); no strict 'refs'; diff --git a/t/030_roles/049_reinitialize_anon_role.t b/t/030_roles/049_reinitialize_anon_role.t new file mode 100644 index 0000000..6e6db9a --- /dev/null +++ b/t/030_roles/049_reinitialize_anon_role.t @@ -0,0 +1,31 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +{ + package Role::Metarole; + use Moose::Role; +} + +my ($role2); +{ + my $role1 = Moose::Meta::Role->create_anon_role( + methods => { + foo => sub { }, + }, + ); + ok($role1->has_method('foo'), "role has method foo"); + $role2 = Moose::Util::MetaRole::apply_metaroles( + for => $role1->name, + role_metaroles => { role => ['Role::Metarole'] }, + ); + isnt($role1, $role2, "anon role was reinitialized"); + is($role1->name, $role2->name, "but it's the same anon role"); + is_deeply([sort $role2->get_method_list], ['foo', 'meta'], + "has the right methods"); +} +is_deeply([sort $role2->get_method_list], ['foo', 'meta'], + "still has the right methods"); + +done_testing;