add a warning for immutablizing a class with mutable ancestors
[gitmo/Moose.git] / t / 060_compat / 003_foreign_inheritence.t
CommitLineData
e522431d 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
7ff56534 6use Test::More tests => 6;
e522431d 7use Test::Exception;
8
7ff56534 9
e522431d 10
11{
8b8fa50d 12
13 package Elk;
14 use strict;
15 use warnings;
16
17 sub new {
18 my $class = shift;
19 bless { no_moose => "Elk" } => $class;
20 }
21
22 sub no_moose { $_[0]->{no_moose} }
23
24 package Foo::Moose;
25 use Moose;
26
27 extends 'Elk';
28
29 has 'moose' => ( is => 'ro', default => 'Foo' );
30
31 sub new {
32 my $class = shift;
33 my $super = $class->SUPER::new(@_);
34 return $class->meta->new_object( '__INSTANCE__' => $super, @_ );
35 }
36
77ed022c 37 __PACKAGE__->meta->make_immutable( inline_constructor => 0, debug => 0 );
b43a4bca 38
0305961b 39 package Bucket;
40 use metaclass 'Class::MOP::Class';
8b8fa50d 41
42 __PACKAGE__->meta->add_attribute(
43 'squeegee' => ( accessor => 'squeegee' ) );
44
21f1fbdc 45 __PACKAGE__->meta->make_immutable(inline_constructor => 0);
46
0305961b 47 package Old::Bucket::Nose;
8b8fa50d 48
0305961b 49 # see http://www.moosefoundation.org/moose_facts.htm
50 use Moose;
8b8fa50d 51
0305961b 52 extends 'Bucket';
2f9e53fb 53
cdeb30dc 54 package MyBase;
cdeb30dc 55 sub foo { }
56
57 package Custom::Meta1;
58 use base qw(Moose::Meta::Class);
59
60 package Custom::Meta2;
61 use base qw(Moose::Meta::Class);
62
63 package SubClass1;
64 use metaclass 'Custom::Meta1';
65 use Moose;
66
67 extends 'MyBase';
68
69 package SubClass2;
70 use metaclass 'Custom::Meta2';
71 use Moose;
72
8b8fa50d 73 # XXX FIXME subclassing meta-attrs and immutable-ing the subclass fails
e522431d 74}
75
76my $foo_moose = Foo::Moose->new();
8b8fa50d 77isa_ok( $foo_moose, 'Foo::Moose' );
78isa_ok( $foo_moose, 'Elk' );
e522431d 79
8b8fa50d 80is( $foo_moose->no_moose, 'Elk',
81 '... got the right value from the Elk method' );
82is( $foo_moose->moose, 'Foo',
83 '... got the right value from the Foo::Moose method' );
84
85lives_ok {
86 Old::Bucket::Nose->meta->make_immutable( debug => 0 );
87}
88'Immutability on Moose class extending Class::MOP class ok';
b43a4bca 89
a5e883ae 90lives_ok {
635b9d7e 91 SubClass2->meta->superclasses('MyBase');
8b8fa50d 92}
93'Can subclass the same non-Moose class twice with different metaclasses';
ab76842e 94