deprecated has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a module and I'd like scripts using it to be able to turn on debugging. At first, I wanted use a very simple interface like Storable does,
$Storable::forgive_me = 1;
But then it occurred to me that perhaps I would be able to be a little more flexible with a sub. So I came up with something like this:
Package DebugMe; use vars qw( $dl ); # debug level sub debug { use Carp; use Data::Dumper; $dl |= shift; } # so the usage would be this: DebugMe::debug( 1 ); # change debugging level to 1 DebugMe::debug( 2 ); # change degbugging level to 2
However, I dont want the user to have any warnings if they arent interested in debugging because they dont have Data::Dumper or (isnt it part of the core) Carp. I looked through perldoc perlmod and also through perldoc -f use and perldoc -f require. I havent seen whether it gets use'd every time, or whether it only gets called when its needed.

Could somebody clarify this for me?

Thanks,
brother dep.

--
Laziness, Impatience, Hubris, and Generosity.

Replies are listed 'Best First'.
Re (tilly) 1: OO Debugging Schemes (akin to Storable.pm)
by tilly (Archbishop) on Apr 20, 2001 at 05:44 UTC
    Both Data::Dumper and Carp are part of the core.

    BTW you have a typo. You clearly want ||=, not |=. (Logical or, not bitwise.)

    As for your package, the right way IMHO to do it is to have a method or function for debugging that you can call, that you always call, and have that test the debug level against the level to output the warning for...

Re: OO Debugging Schemes (akin to Storable.pm)
by merlyn (Sage) on Apr 20, 2001 at 00:22 UTC