A Perl interpreter context. This is the main class
for executing Perl code in the managed world.
Interpreter Constructor
public Interpreter ()
Creates a new instance of a Perl interpreter with taint checking and warnings.
Interpreter Constructor
public
Interpreter (
bool taintcheck,
bool warnings)
Creates a new instance of a Perl interpreter.
Parameters
- taintcheck
- Whether taint checking should be performed.
- warnings
- Whether warnings should be enabled.
Interpreter Constructor
Creates a new Perl interpreter whose state is cloned from the given interpreter.
Parameters
- clonedFrom
- The interpreter whose state is to be cloned.
WarnHandler
The handler for when warnings are emitted by Perl code.
Remarks
WarnHandler is set to a default handler which prints warnings to Console.Error, much like Perl itself would do. Set this field to trap warnings.
A warn signal handler (in Perl) is installed by PerlSharp when an interpreter is created. If the signal handler is removed, WarnHandler will never be called.
Require
Loads (require's) in the specified file.
Parameters
- file
- The name of the Perl file to load. Either an absolute path or relative to something in @INC.
Exceptions
Remarks
This is equivalent to Perl's "require" statement. Perl will search @INC, just like if Eval("require $file") was called.
Use
Loads a package to be used.
Parameters
- package
- The name of the package to use (i.e. XML::LibXML)
Remarks
This is equivalent to Perl's use statement.
Eval
Evaluates the Perl expression.
Parameters
- expression
- The string expression to evaluate.
Returns
The value of the expression, as a Perl.Value.
Exceptions
Remarks
Expressions are evaluated in a "scalar context." Expressions
that return arrays or hashes will come back into the managed world
as a single scalar, possibly the number of elements returned.
Use references to array or hashes to pass them back to managed code.
Call
Calls a subroutine.
Parameters
- subroutine
- The name of the sub to call.
- args
- The arguments to pass to the sub. Managed objects will be converted to Perl.Value's.
Returns
The return value of calling the sub.
Exceptions
Remarks
See Eval.
CallParams
Calls a sub, with parameters passed as a param array.
Parameters
- subroutine
- The name of the sub to call.
- args
- The arguments to pass to the sub. Managed objects will be converted to Perl.Value's.
Returns
The return value of calling the sub.
Exceptions
Remarks
See Call(string,object[]).
Call
Calls a subroutine.
Parameters
- subroutine
- The subroutine to call. This can be a
string-valued scalar with the name of the subroutine,
or a Code object that references a sub.
- args
- The arguments to pass to the sub. Managed objects will be converted to Perl.Value's.
Returns
The return value of the call to the sub.
Exceptions
Remarks
See Call(string,object[]).
EvalUnwrap
Evaluates the expression and unwraps the return value if it is a reference.
Parameters
- expression
- The expression to evaluate.
Returns
The result of evaluating the expression. If a reference results, it is dereferenced first.
Exceptions
Remarks
This is a helper function that merely wraps Eval(string).
GetArray
Returns the global array with the given name.
Parameters
- name
- The name of the variable. Omit the "@".
Returns
The variable "@name".
Remarks
The actual variable is returned. Modifications
to the return of this function will alter the variable itself.
The variable is created if it doesn't exist.
GetArray
Returns the global array with the given name.
Parameters
- name
- The name of the variable. Omit the "@".
- create
- Whether to create the variable if it is not already defined.
Returns
The variable "@name", or null if it is not defined and create is false.
Remarks
The actual variable is returned. Modifications
to the return of this function will alter the variable itself.
GetHash
Returns the global hash with the given name.
Parameters
- name
- The name of the variable. Omit the "%".
Returns
The variable "%name".
Remarks
The actual variable is returned. Modifications
to the return of this function will alter the variable itself.
The variable is created if it doesn't exist.
GetHash
Returns the global hash with the given name.
Parameters
- name
- The name of the variable. Omit the "%".
- create
- Whether to create the variable if it is not already defined.
Returns
The variable "%name", or null if it is not defined and create is false.
Remarks
The actual variable is returned. Modifications
to the return of this function will alter the variable itself.
GetScalar
Returns the global scalar with the given name.
Parameters
- name
- The name of the variable. Omit the "$".
Returns
The variable "$name".
Remarks
The actual variable is returned. Modifications
to the return of this function will alter the variable itself.
The variable is created if it doesn't exist.
GetScalar
Returns the global scalar with the given name.
Parameters
- name
- The name of the variable.
- create
- Whether to create the variable if it is not already defined.
Returns
The variable "$name", or null if it is not defined and create is false.
Remarks
The actual variable is returned. Modifications
to the return of this function will alter the variable itself.
GetReference
Returns the global reference (ref, blessed object, code ref) with the given name.
Parameters
- name
- The name of the variable.
Returns
The variable "$name", or null if it is not defined.
If $name is a scalar, a Scalar is returned. Otherwise, one of the
reference types (Reference, Code, Blessed) may be returned.
Remarks
The actual variable is returned. Modifications
to the return of this function will alter the variable itself.
AddExtensionObject
Defines a Perl package that interfaces into the managed world.
Parameters
- obj
- The extension object.
Remarks
The public methods of the extension object are added into
the Perl package with the same name as the object's type's full name,
but with periods replaced by double colons. (e.g. Perl::Interpreter)
Calls to subs in that package invoke members of obj.
AddExtensionObject
Defines a Perl package that interfaces into the managed world.
Parameters
- package
- The name of the Perl package to add the methods into.
- obj
- The extension object.
Remarks
The public methods of the extension object are added into
the specified Perl package. Calls to subs in that package invoke
the methods of obj.
AddSimpleExtension
Defines a Perl sub in the main package that interfaces into the managed world.
Parameters
- target
- The instance of the object to invoke the method on, or null if method is static.
- method
- The instance or static method to invoke.
Remarks
The method is defind in Perl with the same name as the method.
Calling this with System.Console.WriteLine as method will result in
the creation of a Perl sub named "WriteLine" that when called will
invoke System.Console.WriteLine.
AddSimpleExtension
Defines a Perl sub in the main package that interfaces into the managed world.
Parameters
- target
- The instance of the object to invoke the method on.
- method
- The name of the instance or static method of target to invoke.
Remarks
The method is defind in Perl with the same name as the method.
AddExtension
Defines a named Perl sub that interfaces into the managed world.
Parameters
- target
- The instance of the object to invoke the method on, or null if method is static.
- method
- The instance or static method to invoke.
Remarks
The method is defind in Perl with the same name as the method
in the package with the same name as the declaring type of the method,
but with periods replaced by double colons.
Calling this with System.Console.WriteLine as method will result in
the creation of a Perl sub named "System::Console::WriteLine" that when called will
invoke System.Console.WriteLine.
AddExtension
Defines a Perl sub in the named package that interfaces into the managed world.
Parameters
- name
- The Perl name for the subroutine. A package can be specified.
- target
- The instance of the object to invoke the method on, or null if method is static.
- method
- The instance or static method to invoke.
AddExtension
Defines a Perl sub that is a callback to a delegate.
Parameters
- deleg
- The delegate to call when the Perl sub is invoked.
Remarks
The delegate is created in the Perl package named by the
declaring type of the method the delegate refers to. See
AddExtension(object,System.Reflection.MethodInfo).
AddExtension
Defines a Perl sub that is a callback to a delegate.
Parameters
- name
- The Perl name for the sub. A package may be specified.
- deleg
- The delegate to call when the Perl sub is invoked.
Remarks
See AddExtension(string,object,System.Reflection.MethodInfo).
Convert
Converts a managed object into one of the Value types.
Parameters
- value
- The object to convert.
Returns
The Value corresponding to the object.
Remarks
The following conversions are performed: Values are returned unchanged.
IDictionary objects are returned as Hashes, with its keys and values similarly converted.
ICollection objects are returned as Arrays, with its elements similarly converted.
Everything else is converted to a Scalar. Numeric and string types are converted directly to Scalars. For other types, the return value of ToString called on them is used.
Convert
Converts a Value object to the usual managed equivalent.
Parameters
- value
- The Perl object to convert.
Returns
The managed object.
Remarks
The following conversions are made:
Arrays are converted to ArrayLists.
Hashes are converted to Hashtables.
The elements of Arrays and Hashes are not converted.
Scalars are converted to strings.
References are dereferenced before conversion.
Anything else is converted to null.
Convert
Converts a Value object to another type.
Parameters
- value
- The Perl object to convert.
- select
- The type of object to convert to.
Returns
The converted object.
Remarks
The following conversions are made:
If value is assignable to select and select is not Object, value is returned unchanged.
If select is ArrayList or one of its ancestors and value is an Array, an ArrayList is returned.
If select is Hashtable or one of its ancestors and value is a Hash, then a Hashtable is returned.
The elements of Arrays and Hashes are not converted.
Scalars are converted to ints, longs, floats, doubles, and strings if one of those types is specified as select. Otherwise, Scalars are converted to strings.
References are dereferenced before conversion.
Anything else is converted to null.