Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Debugging CGI app written in Perl and run on Apache.

Posted on 2010-09-11
6
Medium Priority
?
699 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
Independent Software Vendors: 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you are like me and like multiple layers of protection, read on!
Want to know how to use Exchange Server Eseutil command? Go through this article as it gives you the know-how.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

877 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