}
# NOTE:
# this will only work for a HASH instance type
- if ($class->is_anon_class) {
+ if (Class::MOP::metaclass_is_weak($class->name)) {
(reftype($instance) eq 'HASH')
|| confess "Currently only HASH based instances are supported with instance of anon-classes";
# NOTE:
$old_metaclass->rebless_instance_away($instance, $self, %params)
if $old_metaclass;
- if ($old_metaclass->is_anon_class) {
+ if (Class::MOP::metaclass_is_weak($old_metaclass->name)) {
delete $instance->{__MOP__};
}
# NOTE:
# this will only work for a HASH instance type
- if ($self->is_anon_class) {
+ if (Class::MOP::metaclass_is_weak($self->name)) {
(reftype($instance) eq 'HASH')
|| confess "Currently only HASH based instances are supported with instance of anon-classes";
# NOTE:
}
}
+{
+ my $meta = Class::MOP::Class->create(
+ 'Baz',
+ weaken => 1,
+ );
+ $instance = $meta->new_object;
+}
+{
+ my $meta = Class::MOP::class_of($instance);
+ Scalar::Util::weaken($meta);
+ ok($meta, "weak class is kept alive by existing instances");
+
+ undef $instance;
+ ok(!$meta, "weak class is collected once instances go away");
+}
+
done_testing;