Nearly-working threads re-structuring. Do not integrate,
[p5sagit/p5-mst-13.2.git] / ext / Opcode / Safe.pm
index 21121f5..22ba03f 100644 (file)
@@ -3,7 +3,7 @@ package Safe;
 use 5.003_11;
 use strict;
 
-our $VERSION = "2.06";
+our $VERSION = "2.07";
 
 use Carp;
 
@@ -47,6 +47,7 @@ sub new {
     # the whole glob *_ rather than $_ and @_ separately, otherwise
     # @_ in non default packages within the compartment don't work.
     $obj->share_from('main', $default_share);
+    Opcode::_safe_pkg_prep($obj->{Root});
     return $obj;
 }
 
@@ -167,14 +168,13 @@ sub share_from {
        my ($var, $type);
        $type = $1 if ($var = $arg) =~ s/^(\W)//;
        # warn "share_from $pkg $type $var";
-       my $obj_to_share =  (!$type)       ? \&{$pkg."::$var"}
+       *{$root."::$var"} = (!$type)       ? \&{$pkg."::$var"}
                          : ($type eq '&') ? \&{$pkg."::$var"}
                          : ($type eq '$') ? \${$pkg."::$var"}
                          : ($type eq '@') ? \@{$pkg."::$var"}
                          : ($type eq '%') ? \%{$pkg."::$var"}
                          : ($type eq '*') ?  *{$pkg."::$var"}
                          : croak(qq(Can't share "$type$var" of unknown type));
-       Opcode::_safe_call_sv($root, $obj->{Mask}, sub { *{$var} = $obj_to_share });
     }
     $obj->share_record($pkg, $vars) unless $no_record or !$vars;
 }
@@ -214,11 +214,11 @@ sub reval {
     # Create anon sub ref in root of compartment.
     # Uses a closure (on $expr) to pass in the code to be executed.
     # (eval on one line to keep line numbers as expected by caller)
-    my $evalcode = sprintf('package %s; sub { eval $expr; }', $root);
+       my $evalcode = sprintf('package %s; sub { eval $expr; }', $root);
     my $evalsub;
 
-    if ($strict) { use strict; $evalsub = eval $evalcode; }
-    else         {  no strict; $evalsub = eval $evalcode; }
+       if ($strict) { use strict; $evalsub = eval $evalcode; }
+       else         {  no strict; $evalsub = eval $evalcode; }
 
     return Opcode::_safe_call_sv($root, $obj->{Mask}, $evalsub);
 }
@@ -380,7 +380,7 @@ respectfully.
 =item share (NAME, ...)
 
 This shares the variable(s) in the argument list with the compartment.
-This is almost identical to exporting variables using the L<Exporter(3)>
+This is almost identical to exporting variables using the L<Exporter>
 module.
 
 Each NAME must be the B<name> of a variable, typically with the leading