Introducing Template::Plugin::StashValidate

I've been using MooseX::Params::Validate more and more recently for checking incoming parameters. I'm a big fan of the Moose type system, and love the implicit documentation you get from having a block at the top of your sub that lays out exactly what you're expecting to be passed in.

A coworker was recently looking for something similar for Template Toolkit - rather than simply digging around in the Stash for values that you hope are there (and are the right type), could you actually insist that they were there? I said I thought it was a pretty simple plugin, and then went about proving it...

Template::Plugin::StashValidate allows you to specify a minimum set of values (and their types) that your Template Toolkit template is expecting to recieve. You invoke it as a plugin, with exactly the same arguments as MooseX::Params::Validate:

[% USE StashValidate {
'advice_discrepant' => { 'isa' => 'ArrayRef | HashRef', 'optional' => 1 },
'title' => { 'isa' => 'Str', default' => 'My great page' }
} %]

Leave a comment

About Peter Sergeant

user-pic I blog about Perl.