adding in the C3 example
[gitmo/Class-MOP.git] / t / 107_C3MethodDispatchOrder_test.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 5;
7 use File::Spec;
8
9 BEGIN { 
10     use_ok('Class::MOP');    
11     require_ok(File::Spec->catdir('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