Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

Script Debugging Modules?

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


mike at nachbaur

Dec 10, 2000, 11:58 AM

Post #1 of 4 (426 views)
Permalink
Script Debugging Modules?

I'm starting a rather large project right now, and I want to make debugging
as easy as possible for me. The only way I know of debugging under mod_perl
is the typical 'print STDERR foo' technique. There must be a better way
then that, whether automating the 'print STDERR', or giving me logs of what
was called when (doubtful).

Basically, I was thinking of having something like syslog, but for my perl
modules. I'd also like to be able to limit the debugging output on a
per-module basis. Anyone know of anything like this, before I build one?

Thanks.

-man
Michael A Nachbaur


stas at stason

Dec 10, 2000, 12:04 PM

Post #2 of 4 (386 views)
Permalink
Re: Script Debugging Modules? [In reply to]

On Sun, 10 Dec 2000, Michael A. Nachbaur wrote:

> I'm starting a rather large project right now, and I want to make debugging
> as easy as possible for me. The only way I know of debugging under mod_perl
> is the typical 'print STDERR foo' technique. There must be a better way
> then that, whether automating the 'print STDERR', or giving me logs of what
> was called when (doubtful).

You can do the normal -d debug under mod_perl, see:
http://perl.apache.org/guide/debug.html

BTW, has anyone came with a solution for ptkdb to work more than once
under mod_perl? The author has never replied to my inqueries :(

> Basically, I was thinking of having something like syslog, but for my perl
> modules. I'd also like to be able to limit the debugging output on a
> per-module basis. Anyone know of anything like this, before I build one?

package Foo;
use constant DEBUG => 1;
...
warn "foo" if DEBUG;
...

package Bar;
use constant DEBUG => 0;
...
warn "bar" if DEBUG;
...

you get the idea... Only warns in Foo will work...

you can keep the debug statements in the code without having any overhead
of doing if DEBUG, since they are stripped at compile time.


_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas [at] stason http://apachetoday.com http://logilune.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


moseley at hank

Dec 10, 2000, 8:26 PM

Post #3 of 4 (386 views)
Permalink
Re: Script Debugging Modules? [In reply to]

At 08:04 PM 12/10/00 +0100, Stas Bekman wrote:
>use constant DEBUG => 0;
>...
>warn "bar" if DEBUG;

>you can keep the debug statements in the code without having any overhead
>of doing if DEBUG, since they are stripped at compile time.

Just how smart is the compiler?

Maybe all these debugging options indicate there's too much stuff in this
module, but...

use constant DEBUG_TEMPLATE => 1;
use constant DEBUG_SESSION => 2;
use constant DEBUG_REQUEST => 4;
use constant DEBUG_QUERY => 8;
use constant DEBUG_QUERY_PARSED => 16;

my $debug = DEBUG_REQUEST|DEBUG_QUERY;

...

warn "query = '$query'\n" if $debug & DEBUG_QUERY;

Is the compiler that smart, or is there a better way such as

use constant DEBUG_TEMPLATE => 0; # OFF
use constant DEBUG_SESSION => 1; # ON
use constant DEBUG_REQUEST => 0;
use constant DEBUG_QUERY => 1; # ON
use constant DEBUG_QUERY_PARSED => 0;

warn $query if DEBUG_QUERY || DEBUG_QUERY_PARSED;



Bill Moseley
mailto:moseley [at] hank


daniel at chetlin

Dec 11, 2000, 4:37 AM

Post #4 of 4 (387 views)
Permalink
Re: Script Debugging Modules? [In reply to]

On Sun, Dec 10, 2000 at 07:26:38PM -0800, Bill Moseley wrote:
> Just how smart is the compiler?
[snip]
> use constant DEBUG_TEMPLATE => 1;
> use constant DEBUG_SESSION => 2;
> use constant DEBUG_REQUEST => 4;
> use constant DEBUG_QUERY => 8;
> use constant DEBUG_QUERY_PARSED => 16;
>
> my $debug = DEBUG_REQUEST|DEBUG_QUERY;
>
> warn "query = '$query'\n" if $debug & DEBUG_QUERY;

Not quite that smart. It has no idea if `$debug' will have changed by
the time you're asking about it. However, if you make `$debug' into a
constant, it will work (where "work" is defined as "optimize out the
conditional").

use constant FOO => 1;
use constant BAR => 2;
use constant FOOBAR => FOO|BAR;
warn "baz" if FOOBAR & FOO;

> use constant DEBUG_TEMPLATE => 0; # OFF
> use constant DEBUG_SESSION => 1; # ON
> use constant DEBUG_REQUEST => 0;
> use constant DEBUG_QUERY => 1; # ON
> use constant DEBUG_QUERY_PARSED => 0;
>
> warn $query if DEBUG_QUERY || DEBUG_QUERY_PARSED;

This will also work, but I like the first approach better. It allows you
to factor out the component you want to debug.

-dlc

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.