Creates compartments for evaluating untrusted Perl code. Each compartment has an associated operator mask for excluding particular Perl operators from the compartment. (See the Opcode module for more information on operators and operator masks.) The default mask is applied during compilation to prevent all operations that give access to the system. Safe provides the following methods.
$cpt = new Safe [(namespace, mask)]
Constructor. Creates a new compartment. Takes the following arguments:
Sets operator mask for the compartment if mask is specified; otherwise, it gets the current mask.
Evaluates the contents of file filenameinside the compartment.
Evaluates string as Perl code inside the compartment.
If namespace is specified, sets the root namespace for the compartment; otherwise, gets the current namespace.
$cpt->share (varname[, ...])
Shares the variable(s) in the argument list with the compartment.
$cpt->trap (op[, ...])
For each operator specified in the argument list, sets the corresponding bit in the compartment's operator mask.
$cpt->untrap (op[, ...])
For each operator specified in the argument list, resets the corresponding bit in the compartment's operator mask.
Returns a glob for the symbol table entry of varname in the compartment's package.
The following subroutines are available for export by Safe. The operator names can be found in the array op_name in the file opcode.h in the Perl distribution.
Returns a mask with all operators unmasked.
Returns a mask with all operators masked.
Takes an operator mask mask and returns a list of the names of operators masked in mask.
Returns the number of operators in a mask (and hence its length).
opcode (op[, ...])
Takes a list of operator names and returns the corresponding list of opcodes.
Returns the operator mask in effect at the time the invocation to the subroutine was compiled.
opname (op[, ...])
Takes a list of opcodes and returns the corresponding list of operator names.
ops_to_mask (op[, ...])
Takes a list of operator names and returns an operator mask with those operators masked.
Copyright © 2002 O'Reilly & Associates. All rights reserved.