Template::Mustache::Trait - turn an attribute into a Mustache template
version 1.4.0
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
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' }, );
Pieter van de Bruggen <pvande@cpan.org>
Yanick Champoux <yanick@cpan.org>
Ricardo Signes <rjbs@cpan.org>
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.
To install Template::Mustache, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Template::Mustache
CPAN shell
perl -MCPAN -e shell install Template::Mustache
For more information on module installation, please visit the detailed CPAN module installation guide.