Re: samples of mod_perl 2.0-RC5 compliant modules

[prev] [thread] [next] [Date index for 2005/04/14]

From: Geoffrey Young
Subject: Re: samples of mod_perl 2.0-RC5 compliant modules
Date: 23:29 on 14 Apr 2005

Philip M. Gollucci wrote:
> John D Groenveld wrote:
> 
>> In message <425E747C.2020008@xxxxxxxxxxxxxxx.xxx>, Geoffrey Young writes:
>>  
>>
>>> I've updated all of my mod_perl 2.0 CPAN modules so that they work
>>> with the
>>> latest mod_perl 2.0 release (RC5 aka 1.999_22) and Apache-Test 1.22. 
>>> here
>>>   
>>
>>
>> For those of us supporting Apache 1 and 2, is this right?
>>
>> package My::Apache::Foo;
>>
>>  
>>
>> use constant MP2 => eval { require mod_perl2; 1 } || 0;
>>
>> BEGIN {
>>    if (MP2) {
>>        require mod_perl2;
>>        require Apache2::Const;
>>    } else {
>>        require mod_perl;
>>        require Apache::Constants;
>>    }
>> }

that's fine.  note that the 'require mod_perl2' is redundant here, and not
typically necessary anyway.

>>
>> John
>> groenveld@xxx.xxx
>>  
>>
> For performance and consistancy, you'd be better off using
> 
> use constant MP2 => |$ENV{MOD_PERL_API_VERSION}| == 2 ? 1 : 0;
> 
> or just use the ENV directly

well, even without the abs signs that has a problem, namely what happens if
mod_perl isn't present at all :)  but if you're in a handler then that's a
given...

fwiw, the way CGI.pm ended up was like this:

  if (exists $ENV{MOD_PERL}) {
    if ($ENV{MOD_PERL_API_VERSION} == 2) {
      $MOD_PERL = 2;
      require Apache2::Response;
      require Apache2::RequestRec;
      require Apache2::RequestUtil;
      require APR::Pool;
    } else {
      $MOD_PERL = 1;
      require Apache;
    }
  }

HTH

--Geoff

samples of mod_perl 2.0-RC5 compliant modules
Geoffrey Young 13:47 on 14 Apr 2005

Re: samples of mod_perl 2.0-RC5 compliant modules
John D Groenveld 22:01 on 14 Apr 2005

Re: samples of mod_perl 2.0-RC5 compliant modules
Philip M. Gollucci 22:21 on 14 Apr 2005

Re: samples of mod_perl 2.0-RC5 compliant modules
Philip M. Gollucci 22:29 on 14 Apr 2005

Re: samples of mod_perl 2.0-RC5 compliant modules
Geoffrey Young 23:29 on 14 Apr 2005

Generated at 23:15 on 17 Apr 2005 by mariachi v0.52