adding the some preliminary junk
[gitmo/Class-C3-XS.git] / t / 22_uninitialize.t
CommitLineData
8995e827 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 12;
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
17 <A>
18 / \
19<B> <C>
20 \ /
21 <D>
22
23=cut
24
25{
26 package Diamond_A;
27 use Class::C3;
28 sub hello { 'Diamond_A::hello' }
29}
30{
31 package Diamond_B;
32 use base 'Diamond_A';
33 use Class::C3;
34}
35{
36 package Diamond_C;
37 use Class::C3;
38 use base 'Diamond_A';
39 sub goodbye { 'Diamond_C::goodbye' }
40 sub hello { 'Diamond_C::hello' }
41}
42{
43 package Diamond_D;
44 use base ('Diamond_B', 'Diamond_C');
45 use Class::C3;
46
47 our @hello = qw(h e l l o);
48 our $hello = 'hello';
49 our %hello = (h => 1, e => 2, l => "3 & 4", o => 5)
50}
51
52Class::C3::initialize();
53
54is(Diamond_D->hello, 'Diamond_C::hello', '... method resolves with the correct MRO');
55is(Diamond_D->goodbye, 'Diamond_C::goodbye', '... method resolves with the correct MRO');
56
57{
58 no warnings 'redefine';
59 no strict 'refs';
60 *{"Diamond_D::goodbye"} = sub { 'Diamond_D::goodbye' };
61}
62
63is(Diamond_D->goodbye, 'Diamond_D::goodbye', '... method overwritten');
64
65is($Diamond_D::hello, 'hello', '... our SCALAR package vars are here');
66is_deeply(
67 \@Diamond_D::hello,
68 [ qw(h e l l o) ],
69 '... our ARRAY package vars are here');
70is_deeply(
71 \%Diamond_D::hello,
72 { h => 1, e => 2, l => "3 & 4", o => 5 },
73 '... our HASH package vars are here');
74
75Class::C3::uninitialize();
76
77is(Diamond_D->hello, 'Diamond_A::hello', '... method resolves with reinitialized MRO');
78is(Diamond_D->goodbye, 'Diamond_D::goodbye', '... uninitialize does not mess with the manually changed method');
79
80is($Diamond_D::hello, 'hello', '... our SCALAR package vars are still here');
81is_deeply(
82 \@Diamond_D::hello,
83 [ qw(h e l l o) ],
84 '... our ARRAY package vars are still here');
85is_deeply(
86 \%Diamond_D::hello,
87 { h => 1, e => 2, l => "3 & 4", o => 5 },
88 '... our HASH package vars are still here');
89