Interface Evaluator
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
EvaluatorImpl
VmEvalException if
an error occurs during evaluation.
Evaluated modules, and modules imported by them, are cached based on their origin. This is
important to guarantee consistent evaluation results, for example when the same module is used by
multiple other modules. To reset the cache, close() the current instance and create a
new one.
Construct an evaluator through EvaluatorBuilder.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Releases all resources held by this evaluator.evaluate(ModuleSource moduleSource) Evaluates the module, returning the Java representation of the module object.evaluateExpression(ModuleSource moduleSource, String expression) Evaluates the Pkl expression represented asexpression, returning the Java representation of the result.byte[]evaluateExpressionPklBinary(ModuleSource moduleSource, String expression) Evaluates the Pkl expression represented asexpression, returning a byte array of thepkl-binary-encoded representation of the result.evaluateExpressionString(ModuleSource moduleSource, String expression) Evaluates the Pkl expression, returning the stringified result.byte[]evaluateOutputBytes(ModuleSource moduleSource) Evaluates a module'soutput.bytesproperty.evaluateOutputFiles(ModuleSource moduleSource) Evaluates a module'soutput.filesproperty.evaluateOutputText(ModuleSource moduleSource) Evaluates a module'soutput.textproperty.evaluateOutputValue(ModuleSource moduleSource) Evaluates a module'soutput.valueproperty.<T> TevaluateOutputValueAs(ModuleSource moduleSource, PClassInfo<T> classInfo) Evaluates the module'soutput.valueproperty, and validates that its type matches the provided class info.evaluateSchema(ModuleSource moduleSource) Evaluates the module's schema, which describes the properties, methods, and classes of a module.evaluateTest(ModuleSource moduleSource, boolean overwrite) Runs tests within the module, and returns the test results.static EvaluatorShorthand forEvaluatorBuilder.preconfigured().build().
-
Method Details
-
preconfigured
Shorthand forEvaluatorBuilder.preconfigured().build(). -
evaluate
Evaluates the module, returning the Java representation of the module object.- Throws:
PklException- if an error occurs during evaluationIllegalStateException- if this evaluator has already been closed
-
evaluateOutputText
Evaluates a module'soutput.textproperty.- Throws:
PklException- if an error occurs during evaluationIllegalStateException- if this evaluator has already been closed
-
evaluateOutputBytes
Evaluates a module'soutput.bytesproperty.- Throws:
PklException- if an error occurs during evaluationIllegalStateException- if this evaluator has already been closed- Since:
- 0.29.0
-
evaluateOutputValue
Evaluates a module'soutput.valueproperty.- Throws:
PklException- if an error occurs during evaluationIllegalStateException- if this evaluator has already been closed
-
evaluateOutputFiles
Evaluates a module'soutput.filesproperty.- Throws:
PklException- if an error occurs during evaluationIllegalStateException- if this evaluator has already been closed
-
evaluateExpression
Evaluates the Pkl expression represented asexpression, returning the Java representation of the result.The following table describes how Pkl types are represented in Java:
Pkl type Java type Null PNullString StringBoolean BooleanInt LongFloat DoubleTyped, Dynamic PObject(PModuleif the object is a module)Mapping, Map MapListing, List ListSet SetPair PairRegex PatternDataSize DataSizeDuration DurationClass PClassTypeAlias TypeAliasBytes byte[]The following Pkl types have no Java representation, and an error is thrown if an expression computes to a value of these types:
- IntSeq
- Function
- Throws:
PklException- if an error occurs during evaluationIllegalStateException- if this evaluator has already been closed
-
evaluateExpressionPklBinary
Evaluates the Pkl expression represented asexpression, returning a byte array of thepkl-binary-encoded representation of the result.- Throws:
PklException- if an error occurs during evaluationIllegalStateException- if this evaluator has already been closed
-
evaluateExpressionString
Evaluates the Pkl expression, returning the stringified result.This is equivalent to wrapping the expression with
.toString()- Throws:
PklException- if an error occurs during evaluationIllegalStateException- if this evaluator has already been closed
-
evaluateSchema
Evaluates the module's schema, which describes the properties, methods, and classes of a module.- Throws:
PklException- if an error occurs during evaluationIllegalStateException- if this evaluator has already been closed
-
evaluateOutputValueAs
Evaluates the module'soutput.valueproperty, and validates that its type matches the provided class info.- Throws:
PklException- if an error occurs during evaluationIllegalStateException- if this evaluator has already been closed
-
evaluateTest
Runs tests within the module, and returns the test results.This requires that the target module be a test module; it must either amend or extend module
"pkl:test". Otherwise, a type mismatch error is thrown.This method will write possibly
pkl-expected.pcfandpkl-actual.pcffiles as a sibling of the test module. Theoverwriteparameter causes the evaluator to overwritepkl-expected.pklfiles if they currently exist.- Throws:
PklException- if an error occurs during evaluationIllegalStateException- if this evaluator has already been closed
-
close
void close()Releases all resources held by this evaluator. If anevaluatemethod is currently executing, this method blocks until cancellation of that execution has completed.Once an evaluator has been closed, it can no longer be used, and calling
evaluatemethods will throwIllegalStateException. However, objects previously returned byevaluatemethods remain valid.- Specified by:
closein interfaceAutoCloseable
-