kraih/mojo — pull request #403 by jberger (2012-10-25 16:54:49+00:00)
Title: Mojo::Template uses _escape function in its sandbox namespace if it exists

I was sad to see that custom escape handling was remove with 6dc78f369b612795849d97a11ed84f890e3a03b9, but I understood, the mechanism was too hackish, both as a string of Perl code and as a redefinable helper. I thought for a while and I think I have hit on something that not only helps me but helps Mojolicious as well!

This simple patch checks if the sandbox namespace already has a function named `_escape`. If not it defines one, just as before. This means that

1. The _escape function wont be overridden repeatedly (costing cycles)
2. The default string no longer needs the `no warnings 'redefine'`
3. I can put a function in my own namespace (e.g. `Mojo::Template::Sandbox::LaTeX::_escape`) and it will not be overridden