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