8 BEGIN { require "./test.pl"; }
12 # Used to segfault (bug #15479)
15 qr/Odd number of elements in hash assignment at - line 1\./,
16 { switches => [ '-w' ] },
17 'delete $::{STDERR} and print a warning',
22 'BEGIN { $::{"X::"} = 2 }',
24 { switches => [ '-w' ] },
25 q(Insert a non-GV in a stash, under warnings 'once'),
28 # Used to segfault, too
30 skip_if_miniperl('requires XS');
32 'sub foo::bar{}; $mro::{get_mro}=*foo::bar; undef %foo::; require mro',
34 { switches => [ '-w' ] },
35 q(Defining an XSUB over an existing sub with no stash under warnings),
40 no warnings 'deprecated';
41 ok( defined %oedipa::maas::, q(stashes happen to be defined if not used) );
42 ok( defined %{"oedipa::maas::"}, q(- work with hard refs too) );
44 ok( defined %tyrone::slothrop::, q(stashes are defined if seen at compile time) );
45 ok( defined %{"tyrone::slothrop::"}, q(- work with hard refs too) );
47 ok( defined %bongo::shaftsbury::, q(stashes are defined if a var is seen at compile time) );
48 ok( defined %{"bongo::shaftsbury::"}, q(- work with hard refs too) );
51 package tyrone::slothrop;
52 $bongo::shaftsbury::scalar = 1;
57 # Unbalanced string table refcount: (1) for "A::" during global destruction.
60 local $ENV{PERL_DESTRUCT_LEVEL} = 2;
62 'package A; sub a { // }; %::=""',
70 ok( eval { no warnings 'deprecated'; defined %achtfaden:: }, 'works in eval{}' );
71 ok( eval q{ no warnings 'deprecated'; defined %schoenmaker:: }, 'works in eval("")' );
73 # now tests with strictures
77 no warnings 'deprecated';
78 ok( defined %pig::, q(referencing a non-existent stash doesn't produce stricture errors) );
79 ok( !exists $pig::{bodine}, q(referencing a non-existent stash element doesn't produce stricture errors) );
83 eval { require B; 1 } or skip "no B", 29;
85 *b = \&B::svref_2object;
86 my $CVf_ANON = B::CVf_ANON();
95 isa_ok( $gv, "B::GV", "deleted stash entry leaves CV with valid GV");
96 is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
97 is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
98 is( eval { $gv->STASH->NAME }, "one", "...but leaves stash intact");
107 isa_ok( $gv, "B::GV", "cleared stash leaves CV with valid GV");
108 is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
109 is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
110 is( eval { $gv->STASH->NAME }, "two", "...but leaves stash intact");
119 isa_ok( $gv, "B::GV", "undefed stash leaves CV with valid GV");
120 is( b($sub)->CvFLAGS & $CVf_ANON, $CVf_ANON, "...and CVf_ANON set");
121 is( eval { $gv->NAME }, "__ANON__", "...and an __ANON__ name");
122 is( eval { $gv->STASH->NAME }, "__ANON__", "...and an __ANON__ stash");
130 my $gv = B::svref_2object($sub)->GV;
131 ok($gv->isa(q/B::GV/), "cleared stash leaves anon CV with valid GV");
133 my $st = eval { $gv->STASH->NAME };
134 is($st, q/four/, "...but leaves the stash intact");
142 $gv = B::svref_2object($sub)->GV;
143 ok($gv->isa(q/B::GV/), "undefed stash leaves anon CV with valid GV");
145 $st = eval { $gv->STASH->NAME };
146 { local $TODO = 'STASHES not anonymized';
147 is($st, q/__ANON__/, "...and an __ANON__ stash");
154 my $stash_glob = delete $::{"six::"};
155 # Now free the GV while the stash still exists (though detached)
156 delete $$stash_glob{"six"};
157 $gv = B::svref_2object($sub)->GV;
158 ok($gv->isa(q/B::GV/),
159 'anonymised CV whose stash is detached still has a GV');
160 is $gv->STASH->NAME, '__ANON__',
161 'CV anonymised when its stash is detached becomes __ANON__::__ANON__';
163 # CvSTASH should be null on a named sub if the stash has been deleted
170 my $cv = B::svref_2object($rfoo);
171 # (is there a better way of testing for NULL ?)
172 my $stash = $cv->STASH;
173 like($stash, qr/B::SPECIAL/, "NULL CvSTASH on named sub");
176 # on glob reassignment, orphaned CV should have anon CvGV
187 my $cv = B::svref_2object($r);
189 ok($gv->isa(q/B::GV/), "orphaned CV has valid GV");
190 is($gv->NAME, '__ANON__', "orphaned CV has anon GV");
193 # deleting __ANON__ glob shouldn't break things
199 my $named = eval q[\&named];
201 delete $FOO3::{named}; # make named anonymous
203 delete $FOO3::{__ANON__}; # whoops!
205 $cv = B::svref_2object($named);
207 ok($gv->isa(q/B::GV/), "ex-named CV has valid GV");
208 is($gv->NAME, '__ANON__', "ex-named CV has anon GV");
210 $cv = B::svref_2object($anon);
212 ok($gv->isa(q/B::GV/), "anon CV has valid GV");
213 is($gv->NAME, '__ANON__', "anon CV has anon GV");
226 my $br = B::svref_2object($r);
227 is ($br->STASH->NAME, 'bloop',
228 'stub records the package it was compiled in');
229 # Arguably this shouldn't quite be here, but it's easy to add it
230 # here, and tricky to figure out a different good place for it.
231 like ($br->FILE, qr/stash/i,
232 'stub records the file it was compiled in');
234 # We need to take this reference "late", after the subroutine is
236 $br = B::svref_2object(eval 'sub whack {}; \&whack');
239 is ($br->STASH->NAME, 'main',
240 'definition overrides the package it was compiled in');
241 like ($br->FILE, qr/eval/,
242 'definition overrides the file it was compiled in');
248 'sub foo { 1 }; use overload q/""/ => \&foo;' .
249 'delete $main::{foo}; bless []',
252 "no segfault with overload/deleted stash entry [#58530]",
255 # make sure having a sub called __ANON__ doesn't confuse perl.
259 sub __ANON__ { $c = (caller(0))[3]; }
261 is ($c, 'main::__ANON__', '__ANON__ sub called ok');
265 # Stashes that are effectively renamed
274 # effectively rename a stash
275 *slin:: = *rile::; *rile:: = *zor::;
277 ::is *$globref, "*rile::tat",
278 'globs stringify the same way when stashes are moved';
279 ::is ref $obj, "rile",
280 'ref() returns the same thing when an object’s stash is moved';
281 ::like "$obj", qr "^rile=ARRAY\(0x[\da-f]+\)\z",
282 'objects stringify the same way when their stashes are moved';
284 local $::TODO = $Config{useithreads} ? "fails under threads" : undef;
285 ::is eval '__PACKAGE__', 'rile',
286 '__PACKAGE__ returns the same when the current stash is moved';
289 # Now detach it completely from the symtab, making it effect-
291 my $life_raft = \%slin::;
294 ::is *$globref, "*rile::tat",
295 'globs stringify the same way when stashes are detached';
296 ::is ref $obj, "rile",
297 'ref() returns the same thing when an object’s stash is detached';
298 ::like "$obj", qr "^rile=ARRAY\(0x[\da-f]+\)\z",
299 'objects stringify the same way when their stashes are detached';
301 local $::TODO = $Config{useithreads} ? "fails under threads" : undef;
302 ::is eval '__PACKAGE__', 'rile',
303 '__PACKAGE__ returns the same when the current stash is detached';
307 # Setting the name during undef %stash:: should have no effect.
309 my $glob = \*Phoo::glob;
310 sub o::DESTROY { eval '++$Phoo::bar' }
312 ${"Phoo::thing1"} = bless [], "o";
314 is "$$glob", "*__ANON__::glob",
315 "setting stash name during undef has no effect";
318 # [perl #88134] incorrect package structure
323 ok eval { Bear::::baz() },
324 'packages ending with :: are self-consistent';
327 # [perl #88138] ' not equivalent to :: before a null
329 is ${"a::\0b"}, "c", "' is equivalent to :: before a null";
331 # [perl #101486] Clobbering the current package
334 BEGIN { *Do:: = *Re:: }
337 ', 'no crashing or errors when clobbering the current package';