GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Template::Mustache::Trait(3) User Contributed Perl Documentation Template::Mustache::Trait(3)

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.

2022-03-03 perl v5.40.2

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.