NAME
Safe::Hole - make a hole to the original main compartment in the Safe compartment
SYNOPSIS
use Safe;
use Safe::Hole;
$cpt = new Safe;
$hole = new Safe::Hole;
sub test { Test->test; }
$Testobj = new Test;
# $cpt->share('&test'); # alternate as next line
$hole->wrap(\&test, $cpt, '&test');
# ${$cpt->varglob('Testobj')} = $Testobj; # alternate as next line
$hole->wrap($Testobj, $cpt, '$Testobj');
$cpt->reval('test; $Testobj->test;');
print $@ if $@;
package Test;
sub new { bless {},shift(); }
sub test { my $self = shift; $self->test2; }
sub test2 { print "Test->test2 called\n"; }
DESCRIPTION
We can call outside defined subroutines from the Safe compartment
using share(), or can call methods through the object that is copied into
the Safe compartment using varglob(). But that subroutines or methods
are executed in the Safe compartment too, so they cannot call another
subroutines that are dinamically qualified with the package name such as
class methods.
Through Safe::Hole, we can execute outside defined subroutines in the
original main compartment from the Safe compartment.
Methods
- new [NAMESPACE]
-
Class method. Constructor. NAMESPACE is the alternate root namespace that makes the compartment in which call() method execute the subroutine. Default of NAMESPACE means 'main'. We use the default usually.
- call $coderef [,@args]
-
Object method. Call the subroutine refered by $coderef in the compartment that is specified with constructor new. @args are passed to called $coderef.
- wrap $ref [,$cpt ,$name]
-
Object method. If $ref is a code reference, this method returns the anonymous subroutine reference that calls $ref using call() method of Safe::Hole (see above). If $ref is a class object, this method makes a wrapper class of that object and returns a new object of the wrapper class. Through the wrapper class, all original class methods called using call() method of Safe::Hole. If $cpt as Safe object and $name as subroutine or scalar name specified, this method works like share() method of Safe. When $ref is a code reference $name must like '&subroutine'. When $ref is a object $name must like '$var'. Name $name may not be same as referent of $ref. For example: $hole->wrap(\&foo, $cpt, '&bar'); $hole->wrap(sub{...}, $cpt, '&foo'); $hole->wrap($objfoo, $cpt, '$objbar');
- root
-
Object method. Return the namespace that is specified with constructor new.
Warning
You MUST NOT share the Safe::Hole object with the Safe compartment. If you do it the Safe compartment is NOT safe.
AUTHOR
Sey Nakajima <sey@jkc.co.jp>
SEE ALSO
Safe(3).
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 169:
'=item' outside of any '=over'
- Around line 174:
You forgot a '=back' before '=head2'