Interface ModuleKey

All Superinterfaces:
ReaderBase
All Known Implementing Classes:
ModuleKeys.ExternalResolver, ModuleKeys.ProjectPackage

public interface ModuleKey extends ReaderBase
SPI for identifying, resolving, caching, and resolving a Pkl module. Standard implementations can be created using ModuleKeys.
  • Method Details

    • getUri

      URI getUri()
      Returns the absolute URI of this module. This URI is used for identifying the module in user facing messages, for example stack traces. Typically, this URI contains all information necessary for resolving and loading the module.
    • resolve

      Resolves this module to a canonical form suitable for loading and caching the module. This may involve I/O. Throws FileNotFoundException if this module cannot be found.
      Throws:
      IOException
      SecurityManagerException
    • resolveUri

      default URI resolveUri(URI uri) throws IOException, SecurityManagerException
      Throws:
      IOException
      SecurityManagerException
    • isCached

      default boolean isCached()
      Tells if this module should be cached in memory.

      Caching a module means caching its entire evaluation state, not just its resolved URI or source code.

      Turning off module caching is mostly useful for synthetic modules that cannot be referenced (imported) from other modules. An example for this is a module representing code typed in a REPL.

    • isLocal

      default boolean isLocal()
      Tells if the modules represented by this module key is local to the environment.

      A module that is local, and also ReaderBase.hasHierarchicalUris(), supports triple-dot imports.

      As a best practice, a module key should be considered local if its source can be loaded in a low latency environment (for example, from disk or from memory). On the flip-side, a module loaded from a remove server should not be considered local.

    • getFileCacheLocation

      @Nullable default @Nullable Path getFileCacheLocation()
      The relative file cache path for this module, or null if this module should not be cached on the file system.