File: 200_Class_C3_compatibility.t

package info (click to toggle)
libclass-mop-perl 1.04-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,244 kB
  • ctags: 1,272
  • sloc: perl: 5,192; ansic: 241; makefile: 2
file content (64 lines) | stat: -rw-r--r-- 1,495 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use strict;
use warnings;

use Test::More;

=pod

This tests that Class::MOP works correctly
with Class::C3 and it's somewhat insane
approach to method resolution.

=cut

use Class::MOP;

{
    package Diamond_A;
    use mro 'c3';
    use metaclass; # everyone will just inherit this now :)

    sub hello { 'Diamond_A::hello' }
}
{
    package Diamond_B;
    use mro 'c3';
    use base 'Diamond_A';
}
{
    package Diamond_C;
    use mro 'c3';
    use base 'Diamond_A';

    sub hello { 'Diamond_C::hello' }
}
{
    package Diamond_D;
    use mro 'c3';
    use base ('Diamond_B', 'Diamond_C');
}

# we have to manually initialize
# Class::C3 since we potentially
# skip this test if it is not present
Class::C3::initialize();

is_deeply(
#    [ Class::C3::calculateMRO('Diamond_D') ],
    [ Diamond_D->meta->class_precedence_list ],
    [ qw(Diamond_D Diamond_B Diamond_C Diamond_A) ],
    '... got the right MRO for Diamond_D');

ok(Diamond_A->meta->has_method('hello'), '... A has a method hello');
ok(!Diamond_B->meta->has_method('hello'), '... B does not have a method hello');

ok(Diamond_C->meta->has_method('hello'), '... C has a method hello');
ok(!Diamond_D->meta->has_method('hello'), '... D does not have a method hello');

SKIP: {
    skip "C3 does not make aliases on 5.9.5+", 2 if $] > 5.009_004;
    ok(defined &Diamond_B::hello, '... B does have an alias to the method hello');
    ok(defined &Diamond_D::hello, '... D does have an alias to the method hello');
}

done_testing;