in reply to Template engine question
Not exactly as you want, but Template::Toolkit allows you to make SQL query directly from your template.