5331463558563bebc5cda987c50c0a5dbddbafe3
[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;
7 use File::Spec;
8
9 BEGIN {
10     eval "use Algorithm::C3";
11     plan skip_all => "Algorithm::C3 required for this test" if $@;
12     plan tests => 4;use Class::MOP;    
13     require_ok(File::Spec->catfile('examples', 'C3MethodDispatchOrder.pod'));
14 }
15
16 {
17     package Diamond_A;
18     use metaclass 'C3MethodDispatchOrder'; 
19     
20     sub hello { 'Diamond_A::hello' }
21
22     package Diamond_B;
23     use metaclass 'C3MethodDispatchOrder'; 
24     __PACKAGE__->meta->superclasses('Diamond_A'); 
25     
26     package Diamond_C;
27     use metaclass 'C3MethodDispatchOrder';     
28     __PACKAGE__->meta->superclasses('Diamond_A');     
29     
30     sub hello { 'Diamond_C::hello' }
31
32     package Diamond_D;
33     use metaclass 'C3MethodDispatchOrder';     
34     __PACKAGE__->meta->superclasses('Diamond_B', 'Diamond_C');
35 }
36
37 is_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
42 is(Diamond_D->hello, 'Diamond_C::hello', '... got the right dispatch order');
43 is(Diamond_D->can('hello')->(), 'Diamond_C::hello', '... can(method) resolved itself as expected');
44
45