File: 22_uninitialize.t

package info (click to toggle)
libclass-c3-perl 0.35-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 260 kB
  • sloc: perl: 476; makefile: 8
file content (80 lines) | stat: -rw-r--r-- 1,898 bytes parent folder | download | duplicates (3)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use strict;
use warnings;

use Test::More tests => 11;

=pod

   <A>
  /   \
<B>   <C>
  \   /
   <D>

=cut

{
    package Diamond_A;
    use Class::C3;
    sub hello { 'Diamond_A::hello' }
}
{
    package Diamond_B;
    BEGIN { our @ISA = ('Diamond_A'); }
    use Class::C3;
}
{
    package Diamond_C;
    use Class::C3;
    BEGIN { our @ISA = ('Diamond_A'); }
    sub goodbye { 'Diamond_C::goodbye' }
    sub hello   { 'Diamond_C::hello'   }
}
{
    package Diamond_D;
    BEGIN { our @ISA = ('Diamond_B', 'Diamond_C'); }
    use Class::C3;

    our @hello = qw(h e l l o);
    our $hello = 'hello';
    our %hello = (h => 1, e => 2, l => "3 & 4", o => 5)
}

Class::C3::initialize();

is(Diamond_D->hello, 'Diamond_C::hello', '... method resolves with the correct MRO');
is(Diamond_D->goodbye, 'Diamond_C::goodbye', '... method resolves with the correct MRO');

{
    no warnings 'redefine';
    no strict 'refs';
    *{"Diamond_D::goodbye"} = sub { 'Diamond_D::goodbye' };
}

is(Diamond_D->goodbye, 'Diamond_D::goodbye', '... method overwritten');

is($Diamond_D::hello, 'hello', '... our SCALAR package vars are here');
is_deeply(
    \@Diamond_D::hello,
    [ qw(h e l l o) ],
    '... our ARRAY package vars are here');
is_deeply(
    \%Diamond_D::hello,
    { h => 1, e => 2, l => "3 & 4", o => 5 },
    '... our HASH package vars are here');

Class::C3::uninitialize();

is(Diamond_D->hello, 'Diamond_A::hello', '... method resolves with reinitialized MRO');
is(Diamond_D->goodbye, 'Diamond_D::goodbye', '... uninitialize does not mess with the manually changed method');

is($Diamond_D::hello, 'hello', '... our SCALAR package vars are still here');
is_deeply(
    \@Diamond_D::hello,
    [ qw(h e l l o) ],
    '... our ARRAY package vars are still here');
is_deeply(
    \%Diamond_D::hello,
    { h => 1, e => 2, l => "3 & 4", o => 5 },
    '... our HASH package vars are still here');