On Sun, 2003-12-14 at 18:33, Stas Bekman wrote:
The following is yet another attempt to avoid collisions between Apache::compat and the real mp2 APIs.
That is indeed an annoying problem.
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 would probably prefer to use import() just to make things as easy as possible for the potential users of Apache::compat(), but as long as it's documented, I don't think I'd mind much.
You shouldn't need to use this function at all ;)
I prefer not to call it import, because it explicitly says override_mp2_api
'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.pm 19 Nov 2003 19:30:11 -0000 1.90 +++ lib/Apache/compat.pm 15 Dec 2003 02:02:10 -0000 @@ -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 +);
Why make this code a SCALAR, instead of creating an anonymous sub right there?
What do you mean?
__________________________________________________________________ Stas Bekman JAm_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]