Think about Loose Coupling | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
How does one debug a Perl program containing multiple subroutines that generate HTML pages that use Javascript on the Web (and uses SQL to pull data from the database)? If you're very lucky, he used some sort of HTML templating module. (HTML::Template is probably the easiest to get started with.) That can help immensely because it avoids having oodles of print statements spewing out HTML code at numerous places in your code. Unfortunately, I suspect you aren't that lucky. If you're lucky, the 8,000 line file is done as a separate module (something.pm), with just a short perl program calling the initial subroutine in that module. If that's the case, it's easy to write short perl programs of your own to call subroutines in that module to test things out. For example, if there is a subroutine in the module that accepts an employee name as a parameter and returns that employee's salary, you can easily write a short perl program to call that subroutine, pass it a hard-coded name for testing purposes, and then print out the salary that is returned on the command line. That allows you to debug just that tiny segment of code from the command line, rather than dealing with the entire CGI environment in a web browser. Unfortunately, I suspect you aren't that lucky in this bit, either. If the changes you will be making are quite minor, I would recommend making the changes first and verifying that they work before doing any significant structural work. If the changes are going to be extensive, then I would suggest restructuring the existing code first to make it easier to make the future changes. Suggested modules: CGI.pm, DBI.pm, HTML::Template, Config::IniFiles, Test::More, HTML::FillInForm, CGI::Application, CGI::Application::ValidateRM. These let you easily read data from a form (via CGI.pm), read from the database (via DBI.pm), display values in an HTML page (via HTML::Template), read from a configuration file (Config::IniFiles), run automated tests to ensure that a routine that you had working earlier hasn't been broken by later changes (Test::More), pre-populate a web form (HTML::FillInForm), handle CGI interactions via run-modes (CGI::Application), and validate data entered in a form (CGI::Application::ValidateRM). An 8,000 line program without "use warnings" and "use strict" that incorporates HTML, JavaScript, and SQL without modules and automated tests is pretty much a textbook example of what NOT to drop on someone who is new to Perl. Look on the bright side -- every Perl project you have after this one will be easier! :-) Wally Hartshorn In reply to Re: Sub-initiate needs help getting started
by Wally Hartshorn
|
|