Commit | Line | Data |
72c21074 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More no_plan => 1; |
7 | |
8 | BEGIN { |
9 | use_ok('Class::MOP'); |
10 | use_ok('Class::MOP::SafeMixin'); |
11 | } |
12 | |
13 | ## Mixin a class without a superclass. |
14 | { |
15 | package FooMixin; |
72c21074 |
16 | sub foo { 'FooMixin::foo' } |
17 | |
18 | package Foo; |
19 | use metaclass 'Class::MOP::SafeMixin'; |
20 | Foo->meta->mixin('FooMixin'); |
21 | sub new { (shift)->meta->new_object(@_) } |
22 | } |
23 | |
24 | my $foo = Foo->new(); |
25 | isa_ok($foo, 'Foo'); |
26 | |
27 | can_ok($foo, 'foo'); |
28 | is($foo->foo, 'FooMixin::foo', '... got the right value from the mixin method'); |
29 | |
30 | ## Mixin a class who shares a common ancestor |
31 | { |
32 | package Baz; |
33 | our @ISA = ('Foo'); |
34 | sub baz { 'Baz::baz' } |
35 | |
36 | package Bar; |
37 | our @ISA = ('Foo'); |
38 | |
de19f115 |
39 | package Foo::Baz; |
40 | our @ISA = ('Foo'); |
41 | eval { Foo::Baz->meta->mixin('Baz') }; |
42 | ::ok(!$@, '... the classes superclass must extend a subclass of the superclass of the mixins'); |
43 | |
44 | } |
45 | |
46 | my $foo_baz = Foo::Baz->new(); |
47 | isa_ok($foo_baz, 'Foo::Baz'); |
48 | isa_ok($foo_baz, 'Foo'); |
49 | |
50 | can_ok($foo_baz, 'baz'); |
51 | is($foo_baz->baz(), 'Baz::baz', '... got the right value from the mixin method'); |
52 | |
53 | { |
72c21074 |
54 | package Foo::Bar; |
55 | our @ISA = ('Foo', 'Bar'); |
56 | |
57 | package Foo::Bar::Baz; |
58 | our @ISA = ('Foo::Bar'); |
59 | eval { Foo::Bar::Baz->meta->mixin('Baz') }; |
60 | ::ok(!$@, '... the classes superclass must extend a subclass of the superclass of the mixins'); |
61 | } |
62 | |
63 | my $foo_bar_baz = Foo::Bar::Baz->new(); |
64 | isa_ok($foo_bar_baz, 'Foo::Bar::Baz'); |
65 | isa_ok($foo_bar_baz, 'Foo::Bar'); |
66 | isa_ok($foo_bar_baz, 'Foo'); |
67 | isa_ok($foo_bar_baz, 'Bar'); |
68 | |
69 | can_ok($foo_bar_baz, 'baz'); |
70 | is($foo_bar_baz->baz(), 'Baz::baz', '... got the right value from the mixin method'); |
71 | |