http://www.perlmonks.org?node_id=328145


in reply to HTML::Template, CGI:Application and design methodologies

Take a step back from your application and your CGI::Application work. As you said, with CGI::Application you must return the entire content from the method call. When you generate a webpage with your existing app, your browser cannot render or display the page until it has the entire page, so it's essentially the same thing. You could just wrap your entire bit of cgi code in a sub and then return the entire page, you'd get what you want but lose any benefits.

As for how I prefer to generate content, I say follow what you call templatizing the entire page. Try to break up your different sections into their own functions, then call them to populate your template. Hmmm, looks like I answered by saying, "both."

I wasn't really exposed to this methodology until I was involved with a largish Java j2ee web project (at which point I asked, "why don't we do this in perl," after which I discovered cgi::application and another framework and realized we did) and even more so later with a portal project. Every bit of content in the portal came from it's own object/function and the portal is just there to put a nice skin on them (using a template.)

Once you start writing this way, it becomes much easier. Code reuse and all that blah blah blah. Take the chatterbox client to the right. It doesn't care about tags, it just dumps what it's got and the site takes care of it. You could wrap the chatterbox in a table cell like it is now or wrap it with html body tags and make it a page by itself.

HTH