[mp2 patch] introducing Apache::compat "scoping"

2003-12-14 Thread Stas Bekman
The following is yet another attempt to avoid collisions between 
Apache::compat and the real mp2 APIs.

Similar to 'use' and 'no' pragma, I'm suggesting to introduce the new 
functions override_mp2_api and restore_mp2_api for those APIs in 
Apache::compat that collide with 2.0 API. The only difference is that one 
needs an explicit call to restore_mp2_api, which I suppose could be done by 
returning an object, which if made a lexically scoped will call 
restore_mp2_api on its own (i.e. DESTROY), but since it's going to be used 
very infrequently and eventually won't be needed at all, I don't see a reason 
to bother. See the compat/request test change for an example in the patch below.

I decided not to use the import() method, but have an explicit function call, 
since import() may make some people think that it imports the overriden 
methods, which it doesn't.

I think there are only two functions at the moment that collide with mp2 API:
Apache::RequestRec::notes and Apache::RequestRec::finfo. There is also 
APR::URI::unparse, which introduces a special case but I think it's harmless.

in June I posted an implementation for 2 more colliding functions:
Apache::Connection::local_addr
Apache::Connection::remote_addr
http://marc.theaimsgroup.com/?l=apache-modperl-dev&m=105452446932154&w=2
which I will now be able to commit using this new functionality.
The cool thing is that we can introduce a sub-class of Registry which will do 
the wrapping into a handler like so:

 'sub handler {' .
 'Apache::compat::override_mp2_api('Apache::RequestRec::notes');' .
  $code .
 'Apache::compat::restore_mp2_api('Apache::RequestRec::notes');' .
 '}';
or something like that (overriding other subs as well).

Here is the patch:

Index: lib/Apache/compat.pm
===
RCS file: /home/cvs/modperl-2.0/lib/Apache/compat.pm,v
retrieving revision 1.90
diff -u -r1.90 compat.pm
--- lib/Apache/compat.pm19 Nov 2003 19:30:11 -  1.90
+++ lib/Apache/compat.pm15 Dec 2003 02:02:10 -
@@ -50,6 +50,86 @@
 $INC{'Apache/Table.pm'} = __FILE__;
 }
+# api => "overriding code"
+# the overriding code, needs to "return" the original CODE reference
+# when eval'ed , so that it can be restored later
+my %overridable_mp2_api = (
+'Apache::RequestRec::notes' => <<'EOI',
+{
+require Apache::RequestRec;
+my $notes_sub = *Apache::RequestRec::notes{CODE};
+*Apache::RequestRec::notes = sub {
+my $r = shift;
+return wantarray()
+?   ($r->table_get_set(scalar($r->$notes_sub), @_))
+: scalar($r->table_get_set(scalar($r->$notes_sub), @_));
+};
+$notes_sub;
+}
+EOI
+
+'Apache::RequestRec::finfo' => <<'EOI',
+{
+require APR::Finfo;
+my $finfo_sub = *APR::Finfo::finfo{CODE};
+sub Apache::RequestRec::finfo {
+my $r = shift;
+stat $r->filename;
+\*_;
+}
+$finfo_sub;
+}
+EOI
+);
+
+my %overridden_mp2_api = ();
+
+# this function enables back-compatible APIs which can't coexist with
+# mod_perl 2.0 APIs with the same name and therefore it should be
+# avoided if possible.
+#
+# it expects a list of fully qualified functions, like
+# "Apache::RequestRec::finfo"
+sub override_mp2_api {
+my (@subs) = @_;
+
+for my $sub (@subs) {
+unless (exists $overridable_mp2_api{$sub}) {
+die __PACKAGE__ . ": $sub is not overridable";
+}
+if(exists $overridden_mp2_api{$sub}) {
+warn __PACKAGE__ . ": $sub has been already overridden";
+next;
+}
+$overridden_mp2_api{$sub} = eval $overridable_mp2_api{$sub};
+unless (exists $overridden_mp2_api{$sub} &&
+ref($overridden_mp2_api{$sub}) eq 'CODE') {
+die "overriding $sub didn't return a CODE ref";
+}
+}
+}
+
+# restore_mp2_api does the opposite of override_mp2_api(), it removes
+# the overriden API and restores the original mod_perl 2.0 API
+sub restore_mp2_api {
+my (@subs) = @_;
+
+for my $sub (@subs) {
+unless (exists $overridable_mp2_api{$sub}) {
+die __PACKAGE__ . ": $sub is not overridable";
+}
+unless (exists $overridden_mp2_api{$sub}) {
+warn __PACKAGE__ . ": can't restore $sub, " .
+"as it has not been overridden";
+next;
+}
+my $original_sub = delete $overridden_mp2_api{$sub};
+no warnings 'redefine';
+no strict 'refs';
+*$sub = $original_sub;
+}
+}
+
 sub request {
 my $what = shift;
@@ -249,15 +329,6 @@
 : scalar($r->table_get_set(scalar($r->err_headers_out), @_));
 }
-{
-my $notes_sub = *Apache::RequestRec::notes{CODE};
-*Apache::RequestRec::notes = sub {
-my $r = shift;
-return wantarray()
-?   ($r->table_get_set(scalar($r->$notes_sub), @_))
-: scalar($r->table_get_set(scalar($r->$notes_sub), @_));
-}
-}
 sub 

mp2-1.99_12 release next week?

2003-12-14 Thread Stas Bekman
I'd like to make the _12 release next week. The usual plan suggestion:
- post a release candidate on Thu-Fri
- release on Monday
Unless someone else wishes to wear the RM cap, I'll do this release.

If you want something to go in into that release please say that asap.

The next _13 release will probably happen somewhere at the end of January and 
will probably coincide with the release of 5.8.3 (and I hope that there will 
be no problems introduced this time, as it was with the last 3 releases 5.8.0, 
5.8.1 and 5.8.2).

Thanks.

__
Stas BekmanJAm_pH --> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: [MP2] failed to resolve handler `Apache::PerlSections'

2003-12-14 Thread Stas Bekman
Enrico Sorcinelli wrote:

Watch this thread's resolution (which wasn't reached yet) and some sort of 
solution will be applied.


I'll do it :-)
As nobody has given any further comments I went ahead and committed this 
change. Please test with the current cvs, Enrico.

Thanks.

__
Stas BekmanJAm_pH --> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: cvs commit: modperl-2.0 Changes

2003-12-14 Thread Stas Bekman
[EMAIL PROTECTED] wrote:
stas2003/12/14 21:29:35

  Modified:lib/ModPerl BuildOptions.pm
   lib/Apache Build.pm
   .Changes
  Log:
  libgtop config (needed for enabling MOD_PERL_TRACE=m) is now searched
  using the gnome packaging tools if available (pkg-config for gnome-2.x
  and gnome-config for gnome-1.x)
Philippe, can you please check that the old default config ldopts addition is 
still working? I couldn't test it on my setup, which doesn't install libgtop 
into the global /usr/lib or ldconfig cache dirs). Thanks.

__
Stas BekmanJAm_pH --> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]