Make sure method map is updated after a method is removed
[gitmo/Class-MOP.git] / t / 071_immutable_w_custom_metaclass.t
1 use strict;
2 use warnings;
3
4 use FindBin;
5 use File::Spec::Functions;
6
7 use Test::More tests => 14;
8 use Test::Exception;
9 use Scalar::Util;
10
11 use Class::MOP;
12
13 use lib catdir($FindBin::Bin, 'lib');
14
15 {
16     package Foo;
17
18     use strict;
19     use warnings;
20     use metaclass;
21
22     __PACKAGE__->meta->make_immutable;
23
24     package Bar;
25
26     use strict;
27     use warnings;
28     use metaclass;
29
30     __PACKAGE__->meta->make_immutable;
31
32     package Baz;
33
34     use strict;
35     use warnings;
36     use metaclass 'MyMetaClass';
37
38     sub mymetaclass_attributes{
39       shift->meta->mymetaclass_attributes;
40     }
41
42     ::lives_ok {
43         Baz->meta->superclasses('Bar');
44     } '... we survive the metaclass incompatibility test';
45 }
46
47 {
48     my $meta = Baz->meta;
49     ok($meta->is_mutable, '... Baz is mutable');
50     isnt(Scalar::Util::blessed(Foo->meta), Scalar::Util::blessed(Bar->meta),
51          'Foo and Bar immutable metaclasses do not match');
52     is(Scalar::Util::blessed($meta), 'MyMetaClass', 'Baz->meta blessed as MyMetaClass');
53     ok(Baz->can('mymetaclass_attributes'), '... Baz can do method before immutable');
54     ok($meta->can('mymetaclass_attributes'), '... meta can do method before immutable');
55     lives_ok { $meta->make_immutable } "Baz is now immutable";
56     ok($meta->is_immutable, '... Baz is immutable');
57     isa_ok($meta, 'MyMetaClass', 'Baz->meta');
58     ok(Baz->can('mymetaclass_attributes'), '... Baz can do method after imutable');
59     ok($meta->can('mymetaclass_attributes'), '... meta can do method after immutable');
60     isnt(Scalar::Util::blessed(Baz->meta), Scalar::Util::blessed(Bar->meta), 'Baz and Bar immutable metaclasses are different');
61     lives_ok { $meta->make_mutable } "Baz is now mutable";
62     ok($meta->is_mutable, '... Baz is mutable again');
63 }