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).


In reply to Re: ifdef in modules by clee
in thread ifdef in modules by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.