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; |
16 | use metaclass; |
17 | sub foo { 'FooMixin::foo' } |
18 | |
19 | package Foo; |
20 | use metaclass 'Class::MOP::SafeMixin'; |
21 | Foo->meta->mixin('FooMixin'); |
22 | sub new { (shift)->meta->new_object(@_) } |
23 | } |
24 | |
25 | my $foo = Foo->new(); |
26 | isa_ok($foo, 'Foo'); |
27 | |
28 | can_ok($foo, 'foo'); |
29 | is($foo->foo, 'FooMixin::foo', '... got the right value from the mixin method'); |
30 | |
31 | ## Mixin a class who shares a common ancestor |
32 | { |
33 | package Baz; |
34 | our @ISA = ('Foo'); |
35 | sub baz { 'Baz::baz' } |
36 | |
37 | package Bar; |
38 | our @ISA = ('Foo'); |
39 | |
40 | package Foo::Bar; |
41 | our @ISA = ('Foo', 'Bar'); |
42 | |
43 | package Foo::Bar::Baz; |
44 | our @ISA = ('Foo::Bar'); |
45 | eval { Foo::Bar::Baz->meta->mixin('Baz') }; |
46 | ::ok(!$@, '... the classes superclass must extend a subclass of the superclass of the mixins'); |
47 | } |
48 | |
49 | my $foo_bar_baz = Foo::Bar::Baz->new(); |
50 | isa_ok($foo_bar_baz, 'Foo::Bar::Baz'); |
51 | isa_ok($foo_bar_baz, 'Foo::Bar'); |
52 | isa_ok($foo_bar_baz, 'Foo'); |
53 | isa_ok($foo_bar_baz, 'Bar'); |
54 | |
55 | can_ok($foo_bar_baz, 'baz'); |
56 | is($foo_bar_baz->baz(), 'Baz::baz', '... got the right value from the mixin method'); |
57 | |