The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

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

VERSION

version 1.00

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 Dancer2 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 Dancer2::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

D Ruth Holloway <ruth@hiruthie.me>

COPYRIGHT AND LICENSE

This software is copyright (c) 2020 by D Ruth Holloway.

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