You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by John Siracusa <si...@mindspring.com> on 2004/09/20 21:02:33 UTC
Best way to distinguish between mod_perl 1 and 2
I'm looking for the best, most reliable way to determine if I'm running
under mod_perl 1 or 2, or not under mod_perl at all. I suppose I can look
at $ENV{'MOD_PERL'}, but that reminds me a bit too much of a user-agent
style opaque string that I may not be able to trust or predict. Also, what
if I see "mod_perl/1.99" in that string? It just seems odd.
So, any other suggestions? This needs to be code I can run even outside any
mod_perl environment. I'll wrap it in an eval if I have to, but the low
overhead of looking at $ENV{'MOD_PERL'} is kind of attractive...
-John
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: Best way to distinguish between mod_perl 1 and 2
Posted by Stas Bekman <st...@stason.org>.
Tom Schindl wrote:
> Hi,
>
> !please always reply to the mailing list so the thread doesn't get broken!
>
> well mp uses this value internally and many CPAN-Modules do so either.
> Versions
>
> mp1 = VERSION < 1.99
> mp2 = VERSION >= 1.99
>
> The real syntax would be:
>
> ----------------->8-----------------
> use mod_perl; ## exists in mp1 and mp2
[...]
save your fingers and post the URL instead :)
http://perl.apache.org/docs/2.0/user/porting/porting.html#Porting_a_Module_to_Run_under_both_mod_perl_2_0_and_mod_perl_1_0
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: Best way to distinguish between mod_perl 1 and 2
Posted by Glenn Strauss <gs...@gluelogic.com>.
On Mon, Sep 20, 2004 at 10:53:09PM +0200, Tom Schindl wrote:
> Hi,
>
> !please always reply to the mailing list so the thread doesn't get broken!
>
> well mp uses this value internally and many CPAN-Modules do so either.
> Versions
>
> mp1 = VERSION < 1.99
> mp2 = VERSION >= 1.99
>
> The real syntax would be:
>
> ----------------->8-----------------
> use mod_perl; ## exists in mp1 and mp2
>
> ## set the constant to 0 if mp1 and to 1 if mp2
> ## but also subversions are working like this e.g. >= 1.99_12 which
> ## means the version the version must be at least 1.99_13
> use constant MP2 => ($mod_perl::VERSION >= 1.99);
>
> BEGIN {
> if( MP2 ) {
> require Apache::Const;
> Apache::Const->import(-compile =>
> 'HTTP_UNAUTHORIZED','HTTP_INTERNAL_SERVER_ERROR','DECLINED','HTTP_FORBIDDEN','OK');
> } else {
> require Apache::Constants;
>
> Apache::Constants->import('HTTP_UNAUTHORIZED','HTTP_INTERNAL_SERVER_ERROR','DECLINED','HTTP_FORBIDDEN','OK');
> }
> }
>
> ## proceed with your code
> ----------------->8-----------------
>
> Tom
>
>
> John Siracusa wrote:
> >On Mon, 20 Sep 2004 21:19:58 +0200, Tom Schindl <to...@gmx.at> wrote:
> >
> >>Are you looking for this:
> >>-------------->8--------------
> >>use constant MP2 => ($mod_perl::VERSION >= 1.99_12);
> >>-------------->8--------------
> >
> >
> >I don't know. What is that? :) Is that the "officially blessed" way
> >to do this, or just another alternative that happens to work? Also,
> >what's the equivalent for MP1? "$mod_perl::VERSION < 1.99_12"?
> >
> >-John
I use the following, avoiding the need to pull in mod_perl.pm
unless the MOD_PERL environment variable exists.
use constant MOD_PERL => exists($::ENV{'MOD_PERL'})
? (require('mod_perl.pm'), $mod_perl::VERSION >= 1.99)
? $mod_perl::VERSION
: 1
: 0;
and then the Perl optimizer will take care of optimizing
away my simple tests for
(MOD_PERL) == 0 (not mod_perl)
(MOD_PERL) == 1 (mod_perl 1)
(MOD_PERL) > 1 (value 1.99 and above for mod_perl 2 and above)
Cheers,
Glenn
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: Best way to distinguish between mod_perl 1 and 2
Posted by Tom Schindl <to...@gmx.at>.
Hi,
!please always reply to the mailing list so the thread doesn't get broken!
well mp uses this value internally and many CPAN-Modules do so either.
Versions
mp1 = VERSION < 1.99
mp2 = VERSION >= 1.99
The real syntax would be:
----------------->8-----------------
use mod_perl; ## exists in mp1 and mp2
## set the constant to 0 if mp1 and to 1 if mp2
## but also subversions are working like this e.g. >= 1.99_12 which
## means the version the version must be at least 1.99_13
use constant MP2 => ($mod_perl::VERSION >= 1.99);
BEGIN {
if( MP2 ) {
require Apache::Const;
Apache::Const->import(-compile =>
'HTTP_UNAUTHORIZED','HTTP_INTERNAL_SERVER_ERROR','DECLINED','HTTP_FORBIDDEN','OK');
} else {
require Apache::Constants;
Apache::Constants->import('HTTP_UNAUTHORIZED','HTTP_INTERNAL_SERVER_ERROR','DECLINED','HTTP_FORBIDDEN','OK');
}
}
## proceed with your code
----------------->8-----------------
Tom
John Siracusa wrote:
> On Mon, 20 Sep 2004 21:19:58 +0200, Tom Schindl <to...@gmx.at> wrote:
>
>>Are you looking for this:
>>-------------->8--------------
>>use constant MP2 => ($mod_perl::VERSION >= 1.99_12);
>>-------------->8--------------
>
>
> I don't know. What is that? :) Is that the "officially blessed" way
> to do this, or just another alternative that happens to work? Also,
> what's the equivalent for MP1? "$mod_perl::VERSION < 1.99_12"?
>
> -John
>
>
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: Best way to distinguish between mod_perl 1 and 2
Posted by Tom Schindl <to...@gmx.at>.
Are you looking for this:
-------------->8--------------
use constant MP2 => ($mod_perl::VERSION >= 1.99_12);
-------------->8--------------
Tom
John Siracusa wrote:
> I'm looking for the best, most reliable way to determine if I'm running
> under mod_perl 1 or 2, or not under mod_perl at all. I suppose I can look
> at $ENV{'MOD_PERL'}, but that reminds me a bit too much of a user-agent
> style opaque string that I may not be able to trust or predict. Also, what
> if I see "mod_perl/1.99" in that string? It just seems odd.
>
> So, any other suggestions? This needs to be code I can run even outside any
> mod_perl environment. I'll wrap it in an eval if I have to, but the low
> overhead of looking at $ENV{'MOD_PERL'} is kind of attractive...
>
> -John
>
>
>
Reclaim Your Inbox!
http://www.mozilla.org/products/thunderbird
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html