For Mustache Templates in Perl, use Text::Caml

I like Mustache templates. Unfortunately, the obvious Mustache parser in Perl (Template::Mustache) is under-documented, over-documented, and not worth documenting. It has little example code and doesn’t make it at all clear that you basically have to subclass it for any real use.

Fortunately, this problem has been solved in Text::Caml. My one issue is that it’s too sensitive to whitespace. It’s good to give your eyes a resting place for sections and partials, like this:

{{# section}}
    {{> partial}}
{{/ section}}

But Text::Caml will consider the leading whitespace as part of the name. Looking over the main Mustache docs, none of the examples show leading whitespace, and it’s never specified what to do with whitespace. So I guess Text::Caml isn’t technically wrong. I just don’t like it this way.

Other than that, it’s great.

Edit: Turns out the Mustache spec does say that partials and sections should be insensitive to whitespace:

https://github.com/mustache/spec/blob/master/specs/partials.yml (starting line 104)
https://github.com/mustache/spec/blob/master/specs/sections.yml (starting line 252)

Edit 2: I reported the whitespace issue to the author’s github issue tracker, expecting it to be a fairly low priority. He ended up fixing it the next day :)