Solved

Debugging CGI app written in Perl and run on Apache.

Posted on 2010-09-11
6
669 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now