xref: /openbsd-src/gnu/usr.bin/perl/t/comp/package.t (revision e068048151d29f2562a32185e21a8ba885482260)
1#!./perl
2
3BEGIN {
4    @INC = qw(. ../lib);
5    chdir 't' if -d 't';
6}
7
8print "1..14\n";
9
10$blurfl = 123;
11$foo = 3;
12
13package xyz;
14
15sub new {bless [];}
16
17$bar = 4;
18
19{
20    package ABC;
21    no warnings qw(syntax deprecated);
22    $blurfl = 5;
23    $main'a = $'b;
24}
25{
26    no warnings qw(syntax deprecated);
27    $ABC'dyick = 6;
28}
29
30$xyz = 2;
31
32$main = join(':', sort(keys %main::));
33$xyz = join(':', sort(keys %xyz::));
34$ABC = join(':', sort(keys %ABC::));
35
36if ('a' lt 'A') {
37    print $xyz eq 'bar:main:new:xyz:ABC' ? "ok 1\n" : "not ok 1 '$xyz'\n";
38} else {
39    print $xyz eq 'ABC:BEGIN:bar:main:new:xyz' ? "ok 1\n" : "not ok 1 '$xyz'\n";
40}
41print $ABC eq 'BEGIN:blurfl:dyick' ? "ok 2\n" : "not ok 2 '$ABC'\n";
42{
43    no warnings qw(syntax deprecated);
44    print $main'blurfl == 123 ? "ok 3\n" : "not ok 3\n";
45}
46
47package ABC;
48
49print $blurfl == 5 ? "ok 4\n" : "not ok 4\n";
50eval 'print $blurfl == 5 ? "ok 5\n" : "not ok 5\n";';
51eval 'package main; print $blurfl == 123 ? "ok 6\n" : "not ok 6\n";';
52print $blurfl == 5 ? "ok 7\n" : "not ok 7\n";
53
54package main;
55
56sub c { caller(0) }
57
58sub foo {
59   my $s = shift;
60   if ($s) {
61	package PQR;
62	main::c();
63   }
64}
65
66print((foo(1))[0] eq 'PQR' ? "ok 8\n" : "not ok 8\n");
67
68my $Q = xyz->new();
69undef %xyz::;
70eval { $a = *xyz::new{PACKAGE}; };
71print $a eq "__ANON__" ? "ok 9\n" : "not ok 9 # '$a'\n";
72
73eval { $Q->param; };
74print $@ =~ /^Can't use anonymous symbol table for method lookup/ ?
75  "ok 10\n" : "not ok 10 # '$@'\n";
76
77print "$Q" =~ /^__ANON__=/ ? "ok 11\n" : "not ok 11 # '$Q'\n";
78
79print ref $Q eq "__ANON__" ? "ok 12\n" : "not ok 12 # '$Q'\n";
80
81package bug32562;
82
83print       __PACKAGE__  eq 'bug32562' ? "ok 13\n" : "not ok 13\n";
84print eval '__PACKAGE__' eq 'bug32562' ? "ok 14\n" : "not ok 14\n";
85
86