bunch of stuff
[gitmo/Class-MOP.git] / t / 300_basic_safe_mixin.t
CommitLineData
72c21074 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More no_plan => 1;
7
8BEGIN {
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
24my $foo = Foo->new();
25isa_ok($foo, 'Foo');
26
27can_ok($foo, 'foo');
28is($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
46my $foo_baz = Foo::Baz->new();
47isa_ok($foo_baz, 'Foo::Baz');
48isa_ok($foo_baz, 'Foo');
49
50can_ok($foo_baz, 'baz');
51is($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
63my $foo_bar_baz = Foo::Bar::Baz->new();
64isa_ok($foo_bar_baz, 'Foo::Bar::Baz');
65isa_ok($foo_bar_baz, 'Foo::Bar');
66isa_ok($foo_bar_baz, 'Foo');
67isa_ok($foo_bar_baz, 'Bar');
68
69can_ok($foo_bar_baz, 'baz');
70is($foo_bar_baz->baz(), 'Baz::baz', '... got the right value from the mixin method');
71