On Today at 12:54pm, SB=>Stas Bekman <[EMAIL PROTECTED]> wrote:

SB> [..snip..]
SB> 
SB> I think here and below you don't need to do this branching. since the 
SB> C function mod_perl_push_handlers ignores the first argument, 
SB> Apache->server->push_handlers() should work just fine under mp1, but I 
SB> didn't test it.
SB> 

As you said someone should test it under mp1. So, that makes the patch 
even simpler (find inline and attached):

--- Apache/DBI.pm-orig  2004-09-01 15:08:24.000000000 -0400
+++ Apache/DBI.pm       2004-10-22 14:22:24.040366730 -0400
@@ -11,6 +11,9 @@
 
 $Apache::DBI::VERSION = '0.94';
 
+use mod_perl;
+use constant MP2 => ($mod_perl::VERSION >= 1.99);
+
 # 1: report about new connect
 # 2: full debug output
 $Apache::DBI::DEBUG = 0;
@@ -31,10 +34,8 @@
 sub connect_on_init { 
     # provide a handler which creates all connections during server startup
 
-    # TODO - Should check for mod_perl 2 and do the right thing there
-    carp "Apache.pm was not loaded\n" and return unless $INC{'Apache.pm'};
-    if([EMAIL PROTECTED] and Apache->can('push_handlers')) {
-        Apache->push_handlers(PerlChildInitHandler => \&childinit);
+    if([EMAIL PROTECTED] and (MP2 ? 1 : Apache->can('push_handlers'))) {
+        Apache->server->push_handlers(PerlChildInitHandler => \&childinit);
     }
     # store connections
     push @ChildConnect, [EMAIL PROTECTED];
@@ -93,10 +94,10 @@
 
     # this PerlCleanupHandler is supposed to initiate a rollback after the script has 
finished if AutoCommit is off.
     my $needCleanup = ($Idx =~ /AutoCommit[^\d]+0/) ? 1 : 0;
-    # TODO - Fix mod_perl 2.0 here
-    if(!$Rollback{$Idx} and $needCleanup and Apache->can('push_handlers')) {
+    if(!$Rollback{$Idx} and $needCleanup and
+            (MP2 ? 1 : Apache->can('push_handlers'))) {
         print STDERR "$prefix push PerlCleanupHandler \n" if $Apache::DBI::DEBUG > 1;
-        Apache->push_handlers("PerlCleanupHandler", \&cleanup);
+        Apache->server->push_handlers("PerlCleanupHandler", \&cleanup);
         # make sure, that the rollback is called only once for every 
         # request, even if the script calls connect more than once
         $Rollback{$Idx} = 1;

--
Haroon Rafique
<[EMAIL PROTECTED]>
--- Apache/DBI.pm-orig  2004-09-01 15:08:24.000000000 -0400
+++ Apache/DBI.pm       2004-10-22 14:22:24.040366730 -0400
@@ -11,6 +11,9 @@
 
 $Apache::DBI::VERSION = '0.94';
 
+use mod_perl;
+use constant MP2 => ($mod_perl::VERSION >= 1.99);
+
 # 1: report about new connect
 # 2: full debug output
 $Apache::DBI::DEBUG = 0;
@@ -31,10 +34,8 @@
 sub connect_on_init { 
     # provide a handler which creates all connections during server startup
 
-    # TODO - Should check for mod_perl 2 and do the right thing there
-    carp "Apache.pm was not loaded\n" and return unless $INC{'Apache.pm'};
-    if([EMAIL PROTECTED] and Apache->can('push_handlers')) {
-        Apache->push_handlers(PerlChildInitHandler => \&childinit);
+    if([EMAIL PROTECTED] and (MP2 ? 1 : Apache->can('push_handlers'))) {
+        Apache->server->push_handlers(PerlChildInitHandler => \&childinit);
     }
     # store connections
     push @ChildConnect, [EMAIL PROTECTED];
@@ -93,10 +94,10 @@
 
     # this PerlCleanupHandler is supposed to initiate a rollback after the script has 
finished if AutoCommit is off.
     my $needCleanup = ($Idx =~ /AutoCommit[^\d]+0/) ? 1 : 0;
-    # TODO - Fix mod_perl 2.0 here
-    if(!$Rollback{$Idx} and $needCleanup and Apache->can('push_handlers')) {
+    if(!$Rollback{$Idx} and $needCleanup and
+            (MP2 ? 1 : Apache->can('push_handlers'))) {
         print STDERR "$prefix push PerlCleanupHandler \n" if $Apache::DBI::DEBUG > 1;
-        Apache->push_handlers("PerlCleanupHandler", \&cleanup);
+        Apache->server->push_handlers("PerlCleanupHandler", \&cleanup);
         # make sure, that the rollback is called only once for every 
         # request, even if the script calls connect more than once
         $Rollback{$Idx} = 1;
-- 
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

Reply via email to