You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Haroon Rafique <ha...@utoronto.ca> on 2004/10/22 18:35:47 UTC
getting rid of Apache::compat dependency in Apache::DBI
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(!@ChildConnect and Apache->can('push_handlers')) {
- Apache->push_handlers(PerlChildInitHandler => \&childinit);
+ if(!@ChildConnect 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, [@_];
@@ -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
<ha...@utoronto.ca>
Re: getting rid of Apache::compat dependency in Apache::DBI
Posted by Stas Bekman <st...@stason.org>.
Haroon Rafique wrote:
> On Today at 12:54pm, SB=>Stas Bekman <st...@stason.org> 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):
much better :)
--
__________________________________________________________________
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: getting rid of Apache::compat dependency in Apache::DBI
Posted by Haroon Rafique <ha...@utoronto.ca>.
On Today at 12:54pm, SB=>Stas Bekman <st...@stason.org> 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(!@ChildConnect and Apache->can('push_handlers')) {
- Apache->push_handlers(PerlChildInitHandler => \&childinit);
+ if(!@ChildConnect and (MP2 ? 1 : Apache->can('push_handlers'))) {
+ Apache->server->push_handlers(PerlChildInitHandler => \&childinit);
}
# store connections
push @ChildConnect, [@_];
@@ -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
<ha...@utoronto.ca>
Re: getting rid of Apache::compat dependency in Apache::DBI
Posted by Stas Bekman <st...@stason.org>.
Haroon Rafique wrote:
> 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 :-) ?
[...]
> - if(!@ChildConnect and Apache->can('push_handlers')) {
> - Apache->push_handlers(PerlChildInitHandler => \&childinit);
> + if(!@ChildConnect and (MP2 ? 1 : Apache->can('push_handlers'))) {
> + if( MP2 ) {
> + Apache->server->push_handlers(PerlChildInitHandler => \&childinit);
> + } else {
> + Apache->push_handlers(PerlChildInitHandler => \&childinit);
I think here and below you don't need to do this branching. since the C
function mod_perl_push_handlers ignores the first argument,
Apache->server->push_handlers() should work just fine under mp1, but I
didn't test it.
--
__________________________________________________________________
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: getting rid of Apache::compat dependency in Apache::DBI
Posted by Joe Thomas <jo...@tellme.com>.
I sent a patch that touches some of the same code a couple months back, and
I never got any feedback on it. It fixes a bug where database handles won't
get rolled back properly if there's more than one handle in use, because
$Idx can only keep track of one handle at a time:
http://mathforum.org/epigone/modperl/pryfrirshoo
(This patch also incorporates a patch from Patrick Mulvany that makes the
cleanup handler return database handles to the same
AutoCommit/PrintError/RaiseError/etc. state they were in initially.)
The epigone mail archive doesn't display my quoted-printable attachment very
nicely, but it is decodable. I can send it again with a different mailer if
that will help. (Suggestions welcome.)
Joe
-----Original Message-----
From: Haroon Rafique [mailto:haroon.rafique@utoronto.ca]
Sent: Friday, October 22, 2004 9:36 AM
To: modperl@perl.apache.org
Subject: getting rid of Apache::compat dependency in Apache::DBI
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(!@ChildConnect and Apache->can('push_handlers')) {
- Apache->push_handlers(PerlChildInitHandler => \&childinit);
+ if(!@ChildConnect 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, [@_];
@@ -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
<ha...@utoronto.ca>
--
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