NAME
Template::Mustache::Trait - turn an attribute into a Mustache template
VERSION
version 1.4.0
SYNOPSIS
package Foo;
use Moose;
use Template::Mustache::Trait;
has greet => (
is => 'ro',
traits => [ 'Mustache' ],
default => 'Hello {{ name }}',
lazy => 1,
handles => { greeting => 'render' },
);
has bye => (
is => 'ro',
traits => [ 'Mustache' ],
default => 'Bye {{ name }}',
lazy => 1,
handles => { see_ya => 'render' },
);
has name => (
is => 'rw',
default => 'world'
);
# ... later on ...
say Foo->new->greet; # => Hello world
DESCRIPTION
This trait expects the default value to be either a Mustache template string or a function returning a template string. It will turns this template into a Template::Mustache object using the parent object as its context. I.e.,
has greet => (
is => 'ro',
traits => [ 'Mustache' ],
default => 'Hello {{ name }}',
lazy => 1,
handles => { greeting => 'render' },
);
# equivalent to
has greet => (
is => 'ro',
default => sub {
my $self = shift;
return Template::Mustache->new(
template=> 'Hello {{ name }}',
context => $self
);
},
lazy => 1,
handles => { greeting => 'render' },
);
AUTHORS
Pieter van de Bruggen <pvande@cpan.org>
Yanick Champoux <yanick@cpan.org>
Ricardo Signes <rjbs@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2022, 2021, 2019, 2018, 2017, 2016, 2015, 2011 by Pieter van de Bruggen.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.