This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix for bug: [perl #32562] __PACKAGE__ symbol has wrong value
[perl5.git] / t / comp / package.t
CommitLineData
a687059c
LW
1#!./perl
2
9508c957 3print "1..14\n";
a687059c
LW
4
5$blurfl = 123;
6$foo = 3;
7
c09412fc 8package xyz;
a687059c 9
e27ad1f2
AV
10sub new {bless [];}
11
a687059c
LW
12$bar = 4;
13
14{
15 package ABC;
16 $blurfl = 5;
17 $main'a = $'b;
18}
19
20$ABC'dyick = 6;
21
22$xyz = 2;
23
a0d0e21e 24$main = join(':', sort(keys %main::));
c09412fc 25$xyz = join(':', sort(keys %xyz::));
a0d0e21e 26$ABC = join(':', sort(keys %ABC::));
a687059c 27
9d116dd7 28if ('a' lt 'A') {
e27ad1f2 29 print $xyz eq 'bar:main:new:xyz:ABC' ? "ok 1\n" : "not ok 1 '$xyz'\n";
9d116dd7 30} else {
e27ad1f2 31 print $xyz eq 'ABC:bar:main:new:xyz' ? "ok 1\n" : "not ok 1 '$xyz'\n";
9d116dd7 32}
463ee0b2 33print $ABC eq 'blurfl:dyick' ? "ok 2\n" : "not ok 2 '$ABC'\n";
a687059c 34print $main'blurfl == 123 ? "ok 3\n" : "not ok 3\n";
463ee0b2 35
a687059c 36package ABC;
463ee0b2 37
a687059c
LW
38print $blurfl == 5 ? "ok 4\n" : "not ok 4\n";
39eval 'print $blurfl == 5 ? "ok 5\n" : "not ok 5\n";';
40eval 'package main; print $blurfl == 123 ? "ok 6\n" : "not ok 6\n";';
41print $blurfl == 5 ? "ok 7\n" : "not ok 7\n";
7ad382f4
GS
42
43package main;
44
45sub c { caller(0) }
46
47sub foo {
48 my $s = shift;
49 if ($s) {
50 package PQR;
51 main::c();
52 }
53}
54
55print((foo(1))[0] eq 'PQR' ? "ok 8\n" : "not ok 8\n");
e27ad1f2
AV
56
57my $Q = xyz->new();
58undef %xyz::;
59eval { $a = *xyz::new{PACKAGE}; };
60print $a eq "__ANON__" ? "ok 9\n" : "not ok 9\n";
61
62eval { $Q->param; };
63print $@ =~ /^Can't use anonymous symbol table for method lookup/ ?
64 "ok 10\n" : "not ok 10\n";
65
66print "$Q" =~ /^__ANON__=/ ? "ok 11\n" : "not ok 11\n";
67
68print ref $Q eq "__ANON__" ? "ok 12\n" : "not ok 12\n";
69
9508c957 70package bug32562;
e27ad1f2 71
9508c957
RGS
72print __PACKAGE__ eq 'bug32562' ? "ok 13\n" : "not ok 13\n";
73print eval '__PACKAGE__' eq 'bug32562' ? "ok 14\n" : "not ok 14\n";