File: 107_C3MethodDispatchOrder_test.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 (43 lines) | stat: -rw-r--r-- 1,123 bytes parent folder | download
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
use strict;
use warnings;

use Test::More;
use File::Spec;
use Class::MOP;

BEGIN {
    eval "use Algorithm::C3";
    plan skip_all => "Algorithm::C3 required for this test" if $@;
    require_ok(File::Spec->catfile('examples', 'C3MethodDispatchOrder.pod'));
}

{
    package Diamond_A;
    use metaclass 'C3MethodDispatchOrder';

    sub hello { 'Diamond_A::hello' }

    package Diamond_B;
    use metaclass 'C3MethodDispatchOrder';
    __PACKAGE__->meta->superclasses('Diamond_A');

    package Diamond_C;
    use metaclass 'C3MethodDispatchOrder';
    __PACKAGE__->meta->superclasses('Diamond_A');

    sub hello { 'Diamond_C::hello' }

    package Diamond_D;
    use metaclass 'C3MethodDispatchOrder';
    __PACKAGE__->meta->superclasses('Diamond_B', 'Diamond_C');
}

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

is(Diamond_D->hello, 'Diamond_C::hello', '... got the right dispatch order');
is(Diamond_D->can('hello')->(), 'Diamond_C::hello', '... can(method) resolved itself as expected');

done_testing;