Some thoughts on Perl template processing
Published in
3 min readNov 2, 2021
Template processors and engines are one of those pieces of software where it seems every developer wants to reinvent the wheel. Goodness knows I’ve done it earlier in my career. Tell me if this sounds familiar:
- You need to mix data into a document so you start with Perl’s string interpolation in
"
double quotes"
orsprintf
formats. (Or maybe you investigateformat
s, but the less said about them the better.) - You realize your documents need to display things based on certain conditions, or you want to loop over a list or some other structure.
- You add these features via keyword parsing and escape characters, thinking it’s OK since this is just a small bespoke project.
- Before you know it you’ve invented another domain-specific language (DSL) and have to support it on top of the application you were trying to deliver in the first place.
Stop. Just stop. Decades of others who have walked this same path have already done this for you. Especially if you’re using a web framework like Dancer, Mojolicious, or Catalyst, where the template processor is either built-in or pluggable from CPAN. Even if you’re not developing a web application there are several general-purpose options of various capabilities like Template Toolkit and…