NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Badger::Debug (Score:1)
I also use the $DEBUG/DEBUG idiom in pretty much every module I write. Being rather lazy I wrote Badger::Debug to do the job for me.
If you add the following to the top of your module:
package Your::Module;
use Badger::Debug default => 0;
Then you'll get both the $DEBUG package variable and DEBUG compile time constant defined for you (in this case, set to 0). The end result is almost exactly as per your example.
It also has a 'modules' option which you can use to enable debugging in various modules of your choice.
use Badger::Debug modules => 'Your::Module';
use Your::Module;
Now both $DEBUG and DEBUG will be set to 1 when Your::Module loads.
See http://badgerpower.com/docs/Badger/Debug.html#section_SYNOPSIS for further information.
Badger::Debug also plays nicely with Badger::Class. This implements a number of useful idioms/patterns that I/we tend to use a lot. For example:
package Your::Module;
use Badger::Class
version => 0.01, # set $VERSION and VERSION
debug => 0, # set $DEBUG and DEBUG
base => 'Badger::Base', # set base class
accessors => 'foo bar', # define accessors
mutators => 'wam bam', # define mutators
utils => 'blessed', # import from [Scalar|List|Hash]::Util
constant => {
PI => 3.14159, # define PI
};
#
All the above is "boring stuff" - supporting code that doesn't really relate to the core functionality of a module. I don't like littering the first 100 or so lines of a module with various idiomatic bits of boilerplate code before I can get started on coding proper. So Badger::Class's raison d'etre is to sweep all that crufty stuff out of the way and hide it behind a nice simple interface.
</plug>
Reply to This