Templating with Perl

One of my duties, as I explained in my last post is to automate things, as everything we allow to be done by human hands causes the chance for error to increase. So scripting things not only reduces that chance for error, but also speeds the process along.

When I started the automation process a month ago, I first tried using the template files that our ESP provided. I'd download the contents when performing a run, make my replacements, and upload the content. Except, the only way for me to do that, and still allow humans to manage it (later) was to apply some CSS classes and IDs, and use some DOM manipulation to place content.

Unfortunately, this setup started to fall apart very quickly, when I realized that I'd need to be able to loop over an existing set of data, and add the contents. So, after about a day, I tossed that idea to the side. I knew that I'd need a templating language, and I'd worked with HTML::Template before, so I wanted to give that a try.

However, we generate different content for each of our 8 sites. As our ESP didn't allow us to use a single master template, we had a different template for each account. This meant 8 templates, which meant 8 sets of updates that would need to be propagated across the templates. I made the executive decision to bring the template file down to my local box, and work there.

During this time, it was determined that two pieces of content would need to be included, per site, for each of the entries. So I created a couple of files for each of the sites. Working through the template, I decided to just <TMPL_INCLUDE> these files. Except that HTML::Template doesn't allow you to include files based on a variable. This meant that it was out.

I went to #perl to determine my next step. They suggested I use Template::Toolkit. After about 10 minutes of research, it was determined that it would be a perfect replacement for my solution. 20 minutes later, and I had a working solution.