adding the some preliminary junk
[gitmo/Class-C3-XS.git] / t / 20_reinitialize.t
CommitLineData
8995e827 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 5;
7
8BEGIN {
9 use_ok('Class::C3');
10 # uncomment this line, and re-run the
11 # test to see the normal p5 dispatch order
12 #$Class::C3::TURN_OFF_C3 = 1;
13}
14
15=pod
16
17Start with this:
18
19 <A>
20 / \
21<B> <C>
22 \ /
23 <D>
24
25=cut
26
27{
28 package Diamond_A;
29 use Class::C3;
30 sub hello { 'Diamond_A::hello' }
31}
32{
33 package Diamond_B;
34 use base 'Diamond_A';
35 use Class::C3;
36}
37{
38 package Diamond_C;
39 use Class::C3;
40 use base 'Diamond_A';
41 sub hello { 'Diamond_C::hello' }
42}
43{
44 package Diamond_D;
45 use base ('Diamond_B', 'Diamond_C');
46 use Class::C3;
47}
48
49Class::C3::initialize();
50
51is_deeply(
52 [ Class::C3::calculateMRO('Diamond_D') ],
53 [ qw(Diamond_D Diamond_B Diamond_C Diamond_A) ],
54 '... got the right MRO for Diamond_D');
55
56=pod
57
58Then change it to this:
59
60<E> <A>
61 \ / \
62 <B> <C>
63 \ /
64 <D>
65
66=cut
67
68{
69 package Diamond_E;
70 use Class::C3;
71 sub hello { 'Diamond_E::hello' }
72}
73
74{
75 no strict 'refs';
76 unshift @{"Diamond_B::ISA"} => 'Diamond_E';
77}
78
79is_deeply(
80 [ Class::C3::calculateMRO('Diamond_D') ],
81 [ qw(Diamond_D Diamond_B Diamond_E Diamond_C Diamond_A) ],
82 '... got the new MRO for Diamond_D');
83
84is(Diamond_D->hello, 'Diamond_C::hello', '... method still resolves with old MRO');
85
86Class::C3::reinitialize();
87
88is(Diamond_D->hello, 'Diamond_E::hello', '... method resolves with reinitialized MRO');