summaryrefslogtreecommitdiff
path: root/t/cmop/immutable_w_custom_metaclass.t
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2015-06-06 17:50:16 +0000
commit5ac2026f7eed78958d69d051e7a8e993dcf51205 (patch)
tree298c3d2f08bdfe5689998b11892d72a897985be1 /t/cmop/immutable_w_custom_metaclass.t
downloadMoose-tarball-5ac2026f7eed78958d69d051e7a8e993dcf51205.tar.gz
Diffstat (limited to 't/cmop/immutable_w_custom_metaclass.t')
-rw-r--r--t/cmop/immutable_w_custom_metaclass.t71
1 files changed, 71 insertions, 0 deletions
diff --git a/t/cmop/immutable_w_custom_metaclass.t b/t/cmop/immutable_w_custom_metaclass.t
new file mode 100644
index 0000000..c0b722d
--- /dev/null
+++ b/t/cmop/immutable_w_custom_metaclass.t
@@ -0,0 +1,71 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Fatal;
+use Scalar::Util;
+
+use Class::MOP;
+
+use lib 't/cmop/lib';
+
+{
+
+ package Foo;
+
+ use strict;
+ use warnings;
+ use metaclass;
+
+ __PACKAGE__->meta->make_immutable;
+
+ package Bar;
+
+ use strict;
+ use warnings;
+ use metaclass;
+
+ __PACKAGE__->meta->make_immutable;
+
+ package Baz;
+
+ use strict;
+ use warnings;
+ use metaclass 'MyMetaClass';
+
+ sub mymetaclass_attributes {
+ shift->meta->mymetaclass_attributes;
+ }
+
+ ::is( ::exception { Baz->meta->superclasses('Bar') }, undef, '... we survive the metaclass incompatibility test' );
+}
+
+{
+ my $meta = Baz->meta;
+ ok( $meta->is_mutable, '... Baz is mutable' );
+ is(
+ Scalar::Util::blessed( Foo->meta ),
+ Scalar::Util::blessed( Bar->meta ),
+ 'Foo and Bar immutable metaclasses match'
+ );
+ is( Scalar::Util::blessed($meta), 'MyMetaClass',
+ 'Baz->meta blessed as MyMetaClass' );
+ ok( Baz->can('mymetaclass_attributes'),
+ '... Baz can do method before immutable' );
+ ok( $meta->can('mymetaclass_attributes'),
+ '... meta can do method before immutable' );
+ is( exception { $meta->make_immutable }, undef, "Baz is now immutable" );
+ ok( $meta->is_immutable, '... Baz is immutable' );
+ isa_ok( $meta, 'MyMetaClass', 'Baz->meta' );
+ ok( Baz->can('mymetaclass_attributes'),
+ '... Baz can do method after imutable' );
+ ok( $meta->can('mymetaclass_attributes'),
+ '... meta can do method after immutable' );
+ isnt( Scalar::Util::blessed( Baz->meta ),
+ Scalar::Util::blessed( Bar->meta ),
+ 'Baz and Bar immutable metaclasses are different' );
+ is( exception { $meta->make_mutable }, undef, "Baz is now mutable" );
+ ok( $meta->is_mutable, '... Baz is mutable again' );
+}
+
+done_testing;