PrePAN

Sign in to PrePAN

Profile

thilp@github

GitHub: thilp PAUSE ID: THILP Bitbucket: thilp

User's Modules

Dancer2::Template::TextTemplate Text::Template engine for Dancer2

I was surprised not to find any template engine for Dancer2 based on (or working like) the excellent Text::Template. Dancer2::Template::MojoTemplate seems to tend toward the same goal (i.e. using Perl as template manipulation language), but it comes with Mojolicious and does not seem as simple as Text::Template for someone that never used Mojolicious and is afraid he will have to learn a whole second framework just for his Dancer2 template engine (that's me). Finally, Text::Template allows me to run my template code in a Safe, which I (rashly) believe MojoTemplate does not.

So I rolled up my sleeves and implemented Dancer2::Template::TextTemplate, a simple "Dancer2::Template::" wrapper around Text::Template, looking at what was done at Dancer2::Template::Toolkit. Due to the very nature of Text::Template instances (one per template file, instead of one for multiple template files like Template::Toolkit does), I also implemented a caching mechanism with CHI, although I don't know (yet) if it was a good idea. Some features are still missing (easy, planned soon): running into a Safe and using Text::Template's "PREPEND".

I've crawled the CPAN a bit but I may have missed a similar module (I was so excited, this is my first true module!). The engine itself seems to work but I've not yet tested its interface to Dancer2 (that shouldn't be a big deal).

So, first question: do you think this module is worth CPAN?

And, if yes, a second question: "Dancer2::Template::TextTemplate" came, as you might guess, quite intuitively, but do you think it is a good name?

thilp@github 1 comment