in reply to Template Toolkit and Dynamic Database Lookups

Class::DBI can basically do what you're asking for. See this article.
  • Comment on Re: Template Toolkit and Dynamic Database Lookups