xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/t/comp/package.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!./perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateprint "1..8\n";
4*0Sstevel@tonic-gate
5*0Sstevel@tonic-gate$blurfl = 123;
6*0Sstevel@tonic-gate$foo = 3;
7*0Sstevel@tonic-gate
8*0Sstevel@tonic-gatepackage xyz;
9*0Sstevel@tonic-gate
10*0Sstevel@tonic-gate$bar = 4;
11*0Sstevel@tonic-gate
12*0Sstevel@tonic-gate{
13*0Sstevel@tonic-gate    package ABC;
14*0Sstevel@tonic-gate    $blurfl = 5;
15*0Sstevel@tonic-gate    $main'a = $'b;
16*0Sstevel@tonic-gate}
17*0Sstevel@tonic-gate
18*0Sstevel@tonic-gate$ABC'dyick = 6;
19*0Sstevel@tonic-gate
20*0Sstevel@tonic-gate$xyz = 2;
21*0Sstevel@tonic-gate
22*0Sstevel@tonic-gate$main = join(':', sort(keys %main::));
23*0Sstevel@tonic-gate$xyz = join(':', sort(keys %xyz::));
24*0Sstevel@tonic-gate$ABC = join(':', sort(keys %ABC::));
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gateif ('a' lt 'A') {
27*0Sstevel@tonic-gate    print $xyz eq 'bar:main:xyz:ABC' ? "ok 1\n" : "not ok 1 '$xyz'\n";
28*0Sstevel@tonic-gate} else {
29*0Sstevel@tonic-gate    print $xyz eq 'ABC:bar:main:xyz' ? "ok 1\n" : "not ok 1 '$xyz'\n";
30*0Sstevel@tonic-gate}
31*0Sstevel@tonic-gateprint $ABC eq 'blurfl:dyick' ? "ok 2\n" : "not ok 2 '$ABC'\n";
32*0Sstevel@tonic-gateprint $main'blurfl == 123 ? "ok 3\n" : "not ok 3\n";
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gatepackage ABC;
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gateprint $blurfl == 5 ? "ok 4\n" : "not ok 4\n";
37*0Sstevel@tonic-gateeval 'print $blurfl == 5 ? "ok 5\n" : "not ok 5\n";';
38*0Sstevel@tonic-gateeval 'package main; print $blurfl == 123 ? "ok 6\n" : "not ok 6\n";';
39*0Sstevel@tonic-gateprint $blurfl == 5 ? "ok 7\n" : "not ok 7\n";
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gatepackage main;
42*0Sstevel@tonic-gate
43*0Sstevel@tonic-gatesub c { caller(0) }
44*0Sstevel@tonic-gate
45*0Sstevel@tonic-gatesub foo {
46*0Sstevel@tonic-gate   my $s = shift;
47*0Sstevel@tonic-gate   if ($s) {
48*0Sstevel@tonic-gate	package PQR;
49*0Sstevel@tonic-gate	main::c();
50*0Sstevel@tonic-gate   }
51*0Sstevel@tonic-gate}
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gateprint((foo(1))[0] eq 'PQR' ? "ok 8\n" : "not ok 8\n");
54