You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Josh Chamas <jo...@chamas.com> on 2003/05/07 22:44:57 UTC
[mp2] $r->current_callback please
Hey,
I was wondering if we could get $r->current_callback into the standard mp2 API.
It will just be one less thing to worry about when making things work across
mp2 & mp1.
Currently, this is implemented in Apache::compat with a call to
Apache::current_callback, but I was wondering if this could be made
standard for $r, maybe in addition to Apache::current_callback() working ...
I have code in Apache::ASP that I am working on that is looking like:
my $current_callback = eval { $r->current_callback } || eval { Apache::current_callback() };
if($current_callback) {
$request_binary_read = ($current_callback =~ /^Perl(Response)?Handler$/) ? 1 : 0;
} else {
$request_binary_read = 1;
}
Like other environments I am sure, Apache::ASP runs in at least 3 modes,
which is why this coding gets hairy... so far its running in mp1, mp2, & mod_cgi.
I have a CGI $r emulator, but it ends up looking more like mp1 than mp2.
Regards,
Josh
________________________________________________________________
Josh Chamas, Founder phone:925-552-0128
Chamas Enterprises Inc. http://www.chamas.com
NodeWorks Link Checking http://www.nodeworks.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: [mp2] $r->current_callback please
Posted by Stas Bekman <st...@stason.org>.
Josh Chamas wrote:
> Hey,
>
> I was wondering if we could get $r->current_callback into the standard
> mp2 API.
> It will just be one less thing to worry about when making things work
> across
> mp2 & mp1.
>
> Currently, this is implemented in Apache::compat with a call to
> Apache::current_callback, but I was wondering if this could be made
> standard for $r, maybe in addition to Apache::current_callback() working
> ...
>
> I have code in Apache::ASP that I am working on that is looking like:
>
> my $current_callback = eval { $r->current_callback } || eval {
> Apache::current_callback() };
> if($current_callback) {
> $request_binary_read = ($current_callback =~
> /^Perl(Response)?Handler$/) ? 1 : 0;
> } else {
> $request_binary_read = 1;
> }
>
> Like other environments I am sure, Apache::ASP runs in at least 3 modes,
> which is why this coding gets hairy... so far its running in mp1, mp2, &
> mod_cgi.
> I have a CGI $r emulator, but it ends up looking more like mp1 than mp2.
It's not $r->current_callback, because in mp2, there are more than twice
callbacks which are unrelated to $r. So it'd be very inconsistent to have to
call $r->current_callback for request phases, but Apache::current_callback for
the rest? Eventually everybody will shift to use mp2, and this kind of alias
will be just annoying. Do you agree?
As for making the code less hairy to support several modes, I believe the best
solution is to write your own wrappers and subclasses, moving all the
specifics there and making a single API for all modes. This will make your
code very clean and free of ugly branches.
For example: dynamically subclass $r (e.g. in Apache::ASP::Request) and
provide your own extensions depending on whether you are running mp1 or mp2,
so $r->current_callback can work regardless.
package Apache::ASPRequest;
sub new {
my (class, $r) = @_;
@Apache::ASPRequest::ISA = ref($r);
bless $r, __PACKAGE__;
}
if (Apache::ASP::MP2) {
*current_callback = sub { shift; Apache::current_callback() }
}
and in Apache::ASP, call my $r = Apache::ASPRequest->new($r), similar to what
Apache::Request does.
I believe you can make this for mp1, non-mp as well, so your code becomes very
clean.
__________________________________________________________________
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
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org