Re: Script Debugging Modules?
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
Re: Script Debugging Modules?
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:[EMAIL PROTECTED] http://apachetoday.com http://logilune.com/ http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
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
Re: Script Debugging Modules?
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:[EMAIL PROTECTED]