You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Randy Kobes <ra...@theoryx5.uwinnipeg.ca> on 2007/02/05 18:17:05 UTC
[RFC] two ajax-related packages
I've placed up at
http://people.apache.org/~randyk/
a couple of modules that provide a mod_perl2 interface
to two Ajax-related packages:
- Apache2-Ajax-0.1.tar.gz: a mod_perl2 interface
to CGI::Ajax, which provides a mechanism for using perl
code asynchronously from javascript-enhanced HTML pages.
- Apache2-Autocomplete-0.1.tar.gz: a mod_perl2 interface
to JavaScript::Autocomplete::Backend, which is a base
class for implementing an autocomplete service
for a form using the Google Suggest protocol.
Both modules require a CGI.pm-compatible module to provide,
in particular, param() and header() methods to,
respectively, fetch parameters and to set the headers.
If the memory requirements of CGI.pm are a concern in a
mod_perl environment, you may want to try
- CGI-Apache2-Ajax-0.1.tar.gz
from the same location - this provides param() and
header() methods via mod_perl2 and librapreq2.
Apache2::Ajax and Apache2::Autocomplete will use
CGI::Apache2::Ajax if available, and if not will use
CGI.pm (version 2.93 or greater).
I'd be interested in any comments about these
packages, including their names. CGI::Apache2::Ajax
was tentatively chosen because, first of all, it only
provides CGI.pm-compatible methods that the above two
Ajax-related applications need, and also, CGI::Ajax
expects the CGI object to satisfy
ref($cgi) =~ /^CGI.*/
Note though that, due to the nature of the APR::* modules
used, CGI::Apache2::Ajax can also be used in a CGI
environment. Thanks.
--
best regards,
Randy Kobes
Re: [RFC] two ajax-related packages
Posted by Issac Goldstand <ma...@beamartyr.net>.
Randy Kobes wrote:
> On Tue, 6 Feb 2007, Issac Goldstand wrote:
>
>> Randy Kobes wrote:
>>> I'd be interested in any comments about these
>>> packages, including their names. CGI::Apache2::Ajax
>>> was tentatively chosen because, first of all, it only
>>> provides CGI.pm-compatible methods that the above two Ajax-related
>>> applications need, and also, CGI::Ajax
>>> expects the CGI object to satisfy
>>> ref($cgi) =~ /^CGI.*/
>>> Note though that, due to the nature of the APR::* modules
>>> used, CGI::Apache2::Ajax can also be used in a CGI
>>> environment. Thanks.
>>>
>>
>> Maybe I'm missing something, but why not autodetect Apache2::Request +
>> mod_perl2 presence and fallback to CGI if it doesn't work?
>>
>> Something like:
>>
>> if (exists $ENV{MOD_PERL_API_VERSION} &&
>> $ENV{MOD_PERL_API_VERSION} >= 2 &&
>> eval {require Apache2::Request}) {
>> ... mod_perl mode ...
>> } else {
>> ... CGI mode ...
>> }
>
> This type of check is done to see if one is running in a
> mod_perl environment, and if so, the Apache2::RequestRec
> object $r is used for things like setting the content-type
> header. For fetching parameters, however, Apache2::Request
> can also be used in a CGI environment, which may be
> useful for applications for which speed and/or memory
> is a concern. Thus, CGI::Apache2::Ajax relies completely
> on mod_perl2 and libapreq2, the intent being that it's
> up to the package needing these methods to use CGI if
> CGI::Apache2::Ajax isn't available (which Apache2-Ajax
> and Apache2-Autocomplete do).
>
Right, but I don't know of too many people using libapreq's perl glue
without mod_perl (and frankly wouldn't expect to at least until APR's
perl glue is separated from the rest of mod_perl)
Re: [RFC] two ajax-related packages
Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Tue, 6 Feb 2007, Issac Goldstand wrote:
> Randy Kobes wrote:
>> I'd be interested in any comments about these
>> packages, including their names. CGI::Apache2::Ajax
>> was tentatively chosen because, first of all, it only
>> provides CGI.pm-compatible methods that the above two Ajax-related
>> applications need, and also, CGI::Ajax
>> expects the CGI object to satisfy
>> ref($cgi) =~ /^CGI.*/
>> Note though that, due to the nature of the APR::* modules
>> used, CGI::Apache2::Ajax can also be used in a CGI
>> environment. Thanks.
>>
>
> Maybe I'm missing something, but why not autodetect Apache2::Request +
> mod_perl2 presence and fallback to CGI if it doesn't work?
>
> Something like:
>
> if (exists $ENV{MOD_PERL_API_VERSION} &&
> $ENV{MOD_PERL_API_VERSION} >= 2 &&
> eval {require Apache2::Request}) {
> ... mod_perl mode ...
> } else {
> ... CGI mode ...
> }
This type of check is done to see if one is running in a
mod_perl environment, and if so, the Apache2::RequestRec
object $r is used for things like setting the content-type
header. For fetching parameters, however, Apache2::Request
can also be used in a CGI environment, which may be
useful for applications for which speed and/or memory
is a concern. Thus, CGI::Apache2::Ajax relies completely
on mod_perl2 and libapreq2, the intent being that it's
up to the package needing these methods to use CGI if
CGI::Apache2::Ajax isn't available (which Apache2-Ajax
and Apache2-Autocomplete do).
--
best regards,
Randy
Re: [RFC] two ajax-related packages
Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Tue, 6 Feb 2007, Jonathan Vanasco wrote:
> On Feb 6, 2007, at 4:04 AM, Issac Goldstand wrote:
>
>> Maybe I'm missing something, but why not autodetect Apache2::Request +
>> mod_perl2 presence and fallback to CGI if it doesn't work?
>>
>> Something like:
>
> I'm going to talk in context of CGI::Apache2::Ajax, as I
> haven't had time to look at the rest.
>
> Personally, I would like to see something in terms of ENV variables
> that one can set to force it to use libapreq or cgi pm
> Thats just because every now and then I switch from one to the other
> to debug
I've uploaded version 0.2 of this package (now called
CGI-Apache2-Wrapper) to CPAN; this contains recognition
of an environment variable USE_CGI_PM which, if set, will
cause a CGI.pm object to be used. This version also
has several additional CGI.pm-compatible methods added,
such as url (with options), cookie(), and upload().
This also drops support for using the mp2/libapreq2
methods in a cgi environment.
Thanks for the comments - let me know if there's
something useful missing, or if something's not
working as it should.
--
best regards,
Randy
Re: [RFC] two ajax-related packages
Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Tue, 6 Feb 2007, Jonathan Vanasco wrote:
> I'm going to talk in context of CGI::Apache2::Ajax, as I
> haven't had time to look at the rest.
>
> Personally, I would like to see something in terms of ENV variables
> that one can set to force it to use libapreq or cgi pm
> Thats just because every now and then I switch from one to the other
> to debug
I also like to do that switch. However, I think that'd
more naturally be done at the level of the application;
the purpose of this module was just to provide a few
CGI.pm-compatible methods via mod_perl2/libapreq2. The
interface used is such that, within an application, one
can do
my $cgi;
if ($some_condition_is_met) {
$cgi = CGI::Apache2::Ajax->new($r);
}
else {
$cgi = CGI->new($r);
}
my $foo = $cgi->param("foo");
and so can switch between CGI.pm and mod_perl2/libapreq2
by adjusting $some_condition_is_met; the method calls
on $cgi are intended to be compatible.
> my other comment is the name:
> its just a bit confusing as it doesn't really handle a lot of
> functionality and abstracts other items. perhaps something like
> CGI::Apache2::AjaxProvider , Apache2::AjaxProvider, or even
> CGI::AjaxProvider. also , just a thought - but something like that seems
> more inline with the purpose of your module.
That's a good suggestion. A couple of people off-list also
raised this, and one suggestion was CGI-Apache2-Wrapper.
CGI::Ajax wants it to start with "CGI", so this sounds
like a good name. I've adjusted Apache2-Ajax and
Apache2-Autocomplete to use this if available; all three
packages are now making their way around CPAN.
Thanks!
--
best regards,
Randy
Re: [RFC] two ajax-related packages
Posted by Jonathan Vanasco <jv...@2xlp.com>.
On Feb 6, 2007, at 4:04 AM, Issac Goldstand wrote:
> Maybe I'm missing something, but why not autodetect Apache2::Request +
> mod_perl2 presence and fallback to CGI if it doesn't work?
>
> Something like:
I'm going to talk in context of CGI::Apache2::Ajax, as I haven't had
time to look at the rest.
Personally, I would like to see something in terms of ENV variables
that one can set to force it to use libapreq or cgi pm
Thats just because every now and then I switch from one to the
other to debug
i only briefly looked at the code, but I believe this would be
separate from the $ENV{MOD_PERL} and the global
$CGI::Apache2::Ajax::MOD_PERL
it would be more like a
CGI::Apache2::Ajax::USE_MOD_PERL_IF_AVAILABLE , so one could change
the behavior on the fly -- just an idea.
my other comment is the name:
its just a bit confusing as it doesn't really handle a lot of
functionality and abstracts other items. perhaps something like
CGI::Apache2::AjaxProvider , Apache2::AjaxProvider, or even
CGI::AjaxProvider. also , just a thought - but something like that
seems more inline with the purpose of your module.
anyways, as always - great work. can't wait to use them -- i know i
will shortly.
// Jonathan Vanasco
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
| SyndiClick.com
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
| FindMeOn.com - The cure for Multiple Web Personality Disorder
| Web Identity Management and 3D Social Networking
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
| RoadSound.com - Tools For Bands, Stuff For Fans
| Collaborative Online Management And Syndication Tools
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
Re: [RFC] two ajax-related packages
Posted by Issac Goldstand <ma...@beamartyr.net>.
Randy Kobes wrote:
> I'd be interested in any comments about these
> packages, including their names. CGI::Apache2::Ajax
> was tentatively chosen because, first of all, it only
> provides CGI.pm-compatible methods that the above two Ajax-related
> applications need, and also, CGI::Ajax
> expects the CGI object to satisfy
> ref($cgi) =~ /^CGI.*/
> Note though that, due to the nature of the APR::* modules
> used, CGI::Apache2::Ajax can also be used in a CGI
> environment. Thanks.
>
Maybe I'm missing something, but why not autodetect Apache2::Request +
mod_perl2 presence and fallback to CGI if it doesn't work?
Something like:
if (exists $ENV{MOD_PERL_API_VERSION} &&
$ENV{MOD_PERL_API_VERSION} >= 2 &&
eval {require Apache2::Request}) {
... mod_perl mode ...
} else {
... CGI mode ...
}
Issac