We only need local $? if we inline calls to DEMOLISH
[gitmo/Moose.git] / t / cmop / Class_C3_compatibility.t
1 use strict;
2 use warnings;
3
4 use Test::More;
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
14 use Class::MOP;
15
16 {
17     package Diamond_A;
18     use mro 'c3';
19     use metaclass; # everyone will just inherit this now :)
20
21     sub hello { 'Diamond_A::hello' }
22 }
23 {
24     package Diamond_B;
25     use mro 'c3';
26     use base 'Diamond_A';
27 }
28 {
29     package Diamond_C;
30     use mro 'c3';
31     use base 'Diamond_A';
32
33     sub hello { 'Diamond_C::hello' }
34 }
35 {
36     package Diamond_D;
37     use mro 'c3';
38     use base ('Diamond_B', 'Diamond_C');
39 }
40
41 # we have to manually initialize
42 # Class::C3 since we potentially
43 # skip this test if it is not present
44 Class::C3::initialize();
45
46 is_deeply(
47 #    [ Class::C3::calculateMRO('Diamond_D') ],
48     [ Diamond_D->meta->class_precedence_list ],
49     [ qw(Diamond_D Diamond_B Diamond_C Diamond_A) ],
50     '... got the right MRO for Diamond_D');
51
52 ok(Diamond_A->meta->has_method('hello'), '... A has a method hello');
53 ok(!Diamond_B->meta->has_method('hello'), '... B does not have a method hello');
54
55 ok(Diamond_C->meta->has_method('hello'), '... C has a method hello');
56 ok(!Diamond_D->meta->has_method('hello'), '... D does not have a method hello');
57
58 SKIP: {
59     skip "C3 does not make aliases on 5.9.5+", 2 if $] > 5.009_004;
60     ok(defined &Diamond_B::hello, '... B does have an alias to the method hello');
61     ok(defined &Diamond_D::hello, '... D does have an alias to the method hello');
62 }
63
64 done_testing;