Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best approach to migrate a CGI to a Framework?

i have a big web application running in perl CGI. It's running ok, it's well written, but as it was done in the past, all the html are defined hardcoded in the CGI calls, so as you could imagine, it's hard to mantain, improve and etc. So now i would like to start to add some templating and integrate with a framework (catalyst or CGI::application). My question is: Somebody here has an experience like that? There is any things that i must pay attention for? I'm aware that with both frameworks i can run native CGI scripts, so it's good because i can run both (CGI native ad "frameworked" code) together without any trauma. Any tips?

like image 770
VP. Avatar asked Sep 29 '08 09:09

VP.


2 Answers

Write tests first (for example with Test::WWW::Mechanize). Then when you change things you always know if something breaks, and what it is that breaks.

Then extract HTML into templates, and commonly used subs into modules. After that it's a piece of cake to switch to a framework.

In general, go step by step so that you always have a working application.

like image 90
moritz Avatar answered Oct 22 '22 00:10

moritz


Extricate the HTML from the processing logic in the CGI script. Identify all code that affects the HTML output, as these are candidates for becoming template variables. Separate that into a HTML file, with the identified parts marked with template variables. Eventually you will be able to refactor the page such that all processing is done at the start of the code and the HTML template just called up at the end of all processing.

like image 27
cruizer Avatar answered Oct 21 '22 23:10

cruizer