Commit | Line | Data |
633776d0 |
1 | use strict; |
2 | use warnings; |
3 | |
a28e50e4 |
4 | use Test::More; |
b10dde3a |
5 | use Test::Fatal; |
633776d0 |
6 | |
7 | { |
8 | package MyClass; |
9 | use Moose; |
10 | |
11 | sub DEMOLISH { } |
12 | } |
13 | |
14 | my $object = MyClass->new; |
15 | |
16 | # Removing the metaclass simulates the case where the metaclass object |
17 | # goes out of scope _before_ the object itself, which under normal |
18 | # circumstances only happens during global destruction. |
19 | Class::MOP::remove_metaclass_by_name('MyClass'); |
20 | |
21 | # The bug happened when DEMOLISHALL called |
22 | # Class::MOP::class_of($object) and did not get a metaclass object |
23 | # back. |
b10dde3a |
24 | is( exception { $object->DESTROY }, undef, 'can call DESTROY on an object without a metaclass object in the CMOP cache' ); |
633776d0 |
25 | |
26 | |
27 | MyClass->meta->make_immutable; |
28 | Class::MOP::remove_metaclass_by_name('MyClass'); |
29 | |
30 | # The bug didn't manifest for immutable objects, but this test should |
31 | # help us prevent it happening in the future. |
b10dde3a |
32 | is( exception { $object->DESTROY }, undef, 'can call DESTROY on an object without a metaclass object in the CMOP cache (immutable version)' ); |
a28e50e4 |
33 | |
34 | done_testing; |