Package org.pkl.core

Class EvaluatorImpl

java.lang.Object
org.pkl.core.EvaluatorImpl
All Implemented Interfaces:
AutoCloseable, Evaluator

public final class EvaluatorImpl extends Object implements Evaluator
  • Constructor Details

  • Method Details

    • evaluate

      public PModule evaluate(ModuleSource moduleSource)
      Description copied from interface: Evaluator
      Evaluates the module, returning the Java representation of the module object.
      Specified by:
      evaluate in interface Evaluator
    • evaluateOutputText

      public String evaluateOutputText(ModuleSource moduleSource)
      Description copied from interface: Evaluator
      Evaluates a module's output.text property.
      Specified by:
      evaluateOutputText in interface Evaluator
    • evaluateOutputBytes

      public byte[] evaluateOutputBytes(ModuleSource moduleSource)
      Description copied from interface: Evaluator
      Evaluates a module's output.bytes property.
      Specified by:
      evaluateOutputBytes in interface Evaluator
    • evaluateOutputValue

      public Object evaluateOutputValue(ModuleSource moduleSource)
      Description copied from interface: Evaluator
      Evaluates a module's output.value property.
      Specified by:
      evaluateOutputValue in interface Evaluator
    • evaluateOutputFiles

      public Map<String,FileOutput> evaluateOutputFiles(ModuleSource moduleSource)
      Description copied from interface: Evaluator
      Evaluates a module's output.files property.
      Specified by:
      evaluateOutputFiles in interface Evaluator
    • evaluateExpression

      public Object evaluateExpression(ModuleSource moduleSource, String expression)
      Description copied from interface: Evaluator
      Evaluates the Pkl expression represented as expression, returning the Java representation of the result.

      The following table describes how Pkl types are represented in Java:

      Pkl type Java type
      Null PNull
      String String
      Boolean Boolean
      Int Long
      Float Double
      Typed, Dynamic PObject (PModule if the object is a module)
      Mapping, Map Map
      Listing, List List
      Set Set
      Pair Pair
      Regex Pattern
      DataSize DataSize
      Duration Duration
      Class PClass
      TypeAlias TypeAlias
      Bytes 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
      Specified by:
      evaluateExpression in interface Evaluator
    • evaluateExpressionPklBinary

      public byte[] evaluateExpressionPklBinary(ModuleSource moduleSource, String expression)
      Description copied from interface: Evaluator
      Evaluates the Pkl expression represented as expression, returning a byte array of the pkl-binary-encoded representation of the result.
      Specified by:
      evaluateExpressionPklBinary in interface Evaluator
    • evaluateExpressionString

      public String evaluateExpressionString(ModuleSource moduleSource, String expression)
      Description copied from interface: Evaluator
      Evaluates the Pkl expression, returning the stringified result.

      This is equivalent to wrapping the expression with .toString()

      Specified by:
      evaluateExpressionString in interface Evaluator
    • evaluateSchema

      public ModuleSchema evaluateSchema(ModuleSource moduleSource)
      Description copied from interface: Evaluator
      Evaluates the module's schema, which describes the properties, methods, and classes of a module.
      Specified by:
      evaluateSchema in interface Evaluator
    • evaluateTest

      public TestResults evaluateTest(ModuleSource moduleSource, boolean overwrite)
      Description copied from interface: Evaluator
      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.pcf and pkl-actual.pcf files as a sibling of the test module. The overwrite parameter causes the evaluator to overwrite pkl-expected.pkl files if they currently exist.

      Specified by:
      evaluateTest in interface Evaluator
    • evaluateCommand

      public void evaluateCommand(ModuleSource moduleSource, Set<String> reservedFlagNames, Set<String> reservedFlagShortNames, Consumer<CommandSpec> run)
      Description copied from interface: Evaluator
      Parses the command module into a spec that describes the CLI options and subcommands.

      This requires that the target module be a "pkl:Command" instance.

      Unlike other evaluator methods, the resulting CommandSpec must be handled in a closure. This is because specs must be applied to parsed CLI options to produce command state that is eventually evaluated, which must happen in the active context of an evaluator.

      Specified by:
      evaluateCommand in interface Evaluator
    • evaluateOutputValueAs

      public <T> T evaluateOutputValueAs(ModuleSource moduleSource, PClassInfo<T> classInfo)
      Description copied from interface: Evaluator
      Evaluates the module's output.value property, and validates that its type matches the provided class info.
      Specified by:
      evaluateOutputValueAs in interface Evaluator
    • close

      public void close()
      Description copied from interface: Evaluator
      Releases all resources held by this evaluator. If an evaluate method 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 evaluate methods will throw IllegalStateException. However, objects previously returned by evaluate methods remain valid.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Evaluator