SPUG:inconsistant perl -c

Brian Hatch spug at ifokr.org
Thu Jan 30 16:37:19 CST 2003

To bring closure to my question, here is a set of modules that
would work both in a mod_perl Apache, and with 'perl -c':

$ cat BriOne.pm
use Apache;
use BriTwo;

$ cat BriTwo.pm
use Apache;

# Stuff to do at module load/compile time
sub dostuff {
	my $s = Apache->server();

# Call it only if Apache->server() is defined.
# This only exists if we're running inside an
# apache process, not on the command line.

dostuff() if eval 'Apache->server()';

$ perl -c BriTwo.pm
BriTwo Syntax OK

$ perl -c BriOne.pm
BriOne Syntax OK

The problem is that Apache->server() returns the name of the
server itself, not based on any request.  This is what I want,
because I want to load some skeleton HTML files off the file
system at module load time.  The files are URL dependent (I
have a prod and a stage server, where the pathnames are

So the hackish eval will catch if Apache->server() works
(discards the value - don't need it) and only calls the
sub if we're actually running.

This means all my 'perl -c' tests are accurate.  Previously
they'd die when they hit this code, and I'd need to check
each module separately.

Thanks to the various folks who responded.

Brian Hatch                  Variables won't.
   Systems and                Constants aren't.
   Security Engineer

Every message PGP signed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 240 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/spug-list/attachments/20030130/c9b88ad6/attachment.bin

More information about the spug-list mailing list