f99cac9ba8cd7e8fbc85a910f47b469490fec6e0
[gitmo/Moose.git] / t / 060_compat / 003_foreign_inheritence.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 6;
7 use Test::Exception;
8
9
10
11 {
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
37     __PACKAGE__->meta->make_immutable( inline_constructor => 0, debug => 0 );
38
39     package Bucket;
40     use metaclass 'Class::MOP::Class';
41
42     __PACKAGE__->meta->add_attribute(
43         'squeegee' => ( accessor => 'squeegee' ) );
44
45     package Old::Bucket::Nose;
46
47     # see http://www.moosefoundation.org/moose_facts.htm
48     use Moose;
49
50     extends 'Bucket';
51
52     package MyBase;
53     sub foo { }
54
55     package Custom::Meta1;
56     use base qw(Moose::Meta::Class);
57
58     package Custom::Meta2;
59     use base qw(Moose::Meta::Class);
60
61     package SubClass1;
62     use metaclass 'Custom::Meta1';
63     use Moose;
64
65     extends 'MyBase';
66
67     package SubClass2;
68     use metaclass 'Custom::Meta2';
69     use Moose;
70
71     # XXX FIXME subclassing meta-attrs and immutable-ing the subclass fails
72 }
73
74 my $foo_moose = Foo::Moose->new();
75 isa_ok( $foo_moose, 'Foo::Moose' );
76 isa_ok( $foo_moose, 'Elk' );
77
78 is( $foo_moose->no_moose, 'Elk',
79     '... got the right value from the Elk method' );
80 is( $foo_moose->moose, 'Foo',
81     '... got the right value from the Foo::Moose method' );
82
83 lives_ok {
84     Old::Bucket::Nose->meta->make_immutable( debug => 0 );
85 }
86 'Immutability on Moose class extending Class::MOP class ok';
87
88 lives_ok {
89     SubClass2->meta->superclasses('MyBase');
90 }
91 'Can subclass the same non-Moose class twice with different metaclasses';
92