You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use Template::Mustache;
# Call .render as a class method
Template::Mustache.render('Hello, {{planet}}!', { planet =>'world' }).say;
# Or instantiate an instancemy$stache= Template::Mustache.new::from<./views>;
# Subroutines are calledsay$stache.render('The time is {{time}}', {
time => { ~DateTime.new(now).local }
});
my@people=
{ :name('James T. Kirk'), :title<Captain> },
{ :name('Wesley'), :title('Dread Pirate'), :emcee },
{ :name('Dana Scully'), :title('Special Agent') },
;
# See this template in ./t/views/roster.mustache$stache.render('roster', { :@people }).say;
my%context=event =>'Masters of the Universe Convention',
:@people,
;
my%partials=welcome =>qq:b{Welcome to the {{event}}! We’re pleased to have you here.\n\n},
;
# See this result in ./t/50-readme.t
Template::Mustache.render(q:to/EOF/,
{{> welcome}} {{> roster}} Dinner at 7PM in the Grand Ballroom. Bring a chair! EOF%context,
:from([%partials, './views'])
).say;
Description
Logging
Log levels
Messages are logged with varying severity levels (from most to least severe): Fatal, Error, Warn, Info, Verbose, Audit, Debug, Trace, Trace2
By default, only messages of Error or worse are logged. That default can be changed with the TEMPLATE_MUSTACHE_LOGLEVEL environment variable.
TEMPLATE_MUSTACHE_LOGLEVEL=Debug
The default is overridden with the :log-level option to Template::Mustache.new, or a Template::Mustache::Logger object can be passed via the :logger option.
By default, any messages at level Warn or worse are logged with the warn routine. A CONTROL block can handle such warnings if needed; see Language/phasers for details. Less severe messages (Info and up) are logged with the note routine.
The routine can be set per log level, in the Template::Mustache::Logger.routines hash.
# Use say instead of note for Info and up; the more severe# levels (C<Warn> down to C<Fatal>) still use the warn routinemy$stache= Template::Mustache.new::log-routine(&say);
# But even those can be set explicitly$stache.logger.routines{$_} =&diefor <Warn Error Fatal>;
$stache.render:'{{missing}}', {}; # dies
method log
multi method log(Exception $exception, LogLevel :$level)
Specify :pragma<KEEP-UNUSED-VARIABLES> to either Template::Mustache.new or .render, and any variables which are not defined in the data context will be kept in the rendered text. See t/13-pragmas.t for examples.
More Examples and Tests
The Mustache spec provides a wealth of examples to demonstrate exactly how the format behaves.