in reply to Re^6: ifdef in modules
in thread ifdef in modules

Really? If you leave the 'use ifdef' in your code, it will only marginally affect your load time, won't really affect your compile time (just the part of ignoring POD), and won't affect runtime at all.

Or, another way to look at it is that commenting out the "use ifdef" line is way easier than commenting out all the DEBUGGING lines. :-)

One minor advantage here is that you can control which files have ifdef in them - by only putting them in the files you actually want to debug at a given time, you can just get your debugging info from those modules - a significantly reduced set of messages which may make it easier to debug. Minor, but still an advantage.

What's really unfortunate is that the lib module doesn't play too nice here. We could, however, write a new module, say lib::clean, which would go and reorder the @INC such that all CODE refs are pushed to the front. Then you just need to use it:

package lib::clean; sub import { my (@coderefs, @rest); foreach (@INC) { if (ref $_ && ref $_ eq 'CODE') { push @coderefs, $_; } else { push @rest, $_; } } @INC = (@coderefs, @rest); } 1;

And just 'use lib::clean;' after the 'use lib' line. Just testing that, and it seems to work, too.

Replies are listed 'Best First'.
Re^8: ifdef in modules
by clee (Novice) on Jun 15, 2005 at 17:07 UTC

    I'm not really concerned about the negligible load time. The problem is that production servers won't have the 'ifdef' pragma.

    You're right about commenting out 'use ifdef' being easier than commenting out all DEBUGGING lines.

    Anyways, none of that matters now since you've provided me with a workable solution in lib::clean ;). Hmmm...maybe I could override my dev version of 'lib' instead of putting 'use lib::clean' in the code...

    Thanks again!