NAME

Punk::View::Stencil - the Template::Stencil view engine

SYNOPSIS

views Stencil => {
    template_dir => 'root/templates',
    wrapper      => 'layout.tmpl',
    filters      => { money => sub { sprintf '%.2f', $_[0] } },
};

# in a controller
return $c->render('book/list', { books => $page->{rows} });

DESCRIPTION

The options hashref is handed to "new" in Template::Stencil untouched; see there for the full set (template_dir, wrapper, filters, auto_escape, strict, cache, ...). Template names resolve against template_dir with .tmpl inference, so render('book/list', ...) renders root/templates/book/list.tmpl inside the wrapper layout.

The class is entirely XS. The object is two array slots - the options as registered and the Template::Stencil object built from them - and render reaches the template VM through Stencil's own C ABI, so no Perl frame sits between the dispatcher and the engine.

Punk::Views constructs the view once per worker, handing the registered options to new as a single positional argument, and new builds the Stencil engine there and then - so an engine that will not construct fails at boot along with the rest of the configuration rather than on the first render. Editing a template takes effect without a restart through Stencil's mtime cache.

This needs Template::Stencil 0.02 or newer, which is where that ABI arrived. There is no Perl render path behind it: an engine too old to provide the ABI croaks when the view is constructed, naming the version required, rather than starting an application whose pages cannot render.

SLOTS

opts

The options the engine was registered with (an empty hashref by default).

engine

The underlying Template::Stencil, built by BUILD.

METHODS

new(\%opts)

render($template, \%data)

The two-method engine contract; render returns UTF-8 bytes.

SEE ALSO

Template::Stencil, Punk::Views.

AUTHOR

LNATION <email@lnation.org>

LICENSE AND COPYRIGHT

This software is Copyright (c) 2026 by LNATION <email@lnation.org>.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)