However, I'm a bit in two minds about its name: begin. The reason I chose "begin" as the name, is that it is based on the behaviour of the =begin pod directive. I'm also thinking that "debug" might be a good name. But that doesn't indicate how the magic is achieved.
Anyway, I wonder what my fellow monks would want to say about it.
or:export DEBUGGING=1 perl -Mbegin yourscript.pl
or:perl -Mbegin=VERBOSE yourscript.pl
with:perl -Mbegin=all yourscript.pl
======= yourscript.pl =================== # code that's always compiled and executed =begin DEBUGGING warn "Only compiled and executed when DEBUGGING or 'all' enabled\n" =cut # code that's always compiled and executed =begin VERBOSE warn "Only compiled and executed when VERBOSE or 'all' enabled\n" =cut # code that's always compiled and executed ========================================
To prevent interference with other pod handlers, the name of the pod handler must be in uppercase.
If a =begin pod section is considered for replacement, then a scope is created around that pod section so that there is no interference with any of the code around it. For example:
is converted on the fly (before Perl compiles it) to:my $foo = 2; =begin DEBUGGING my $foo = 1; warn "debug foo = $foo\n"; =cut warn "normal foo = $foo\n";
my $foo = 2; { my $foo = 1; warn "foo = $foo\n"; } warn "normal foo = $foo\n";
But of course, this happens only if the "begin" pragma is loaded and the environment variable DEBUGGING is set.
All other feedback is of course always appreciated!
Liz
Update:
I've decided to change the name of the pragma (as seen by the outside world) to "ifdef". I've also fixed the problems found by "Mr. Muskrat" and dbwiz and added an API for AUTOLOADing modules that may want to do the same source code conversion. For the impatient ones, also available from my own CPAN modules site.
In reply to Debug code out of production systems by liz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |