On Thu, 18 May 2000, Matt Sergeant wrote:
> On Thu, 18 May 2000, Kenneth Lee wrote:
>
> > modperlers,
> >
> > does it make sense if i put some mod_perl specific codes inside
> > an eval() so that the code runs on machines that have or haven't
> > mod_perl installed?
> >
> > eval <<'MOD_PERL_CODE' if $ENV{MOD_PERL};
> > use Apache ();
> > my $r = Apache->request;
> > ...
> > MOD_PERL_CODE
>
> Better still:
>
> eval {
> die unless $ENV{MOD_PERL};
> require Apache;
> my $r = $Apache->request;
> ...
> };
>
> Then you've got no (at least much less than the above) run-time overhead.
better still:
use constant IS_MODPERL => $ENV{MOD_PERL};
BEGIN {
import Apache::Constants qw(OK) if IS_MODPERL;
}
if (IS_MODPERL) {
my $r = Apache->request;
}
_zero_ runtime overhead, since IS_MODPERL is constant folded, that block
is optimized away at compile time outside of mod_perl.
you shouldn't need to 'use Apache ()', mod_perl does that for you, along
with Apache::Constants. in any case, have your startup script require any
Apache:: modules you need and import in a BEGIN block if needed.