This would make a good Template::Toolkit
plugin
.