I'm not sure if this is a style or function question. I'd like to have a module called Debug.pm that has a variable in it that if set to '1' by anything (main script, or other modules) will print debug messages.
Reading the Orielly "Practical mod_perl" I thought it was clear what I needed to do, but I am finding it difficult. The following works as one file, but when I break the Debug part into its own file, the value of $D just increments with every re-load...
#!/usr/local/bin/perl
use strict; use warnings; use CGI qw(:standard); use Debug;
print header();
Debug::report('I should not see this line'); $Debug::D++; Debug::report('I should see this line'); $Debug::D++; Debug::report('This one too');
package Debug; use strict; use warnings;
use vars qw($D); $D = 0;
sub report { my $string = shift;
print "DEBUG ($D): $string<br>\n" if $D; }
1;
Can anyone explain to me why I can't have a global variable when I put Debug into its own file?
Well that's mod_perl. It will compile your script only once perl forked-process|thread (which means it also loads your Debug.pm only once) hence all global variables hold their value.
This means the following: * you should see: ---------------8<--------------- I should see this line This one too ---------------8<--------------- when the request is served by new forked/thread process which has not already loaded your YourModule.pm. * you should see : ---------------8<--------------- I should not see this line I should see this line This one too ---------------8<--------------- on any next request servered by *exactly this* apache-child.
What you could do: * reset $Debug::D directly before print header() e.g. Debug::reset() * make an object out of debug: e.g. $debug = new Debug(), $debug->increment_counter() * use mod_perls logging capabilities.
Can anyone tell me how to accomplish what I'm after?
Do you want to increase/decrease verbosity or why are you incrementing $D????
Tom
Thanks, Nathanial Hendler Tucson, AZ USA http://retards.org/
-- Report problems: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html List etiquette: http://perl.apache.org/maillist/email-etiquette.html