6 require Config; import Config;
7 if ($Config{'extensions'} !~ /\bOpcode\b/ && $Config{'osname'} ne 'VMS') {
16 package test; # test from somewhere other than main
20 use Opcode 1.00, qw(opdesc opset opset_to_ops opset_to_hex
21 opmask_add full_opset empty_opset opcodes opmask define_optag);
25 my $last_test; # initalised at end
26 print "1..$last_test\n";
30 # create and destroy some automatic Safe compartments first
31 $cpt = new Safe or die;
32 $cpt = new Safe or die;
33 $cpt = new Safe or die;
35 $cpt = new Safe "Root" or die;
40 $cpt->share(qw($foo));
42 print ${$cpt->varglob('foo')} == 42 ? "ok $t\n" : "not ok $t\n"; $t++;
44 ${$cpt->varglob('foo')} = 9;
46 print $foo == 9 ? "ok $t\n" : "not ok $t\n"; $t++;
48 print $cpt->reval('$foo') == 9 ? "ok $t\n" : "not ok $t\n"; $t++;
49 # check 'main' has been changed:
50 print $cpt->reval('$::foo') == 9 ? "ok $t\n" : "not ok $t\n"; $t++;
51 print $cpt->reval('$main::foo') == 9 ? "ok $t\n" : "not ok $t\n"; $t++;
52 # check we can't see our test package:
53 print $cpt->reval('$test::foo') ? "not ok $t\n" : "ok $t\n"; $t++;
54 print $cpt->reval('${"test::foo"}') ? "not ok $t\n" : "ok $t\n"; $t++;
56 $cpt->erase; # erase the compartment, e.g., delete all variables
58 print $cpt->reval('$foo') ? "not ok $t\n" : "ok $t\n"; $t++;
60 # Note that we *must* use $cpt->varglob here because if we used
61 # $Root::foo etc we would still see the original values!
62 # This seems to be because the compiler has created an extra ref.
64 print ${$cpt->varglob('foo')} ? "not ok $t\n" : "ok $t\n"; $t++;
67 print "ok $last_test\n";
68 BEGIN { $last_test = 28 }