From: Jesse Luehrs Date: Thu, 30 Sep 2010 22:36:50 +0000 (-0500) Subject: fix up the __MOP__ slot when reblessing to or from anon classes X-Git-Tag: 1.10~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1e40bca86928bcefbce9d8d00fc7eed17bb6c554;p=gitmo%2FClass-MOP.git fix up the __MOP__ slot when reblessing to or from anon classes --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 122ed9a..0c9e9d7 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -681,6 +681,10 @@ sub _force_rebless_instance { $old_metaclass->rebless_instance_away($instance, $self, %params) if $old_metaclass; + if ($old_metaclass->is_anon_class) { + delete $instance->{__MOP__}; + } + my $meta_instance = $self->get_meta_instance; # rebless! @@ -688,6 +692,19 @@ sub _force_rebless_instance { $meta_instance->rebless_instance_structure($_[1], $self); $self->_fixup_attributes_after_rebless($instance, $old_metaclass, %params); + + # NOTE: + # this will only work for a HASH instance type + if ($self->is_anon_class) { + (reftype($instance) eq 'HASH') + || confess "Currently only HASH based instances are supported with instance of anon-classes"; + # NOTE: + # At some point we should make this official + # as a reserved slot name, but right now I am + # going to keep it here. + # my $RESERVED_MOP_SLOT = '__MOP__'; + $instance->{'__MOP__'} = $self; + } } sub rebless_instance {