xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/t/op/ref.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!./perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateBEGIN {
4*0Sstevel@tonic-gate    chdir 't' if -d 't';
5*0Sstevel@tonic-gate    @INC = qw(. ../lib);
6*0Sstevel@tonic-gate}
7*0Sstevel@tonic-gate
8*0Sstevel@tonic-gateprint "1..69\n";
9*0Sstevel@tonic-gate
10*0Sstevel@tonic-gaterequire 'test.pl';
11*0Sstevel@tonic-gate
12*0Sstevel@tonic-gate# Test glob operations.
13*0Sstevel@tonic-gate
14*0Sstevel@tonic-gate$bar = "ok 1\n";
15*0Sstevel@tonic-gate$foo = "ok 2\n";
16*0Sstevel@tonic-gate{
17*0Sstevel@tonic-gate    local(*foo) = *bar;
18*0Sstevel@tonic-gate    print $foo;
19*0Sstevel@tonic-gate}
20*0Sstevel@tonic-gateprint $foo;
21*0Sstevel@tonic-gate
22*0Sstevel@tonic-gate$baz = "ok 3\n";
23*0Sstevel@tonic-gate$foo = "ok 4\n";
24*0Sstevel@tonic-gate{
25*0Sstevel@tonic-gate    local(*foo) = 'baz';
26*0Sstevel@tonic-gate    print $foo;
27*0Sstevel@tonic-gate}
28*0Sstevel@tonic-gateprint $foo;
29*0Sstevel@tonic-gate
30*0Sstevel@tonic-gate$foo = "ok 6\n";
31*0Sstevel@tonic-gate{
32*0Sstevel@tonic-gate    local(*foo);
33*0Sstevel@tonic-gate    print $foo;
34*0Sstevel@tonic-gate    $foo = "ok 5\n";
35*0Sstevel@tonic-gate    print $foo;
36*0Sstevel@tonic-gate}
37*0Sstevel@tonic-gateprint $foo;
38*0Sstevel@tonic-gate
39*0Sstevel@tonic-gate# Test fake references.
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gate$baz = "ok 7\n";
42*0Sstevel@tonic-gate$bar = 'baz';
43*0Sstevel@tonic-gate$foo = 'bar';
44*0Sstevel@tonic-gateprint $$$foo;
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate# Test real references.
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gate$FOO = \$BAR;
49*0Sstevel@tonic-gate$BAR = \$BAZ;
50*0Sstevel@tonic-gate$BAZ = "ok 8\n";
51*0Sstevel@tonic-gateprint $$$FOO;
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gate# Test references to real arrays.
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gate@ary = (9,10,11,12);
56*0Sstevel@tonic-gate$ref[0] = \@a;
57*0Sstevel@tonic-gate$ref[1] = \@b;
58*0Sstevel@tonic-gate$ref[2] = \@c;
59*0Sstevel@tonic-gate$ref[3] = \@d;
60*0Sstevel@tonic-gatefor $i (3,1,2,0) {
61*0Sstevel@tonic-gate    push(@{$ref[$i]}, "ok $ary[$i]\n");
62*0Sstevel@tonic-gate}
63*0Sstevel@tonic-gateprint @a;
64*0Sstevel@tonic-gateprint ${$ref[1]}[0];
65*0Sstevel@tonic-gateprint @{$ref[2]}[0];
66*0Sstevel@tonic-gateprint @{'d'};
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gate# Test references to references.
69*0Sstevel@tonic-gate
70*0Sstevel@tonic-gate$refref = \\$x;
71*0Sstevel@tonic-gate$x = "ok 13\n";
72*0Sstevel@tonic-gateprint $$$refref;
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gate# Test nested anonymous lists.
75*0Sstevel@tonic-gate
76*0Sstevel@tonic-gate$ref = [[],2,[3,4,5,]];
77*0Sstevel@tonic-gateprint scalar @$ref == 3 ? "ok 14\n" : "not ok 14\n";
78*0Sstevel@tonic-gateprint $$ref[1] == 2 ? "ok 15\n" : "not ok 15\n";
79*0Sstevel@tonic-gateprint ${$$ref[2]}[2] == 5 ? "ok 16\n" : "not ok 16\n";
80*0Sstevel@tonic-gateprint scalar @{$$ref[0]} == 0 ? "ok 17\n" : "not ok 17\n";
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gateprint $ref->[1] == 2 ? "ok 18\n" : "not ok 18\n";
83*0Sstevel@tonic-gateprint $ref->[2]->[0] == 3 ? "ok 19\n" : "not ok 19\n";
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate# Test references to hashes of references.
86*0Sstevel@tonic-gate
87*0Sstevel@tonic-gate$refref = \%whatever;
88*0Sstevel@tonic-gate$refref->{"key"} = $ref;
89*0Sstevel@tonic-gateprint $refref->{"key"}->[2]->[0] == 3 ? "ok 20\n" : "not ok 20\n";
90*0Sstevel@tonic-gate
91*0Sstevel@tonic-gate# Test to see if anonymous subarrays spring into existence.
92*0Sstevel@tonic-gate
93*0Sstevel@tonic-gate$spring[5]->[0] = 123;
94*0Sstevel@tonic-gate$spring[5]->[1] = 456;
95*0Sstevel@tonic-gatepush(@{$spring[5]}, 789);
96*0Sstevel@tonic-gateprint join(':',@{$spring[5]}) eq "123:456:789" ? "ok 21\n" : "not ok 21\n";
97*0Sstevel@tonic-gate
98*0Sstevel@tonic-gate# Test to see if anonymous subhashes spring into existence.
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gate@{$spring2{"foo"}} = (1,2,3);
101*0Sstevel@tonic-gate$spring2{"foo"}->[3] = 4;
102*0Sstevel@tonic-gateprint join(':',@{$spring2{"foo"}}) eq "1:2:3:4" ? "ok 22\n" : "not ok 22\n";
103*0Sstevel@tonic-gate
104*0Sstevel@tonic-gate# Test references to subroutines.
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gatesub mysub { print "ok 23\n" }
107*0Sstevel@tonic-gate$subref = \&mysub;
108*0Sstevel@tonic-gate&$subref;
109*0Sstevel@tonic-gate
110*0Sstevel@tonic-gate$subrefref = \\&mysub2;
111*0Sstevel@tonic-gate$$subrefref->("ok 24\n");
112*0Sstevel@tonic-gatesub mysub2 { print shift }
113*0Sstevel@tonic-gate
114*0Sstevel@tonic-gate# Test the ref operator.
115*0Sstevel@tonic-gate
116*0Sstevel@tonic-gateprint ref $subref	eq CODE  ? "ok 25\n" : "not ok 25\n";
117*0Sstevel@tonic-gateprint ref $ref		eq ARRAY ? "ok 26\n" : "not ok 26\n";
118*0Sstevel@tonic-gateprint ref $refref	eq HASH  ? "ok 27\n" : "not ok 27\n";
119*0Sstevel@tonic-gate
120*0Sstevel@tonic-gate# Test anonymous hash syntax.
121*0Sstevel@tonic-gate
122*0Sstevel@tonic-gate$anonhash = {};
123*0Sstevel@tonic-gateprint ref $anonhash	eq HASH  ? "ok 28\n" : "not ok 28\n";
124*0Sstevel@tonic-gate$anonhash2 = {FOO => BAR, ABC => XYZ,};
125*0Sstevel@tonic-gateprint join('', sort values %$anonhash2) eq BARXYZ ? "ok 29\n" : "not ok 29\n";
126*0Sstevel@tonic-gate
127*0Sstevel@tonic-gate# Test bless operator.
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gatepackage MYHASH;
130*0Sstevel@tonic-gate
131*0Sstevel@tonic-gate$object = bless $main'anonhash2;
132*0Sstevel@tonic-gateprint ref $object	eq MYHASH  ? "ok 30\n" : "not ok 30\n";
133*0Sstevel@tonic-gateprint $object->{ABC}	eq XYZ     ? "ok 31\n" : "not ok 31\n";
134*0Sstevel@tonic-gate
135*0Sstevel@tonic-gate$object2 = bless {};
136*0Sstevel@tonic-gateprint ref $object2	eq MYHASH  ? "ok 32\n" : "not ok 32\n";
137*0Sstevel@tonic-gate
138*0Sstevel@tonic-gate# Test ordinary call on object method.
139*0Sstevel@tonic-gate
140*0Sstevel@tonic-gate&mymethod($object,33);
141*0Sstevel@tonic-gate
142*0Sstevel@tonic-gatesub mymethod {
143*0Sstevel@tonic-gate    local($THIS, @ARGS) = @_;
144*0Sstevel@tonic-gate    die 'Got a "' . ref($THIS). '" instead of a MYHASH'
145*0Sstevel@tonic-gate	unless ref $THIS eq MYHASH;
146*0Sstevel@tonic-gate    print $THIS->{FOO} eq BAR  ? "ok $ARGS[0]\n" : "not ok $ARGS[0]\n";
147*0Sstevel@tonic-gate}
148*0Sstevel@tonic-gate
149*0Sstevel@tonic-gate# Test automatic destructor call.
150*0Sstevel@tonic-gate
151*0Sstevel@tonic-gate$string = "not ok 34\n";
152*0Sstevel@tonic-gate$object = "foo";
153*0Sstevel@tonic-gate$string = "ok 34\n";
154*0Sstevel@tonic-gate$main'anonhash2 = "foo";
155*0Sstevel@tonic-gate$string = "";
156*0Sstevel@tonic-gate
157*0Sstevel@tonic-gateDESTROY {
158*0Sstevel@tonic-gate    return unless $string;
159*0Sstevel@tonic-gate    print $string;
160*0Sstevel@tonic-gate
161*0Sstevel@tonic-gate    # Test that the object has not already been "cursed".
162*0Sstevel@tonic-gate    print ref shift ne HASH ? "ok 35\n" : "not ok 35\n";
163*0Sstevel@tonic-gate}
164*0Sstevel@tonic-gate
165*0Sstevel@tonic-gate# Now test inheritance of methods.
166*0Sstevel@tonic-gate
167*0Sstevel@tonic-gatepackage OBJ;
168*0Sstevel@tonic-gate
169*0Sstevel@tonic-gate@ISA = (BASEOBJ);
170*0Sstevel@tonic-gate
171*0Sstevel@tonic-gate$main'object = bless {FOO => foo, BAR => bar};
172*0Sstevel@tonic-gate
173*0Sstevel@tonic-gatepackage main;
174*0Sstevel@tonic-gate
175*0Sstevel@tonic-gate# Test arrow-style method invocation.
176*0Sstevel@tonic-gate
177*0Sstevel@tonic-gateprint $object->doit("BAR") eq bar ? "ok 36\n" : "not ok 36\n";
178*0Sstevel@tonic-gate
179*0Sstevel@tonic-gate# Test indirect-object-style method invocation.
180*0Sstevel@tonic-gate
181*0Sstevel@tonic-gate$foo = doit $object "FOO";
182*0Sstevel@tonic-gateprint $foo eq foo ? "ok 37\n" : "not ok 37\n";
183*0Sstevel@tonic-gate
184*0Sstevel@tonic-gatesub BASEOBJ'doit {
185*0Sstevel@tonic-gate    local $ref = shift;
186*0Sstevel@tonic-gate    die "Not an OBJ" unless ref $ref eq OBJ;
187*0Sstevel@tonic-gate    $ref->{shift()};
188*0Sstevel@tonic-gate}
189*0Sstevel@tonic-gate
190*0Sstevel@tonic-gatepackage UNIVERSAL;
191*0Sstevel@tonic-gate@ISA = 'LASTCHANCE';
192*0Sstevel@tonic-gate
193*0Sstevel@tonic-gatepackage LASTCHANCE;
194*0Sstevel@tonic-gatesub foo { print $_[1] }
195*0Sstevel@tonic-gate
196*0Sstevel@tonic-gatepackage WHATEVER;
197*0Sstevel@tonic-gatefoo WHATEVER "ok 38\n";
198*0Sstevel@tonic-gate
199*0Sstevel@tonic-gate#
200*0Sstevel@tonic-gate# test the \(@foo) construct
201*0Sstevel@tonic-gate#
202*0Sstevel@tonic-gatepackage main;
203*0Sstevel@tonic-gate@foo = \(1..3);
204*0Sstevel@tonic-gate@bar = \(@foo);
205*0Sstevel@tonic-gate@baz = \(1,@foo,@bar);
206*0Sstevel@tonic-gateprint @bar == 3 ? "ok 39\n" : "not ok 39\n";
207*0Sstevel@tonic-gateprint grep(ref($_), @bar) == 3 ? "ok 40\n" : "not ok 40\n";
208*0Sstevel@tonic-gateprint @baz == 3 ? "ok 41\n" : "not ok 41\n";
209*0Sstevel@tonic-gate
210*0Sstevel@tonic-gatemy(@fuu) = \(1..2,3);
211*0Sstevel@tonic-gatemy(@baa) = \(@fuu);
212*0Sstevel@tonic-gatemy(@bzz) = \(1,@fuu,@baa);
213*0Sstevel@tonic-gateprint @baa == 3 ? "ok 42\n" : "not ok 42\n";
214*0Sstevel@tonic-gateprint grep(ref($_), @baa) == 3 ? "ok 43\n" : "not ok 43\n";
215*0Sstevel@tonic-gateprint @bzz == 3 ? "ok 44\n" : "not ok 44\n";
216*0Sstevel@tonic-gate
217*0Sstevel@tonic-gate# also, it can't be an lvalue
218*0Sstevel@tonic-gateeval '\\($x, $y) = (1, 2);';
219*0Sstevel@tonic-gateprint $@ =~ /Can\'t modify.*ref.*in.*assignment/ ? "ok 45\n" : "not ok 45\n";
220*0Sstevel@tonic-gate
221*0Sstevel@tonic-gate# test for proper destruction of lexical objects
222*0Sstevel@tonic-gate
223*0Sstevel@tonic-gatesub larry::DESTROY { print "# larry\nok 46\n"; }
224*0Sstevel@tonic-gatesub curly::DESTROY { print "# curly\nok 47\n"; }
225*0Sstevel@tonic-gatesub moe::DESTROY   { print "# moe\nok 48\n"; }
226*0Sstevel@tonic-gate
227*0Sstevel@tonic-gate{
228*0Sstevel@tonic-gate    my ($joe, @curly, %larry);
229*0Sstevel@tonic-gate    my $moe = bless \$joe, 'moe';
230*0Sstevel@tonic-gate    my $curly = bless \@curly, 'curly';
231*0Sstevel@tonic-gate    my $larry = bless \%larry, 'larry';
232*0Sstevel@tonic-gate    print "# leaving block\n";
233*0Sstevel@tonic-gate}
234*0Sstevel@tonic-gate
235*0Sstevel@tonic-gateprint "# left block\n";
236*0Sstevel@tonic-gate
237*0Sstevel@tonic-gate# another glob test
238*0Sstevel@tonic-gate
239*0Sstevel@tonic-gate$foo = "not ok 49";
240*0Sstevel@tonic-gate{ local(*bar) = "foo" }
241*0Sstevel@tonic-gate$bar = "ok 49";
242*0Sstevel@tonic-gatelocal(*bar) = *bar;
243*0Sstevel@tonic-gateprint "$bar\n";
244*0Sstevel@tonic-gate
245*0Sstevel@tonic-gate$var = "ok 50";
246*0Sstevel@tonic-gate$_   = \$var;
247*0Sstevel@tonic-gateprint $$_,"\n";
248*0Sstevel@tonic-gate
249*0Sstevel@tonic-gate# test if reblessing during destruction results in more destruction
250*0Sstevel@tonic-gate
251*0Sstevel@tonic-gate{
252*0Sstevel@tonic-gate    package A;
253*0Sstevel@tonic-gate    sub new { bless {}, shift }
254*0Sstevel@tonic-gate    DESTROY { print "# destroying 'A'\nok 52\n" }
255*0Sstevel@tonic-gate    package _B;
256*0Sstevel@tonic-gate    sub new { bless {}, shift }
257*0Sstevel@tonic-gate    DESTROY { print "# destroying '_B'\nok 51\n"; bless shift, 'A' }
258*0Sstevel@tonic-gate    package main;
259*0Sstevel@tonic-gate    my $b = _B->new;
260*0Sstevel@tonic-gate}
261*0Sstevel@tonic-gate
262*0Sstevel@tonic-gate# test if $_[0] is properly protected in DESTROY()
263*0Sstevel@tonic-gate
264*0Sstevel@tonic-gate{
265*0Sstevel@tonic-gate    my $i = 0;
266*0Sstevel@tonic-gate    local $SIG{'__DIE__'} = sub {
267*0Sstevel@tonic-gate	my $m = shift;
268*0Sstevel@tonic-gate	if ($i++ > 4) {
269*0Sstevel@tonic-gate	    print "# infinite recursion, bailing\nnot ok 53\n";
270*0Sstevel@tonic-gate	    exit 1;
271*0Sstevel@tonic-gate        }
272*0Sstevel@tonic-gate	print "# $m";
273*0Sstevel@tonic-gate	if ($m =~ /^Modification of a read-only/) { print "ok 53\n" }
274*0Sstevel@tonic-gate    };
275*0Sstevel@tonic-gate    package C;
276*0Sstevel@tonic-gate    sub new { bless {}, shift }
277*0Sstevel@tonic-gate    DESTROY { $_[0] = 'foo' }
278*0Sstevel@tonic-gate    {
279*0Sstevel@tonic-gate	print "# should generate an error...\n";
280*0Sstevel@tonic-gate	my $c = C->new;
281*0Sstevel@tonic-gate    }
282*0Sstevel@tonic-gate    print "# good, didn't recurse\n";
283*0Sstevel@tonic-gate}
284*0Sstevel@tonic-gate
285*0Sstevel@tonic-gate# test if refgen behaves with autoviv magic
286*0Sstevel@tonic-gate
287*0Sstevel@tonic-gate{
288*0Sstevel@tonic-gate    my @a;
289*0Sstevel@tonic-gate    $a[1] = "ok 54\n";
290*0Sstevel@tonic-gate    print ${\$_} for @a;
291*0Sstevel@tonic-gate}
292*0Sstevel@tonic-gate
293*0Sstevel@tonic-gate# This test is the reason for postponed destruction in sv_unref
294*0Sstevel@tonic-gate$a = [1,2,3];
295*0Sstevel@tonic-gate$a = $a->[1];
296*0Sstevel@tonic-gateprint "not " unless $a == 2;
297*0Sstevel@tonic-gateprint "ok 55\n";
298*0Sstevel@tonic-gate
299*0Sstevel@tonic-gate# This test used to coredump. The BEGIN block is important as it causes the
300*0Sstevel@tonic-gate# op that created the constant reference to be freed. Hence the only
301*0Sstevel@tonic-gate# reference to the constant string "pass" is in $a. The hack that made
302*0Sstevel@tonic-gate# sure $a = $a->[1] would work didn't work with references to constants.
303*0Sstevel@tonic-gate
304*0Sstevel@tonic-gatemy $test = 56;
305*0Sstevel@tonic-gate
306*0Sstevel@tonic-gateforeach my $lexical ('', 'my $a; ') {
307*0Sstevel@tonic-gate  my $expect = "pass\n";
308*0Sstevel@tonic-gate  my $result = runperl (switches => ['-wl'], stderr => 1,
309*0Sstevel@tonic-gate    prog => $lexical . 'BEGIN {$a = \q{pass}}; $a = $$a; print $a');
310*0Sstevel@tonic-gate
311*0Sstevel@tonic-gate  if ($? == 0 and $result eq $expect) {
312*0Sstevel@tonic-gate    print "ok $test\n";
313*0Sstevel@tonic-gate  } else {
314*0Sstevel@tonic-gate    print "not ok $test # \$? = $?\n";
315*0Sstevel@tonic-gate    print "# expected ", _qq ($expect), ", got ", _qq ($result), "\n";
316*0Sstevel@tonic-gate  }
317*0Sstevel@tonic-gate  $test++;
318*0Sstevel@tonic-gate}
319*0Sstevel@tonic-gate
320*0Sstevel@tonic-gatesub x::DESTROY {print "ok ", $test + shift->[0], "\n"}
321*0Sstevel@tonic-gate{ my $a1 = bless [3],"x";
322*0Sstevel@tonic-gate  my $a2 = bless [2],"x";
323*0Sstevel@tonic-gate  { my $a3 = bless [1],"x";
324*0Sstevel@tonic-gate    my $a4 = bless [0],"x";
325*0Sstevel@tonic-gate    567;
326*0Sstevel@tonic-gate  }
327*0Sstevel@tonic-gate}
328*0Sstevel@tonic-gate$test+=4;
329*0Sstevel@tonic-gate
330*0Sstevel@tonic-gatemy $result = runperl (switches=>['-l'],
331*0Sstevel@tonic-gate                      prog=> 'print 1; print qq-*$\*-;print 1;');
332*0Sstevel@tonic-gatemy $expect = "1\n*\n*\n1\n";
333*0Sstevel@tonic-gateif ($result eq $expect) {
334*0Sstevel@tonic-gate  print "ok $test\n";
335*0Sstevel@tonic-gate} else {
336*0Sstevel@tonic-gate  print "not ok $test\n";
337*0Sstevel@tonic-gate  foreach ($expect, $result) {
338*0Sstevel@tonic-gate    s/\n/\\n/gs;
339*0Sstevel@tonic-gate  }
340*0Sstevel@tonic-gate  print "# expected \"$expect\", got \"$result\"\n";
341*0Sstevel@tonic-gate}
342*0Sstevel@tonic-gate
343*0Sstevel@tonic-gate# bug #21347
344*0Sstevel@tonic-gate
345*0Sstevel@tonic-gaterunperl(prog => 'sub UNIVERSAL::AUTOLOAD { qr// } a->p' );
346*0Sstevel@tonic-gateif ($? != 0) { print "not " };
347*0Sstevel@tonic-gateprint "ok ",++$test," - UNIVERSAL::AUTOLOAD called when freeing qr//\n";
348*0Sstevel@tonic-gate
349*0Sstevel@tonic-gaterunperl(prog => 'sub UNIVERSAL::DESTROY { warn } bless \$a, A', stderr => 1);
350*0Sstevel@tonic-gateif ($? != 0) { print "not " };
351*0Sstevel@tonic-gateprint "ok ",++$test," - warn called inside UNIVERSAL::DESTROY\n";
352*0Sstevel@tonic-gate
353*0Sstevel@tonic-gate
354*0Sstevel@tonic-gate# bug #22719
355*0Sstevel@tonic-gate
356*0Sstevel@tonic-gaterunperl(prog => 'sub f { my $x = shift; *z = $x; } f({}); f();');
357*0Sstevel@tonic-gateif ($? != 0) { print "not " };
358*0Sstevel@tonic-gateprint "ok ",++$test," - coredump on typeglob = (SvRV && !SvROK)\n";
359*0Sstevel@tonic-gate
360*0Sstevel@tonic-gate# bug #27268: freeing self-referential typeglobs could trigger
361*0Sstevel@tonic-gate# "Attempt to free unreferenced scalar" warnings
362*0Sstevel@tonic-gate
363*0Sstevel@tonic-gate$result = runperl(
364*0Sstevel@tonic-gate    prog => 'use Symbol;my $x=bless \gensym,"t"; print;*$$x=$x',
365*0Sstevel@tonic-gate    stderr => 1
366*0Sstevel@tonic-gate);
367*0Sstevel@tonic-gateprint "not " if length $result;
368*0Sstevel@tonic-gateprint "ok ",++$test," - freeing self-referential typeglob\n";
369*0Sstevel@tonic-gateprint "# got: $result\n" if length $result;
370*0Sstevel@tonic-gate
371*0Sstevel@tonic-gate# test global destruction
372*0Sstevel@tonic-gate
373*0Sstevel@tonic-gate++$test;
374*0Sstevel@tonic-gatemy $test1 = $test + 1;
375*0Sstevel@tonic-gatemy $test2 = $test + 2;
376*0Sstevel@tonic-gate
377*0Sstevel@tonic-gatepackage FINALE;
378*0Sstevel@tonic-gate
379*0Sstevel@tonic-gate{
380*0Sstevel@tonic-gate    $ref3 = bless ["ok $test2\n"];	# package destruction
381*0Sstevel@tonic-gate    my $ref2 = bless ["ok $test1\n"];	# lexical destruction
382*0Sstevel@tonic-gate    local $ref1 = bless ["ok $test\n"];	# dynamic destruction
383*0Sstevel@tonic-gate    1;					# flush any temp values on stack
384*0Sstevel@tonic-gate}
385*0Sstevel@tonic-gate
386*0Sstevel@tonic-gateDESTROY {
387*0Sstevel@tonic-gate    print $_[0][0];
388*0Sstevel@tonic-gate}
389