Solved

Debugging CGI app written in Perl and run on Apache.

Posted on 2010-09-11
6
675 Views
Last Modified: 2013-12-25
Hi, what is the best way of debugging CGI application written in perl and run with Apache Web Server?

For now I'm using print STDERR "debug text" and watching error logs, but that's quite inefficient.
0
Comment
Question by:DalHorinek
6 Comments
 
LVL 10

Expert Comment

by:jeromee
ID: 33654324
DalHorinek,
here's the best way to go about it... It's a bit difficult to set up at first but once you are set up there's no better way.
I assume that you use your cgi app to handle HTML"form".
make sure that you use the GET (vs POST) way of submitting forms which look like this once your form has been subnitted: http://my.website.com/cgi-bin/my_app.pl?arg1=val1&arg2=val2 where 2 arguments are being passed arg1 arg2 with the respective values val1 and val2.

Now to debug the application, locate the cgi application on the disk...say /home/apache/cgi-bin/my_app.pl
   * go to /home/apache/cgi-bin
   * perl -d cgi-bin/my_app.pl  "arg1=val1&arg2=val2"
(note that arg1=val1&arg2=val2 is exactly the same as the ones listed in the URL above)

From that point on, you are under the Perl debugger (more info here: http://perldoc.perl.org/perldebug.html) which is the best way to debug an Perl app.

Note that most of the time your application will be running as the user nobody with a limited shell environment. So, to fully replicate the way your app is run by Apache, you may need to log in as nobody.

Good luck!

0
 
LVL 48

Expert Comment

by:Tintin
ID: 33654597
Are you trying to debug errors or logic?
0
 
LVL 6

Author Comment

by:DalHorinek
ID: 33654695
Both, I'd love something like breakpoints and inspector, at least the inspector to watch what is where ..

I know about embedded debugger, anyway I use CGI module for handling and some around functions and so on, is CGI module able to handle params passed as arguments when run from command line?

Also there is question about sessions ...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
ID: 33654802
I almost always use the Template Toolkit for generating web pages.
http://search.cpan.org/~abw/Template-Toolkit-2.22/lib/Template.pm

Using this, I'll put something like this in my file:
[% IF Debug; Debug; END %]

Then in my code, whenever I want to see what is going on, I'll use this:
$template->{Debug} .= "Some message\n";

The $template is the "\%vars" parameter in the template documentation.

Not as easy as using breakpoints and single-stepping, but you don't have to change your process at all to use it.  Also, once you have it working, all you need to do is remove (or comment out) the debug line in the template, and all your debugging display goes away - you don't need to change the perl code behind it at all (slight speed penalty to leave the debugging code in perl, but this is minor - in most cases anyway).  If you need to add it back in, just uncomment the debug line in the template.  Over using STDERR, it keeps the debug output and the real output together.
0
 
LVL 6

Author Comment

by:DalHorinek
ID: 33654827
Thanks Adam, I use Template Toolkit too, but this approach didn't cross my mind, it seems as good idea, thank you.  
0
 
LVL 6

Author Closing Comment

by:DalHorinek
ID: 33654833
Nice approach presented.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Automatic dictation/transcribing software 9 56
Need to combine two scripts 2 40
size of file 1 22
NAS ISCSI Sharing 8 36
Let’s list some of the technologies that enable smooth teleworking. 
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question