One last tweak to make sure our Sub::Name-using tests _do_ run when we
[gitmo/Class-MOP.git] / t / 071_immutable_w_custom_metaclass.t
CommitLineData
373a16ae 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
04dd7510 6use FindBin;
7use File::Spec::Functions;
8
d9586da2 9use Test::More tests => 15;
373a16ae 10use Test::Exception;
04dd7510 11use Scalar::Util;
373a16ae 12
13BEGIN {
14 use_ok('Class::MOP');
15}
16
04dd7510 17use lib catdir($FindBin::Bin, 'lib');
18
373a16ae 19{
04dd7510 20 package Foo;
21
373a16ae 22 use strict;
23 use warnings;
04dd7510 24 use metaclass;
25
26 __PACKAGE__->meta->make_immutable;
373a16ae 27
373a16ae 28 package Bar;
04dd7510 29
373a16ae 30 use strict;
31 use warnings;
04dd7510 32 use metaclass;
33
373a16ae 34 __PACKAGE__->meta->make_immutable;
04dd7510 35
373a16ae 36 package Baz;
04dd7510 37
373a16ae 38 use strict;
39 use warnings;
04dd7510 40 use metaclass 'MyMetaClass';
41
42 sub mymetaclass_attributes{
43 shift->meta->mymetaclass_attributes;
44 }
373a16ae 45
46 ::lives_ok {
04dd7510 47 Baz->meta->superclasses('Bar');
373a16ae 48 } '... we survive the metaclass incompatability test';
49}
50
04dd7510 51{
52 my $meta = Baz->meta;
d9586da2 53 ok($meta->is_mutable, '... Baz is mutable');
11b56828 54 is(Scalar::Util::blessed(Foo->meta), Scalar::Util::blessed(Bar->meta), 'Foo and Bar immutable metaclasses match');
55 is(Scalar::Util::blessed($meta), 'MyMetaClass', 'Baz->meta blessed as MyMetaClass');
04dd7510 56 ok(Baz->can('mymetaclass_attributes'), '... Baz can do method before immutable');
57 ok($meta->can('mymetaclass_attributes'), '... meta can do method before immutable');
d9586da2 58 lives_ok { $meta->make_immutable } "Baz is now immutable";
59 ok($meta->is_immutable, '... Baz is immutable');
04dd7510 60 isa_ok($meta, 'MyMetaClass', 'Baz->meta');
61 ok(Baz->can('mymetaclass_attributes'), '... Baz can do method after imutable');
62 ok($meta->can('mymetaclass_attributes'), '... meta can do method after immutable');
11b56828 63 isnt(Scalar::Util::blessed(Baz->meta), Scalar::Util::blessed(Bar->meta), 'Baz and Bar immutable metaclasses are different');
d9586da2 64 lives_ok { $meta->make_mutable } "Baz is now mutable";
65 ok($meta->is_mutable, '... Baz is mutable again');
04dd7510 66}