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