Commit | Line | Data |
663f8198 |
1 | use strict; |
2 | use warnings; |
3 | |
efd3d14c |
4 | use Test::More tests => 7; |
663f8198 |
5 | |
6 | =pod |
7 | |
8 | This tests that Class::MOP works correctly |
9 | with Class::C3 and it's somewhat insane |
10 | approach to method resolution. |
11 | |
12 | =cut |
13 | |
efd3d14c |
14 | BEGIN {use Class::MOP; |
663f8198 |
15 | } |
16 | |
17 | { |
18 | package Diamond_A; |
77a143ba |
19 | use mro 'c3'; |
663f8198 |
20 | use metaclass; # everyone will just inherit this now :) |
21 | |
22 | sub hello { 'Diamond_A::hello' } |
23 | } |
24 | { |
25 | package Diamond_B; |
77a143ba |
26 | use mro 'c3'; |
663f8198 |
27 | use base 'Diamond_A'; |
663f8198 |
28 | } |
29 | { |
30 | package Diamond_C; |
77a143ba |
31 | use mro 'c3'; |
663f8198 |
32 | use base 'Diamond_A'; |
33 | |
34 | sub hello { 'Diamond_C::hello' } |
35 | } |
36 | { |
37 | package Diamond_D; |
77a143ba |
38 | use mro 'c3'; |
663f8198 |
39 | use base ('Diamond_B', 'Diamond_C'); |
663f8198 |
40 | } |
41 | |
42 | # we have to manually initialize |
43 | # Class::C3 since we potentially |
44 | # skip this test if it is not present |
45 | Class::C3::initialize(); |
46 | |
47 | is_deeply( |
77a143ba |
48 | # [ Class::C3::calculateMRO('Diamond_D') ], |
49 | [ Diamond_D->meta->class_precedence_list ], |
663f8198 |
50 | [ qw(Diamond_D Diamond_B Diamond_C Diamond_A) ], |
51 | '... got the right MRO for Diamond_D'); |
52 | |
53 | ok(Diamond_A->meta->has_method('hello'), '... A has a method hello'); |
54 | ok(!Diamond_B->meta->has_method('hello'), '... B does not have a method hello'); |
663f8198 |
55 | |
56 | ok(Diamond_C->meta->has_method('hello'), '... C has a method hello'); |
57 | ok(!Diamond_D->meta->has_method('hello'), '... D does not have a method hello'); |
21af8dc9 |
58 | |
59 | SKIP: { |
60 | skip "C3 does not make aliases on 5.9.5+", 2 if $] > 5.009_004; |
61 | ok(defined &Diamond_B::hello, '... B does have an alias to the method hello'); |
62 | ok(defined &Diamond_D::hello, '... D does have an alias to the method hello'); |
63 | } |