Opcode - Disable named opcodes when compiling perl code
use Opcode;
Perl code is always compiled into an internal format before execution.
Evaluating perl code (e.g. via "eval" or "do 'file'") causes the code to be compiled into an internal format and then, provided there was no error in the compilation, executed. The internal format is based on many distinct opcodes.
By default no opmask is in effect and any code can be compiled.
The Opcode module allow you to define an operator mask to be in effect when perl next compiles any code. Attempting to compile code which contains a masked opcode will cause the compilation to fail with an error. The code will not be executed.
The Opcode module is not usually used directly. See the ops pragma and Safe modules for more typical uses.
The Opcode module does not implement an effective sandbox for evaluating untrusted code with the perl interpreter.
Bugs in the perl interpreter that could be abused to bypass Opcode restrictions are not treated as vulnerabilities. See perlsecpolicy for additional information.
The authors make no warranty, implied or otherwise, about the suitability of this software for safety or security purposes.
The authors shall not in any case be liable for special, incidental, consequential, indirect or other similar damages arising from the use of this software.
Your mileage will vary. If in any doubt do not use it.
The canonical list of operator names is the contents of the array PL_op_name defined and initialised in file opcode.h of the Perl source distribution (and installed into the perl library).
Each operator has both a terse name (its opname) and a more verbose or recognisable descriptive name. The opdesc function can be used to return a list of descriptions for a list of operators.
Many of the functions and methods listed below take a list of operators as parameters. Most operator lists can be made up of several types of element. Each element can be one of
Operator names are typically small lowercase words like enterloop, leaveloop, last, next, redo etc. Sometimes they are rather cryptic like gv2cv, i_ncmp and ftsvtx.
Operator tags can be used to refer to groups (or sets) of operators. Tag names always begin with a colon. The Opcode module defines several optags and the user can define others using the define_optag function.
An opname or optag can be prefixed with an exclamation mark, e.g., !mkdir. Negating an opname or optag means remove the corresponding ops from the accumulated set of ops at that point.
An opset as a binary string of approximately 44 bytes which holds a set or zero or more operators.
The opset and opset_to_ops functions can be used to convert from a list of operators to an opset and vice versa.
Wherever a list of operators can be given you can use one or more opsets. See also Manipulating Opsets below.
The Opcode package contains functions for manipulating operator names tags and sets. All are available for export by the package.
In a scalar context opcodes returns the number of opcodes in this version of perl (around 350 for perl-5.7.0).
In a list context it returns a list of all the operator names. (Not yet implemented, use @names = opset_to_ops(full_opset).)
Returns an opset containing the listed operators.
Returns a list of operator names corresponding to those operators in the set.
Returns a string representation of an opset. Can be handy for debugging.