I have set up an issue with a more concrete proposal for better separation of concerns in the templates.
I believe this would allow us to isolate PSGI and CGI-related code in one or two places only (request parsing and the request wrappers) for new code and break them entirely out of the template's responsibility.