move methods back into CMOP::Class, now that they're a separate mixin
[gitmo/Class-MOP.git] / t / 107_C3MethodDispatchOrder_test.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use File::Spec;
6 use Class::MOP;
7
8 BEGIN {
9     eval "use Algorithm::C3";
10     plan skip_all => "Algorithm::C3 required for this test" if $@;
11     require_ok(File::Spec->catfile('examples', 'C3MethodDispatchOrder.pod'));
12 }
13
14 {
15     package Diamond_A;
16     use metaclass 'C3MethodDispatchOrder';
17
18     sub hello { 'Diamond_A::hello' }
19
20     package Diamond_B;
21     use metaclass 'C3MethodDispatchOrder';
22     __PACKAGE__->meta->superclasses('Diamond_A');
23
24     package Diamond_C;
25     use metaclass 'C3MethodDispatchOrder';
26     __PACKAGE__->meta->superclasses('Diamond_A');
27
28     sub hello { 'Diamond_C::hello' }
29
30     package Diamond_D;
31     use metaclass 'C3MethodDispatchOrder';
32     __PACKAGE__->meta->superclasses('Diamond_B', 'Diamond_C');
33 }
34
35 is_deeply(
36     [ Diamond_D->meta->class_precedence_list ],
37     [ qw(Diamond_D Diamond_B Diamond_C Diamond_A) ],
38     '... got the right MRO for Diamond_D');
39
40 is(Diamond_D->hello, 'Diamond_C::hello', '... got the right dispatch order');
41 is(Diamond_D->can('hello')->(), 'Diamond_C::hello', '... can(method) resolved itself as expected');
42
43 done_testing;