Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Debug code out of production systems

by dbwiz (Curate)
on Jan 24, 2004 at 23:38 UTC ( #323891=note: print w/ replies, xml ) Need Help??


in reply to Debug code out of production systems

liz,

Thanks for writing this pragma. I like the idea and I have started using it immediately.

However, I don't like the name and I am sure that many others will object about it. While it is clear how it does the trick, it is really misleading about what the pragma does.

I would rather have a debug pragma, and a quick search and replace in your module shows that it can be done, so that a sample code would look like the following:

print "before\n"; =debug MIDDLE print "inside\n"; =cut print "after\n";

And when I call it with this pragma, it works just fine.

perl -Mdebug=MIDDLE test.pl

You could also implement it as a pragma with two parameters, one for the tag and one for the label to activate. Possible names would be "podebug," "debugpod," "tagdebug," or "debpod." Not really suggesting, just brainstorming.

Anyway, with this enhanced pragma, I would call my script as

perl -Mdebpod=debug,MIDDLE test.pl # or, if I change my mind about the tag, perl -Mdebpod=begin,MIDDLE test.pl

However, I should point out a possible problem. The following code contains valid POD but the embedded code doesn't get executed by the "begin" pragma. Not only that, but also the code after the POD block disappears.

print "before\n"; =pod Whatever I want to include here. Comments or code, it doesn't matter. =begin DEBUGGING print "inside\n"; =cut print "after\n";

Using the "begin" pragma, this code will only print "before\n". You should either fix it or amend the docs about this risk.


Comment on Re: Debug code out of production systems
Select or Download Code
Re: Re: Debug code out of production systems
by liz (Monsignor) on Jan 25, 2004 at 00:09 UTC
    While it is clear how it does the trick, it is really misleading about what the pragma does.
    I have some of that feeling as well. But please note that this pragma is only intended to be called from the commandline (it actually emits a warning when you're trying to use it inside a script). So my thinking was, use "begin" as a pragma to activate certain =begin pod sections.

    I would rather have a debug pragma
    I've thought about using =debug as a pod delimiter. The thing is that many pod processor generate a lot of noise when they encounter an unknown =pod delimiter. Wherease if they don't know how to handle =begin, they're supposed to ignore it.

    ...a quick search and replace in your module shows that it can be done...
    Indeed. That shouldn't be the problem. But causing headaches for maintainers of pod parsers may be a problem.

    ...as a pragma with two parameters, one for the tag and one for the label to activate.
    I think that would make it more confusing and obfuscating. I think the namespace idea that I head, may be more handy.

    ... the code after the POD block disappears.
    That's because:

    print "before\n"; =pod Whatever I want to include here. Comments or code, it doesn't matter. =begin DEBUGGING print "inside\n"; =cut print "after\n";
    becomes after conversion:
    print "before\n"; =pod Whatever I want to include here. Comments or code, it doesn't matter. { print "inside\n"; } print "after\n";
    which makes clear why the code disappears. I could check for that at the expense at a more complex filter. Or add another CAVEAT. Probably the first.

    Thanks for the feedback.

    Liz

      "I've thought about using =debug as a pod delimiter. The thing is that many pod processor generate a lot of noise when they encounter an unknown =pod delimiter. Wherease if they don't know how to handle =begin, they're supposed to ignore it. "

      Couldn't you use the =for directive =for debug? That does not emit warnings.


      -Lee
      "To be civilized is to deny one's nature."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://323891]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2014-10-26 07:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (152 votes), past polls