File: 023_DEMOLISH_fails_without_metaclass.t

package info (click to toggle)
libmoose-perl 1.09-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,004 kB
  • ctags: 1,472
  • sloc: perl: 25,387; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 968 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use strict;
use warnings;

use Test::More;
use Test::Exception;

{
    package MyClass;
    use Moose;

    sub DEMOLISH { }
}

my $object = MyClass->new;

# Removing the metaclass simulates the case where the metaclass object
# goes out of scope _before_ the object itself, which under normal
# circumstances only happens during global destruction.
Class::MOP::remove_metaclass_by_name('MyClass');

# The bug happened when DEMOLISHALL called
# Class::MOP::class_of($object) and did not get a metaclass object
# back.
lives_ok { $object->DESTROY }
'can call DESTROY on an object without a metaclass object in the CMOP cache';


MyClass->meta->make_immutable;
Class::MOP::remove_metaclass_by_name('MyClass');

# The bug didn't manifest for immutable objects, but this test should
# help us prevent it happening in the future.
lives_ok { $object->DESTROY }
'can call DESTROY on an object without a metaclass object in the CMOP cache (immutable version)';

done_testing;