8 require Config; import Config;
9 if ($Config{'extensions'} !~ /\bOpcode\b/ && $Config{'osname'} ne 'VMS') {
19 package test; # test from somewhere other than main
23 use Opcode 1.00, qw(opdesc opset opset_to_ops opset_to_hex
24 opmask_add full_opset empty_opset opcodes opmask define_optag);
28 my $last_test; # initalised at end
29 print "1..$last_test\n";
33 # create and destroy some automatic Safe compartments first
34 $cpt = new Safe or die;
35 $cpt = new Safe or die;
36 $cpt = new Safe or die;
38 $cpt = new Safe "Root" or die;
43 $cpt->share(qw($foo));
45 print ${$cpt->varglob('foo')} == 42 ? "ok $t\n" : "not ok $t\n"; $t++;
47 ${$cpt->varglob('foo')} = 9;
49 print $foo == 9 ? "ok $t\n" : "not ok $t\n"; $t++;
51 print $cpt->reval('$foo') == 9 ? "ok $t\n" : "not ok $t\n"; $t++;
52 # check 'main' has been changed:
53 print $cpt->reval('$::foo') == 9 ? "ok $t\n" : "not ok $t\n"; $t++;
54 print $cpt->reval('$main::foo') == 9 ? "ok $t\n" : "not ok $t\n"; $t++;
55 # check we can't see our test package:
56 print $cpt->reval('$test::foo') ? "not ok $t\n" : "ok $t\n"; $t++;
57 print $cpt->reval('${"test::foo"}') ? "not ok $t\n" : "ok $t\n"; $t++;
59 $cpt->erase; # erase the compartment, e.g., delete all variables
61 print $cpt->reval('$foo') ? "not ok $t\n" : "ok $t\n"; $t++;
63 # Note that we *must* use $cpt->varglob here because if we used
64 # $Root::foo etc we would still see the original values!
65 # This seems to be because the compiler has created an extra ref.
67 print ${$cpt->varglob('foo')} ? "not ok $t\n" : "ok $t\n"; $t++;
70 print "ok $last_test\n";
71 BEGIN { $last_test = 28 }