Hi,
Currently, Apache::DBI's connect_on_init method requires that Apache::compat be loaded or it carps "Apache.pm was not loaded" and returns.
Find attached a patch for Apache::DBI which gets rid of the dependency for Apache::compat. While in the process, I also fixed a second TODO in sub connect related to mod_perl. I don't know if the call to Apache::Status->menu_item() near __END__ will work as is. Probably not.
Comments are most welcome. I'm sure it needs more work, and that's why we have more than one contributors. Are you out there Ask :-) ?
I will post the patch inline as well, just in case attachments are stripped by the mailing list.
--- Apache/DBI.pm-orig 2004-09-01 15:08:24.000000000 -0400 +++ Apache/DBI.pm 2004-10-22 11:59:26.797654654 -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,12 @@ 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'))) { + if( MP2 ) { + Apache->server->push_handlers(PerlChildInitHandler => \&childinit); + } else { + Apache->push_handlers(PerlChildInitHandler => \&childinit); + } } # store connections push @ChildConnect, [EMAIL PROTECTED]; @@ -93,10 +98,14 @@
# 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); + if( MP2 ) { + Apache->server->push_handlers("PerlCleanupHandler", \&cleanup); + } else { + Apache->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;
Cheers, -- Haroon Rafique <[EMAIL PROTECTED]>
--- Apache/DBI.pm-orig 2004-09-01 15:08:24.000000000 -0400 +++ Apache/DBI.pm 2004-10-22 11:59:26.797654654 -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,12 @@ 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'))) { + if( MP2 ) { + Apache->server->push_handlers(PerlChildInitHandler => \&childinit); + } else { + Apache->push_handlers(PerlChildInitHandler => \&childinit); + } } # store connections push @ChildConnect, [EMAIL PROTECTED]; @@ -93,10 +98,14 @@ # 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); + if( MP2 ) { + Apache->server->push_handlers("PerlCleanupHandler", \&cleanup); + } else { + Apache->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