in reply to ifdef in modules

In case anyone's interested, this is what I ended up doing in my development environment. The purpose of this is to enable debugging code in CGI applications that are only active during development. Note that this is running on a Win32 platform, though I expect it should work on other platforms. Just make sure to substitute the correct paths.

  1. Set environment variables in Apache:
    SetEnv PERL5LIB C:/Perl/site/lib SetEnv PERL5OPT -Mifdef=DEBUGGING
    This will force C:/Perl/site/lib to the front of @INC and enable the 'ifdef' pragma, activating pod sections tagged with 'DEBUGGING'.

  2. Create a new version of 'lib.pm' in 'C:/Perl/site/lib'. This new 'lib.pm' will ensure that the @INC handler installed by 'ifdef' gets pushed to the front of @INC even when 'use lib' is called in the code. This new 'lib.pm' looks like:
    package lib; sub import { # call the built-in lib first require 'C:/Perl/lib/lib.pm'; import(@_); # re-order @INC with CODE refs at front my (@coderefs, @rest); foreach (@INC) { if (ref $_ && ref $_ eq 'CODE') { push @coderefs, $_; } else { push @rest, $_; } } @INC = (@coderefs, @rest); } 1;

Basically, step 1 enables 'ifdef' and makes sure our new 'lib.pm' from step 2 will be called in place of the standard 'lib.pm'. Step 2 forces the @INC handler installed by 'ifdef' to the front of @INC (credit for most of the code belongs to Tanktalus).