.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Eval::Context 3pm" .TH Eval::Context 3pm "2015-05-31" "perl v5.20.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" .Vb 1 \& Eval::Context \- Evalute perl code in context wraper .Ve .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Eval::Context ; \& \& my $context = new Eval::Context(PRE_CODE => "use strict;\enuse warnings;\en") ; \& \& # code will be evaluated with strict and warnings loaded in the context. \& \& $context\->eval(CODE => \*(Aqprint "evaluated in an Eval::Context!" ;\*(Aq) ; \& $context\->eval(CODE_FROM_FILE => \*(Aqfile.pl\*(Aq) ; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module define a subroutine that let you evaluate Perl code in a specific context. The code can be passed directly as a string or as a file name to read from. It also provides some subroutines to let you define and optionally share variables and subroutines between your code and the code you wish to evaluate. Finally there is some support for running your code in a safe compartment. .SH "Don't play with fire!" .IX Header "Don't play with fire!" Don't start using this module, or any other module, thinking it will let you take code from anywhere and be safe. Read perlsec, Safe, Opcode, Taint and other security related documents. Control your input. .SH "SUBROUTINES/METHODS" .IX Header "SUBROUTINES/METHODS" Subroutines that are not part of the public interface are marked with [p]. .SS "new(@named_arguments)" .IX Subsection "new(@named_arguments)" Create an Eval::Context object. The object is used as a repository of \*(L"default\*(R" values for your code evaluations. The context can be used many times. The values can be temporarily overridden during the \f(CW\*(C`eval\*(C'\fR call. .PP .Vb 1 \& my $context = new Eval::Context() ; # default context \& \& my $context = new Eval::Context \& ( \& NAME => \*(Aqlibraries evaluation context\*(Aq, \& PACKAGE => \*(Aqlibraries\*(Aq, \& SAFE => {...} ; \& \& PRE_CODE => "use strict ;\en" \& POST_CODE => sub{}, \& PERL_EVAL_CONTEXT => undef, \& \& INSTALL_SUBS => {...}, \& INSTALL_VARIABLES => [...], \& EVAL_SIDE_PERSISTENT_VARIABLES => {...}, \& \& INTERACTION => {...}, \& DISPLAY_SOURCE_IN_CONTEXT => 1, #useful when debuging \& ) ; .Ve .PP \&\fI\s-1ARGUMENTS\s0\fR .IP "\(bu" 2 \&\f(CW@named_arguments\fR \- setup data for the object .Sp All the arguments optional. The argument passed to \f(CW\*(C`new\*(C'\fR can also be passed to \f(CW\*(C`eval\*(C'\fR. All arguments are named. .RS 2 .IP "\(bu" 4 \&\s-1NAME \-\s0 use when displaying information about the object. .Sp Set automatically to 'Anonymous' if not set. The name will also be reported by perl if an error occurs during your code evaluation. .IP "\(bu" 4 \&\s-1PACKAGE \-\s0 the package the code passed to \f(CW\*(C`eval\*(C'\fR will evaluated be in. .Sp If not set, a unique package name is generated and used for every \f(CW\*(C`eval\*(C'\fR call. .IP "\(bu" 4 \&\s-1REMOVE_PACKAGE_AFTER_EVAL \-\s0 When set the content of the package after evaluation will be erase .Sp The default behavior is to remove all data from after the call to \f(CW\*(C`eval\*(C'\fR. .IP "\(bu" 4 \&\s-1PRE_CODE \-\s0 code prepended to the code passed to \fIeval\fR .IP "\(bu" 4 \&\s-1POST_CODE \-\s0 code appended to the code passed to \fIeval\fR .IP "\(bu" 4 \&\s-1PERL_EVAL_CONTEXT \-\s0 the context to eval code in (void, scalar, list). .Sp This option Works as \*(L"wantarray\*(R" in perlfunc. It will override the context in which \f(CW\*(C`eval\*(C'\fR is called. .IP "\(bu" 4 \&\s-1INSTALL_SUBS \-\s0 subs that will be available in the eval. .Sp A hash where the keys are a function names and the values a code references. .IP "\(bu" 4 \&\s-1SAFE\s0 .Sp This argument must be a hash reference. if the hash is empty, a default safe compartment will be used. Read Safe documentation for more information. .Sp .Vb 1 \& SAFE => {} # default safe environment .Ve .Sp You can have a finer control over the safe compartment \fBEval::Context\fR that will be used. .Sp .Vb 1 \& my $compartment = new Safe(\*(AqABC\*(Aq) ; \& \& my $context = new Eval::Context \& ( \& SAFE => # controlling the safe environment \& { \& PACKAGE => \*(AqABC\*(Aq, \& PRE_CODE => "use my module ;\en" # code we consider safe \& USE_STRICT => 0, # set to 1 by default \& COMPARTMENT => $compartment , # use default if not passed \& } , \& } \& \& $context\->eval(CODE => .....) ; .Ve .RS 4 .IP "\(bu" 4 \&\s-1COMPARTMENT \-\s0 a Safe object, you create, that will be used by \fBEval::Context\fR .IP "\(bu" 4 \&\s-1USE_STRICT \-\s0 Controls if strict is used in the Safe compartment .Sp The default is to use strict. Note that \*(L"Safe\*(R" in perldoc default is to \s-1NOT\s0 use strict (undocumented). .IP "\(bu" 4 \&\s-1PRE_CODE \-\s0 safe code you want to evaluate in the same context as the unsafe code .Sp This let you, for example, use certain modules which provide subroutines to be used in the evaluated code. The default compartment is quite restrictive and you can't even use strict in it without tuning the safe compartment. .RE .RS 4 .Sp A few remarks: .Sp \&\- See on \s-1RT\s0 .Sp \&\- Pass the same package name to your safe compartment and to \fBEval::Context\fR. .Sp \&\- If you really want to be on the safe side, control your input. When you use a module, are you sure the module hasn't been fiddle with? .Sp \&\- Leave strict on. Even for trivial code. .RE .IP "\(bu" 4 \&\s-1INSTALL_VARIABLES \- \s0\*(L"Give me sugar baby\*(R" Ash. .Sp \&\fBEval::Context\fR has mechanisms you can use to set and share variables with the code you will evaluate. There are two sides in an \fBEval::Context\fR. The \fIcaller-side\fR, the side where the calls to \f(CW\*(C`eval\*(C'\fR are made and the \fIeval-side\fR, the side where the code to be evaluated is run. .RS 4 .IP "\(bu" 4 How should you get values back from the eval-side .Sp Although you can use the mechanisms below to get values from the \fIeval-side\fR, the cleanest way is to get the results directly from the \f(CW\*(C`eval\*(C'\fR call. .Sp .Vb 1 \& my $context = new Eval::Context() ; \& \& my ($scalr_new_value, $a_string) = \& $context\->eval \& ( \& INSTALL_VARIABLES =>[[ \*(Aq$scalar\*(Aq => 42]] , \& CODE => "\e$scalar++ ;\en (\e$scalar, \*(Aqa string\*(Aq) ;", \& ) ; .Ve .IP "\(bu" 4 initializing variables on the \fIeval side\fR .Sp You can pass \fB\s-1INSTALL_VARIABLES\s0\fR to \f(CW\*(C`new\*(C'\fR or \f(CW\*(C`eval\*(C'\fR. You can initialize different variables for each run of \f(CW\*(C`eval\*(C'\fR. .Sp .Vb 12 \& my $context = new Eval::Context \& ( \& INSTALL_VARIABLES => \& [ \& # variables on eval\-side #initialization source \& [ \*(Aq$data\*(Aq => 42], \& [ \*(Aq$scalar\*(Aq => $scalar_caller_side ], \& [ \*(Aq%hash\*(Aq => \e%hash_caller_side ] \& [ \*(Aq$hash\*(Aq => \e%hash_caller_side ], \& [ \*(Aq$object\*(Aq => $object ], \& ] , \& ) ; .Ve .Sp The variables will be \fBmy\fR variables on the eval-side. .Sp You can declare variables of any of the base types supported by perl. The initialization data , on the caller-side, is serialized and deserialized to make the values available on the eval-side. Modifying the variables on the eval-side does not modify the variables on the caller-side. The initialization data can be scalars or references and even \fBmy\fR variables. .IP "\(bu" 4 Persistent variables .Sp When evaluating code many times in the same context, you may wish to have variables persist between evaluations. \fBEval::Context\fR allows you to declare, define and control such \&\fIstate\fR variables. .Sp This mechanism lets you control which variables are persistent. Access to the persistent variables is controlled per \f(CW\*(C`eval\*(C'\fR run. Persistent variables are \fBmy\fR variables on the \fIeval-side\fR. Modifying the variables on the eval-side does not modify the variables on the \fIcaller-side\fR. .Sp Define persistent variables: .Sp .Vb 3 \& # note: creating persistent variables in \*(Aqnew\*(Aq makes little sense as \& # it will force those values in the persistent variables for every run. \& # This may or may not be what you want. \& \& my $context = new Eval::Context() ; \& \& $context\->eval \& ( \& INSTALL_VARIABLES => \& [ \& [ \*(Aq$scalar\*(Aq => 42 => $Eval::Context::PERSISTENT ] , \& \& # make %hash and $hash available on the eval\-side. both are \& # initialized from the same caller\-side hash \& [ \*(Aq%hash\*(Aq => \e%hash_caller_side => $Eval::Context::PERSISTENT ] , \& [ \*(Aq$hash\*(Aq => \e%hash_caller_side => $Eval::Context::PERSISTENT ] , \& ], \& CODE => \*(Aq$scalar++\*(Aq, \& ) ; .Ve .Sp Later, use the persistent value: .Sp .Vb 7 \& $context\->eval \& ( \& INSTALL_VARIABLES => \& [ \& [ \*(Aq$scalar\*(Aq => $Eval::Context::USE => $Eval::Context::PERSISTENT ] , \& # here you decided %hash and $hash shouldn\*(Aqt be available on the eval\-side \& ], \& \& CODE => \*(Aq$scalar\*(Aq, \& ) ; .Ve .Sp \&\fB\f(CB$Eval::Context::USE\fB\fR means \fI\*(L"make the persistent variable and it's value available on the eval-side\*(R"\fR. Any other value will reinitialize the persistent variable. See also \fB\s-1REMOVE_PERSISTENT\s0\fR in \f(CW\*(C`eval\*(C'\fR. .IP "\(bu" 4 Manually synchronizing caller-side data with persistent eval-side data .Sp Although the first intent of persistent variables is to be used as state variables on the eval-side, you can get persistent variables values on the caller-side. To change the value of an \fIeval-side\fR persistent variable, simply reinitialize it with \fB\s-1INSTALL_VARIABLES\s0\fR next time you call \f(CW\*(C`eval\*(C'\fR. .Sp .Vb 7 \& my $context = new Eval::Context \& ( \& INSTALL_VARIABLES => \& [ \& [\*(Aq%hash\*(Aq => \e%hash_caller_side => $Eval::Context::PERSISTENT] \& ] , \& ) ; \& \& $context\->Eval(CODE => \*(Aq$hash{A}++ ;\*(Aq) ; \& \& # throws exception if you request a non existing variable \& my %hash_after_eval = $context\->GetPersistantVariables(\*(Aq%hash\*(Aq) ; .Ve .IP "\(bu" 4 Getting the list of all the \s-1PERSISTENT\s0 variables .Sp .Vb 1 \& my @persistent_variable_names = $context\->GetPersistantVariablesNames() ; .Ve .IP "\(bu" 4 Creating persistent variables on the eval-side .Sp The mechanism above gave you fine control over persistent variables on the \fIeval-side\fR. The negative side is that \fBonly\fR the variables you made persistent exist on the \fIeval-side\fR. \&\fBEval::Context\fR has another mechanism that allows the \fIeval-side\fR to store variables between evaluations without the \fIcaller-side\fR declaration of the variables. .Sp To allow the \fIeval-side\fR to store any variable, add this to you \f(CW\*(C`new\*(C'\fR call. .Sp .Vb 3 \& my $context = new Eval::Context \& ( \& PACKAGE => \*(Aqmy_package\*(Aq, \& \& EVAL_SIDE_PERSISTENT_VARIABLES => \& { \& SAVE => { NAME => \*(AqSavePersistent\*(Aq, VALIDATOR => sub{} }, \& GET => { NAME => \*(AqGetPersistent\*(Aq, VALIDATOR => sub{} }, \& }, \& ) ; .Ve .Sp The \fIeval-side\fR can now store variables between calls to \f(CW\*(C`eval\*(C'\fR .Sp .Vb 1 \& SavePersistent(\*(Aqname\*(Aq, $value) ; .Ve .Sp later in another call to \f(CW\*(C`eval\*(C'\fR: .Sp .Vb 1 \& my $variable = GetPersistent(\*(Aqname\*(Aq) ; .Ve .Sp By fine tuning \fB\s-1EVAL_SIDE_PERSISTENT_VARIABLES\s0\fR you can control what variables are stored by the \fIeval-side\fR. This should seldom be used and only to help those storing data from the \fIeval-side\fR. .Sp You may have notices in the code above that a package name was passed as argument to \f(CW\*(C`new\*(C'\fR. This is very important as the package names that are automatically generated differ for each \&\f(CW\*(C`eval\*(C'\fR call. If you want to run all you \fIeval-side\fR code in different packages (\fBEval::Context\fR default behavior), you must tell \fBEval::Context\fR where to store the \fIeval-side\fR values. This is done by setting \fB\s-1CATEGORY\s0\fR .Sp The validator sub can verify if the value to be stored are valid, E.G.: variable name, variable value is within range, ... .Sp Here is an example of code run in different packages but can share variables. Only variables which names start with \fIA\fR are valid. .Sp .Vb 10 \& new Eval::Context \& ( \& EVAL_SIDE_PERSISTENT_VARIABLES => \& { \& CATEGORY => \*(AqTEST\*(Aq, \& SAVE => \& { \& NAME => \*(AqSavePersistent\*(Aq, \& VALIDATOR => sub \& { \& my ($self, $name, $value, $package) = @_ ; \& $self\->{INTERACTION}{DIE}\-> \& ( \& $self, \& "SavePersistent: name \*(Aq$name\*(Aq doesn\*(Aqt start with A!" \& ) unless $name =~ /^A/ ; \& }, \& }, \& \& GET => {NAME => \*(AqGetPersistent\*(Aq,VALIDATOR => sub {}}, \& }, \& ) ; \& \& $context\->eval(CODE => \*(AqSavePersistent(\*(AqA_variable\*(Aq, 123) ;\*(Aq) ; .Ve .Sp later: .Sp .Vb 1 \& $context\->eval(CODE => \*(AqGetPersistent(\*(AqA_variable\*(Aq) ;\*(Aq) ; .Ve .IP "\(bu" 4 Shared variables .Sp You can also share references between the \fIcaller-side\fR and the \fIeval-side\fR. .Sp .Vb 11 \& my $context = \& new Eval::Context \& ( \& INSTALL_VARIABLES => \& [ \& # reference to reference only \& [ \*(Aq$scalar\*(Aq => \e$scalar => $Eval::Context::SHARED ], \& [ \*(Aq$hash\*(Aq => \e%hash_caller_side => $Eval::Context::SHARED ], \& [ \*(Aq$object\*(Aq => $object => $Eval::Context::SHARED ], \& ] , \& ) ; .Ve .Sp Modification of the variables on the \fIeval-side\fR will modify the variable on the \fIcaller-side\fR. There are but a few reasons to share references. Note that you can share references to \fBmy\fR variables. .RE .RS 4 .RE .IP "\(bu" 4 \&\s-1INTERACTION\s0 .Sp Lets you define subs used to interact with the user. .Sp .Vb 7 \& INTERACTION => \& { \& INFO => \e&sub, \& WARN => \e&sub, \& DIE => \e&sub, \& EVAL_DIE => \e&sub, \& } .Ve .RS 4 .IP "\s-1INFO \-\s0 defaults to CORE::print" 6 .IX Item "INFO - defaults to CORE::print" This sub will be used when displaying information. .IP "\s-1WARN \-\s0 defaults to Carp::carp" 6 .IX Item "WARN - defaults to Carp::carp" This sub will be used when a warning is displayed. .IP "\s-1DIE \-\s0 defaults to Carp::confess" 6 .IX Item "DIE - defaults to Carp::confess" Used when an error occurs. .IP "\s-1EVAL_DIE \-\s0 defaults to Carp::confess, with a dump of the code to be evaluated" 6 .IX Item "EVAL_DIE - defaults to Carp::confess, with a dump of the code to be evaluated" Used when an error occurs during code evaluation. .RE .RS 4 .RE .IP "\(bu" 4 \&\s-1FILE \-\s0 the file where the object has been created. .Sp This is practical if you want to wrap the object. .Sp \&\fB\s-1FILE\s0\fR and \fB\s-1LINE\s0\fR will be set automatically if not set. .IP "\(bu" 4 \&\s-1LINE \-\s0 the line where the object has been created. Set automatically if not set. .IP "\(bu" 4 \&\s-1DISPLAY_SOURCE_IN_CONTEXT \-\s0 if set, the code to evaluated will be displayed before evaluation .RE .RS 2 .RE .PP \&\fIReturn\fR .IP "\(bu" 2 an \fBEval::Context\fR object. .SS "[p] Setup" .IX Subsection "[p] Setup" Helper sub called by new. .SS "[p] CheckOptionNames" .IX Subsection "[p] CheckOptionNames" Verifies the named options passed as arguments with a list of valid options. Calls \fB{\s-1INTERACTION\s0}{\s-1DIE\s0}\fR in case of error. .SS "[p] SetInteractionDefault" .IX Subsection "[p] SetInteractionDefault" Sets {\s-1INTERACTION\s0} fields that are not set by the user. .SS "[p] CanonizeName" .IX Subsection "[p] CanonizeName" Transform a string into a a string with can be used as a package name or file name usable within perl code. .SS "eval(@named_arguments)" .IX Subsection "eval(@named_arguments)" Evaluates Perl code, passed as a string or read from a file, in the context. .PP .Vb 1 \& my $context = new Eval::Context(PRE_CODE => "use strict;\enuse warnings;\en") ; \& \& $context\->eval(CODE => \*(Aqprint "evaluated in an Eval::Context!";\*(Aq) ; \& $context\->eval(CODE_FROM_FILE => \*(Aqfile.pl\*(Aq) ; .Ve .PP \&\fICall context\fR .PP Evaluation context of the code (void, scalar, list) is the same as the context this subroutine was called in or in the context defined by \fB\s-1PERL_EVAL_CONTEXT\s0\fR if that option is present. .PP \&\fIArguments\fR .PP \&\fB\s-1NOTE:\s0 You can override any argument passed to \fR\f(CW\*(C`new\*(C'\fR\fB. The override is temporary during the duration of this call.\fR .IP "\(bu" 2 \&\f(CW@named_arguments\fR \- Any of \f(CW\*(C`new\*(C'\fR options plus the following. .RS 2 .IP "\(bu" 4 \&\s-1CODE \-\s0 a string containing perl code (valid code or an exception is raised) .IP "\(bu" 4 \&\s-1CODE_FROM_FILE \-\s0 a file containing perl code .IP "\(bu" 4 \&\s-1REMOVE_PERSISTENT \s0 .Sp A list of regex used to match the persistent variable names to be removed, persistent variable removal is done before any variable installation is done .IP "\(bu" 4 \&\s-1FILE\s0 and \s-1LINE \-\s0 will be used in the evaluated code 'file_name' set to the caller's file and line by default .RE .RS 2 .Sp \&\s-1NOTE: \s0\fB\s-1CODE\s0\fR or \fB\s-1CODE_FROM_FILE\s0\fR is \fBmandatory\fR. .RE .PP \&\fIReturn\fR .IP "\(bu" 2 What the code to be evaluated returns .SS "[p] VerifyAndCompleteOptions" .IX Subsection "[p] VerifyAndCompleteOptions" Helper sub for \f(CW\*(C`eval\*(C'\fR. .SS "[p] EvalCleanup" .IX Subsection "[p] EvalCleanup" Handles the package cleanup or persistent variables cleanup after a call to \f(CW\*(C`eval\*(C'\fR. .SS "[p] GetPackageName" .IX Subsection "[p] GetPackageName" Returns a canonized package name. the name is either passed as argument from the caller or a temporary package name. .SS "[p] EvalSetup" .IX Subsection "[p] EvalSetup" Handles the setup of the context before \fIeval-side\fR code is evaluated. Sets the variables and the shared subroutines. .SS "[p] VerifyCodeInput" .IX Subsection "[p] VerifyCodeInput" Verify that \fB\s-1CODE\s0\fR or \fB\s-1CODE_FROM_FILE\s0\fR are properly set. .SS "[p] RemovePersistent" .IX Subsection "[p] RemovePersistent" Handles the removal of persistent variables. .SS "[p] GetCallContextWrapper" .IX Subsection "[p] GetCallContextWrapper" Generates perl code to wrap the code to be evaluated in the right calling context. .SS "[p] SetupSafeCompartment" .IX Subsection "[p] SetupSafeCompartment" If running in safe mode, setup a safe compartment from the argument, otherwise defines the evaluation package. .SS "[p] GetInstalledVariablesCode" .IX Subsection "[p] GetInstalledVariablesCode" Generates variables on the eval-side from the \s-1INSTALL_VARIABLES\s0 definitions. Dispatches the generation to specialize subroutines. .SS "[p] GetPersistentVariablesSetFromCaller" .IX Subsection "[p] GetPersistentVariablesSetFromCaller" Generates code to make persistent variables, defined on the \fIcaller-side\fR available on the \fIeval-side\fR. .SS "[p] GetSharedVariablesSetFromCaller" .IX Subsection "[p] GetSharedVariablesSetFromCaller" Handles the mechanism used to share variables (references) between the \fIcaller-side\fR and the \fIeval-side\fR. .PP Shared variables must be defined and references. If the shared variable is \fBundef\fR, the variable that was previously shared, under the passed name, is used if it exists or an exception is raised. .PP Also check that variables are not \fB\s-1PERSISTENT\s0\fR and \fB\s-1SHARED\s0\fR. .SS "[p] GetVariablesSetFromCaller" .IX Subsection "[p] GetVariablesSetFromCaller" Generates code that creates local variables on the \fIeval-side\fR .SS "\fIGetPersistentVariableNames()\fP" .IX Subsection "GetPersistentVariableNames()" \&\fIArguments\fR \- none .PP \&\fIReturns\fR \- the list of existing persistent variables names .PP .Vb 1 \& my @persistent_variable_names = $context\->GetPersistantVariablesNames() ; .Ve .SS "GetPersistantVariables(@variable_names)" .IX Subsection "GetPersistantVariables(@variable_names)" \&\fIArguments\fR .IP "\(bu" 2 \&\f(CW@variable_names\fR \- list of variable names to retrieve .PP \&\fIReturns\fR \- list of values corresponding to the input names .PP This subroutine will return whatever the \fIcaller-site\fR set or the \fIeval-side\fR modified. Thus if you created a \fI\f(CI%hash\fI\fR persistent variable, a hash (not a hash reference) will be returned. .PP If you request multiple values, list flattening will be in effect. Be careful. .PP .Vb 7 \& my $context = new Eval::Context \& ( \& INSTALL_VARIABLES => \& [ \& [\*(Aq%hash\*(Aq => \e%hash_caller_side => $Eval::Context::PERSISTENT] \& ] , \& ) ; \& \& $context\->Eval(CODE => \*(Aq$hash{A}++ ;\*(Aq) ; \& \& # may throw exception \& my %hash_after_eval = $context\->GetPersistantVariables(\*(Aq%hash\*(Aq) ; .Ve .SS "[p] SetEvalSidePersistenceHandlers" .IX Subsection "[p] SetEvalSidePersistenceHandlers" Set the code needed to handle \fIeval-side\fR persistent variables. .SS "[p] RemoveEvalSidePersistenceHandlers" .IX Subsection "[p] RemoveEvalSidePersistenceHandlers" Removes \fIeval-side\fR persistent variable handlers. Used after calling \f(CW\*(C`eval\*(C'\fR so the next \f(CW\*(C`eval\*(C'\fR can not access \fIeval-side\fR persistent variables without being allowed to do so. .SH "BUGS AND LIMITATIONS" .IX Header "BUGS AND LIMITATIONS" I have reported a very strange error when \fBSafe\fR and \fBCarp\fR are used together. . The error can be reproduced without using \fBEval::Context\fR. .SH "AUTHOR" .IX Header "AUTHOR" .Vb 3 \& Khemir Nadim ibn Hamouda \& CPAN ID: NKH \& mailto:nadim@khemir.net .Ve .SH "LICENSE AND COPYRIGHT" .IX Header "LICENSE AND COPYRIGHT" This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "SUPPORT" .IX Header "SUPPORT" You can find documentation for this module with the perldoc command. .PP .Vb 1 \& perldoc Eval::Context .Ve .PP You can also look for information at: .IP "\(bu" 4 AnnoCPAN: Annotated \s-1CPAN\s0 documentation .Sp .IP "\(bu" 4 \&\s-1RT: CPAN\s0's request tracker .Sp Please report any bugs or feature requests to L . .Sp We will be notified, and then you'll automatically be notified of progress on your bug as we make changes. .IP "\(bu" 4 Search \s-1CPAN\s0 .Sp