NAME

Dancer::Template::Handlebars::Helpers - parent class for Handlebars' helper collections

VERSION

version 0.2.2

SYNOPSIS

    package MyApp::HandlebarsHelpers;

    use parent Dancer::Template::Handlebars::Helpers;

    sub shout :Helper {
        my( $context, $text ) = @_;
        return uc $text;
    }

    sub internal_name :Helper(whisper) {
        my( $context, $text ) = @_;
        return lc $text;
    }

    1;

and then in the Dancer app config.yml:

    engines:
        handlebars:
            helpers:
                - MyApp::HandlebarsHelpers

DESCRIPTION

Base class for modules containing Handlebars helper functions. The helper functions are labelled with the :Helper attribute. A name for the helper function can be passed or, if not, will default to the sub's name.

Behind the curtain, what the attribute does is to add the tagged functions to a module-wide %HANDLEBARS_HELPERS variable, which has the function names as keys and their coderefs as values. For example, to register the functions of the SYNOPSIS without the help of Dancer::Template::Handlebars::Helpers, one could do:

    package MyApp::HandlebarsHelpers;

    our HANDLEBARS_HELPERS = (
        shout   => \&shout,
        whisper => \&internal_name,
    );

    sub shout {
        my( $context, $text ) = @_;
        return uc $text;
    }

    sub internal_name {
        my( $context, $text ) = @_;
        return lc $text;
    }

    1;

AUTHOR

Yanick Champoux <yanick@babyl.dyndns.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Yanick Champoux.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.