+
+ ### cache mod_perl version (light if or if not mod_perl)
+ my $v = (! $ENV{'MOD_PERL'}) ? 0
+ # mod_perl/1.27 or mod_perl/1.99_16 or mod_perl/2.0.1
+ # if MOD_PERL is set - don't die if regex fails - just assume 1.0
+ : ($ENV{'MOD_PERL'} =~ m{ ^ mod_perl / (\d+\.[\d_]+) (?: \.\d+)? $ }x) ? $1
+ : '1.0_0';
+ sub _mod_perl_version () { $v }
+ sub _is_mod_perl_1 () { $v < 1.98 && $v > 0 }
+ sub _is_mod_perl_2 () { $v >= 1.98 }
+
+ ### cache apache request getter (light if or if not mod_perl)
+ my $sub;
+ if (_is_mod_perl_1) { # old mod_perl
+ require Apache;
+ $sub = sub { Apache->request };
+ } elsif (_is_mod_perl_2) {
+ if (eval { require Apache2::RequestRec }) { # debian style
+ require Apache2::RequestUtil;
+ $sub = sub { Apache2::RequestUtil->request };
+ } else { # fedora and mandrake style
+ require Apache::RequestUtil;
+ $sub = sub { Apache->request };
+ }
+ } else {
+ $sub = sub {};
+ }
+ sub apache_request_sub () { $sub }