Changes for version 0.001 - 2026-11-17

  • First release: a Perl port of Nunjucks 3.2.4. The same template, context and options are meant to give the same output and the same error messages as the JavaScript original. Requires Perl 5.40 or newer.
  • Use Text::Nunjucks::Environment as the entry point. The top-level API of Nunjucks' index.js (configure, render, compile, render_string over a default environment) is not in this release, so Text::Nunjucks itself loads no code.
  • Included: the template pipeline, the built-in filters, the "is" tests, the globals (range, cycler, joiner) and the FileSystem and Precompiled loaders. Not included: jinja-compat, precompile and its CLI, NodeResolveLoader, WebLoader, watch, express and the browser bundles.
  • Numbers are IEEE doubles and print as JavaScript prints them on every perl, also with long double or quadmath NVs and on 32-bit perls.
  • Every class lives in its own .pm file and each module loads on its own (use Text::Nunjucks::Template, ::Context, ::Runtime::SafeString and so on). Loading a parent module (Environment, Nodes, Runtime, ...) loads its classes.
  • A render frees its Context when nothing of it is going to run any more, also for templates with macros, caller blocks, imports and includes. A macro your own Perl code keeps and calls after its render ended dies when it reads a template variable.
  • The port sets no depth limit of its own: where Nunjucks stops with a RangeError (many asyncEach items, sequential includes, a template that includes itself, a macro that calls itself) the port renders, bounded only by memory, and an endless recursion runs until memory is exhausted.
  • Paths follow the POSIX model of node's path module; Windows paths (path.win32) come later. The tests that rest on the POSIX model are skipped on Windows, all others run there.
  • See "DIFFERENCES FROM NUNJUCKS" in the Text::Nunjucks documentation for every deliberate and every known open difference, and "SECURITY" before passing template names you do not control to the FileSystem loader.

Modules

Nunjucks templating engine, ported 1:1 from the JavaScript original
1:1 port of Nunjucks src/compiler.js -- emits Perl source
The code generator, emitting Perl source (compiler.js class Compiler)
The per-render bookkeeping of variables and blocks (environment.js class Context)
Stands in for the Context of a render that is over (ADR 0021)
the on/emit surface of src/object.js EmitterObj, as a Moo role (ADR 0002)
1:1 port of Nunjucks src/environment.js -- the template Environment
1:1 port of Nunjucks src/filters.js -- the built-in filters
1:1 port of Nunjucks src/globals.js -- the built-in global functions
1:1 port of Nunjucks src/lexer.js -- the template tokenizer
One lexer token -- type, value, line and column (lexer.js token())
The template tokenizer (lexer.js class Tokenizer)
1:1 port of Nunjucks src/lib.js -- foundation utilities and escaping
Port representation of a JS built-in Error / TypeError (name + message)
Nunjucks TemplateError (src/lib.js) -- name is always 'Template render error'
1:1 port of Nunjucks src/loader.js -- the base Loader (resolve/isRelative)
1:1 port of Nunjucks src/node-loaders.js FileSystemLoader -- templates from search paths on disk
1:1 port of Nunjucks src/precompiled-loader.js -- templates from precompiled code objects
AST node types for Text::Nunjucks, ported 1:1 from nodes.js
AST node Add (fields left, right), ported from nodes.js
AST node And (fields left, right), ported from nodes.js
AST node Array (fields children), ported from nodes.js
AST node AsyncAll (fields arr, name, body, else_), ported from nodes.js
AST node AsyncEach (fields arr, name, body, else_), ported from nodes.js
AST node BinOp (fields left, right), ported from nodes.js
AST node Block (fields name, body), ported from nodes.js
AST node CallExtension (fields extName, prop, args, contentArgs), ported from nodes.js
AST node CallExtensionAsync (fields extName, prop, args, contentArgs), ported from nodes.js
AST node Caller (fields name, args, body), ported from nodes.js
AST node Capture (fields body), ported from nodes.js
AST node Case (fields cond, body), ported from nodes.js
AST node Compare (fields expr, ops), ported from nodes.js
AST node CompareOperand (fields expr, type), ported from nodes.js
AST node Concat (fields left, right), ported from nodes.js
AST node Dict (fields children), ported from nodes.js
AST node Div (fields left, right), ported from nodes.js
AST node Extends (fields template), ported from nodes.js
AST node Filter (fields name, args), ported from nodes.js
AST node FilterAsync (fields name, args, symbol), ported from nodes.js
AST node FloorDiv (fields left, right), ported from nodes.js
AST node For (fields arr, name, body, else_), ported from nodes.js
AST node FromImport (fields template, names, withContext), ported from nodes.js
AST node FunCall (fields name, args), ported from nodes.js
AST node Group (fields children), ported from nodes.js
AST node If (fields cond, body, else_), ported from nodes.js
AST node IfAsync (fields cond, body, else_), ported from nodes.js
AST node Import (fields template, target, withContext), ported from nodes.js
AST node In (fields left, right), ported from nodes.js
AST node Include (fields template, ignoreMissing), ported from nodes.js
AST node InlineIf (fields cond, body, else_), ported from nodes.js
AST node Is (fields left, right), ported from nodes.js
AST node KeywordArgs (fields children), ported from nodes.js
AST node Literal (fields value), ported from nodes.js
AST node LookupVal (fields target, val), ported from nodes.js
AST node Macro (fields name, args, body), ported from nodes.js
AST node Mod (fields left, right), ported from nodes.js
AST node Mul (fields left, right), ported from nodes.js
AST node Neg (fields target), ported from nodes.js
Base class of every AST node (nodes.js class Node)
AST node holding a list of child nodes (nodes.js class NodeList)
AST node Not (fields target), ported from nodes.js
AST node Or (fields left, right), ported from nodes.js
AST node Output (fields children), ported from nodes.js
AST node Pair (fields key, value), ported from nodes.js
AST node Pos (fields target), ported from nodes.js
AST node Pow (fields left, right), ported from nodes.js
AST node Root (fields children), ported from nodes.js
AST node Set (fields targets, value), ported from nodes.js
AST node Sub (fields left, right), ported from nodes.js
AST node Super (fields blockName, symbol), ported from nodes.js
AST node Switch (fields expr, cases, default), ported from nodes.js
AST node Symbol (fields value), ported from nodes.js
AST node TemplateData (fields value), ported from nodes.js
AST node TemplateRef (fields template), ported from nodes.js
AST node UnaryOp (fields target), ported from nodes.js
Abstract AST node with a value field (nodes.js class Value)
1:1 port of Nunjucks src/parser.js -- the recursive-descent parser
The recursive-descent parser (parser.js class Parser)
1:1 port of Nunjucks src/runtime.js -- frames, macros, member lookup
A scope of template variables (runtime.js class Frame)
Marker class for keyword arguments, the __keywords hash (ADR 0009)
The JS null sentinel (ADR 0006)
A template regex literal, with the members of a JS RegExp (ADR 0013)
A string marked as safe from autoescaping (runtime.js SafeString)
A compiled template that renders (environment.js class Template)
1:1 port of Nunjucks src/tests.js -- the built-in `is` tests
1:1 port of Nunjucks src/transformer.js -- the async CPS rewrite