Merge branch 'stable'
[gitmo/Class-MOP.git] / t / 107_C3MethodDispatchOrder_test.t
CommitLineData
f3f5bd34 1use strict;
2use warnings;
3
d89c0fad 4use Test::More;
f3f5bd34 5use File::Spec;
86a4d873 6use Class::MOP;
f3f5bd34 7
0f352882 8use Test::Requires {
9 'Algorithm::C3' => '0.01', # skip all if not installed
10};
11
d89c0fad 12BEGIN {
10dd437b 13 require_ok(File::Spec->catfile('examples', 'C3MethodDispatchOrder.pod'));
f3f5bd34 14}
15
16{
17 package Diamond_A;
86a4d873 18 use metaclass 'C3MethodDispatchOrder';
19
f3f5bd34 20 sub hello { 'Diamond_A::hello' }
21
22 package Diamond_B;
86a4d873 23 use metaclass 'C3MethodDispatchOrder';
24 __PACKAGE__->meta->superclasses('Diamond_A');
25
f3f5bd34 26 package Diamond_C;
86a4d873 27 use metaclass 'C3MethodDispatchOrder';
28 __PACKAGE__->meta->superclasses('Diamond_A');
29
f3f5bd34 30 sub hello { 'Diamond_C::hello' }
31
32 package Diamond_D;
86a4d873 33 use metaclass 'C3MethodDispatchOrder';
f3f5bd34 34 __PACKAGE__->meta->superclasses('Diamond_B', 'Diamond_C');
35}
36
37is_deeply(
38 [ Diamond_D->meta->class_precedence_list ],
39 [ qw(Diamond_D Diamond_B Diamond_C Diamond_A) ],
40 '... got the right MRO for Diamond_D');
41
42is(Diamond_D->hello, 'Diamond_C::hello', '... got the right dispatch order');
43is(Diamond_D->can('hello')->(), 'Diamond_C::hello', '... can(method) resolved itself as expected');
44
86a4d873 45done_testing;