uploadin
[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;
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
25my $foo = Foo->new();
26isa_ok($foo, 'Foo');
27
28can_ok($foo, 'foo');
29is($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
49my $foo_bar_baz = Foo::Bar::Baz->new();
50isa_ok($foo_bar_baz, 'Foo::Bar::Baz');
51isa_ok($foo_bar_baz, 'Foo::Bar');
52isa_ok($foo_bar_baz, 'Foo');
53isa_ok($foo_bar_baz, 'Bar');
54
55can_ok($foo_bar_baz, 'baz');
56is($foo_bar_baz->baz(), 'Baz::baz', '... got the right value from the mixin method');
57