From: Shawn M Moore Date: Sat, 19 Feb 2011 04:11:02 +0000 (-0500) Subject: Make anon role DESTROY logic match that of anon class X-Git-Tag: 2.0001~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5baa691be288f09235cd0970277d1e31da0dda5b;p=gitmo%2FMoose.git Make anon role DESTROY logic match that of anon class --- diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index f503d5a..095fd7e 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -619,8 +619,15 @@ sub consumers { return if in_global_destruction(); # it'll happen soon anyway and this just makes things more complicated - no warnings 'uninitialized'; - return unless $self->name =~ /^$ANON_ROLE_PREFIX/; + $self->free_anon_role + if $self->is_anon_role; + } + + sub free_anon_role { + my $self = shift; + my $name = $self->name; + + my ($first_fragments, $last_fragment) = ($name =~ /^(.*)::(.*)$/); # Moose does a weird thing where it replaces the metaclass for # class when fixing metaclass incompatibility. In that case, @@ -630,12 +637,12 @@ sub consumers { 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'; - foreach my $key (keys %{$ANON_ROLE_PREFIX . $serial_id}) { - delete ${$ANON_ROLE_PREFIX . $serial_id}{$key}; - } - delete ${'main::' . $ANON_ROLE_PREFIX}{$serial_id . '::'}; + @{$name . '::ISA'} = (); + %{$name . '::'} = (); + delete ${$first_fragments}{$last_fragment . '::'}; + + Class::MOP::remove_metaclass_by_name($name); } }