|P is for Practical|
Web presentation patterns, MVC, and reinventing the wheelby relax99 (Monk)
|on Jan 30, 2003 at 20:02 UTC||Need Help??|
relax99 has asked for the
wisdom of the Perl Monks concerning the following question:
Not so long ago I discovered that it is a good idea to use MVC web presentation pattern when programming complex web applications. I was able to get bits and pieces on how to do that from the article on perl.com "Building a Large-scale E-commerce site with Apache and mod_perl" which I'm sure most of you are familiar with. Then, the same pattern is described in "Pattens of Enterprise Application Architecture" by Martin Fowler and numerous articles online. However, the examples there are in Java. I haven't been able to find any good examples of how to structure a web application in Perl. All Perl books contain rather beginner information on CGI and they don't have any information on how to structure big real world web applications in Perl.
Before, the way I structured my code was to separate the model in one or few Perl modules and have the main script use instances of these models. The main script would proceed based on the actions from the user and is generally structured as a huge switch statement like the one below. The web pages are based on HTML templates with dynamic data inserted into them before they're sent to the browser.
This approach worked for me, but I wonder if there's something better? I'm mostly concerned with reuse and maintainability issues.
One other approach that I saw was to use CGI::Application, but it is really the same as my switch statement when you look close at it.
Please feel free to share your thoughts on what a good way to structure a complex web application in Perl is. Right now I feel like I'm reinventing the wheel, because I basically have to come up with the same conclusion and MVC-like structure as, I'm sure, many people had already. (In companies that use Perl as one of their main development languages). It's really frustrating how Perl books teach you CGI programming, but almost never go beyond using HTML-generating functions in CGI.pm (bad idea!)
Do you know of any
Thanks a lot in advance!