You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Thomas Hilbig <th...@yahoo.com> on 2005/08/05 16:49:09 UTC
[mp2] CGI.pm porting/co-existence questions
I have many CGI scripts running under mp2 using
ModPerl::Registry, that I want to re-architect to use
more Apache API's (for speed) and handlers (i.e.
authentication, logging).
I have been getting up to speed on the mp2 docs these
past couple of weeks. I haven't really seen any
good recommendations as to when to use the CGI.pm
methods instead of the Apache2 methods - especially
docs that are updated for mp2, so I can avoid having
to learn the mp1 API and then unlearn/port to mp2.
Has anyone got any tips or seen any current documents
on when/not to use CGI.pm instead of the native Apache
API with respect to;
fetching/setting cookies
fetching parameters (GET arguments or POST)
simple HTML elements
more complex HTML elements (forms, header/body)
print vs. $r->print
Also, the mp2 User's Guide (section 10.9.1) says
CGI.pm now takes $r as an argument to its new()
function. What benefit is this? Is it required?
Tom
__________________________________
Yahoo! Mail for Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
http://mobile.yahoo.com/learn/mail
Re: [mp2] CGI.pm porting/co-existence questions
Posted by Stas Bekman <st...@stason.org>.
Philip M. Gollucci wrote:
> Stas Bekman wrote:
>
>>
>>>>> print vs. $r->print
>>>>
>>>>
>>>>
>>>> This is drastically faster.. especially if you use
>>>> one print
>>>> per request at the end and/or pass a reference to
>>>> the scalar string.
>>
>> Actually this is no longer true. in mp2 you can't pass a reference to
>> a scalar.
>>
>> Still $r->print is faster :)
>
> I think I knew that. Why did that change?
You mean passing by reference? I think it just doesn't make any sense
because of the way mp2's print works. There are filters, so things work
very differently.
--
__________________________________________________________________
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
Re: [mp2] CGI.pm porting/co-existence questions
Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Stas Bekman wrote:
>
>>>> print vs. $r->print
>>>
>>>
>>> This is drastically faster.. especially if you use
>>> one print
>>> per request at the end and/or pass a reference to
>>> the scalar string.
>
>
> Actually this is no longer true. in mp2 you can't pass a reference to a
> scalar.
>
> Still $r->print is faster :)
I think I knew that. Why did that change?
--
END
------------------------------------------------------------
What doesn't kill us can only make us stronger.
Nothing is impossible.
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
http://www.liquidityservicesinc.com
http://www.liquidation.com
http://www.uksurplus.com
http://www.govliquidation.com
http://www.gowholesale.com
Re: [mp2] CGI.pm porting/co-existence questions
Posted by Stas Bekman <st...@stason.org>.
>>> print vs. $r->print
>>
>>This is drastically faster.. especially if you use
>>one print
>>per request at the end and/or pass a reference to
>>the scalar string.
Actually this is no longer true. in mp2 you can't pass a reference to a
scalar.
Still $r->print is faster :)
>>>Also, the mp2 User's Guide (section 10.9.1) says
>>>CGI.pm now takes $r as an argument to its new()
>>>function. What benefit is this? Is it required?
>>
>>For the most part its optional.
>>You may need to look at PerlGlobalRequest
>>
>
> http://perl.apache.org/docs/2.0/user/config/config.html#C_GlobalRequest_
>
> I'm still confused why this is optional in CGI.pm.
> Does it save some cycles by avoiding CGI.pm having to
> sniff around for the Apache requestor?
Right. When you pass $r as an argument you should set -GlobalRequest (see
the url above). Setting the global $r is time consuming, especially in the
threaded environment.
--
__________________________________________________________________
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
Re: [mp2] CGI.pm porting/co-existence questions
Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Thomas Hilbig wrote:
>>>Also, the mp2 User's Guide (section 10.9.1) says
>>>CGI.pm now takes $r as an argument to its new()
>>>function. What benefit is this? Is it required?
>>
>>For the most part its optional.
>>You may need to look at PerlGlobalRequest
>>
>
> http://perl.apache.org/docs/2.0/user/config/config.html#C_GlobalRequest_
>
> I'm still confused why this is optional in CGI.pm.
> Does it save some cycles by avoiding CGI.pm having to
> sniff around for the Apache requestor?
From CGI.pm::new():
....
if (ref($initializer[0])
&& (UNIVERSAL::isa($initializer[0],'Apache')
||
UNIVERSAL::isa($initializer[0],'Apache2::RequestRec')
)) {
$self->r(shift @initializer);
}
....
if ($MOD_PERL) {
if ($MOD_PERL == 1) {
$self->r(Apache->request) unless $self->r;
my $r = $self->r;
$r->register_cleanup(\&CGI::_reset_globals);
}
else {
# XXX: once we have the new API
# will do a real PerlOptions -SetupEnv check
$self->r(Apache2::RequestUtil->request) unless $self->r;
my $r = $self->r;
$r->subprocess_env unless exists $ENV{REQUEST_METHOD};
$r->pool->cleanup_register(\&CGI::_reset_globals);
}
undef $NPH;
}
....
After CGI->new() or CGI->new($r) is called from here on out internall it
will just use $self->r whenver an Apache2::Request object is needed.
I'm not entirely sure it will say you speed passing or not passing it.
The only benefit I see is that you could pass a subclassed version in.
Though I may be missing something.
HTH
--
END
------------------------------------------------------------
What doesn't kill us can only make us stronger.
Nothing is impossible.
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
http://www.liquidityservicesinc.com
http://www.liquidation.com
http://www.uksurplus.com
http://www.govliquidation.com
http://www.gowholesale.com
Re: [mp2] CGI.pm porting/co-existence questions
Posted by Thomas Hilbig <th...@yahoo.com>.
--- "Philip M. Gollucci" <pg...@p6m7g8.com> wrote:
> > fetching/setting cookies
> > fetching parameters (GET arguments or POST)
> use APR::Request::*
> Its faster as its in XS glue code.
That does look like it will do it just as simply as
CGI.pm. APR::Request (libapreq) wasn't part of the
httpd or mp2 binary (ppm) so I hadn't noticed it
before.
> > simple HTML elements
> > more complex HTML elements (forms, header/body)
> shouldn't you be using templates :)
>
> Though to implement the template engine, I use
> CGI.pm for
> popup_menu() and the like.... Cleaner code, but more
> memory.
I don't have any duplication that would benefit from
templates. popup_menu() is a good example where
CGI.pm shines.
>
> I was not aware that Apache2::* or APR::* had
> methods for generating HTML.
I mean having to get into the html code instead of
using the CGI.pm to do it for you. I tend not to take
advantage of the CGI.pm methods anyway.
>
> > print vs. $r->print
> This is drastically faster.. especially if you use
> one print
> per request at the end and/or pass a reference to
> the scalar string.
>
> > Also, the mp2 User's Guide (section 10.9.1) says
> > CGI.pm now takes $r as an argument to its new()
> > function. What benefit is this? Is it required?
> For the most part its optional.
> You may need to look at PerlGlobalRequest
>
http://perl.apache.org/docs/2.0/user/config/config.html#C_GlobalRequest_
>
I'm still confused why this is optional in CGI.pm.
Does it save some cycles by avoiding CGI.pm having to
sniff around for the Apache requestor?
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Re: [mp2] CGI.pm porting/co-existence questions
Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
> fetching/setting cookies
> fetching parameters (GET arguments or POST)
use APR::Request::*
Its faster as its in XS glue code.
> simple HTML elements
> more complex HTML elements (forms, header/body)
shouldn't you be using templates :)
Though to implement the template engine, I use CGI.pm for
popup_menu() and the like.... Cleaner code, but more memory.
I was not aware that Apache2::* or APR::* had methods for generating HTML.
> print vs. $r->print
This is drastically faster.. especially if you use one print
per request at the end and/or pass a reference to the scalar string.
> Also, the mp2 User's Guide (section 10.9.1) says
> CGI.pm now takes $r as an argument to its new()
> function. What benefit is this? Is it required?
For the most part its optional.
You may need to look at PerlGlobalRequest
http://perl.apache.org/docs/2.0/user/config/config.html#C_GlobalRequest_