add tests for wrapping a method metaobject
[gitmo/Class-MOP.git] / t / 107_C3MethodDispatchOrder_test.t
CommitLineData
f3f5bd34 1use strict;
2use warnings;
3
d89c0fad 4use Test::More;
f3f5bd34 5use File::Spec;
6
d89c0fad 7BEGIN {
8 eval "use Algorithm::C3";
9 plan skip_all => "Algorithm::C3 required for this test" if $@;
efd3d14c 10 plan tests => 4;use Class::MOP;
10dd437b 11 require_ok(File::Spec->catfile('examples', 'C3MethodDispatchOrder.pod'));
f3f5bd34 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
35is_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
40is(Diamond_D->hello, 'Diamond_C::hello', '... got the right dispatch order');
41is(Diamond_D->can('hello')->(), 'Diamond_C::hello', '... can(method) resolved itself as expected');
42
43