test tweaks
[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 => 5;    
13
14     use_ok('Class::MOP');    
15     require_ok(File::Spec->catfile('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