SPUG:inconsistant perl -c

Colin Meyer cmeyer at helvella.org
Thu Jan 30 15:40:14 CST 2003

On Thu, Jan 30, 2003 at 10:52:19AM -0800, Brian Hatch wrote:
> Contents of BriOne.pm:
> 	use Apache;
> 	use BriTwo;
> Contents of BriTwo.pm:
> 	use Apache;
        # to see what is happening:
        print STDERR "about to execute \$s = Apache->server();\n";

> 	my $s = Apache->server();
> $ perl -c BriTwo
> BriTwo Syntax OK
> $ perl -c BriOne
> Can't locate object method server via package Apache (perhaps you forgot 
>     to load 'Apache'?) at BriOne.pm line 3.
> Compilation Failed in require at BriOne line 3
> BEGIN failed.

'perl -c ' executes use statements, because they are effectively
equivalent to BEGIN {} blocks. When you 'perl -c BriOne', it executes
BriTwo.pm, and tries at that time to instantiate $s by calling
Apache->server(). Unfortunately, this call does not work when running
outside of the true mod_perl environment (from within httpd).

> How can I make that second perl -c not complain?  It shouldn't.  At
> least I don't think it should.

One way to avoid that error would be to change in BriTwo:
  my $s = Apache->server();

  my $s;
  sub instantiate {
    $s = Apache->server();

and manually call BriTwo::instantiate from BriOne.


More information about the spug-list mailing list