/perl-eval-safe

Simplified safe evaluation of Perl code

Primary LanguagePerlOtherNOASSERTION

Eval::Safe - Simplified safe evaluation of Perl code

DESCRIPTION

Eval::Safe is a Perl module to allow executing Perl code like with the eval function, but in isolation from the main program. This is similar to the Safe module, but faster, as we don't try to be safe.

DOCUMENTATION

The standard Safe module does 4 things when running user-provided code: compiling and running the string as Perl code; running the code in a specific package so that variables in the calling code are not modified by mistake; hiding all the existing packages so that the executed code cannot modify them; and limiting the set of operations that can be executed by the code to further try to make it safe (prevents it from modifying the system, etc.).

By comparison, the Eval::Safe module here only does the first two of these things (compiling the code and changing the namespace in which it is executed) to make it conveniant to run user-provided code, as long as you can trust that code. The benefit is that this is around three times faster than using Safe (especially for small pieces of code).

The documentation for the module can be found on meta::cpan. After the module is installed, you can also get its documentation by running perldoc Eval::Safe (this usually comes in a perl-doc package on most systems).

INSTALLATION

Requirements

Building and installing this module only requires Perl modules from the standard library. So as long as you have Perl installed (which should be the case by default on almost all system), you should be able to install it using one of the method below. This module requires Perl version 5.22 or above. You can check which Perl you have installed with the following command:

perl -v

Installing from the Git sources

To install this module manually from Git, you can run the following commands (you do need to have the make and git program installed):

git clone https://github.com/mkende/perl-eval-safe.git
cd perl-eval-safe
perl Makefile.PL
make
make test
sudo make install

Installing from CPAN

This module is available on CPAN (the Perl package manager). The CPAN command should be installed on any system that has Perl (which, again, should mostly be any system at all). So, to install the module automatically using CPAN, you can just run the following command:

cpan Eval::Safe

Note: if this is the first time that you run the cpan command, you will be asked to configure it. The default answer to most questions is usually fine.

DISTRIBUTION

The main development of this software is done on GitHub. However, it is also available on CPAN.

The following can be used only by the module maintainer on CPAN. To update the CPAN module, remember to increment the version number and then run the following commands:

perl Makefile.PL
make distcheck
# Optionally, to add files not in the manifest:
# make manifest
make dist

Finally, upload the Eval-Safe-version.tar.gz file that has been created through PAUSE, ideally putting it under an Eval-Safe directory.