26 *{'Old::'} = *{'New::'};
30 ok (Old->isa (New::), 'Old inherits from New');
31 ok (New->isa (Old::), 'New inherits from Old');
33 isa_ok (bless ({}, Old::), New::, 'Old object');
34 isa_ok (bless ({}, New::), Old::, 'New object');
37 # Test that replacing a package by assigning to an existing glob
38 # invalidates the isa caches
41 name => 'assigning a glob to a glob',
42 code => '$life_raft = $::{"Left::"}; *Left:: = $::{"Right::"}',
45 name => 'assigning a string to a glob',
46 code => '$life_raft = $::{"Left::"}; *Left:: = "Right::"',
49 name => 'assigning a stashref to a glob',
50 code => '$life_raft = \%Left::; *Left:: = \%Right::',
55 @Subclass::ISA = "Left";
56 @Left::ISA = "TopLeft";
58 sub TopLeft::speak { "Woof!" }
59 sub TopRight::speak { "Bow-wow!" }
61 my $thing = bless [], "Subclass";
63 # mro_package_moved needs to know to skip non-globs
64 $Right::{"gleck::"} = 3;
66 @Right::ISA = 'TopRight';
70 print $thing->speak, "\n";
73 print $thing->speak, "\n";
74 ~ =~ s\__code__\$$_{code}\r,
75 "Bow-wow!\nBow-wow!\n",
77 "replacing packages by $$_{name} updates isa caches";
80 # Similar test, but with nested packages
82 # TopLeft (Woof) TopRight (Bow-wow)
84 # Left::Side <- Right::Side
88 # This test assigns Right:: to Left::, indirectly making Left::Side an
89 # alias to Right::Side (following the arrow in the diagram).
92 name => 'assigning a glob to a glob',
93 code => '$life_raft = $::{"Left::"}; *Left:: = $::{"Right::"}',
96 name => 'assigning a string to a glob',
97 code => '$life_raft = $::{"Left::"}; *Left:: = "Right::"',
100 name => 'assigning a stashref to a glob',
101 code => '$life_raft = \%Left::; *Left:: = \%Right::',
106 @Subclass::ISA = "Left::Side";
107 @Left::Side::ISA = "TopLeft";
109 sub TopLeft::speak { "Woof!" }
110 sub TopRight::speak { "Bow-wow!" }
112 my $thing = bless [], "Subclass";
114 @Right::Side::ISA = 'TopRight';
118 print $thing->speak, "\n";
121 print $thing->speak, "\n";
122 ~ =~ s\__code__\$$_{code}\r,
123 "Bow-wow!\nBow-wow!\n",
125 "replacing nested packages by $$_{name} updates isa caches";
128 # Another nested package test, in which the isa cache needs to be reset on
129 # the subclass of a package that does not exist.
131 # Parenthesized packages do not exist.
133 # outer::inner ( clone::inner )
139 # This test assigns outer:: to clone::, making clone::inner an alias to
142 # Then we also run the test again, but without outer::inner
145 name => 'assigning a glob to a glob',
146 code => '*clone:: = *outer::',
149 name => 'assigning a string to a glob',
150 code => '*clone:: = "outer::"',
153 name => 'assigning a stashref to a glob',
154 code => '*clone:: = \%outer::',
159 @left::ISA = 'outer::inner';
160 @right::ISA = 'clone::inner';
161 {package outer::inner}
165 print "ok 1", "\n" if left->isa("clone::inner");
166 print "ok 2", "\n" if right->isa("outer::inner");
167 ~ =~ s\__code__\$$_{code}\r,
170 "replacing nonexistent nested packages by $$_{name} updates isa caches";
172 # Same test but with the subpackage autovivified after the assignment
175 @left::ISA = 'outer::inner';
176 @right::ISA = 'clone::inner';
180 eval q{package outer::inner};
182 print "ok 1", "\n" if left->isa("clone::inner");
183 print "ok 2", "\n" if right->isa("outer::inner");
184 ~ =~ s\__code__\$$_{code}\r,
187 "Giving nonexistent packages multiple effective names by $$_{name}";
190 no warnings; # temporary; there seems to be a scoping bug, as this does not
191 # work when placed in the blocks below
193 # Test that deleting stash elements containing
194 # subpackages also invalidates the isa cache.
195 # Maybe this does not belong in package_aliases.t, but it is closely
196 # related to the tests immediately preceding.
198 @Pet::ISA = ("Cur", "Hound");
199 @Cur::ISA = "Hylactete";
201 sub Hylactete::speak { "Arff!" }
202 sub Hound::speak { "Woof!" }
204 my $pet = bless [], "Pet";
206 my $life_raft = delete $::{'Cur::'};
208 is $pet->speak, 'Woof!',
209 'deleting a stash from its parent stash invalidates the isa caches';
212 is $pet->speak, 'Woof!',
213 'the deleted stash is gone completely when freed';
215 # Same thing, but with nested packages
217 @Pett::ISA = ("Curr::Curr::Curr", "Hownd");
218 @Curr::Curr::Curr::ISA = "Latrator";
220 sub Latrator::speak { "Arff!" }
221 sub Hownd::speak { "Woof!" }
223 my $pet = bless [], "Pett";
225 my $life_raft = delete $::{'Curr::'};
227 is $pet->speak, 'Woof!',
228 'deleting a stash from its parent stash resets caches of substashes';
231 is $pet->speak, 'Woof!',
232 'the deleted substash is gone completely when freed';
239 @Tike::ISA = "Barker";
241 sub Barker::speak { print "Woof!\n" }
242 sub Latrator::speak { print "Bow-wow!\n" }
244 my $pet = bless [], "Pet";
248 sub Dog::speak { print "Hello.\n" } # strange dog!
249 @Dog::ISA = 'Latrator';
250 *Tike:: = delete $::{'Dog::'};
256 "Assigning a nameless package over one w/subclasses updates isa caches";
258 # mro_package_moved needs to make a distinction between replaced and
259 # assigned stashes when keeping track of what it has seen so far.
263 sub bar::blonk::blonk::phoo { "bbb" }
264 sub veclum::phoo { "lasrevinu" }
265 @feedlebomp::ISA = qw 'phoo::blonk::blonk veclum';
266 *phoo::baz:: = *bar::blonk::; # now bar::blonk:: is on both sides
267 *phoo:: = *bar::; # here bar::blonk:: is both deleted and added
268 *bar:: = *boo::; # now it is only known as phoo::blonk::
270 # At this point, before the bug was fixed, %phoo::blonk::blonk:: ended
271 # up with no effective name, allowing it to be deleted without updating
272 # its subclasses’ caches.
276 $accum .= 'feedlebomp'->phoo; # bbb
277 delete ${"phoo::blonk::"}{"blonk::"};
278 $accum .= 'feedlebomp'->phoo; # bbb (Oops!)
279 @feedlebomp::ISA = @feedlebomp::ISA;
280 $accum .= 'feedlebomp'->phoo; # lasrevinu
282 is $accum, 'bbblasrevinulasrevinu',
283 'nested classes deleted & added simultaneously';
287 # mro_package_moved needs to check for self-referential packages.
288 # This broke Text::Template [perl #78362].
291 *Acme::META::Acme:: = \*Acme::; # indirect self-reference
292 pass("mro_package_moved and self-referential packages");
294 # Deleting a glob whose name does not indicate its location in the symbol
295 # table but which nonetheless *is* in the symbol table.
299 @one::more::ISA = "four";
300 sub four::womp { "aoeaa" }
303 @Childclass::ISA = 'two::more';
304 my $accum = 'Childclass'->womp . '-';
305 my $life_raft = delete ${"two::"}{"more::"};
306 $accum .= eval { 'Childclass'->womp } // '<undef>';
307 is $accum, 'aoeaa-<undef>',
308 'Deleting globs whose loc in the symtab differs from gv_fullname'
311 # Pathological test for undeffing a stash that has an alias.
313 @Subclass::ISA = 'Ghelp';
315 sub Frelp::womp { "clumpren" }
318 @Neen::ISA = "Frelp";
320 is eval { 'Subclass'->womp }, 'clumpren',
321 'Changes to @ISA after undef via original name';
325 @Ghelp::ISA = "Frelp";
327 is eval { 'Subclass'->womp }, 'clumpren',
328 'Changes to @ISA after undef via alias';
331 # Packages whose containing stashes have aliases must lose all names cor-
332 # responding to that container when detached.
334 {package smare::baz} # autovivify
335 *phring:: = *smare::; # smare::baz now also named phring::baz
336 *bonk:: = delete $smare::{"baz::"};
337 # In 5.13.7, it has now lost its smare::baz name (reverting to phring::baz
338 # as the effective name), and gained bonk as an alias.
339 # In 5.13.8, both smare::baz *and* phring::baz names are deleted.
343 *{"phring::baz::frump"} = sub { "hello" };
344 sub frumper::frump { "good bye" };
346 @brumkin::ISA = qw "bonk frumper"; # now wrongly inherits from phring::baz
348 is frump brumkin, "good bye",
349 'detached stashes lose all names corresponding to the containing stash';