Commit | Line | Data |
f3f5bd34 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
d89c0fad |
6 | use Test::More; |
f3f5bd34 |
7 | use File::Spec; |
8 | |
d89c0fad |
9 | BEGIN { |
10 | eval "use Algorithm::C3"; |
11 | plan skip_all => "Algorithm::C3 required for this test" if $@; |
12 | plan tests => 5; |
13 | |
f3f5bd34 |
14 | use_ok('Class::MOP'); |
15 | require_ok(File::Spec->catdir('examples', 'C3MethodDispatchOrder.pod')); |
16 | } |
17 | |
18 | { |
19 | package Diamond_A; |
20 | use metaclass 'C3MethodDispatchOrder'; |
21 | |
22 | sub hello { 'Diamond_A::hello' } |
23 | |
24 | package Diamond_B; |
25 | use metaclass 'C3MethodDispatchOrder'; |
26 | __PACKAGE__->meta->superclasses('Diamond_A'); |
27 | |
28 | package Diamond_C; |
29 | use metaclass 'C3MethodDispatchOrder'; |
30 | __PACKAGE__->meta->superclasses('Diamond_A'); |
31 | |
32 | sub hello { 'Diamond_C::hello' } |
33 | |
34 | package Diamond_D; |
35 | use metaclass 'C3MethodDispatchOrder'; |
36 | __PACKAGE__->meta->superclasses('Diamond_B', 'Diamond_C'); |
37 | } |
38 | |
39 | is_deeply( |
40 | [ Diamond_D->meta->class_precedence_list ], |
41 | [ qw(Diamond_D Diamond_B Diamond_C Diamond_A) ], |
42 | '... got the right MRO for Diamond_D'); |
43 | |
44 | is(Diamond_D->hello, 'Diamond_C::hello', '... got the right dispatch order'); |
45 | is(Diamond_D->can('hello')->(), 'Diamond_C::hello', '... can(method) resolved itself as expected'); |
46 | |
47 | |