You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by jonathan vanasco <jv...@mastersofbranding.com> on 2004/11/14 20:26:27 UTC
New to ModPerl 2
I'm new to using mod_perl2
A few years ago I made a web application in perl cgi, moved it over to
mod_perl1 about a year ago, and now I want to continue development of
it in mod_perl2
I probably made this wrong to begin with, as I learned from a handful
of mod_perl books
In mod_perl1, I have a handler that takes an apache request object
manipulates the cookie/session data into a user, then presents the user
with a page
in mod_perl2, however, there is no Apache::Request (yet) -- so my code
simply doesn't work at all. For some reason I'm not getting any decent
error messages in the log, but playing with the code I've found one of
the first issues to be with the cookies (i was using Apache::Cookie,
which no longer exists), so i've stripped that out to continue testing,
but keep on hitting walls of errors that aren't logged in the error
log.
I've tried installing the development branch of libapr , but that
hasn't been going well on my dev machine (mac osx)
If anyone can enlighten me to some better overall approaches to
code/cookies, and might have something to suggest based on my poorly
worded problem descriptions above, i would be greatly appreciative.
Thanks!
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: New to ModPerl 2
Posted by Stef1 <St...@pandava.com>.
I've used the following for about 6 months without any problem for
reading cookies:
# just copied all Apache related "use", not all needed for the sample
code below of course
use Apache::Connection;
use Apache::RequestRec ();
use Apache::RequestIO ();
use Apache::Request();
use APR::Brigade ();
use APR::Table();
use Apache::Const -compile => qw(OK);
use Apache::Cookie ();
*snip*
$self->{ApRequest}=shift;
*snip*
$hrCookies=Apache::Cookie->fetch ($self->{ApRequest});
foreach $ckey (keys %{$hrCookies}){
*snip*
}
For writing cookies however, I (still) use
$self->{ApRequest}->headers_out->add("Set-Cookie" => $cookie);
because I was not able to let it work with Apache::Cookie. It's possible
of course that the problem I had for writing cookies is solved in the
meanwhile (I've not tried again with newer versions because lack of
time, and this also works fine).
I'm now using Apache 2.0.50, modperl 1.99_16 and libapreq2-2.04
-- Stef
Jonathan Vanasco wrote:
>
> I'm just wondering how people have handled cookie stuff before --
>
> There seems to be a group that has encountered this error, and another
> group that has not -- if anyone is a member of the latter group and
> can share their approach to cookie/request handling (assuming its more
> than just substituting a ($r = shift;) with a ($req
> =Apache::Request->new($r)) i'd love to see it
>
> On Nov 16, 2004, at 8:31 AM, Joe Schaefer wrote:
>
>> OK, thanks! This bug should be fixed with
>> the next release. It's a bit tricky to
>> fix this, because Apache::Request doesn't
>> always inherit from the environment object.
>
>
>
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: New to ModPerl 2
Posted by Jonathan Vanasco <jv...@mastersofbranding.com>.
I'm just wondering how people have handled cookie stuff before --
There seems to be a group that has encountered this error, and another
group that has not -- if anyone is a member of the latter group and can
share their approach to cookie/request handling (assuming its more than
just substituting a ($r = shift;) with a ($req
=Apache::Request->new($r)) i'd love to see it
On Nov 16, 2004, at 8:31 AM, Joe Schaefer wrote:
> OK, thanks! This bug should be fixed with
> the next release. It's a bit tricky to
> fix this, because Apache::Request doesn't
> always inherit from the environment object.
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: New to ModPerl 2
Posted by Joe Schaefer <jo...@sunstarsys.com>.
jonathan vanasco <jv...@mastersofbranding.com> writes:
> On Nov 15, 2004, at 11:18 AM, Joe Schaefer wrote:
[...]
>> Can you please show us the code which segfaults?
[...]
> sub handler
> {
> my $r = shift;
> my $req = Apache::Request->new( $r , DISABLE_UPLOADS=>1);
> my %cookiejar = Apache::Cookie::Jar->new( $req );
OK, thanks! This bug should be fixed with
the next release. It's a bit tricky to
fix this, because Apache::Request doesn't
always inherit from the environment object.
--
Joe Schaefer
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: New to ModPerl 2
Posted by jonathan vanasco <jv...@mastersofbranding.com>.
Assuming this is a segfault, i get the same error:
[Tue Nov 16 00:45:17 2004] [notice] child pid 2237 exit signal Bus
error (10)
The only difference is the env variable to ApacheCookie
This works:
==========================
#file:MyApache/Rocks.pm
#----------------------
package MyApache::Rocks;
#use strict;
#use warnings;
use Apache2;
use Apache2::mod_perl();
use Apache::RequestRec ();
use Apache::RequestIO ();
use Apache::Request ();
use Apache::Cookie();
use Apache::Const -compile => qw(OK);
sub handler
{
my $r = shift;
my $req = Apache::Request->new( $r , DISABLE_UPLOADS=>1);
my %cookiejar = Apache::Cookie::Jar->new( $r );
$r->content_type('text/plain');
print "mod_perl 2.0 rocks!\n";
return Apache::OK;
}
1;
==========================
This does not
==========================
#file:MyApache/Rocks.pm
#----------------------
package MyApache::Rocks;
#use strict;
#use warnings;
use Apache2;
use Apache2::mod_perl();
use Apache::RequestRec ();
use Apache::RequestIO ();
use Apache::Request ();
use Apache::Cookie();
use Apache::Const -compile => qw(OK);
sub handler
{
my $r = shift;
my $req = Apache::Request->new( $r , DISABLE_UPLOADS=>1);
my %cookiejar = Apache::Cookie::Jar->new( $req );
$r->content_type('text/plain');
print "mod_perl 2.0 rocks!\n";
return Apache::OK;
}
1;
On Nov 15, 2004, at 11:18 AM, Joe Schaefer wrote:
> Kurt Hansen <kh...@charityweb.net> writes:
>
> [...]
>
>> A few things that caused me more pain than I care to admit:
>>
>> 1. Apache::Cookie v2 requires an Apache::RequestRec environment
>> variable instead of an Apache::Request variable. Using the latter
>> caused a segmentation fault.
>
> If so, that's really a bug, not a portability issue. Apache::Request
> objects are derived from Apache::RequestRec, so it should be ok to pass
> them to any Apache::Cookie methods which expect an Apache::RequestRec
> object.
>
> Can you please show us the code which segfaults?
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: New to ModPerl 2
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Kurt Hansen <kh...@charityweb.net> writes:
[...]
> A few things that caused me more pain than I care to admit:
>
> 1. Apache::Cookie v2 requires an Apache::RequestRec environment
> variable instead of an Apache::Request variable. Using the latter
> caused a segmentation fault.
If so, that's really a bug, not a portability issue. Apache::Request
objects are derived from Apache::RequestRec, so it should be ok to pass
them to any Apache::Cookie methods which expect an Apache::RequestRec
object.
Can you please show us the code which segfaults?
> 3. Expires method works differently between v1 and v2 of
> Apache::Cookie->new. An empty variable for -expires will default to
> "now" in v2 which means the cookie won't be set since it expires
> immediately. In v1, an empty -expires created a session cookie. To
> get the same behavior in v2, just don't supply an -expires parameter
> in new.
Interesting. It looks like CGI::Cookie has the v2 behavior.
$ perl -MCGI::Cookie -wle '$c = new CGI::Cookie
-name=>1, -value=>2, -expires=>"";
print $c->as_string'
1=2; path=/; expires=Mon, 15-Nov-2004 16:15:09 GMT
I'm not sure if this is a bug in libapreq2. Any other opinions
out there?
--
Joe Schaefer
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: New to ModPerl 2
Posted by Kurt Hansen <kh...@charityweb.net>.
Markus Wichitill wrote:
> jonathan vanasco wrote:
>
>> In mod_perl1, I have a handler that takes an apache request object
>> manipulates the cookie/session data into a user, then presents the
>> user with a page
>>
>> in mod_perl2, however, there is no Apache::Request (yet) -- so my
>> code simply doesn't work at all.
>
>
> Apache::Request 2.0 (libapreq2), like mod_perl 2.0, is officially
> still in development, but mostly done.
>
> http://httpd.apache.org/apreq/
I second the advice to use libapreq2 if your code is based on libapreq1.
I'm almost done with the conversion.
Note, though, that libapreq2 will require some changes in your code, but
probably less than not using libapreq. Be sure to read the
documentation, especially the notes about converting from v1, for
Apache::Request and Apache::Cookie at:
http://httpd.apache.org/apreq/docs/libapreq2/modules.html
A few things that caused me more pain than I care to admit:
1. Apache::Cookie v2 requires an Apache::RequestRec environment variable
instead of an Apache::Request variable. Using the latter caused a
segmentation fault. I believe $r in modperl2 is an Apache::RequestRec
object, so just using your old code call should work fine. I, however,
use HTML::Mason v1.27 which converted $r into an Apache::Request object
which caused me much confusion.
2. Name and Value of a cookie cannot be changed. You'll have to create a
new Apache::Cookie if you want to change either.
3. Expires method works differently between v1 and v2 of
Apache::Cookie->new. An empty variable for -expires will default to
"now" in v2 which means the cookie won't be set since it expires
immediately. In v1, an empty -expires created a session cookie. To get
the same behavior in v2, just don't supply an -expires parameter in new.
Take care,
Kurt Hansen
khansen@charityweb.net
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: New to ModPerl 2
Posted by jonathan vanasco <jv...@mastersofbranding.com>.
On Nov 14, 2004, at 7:04 PM, Dan Brian wrote:
>
> I'll add to your list (of potential confusion) that $r->args may not
> produce the expected results, and not just because of the change away
> from array context described at:
>
>
> <http://perl.apache.org/docs/2.0/user/porting/
> compat.html#C__r_E_gt_args__in_an_Array_Context>
>
> Although Apache::Request inherits methods from Apache::RequestRec,
> args() is one place where there is function overlap:
> Apache::Request->args() returns an Apache::Request::Table object,
> while Apache::RequestRec->args() returns the unparsed query string.
Gee... Thanks...
This is a lot to digest.
I think I may have extended use of deprecated features, and I'm not
averse to refactoring the code
Apache::Compat, apparently is slow
CGI.pm, if i remember, was awkward and also slow
ugh
I think i need a drink
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: New to ModPerl 2
Posted by Dan Brian <da...@brians.org>.
> Note, though, that libapreq2 will require some changes in your code,
> but probably less than not using libapreq. Be sure to read the
> documentation, especially the notes about converting from v1, for
> Apache::Request and Apache::Cookie at:
I'll add to your list (of potential confusion) that $r->args may not
produce the expected results, and not just because of the change away
from array context described at:
<http://perl.apache.org/docs/2.0/user/porting/
compat.html#C__r_E_gt_args__in_an_Array_Context>
Although Apache::Request inherits methods from Apache::RequestRec,
args() is one place where there is function overlap:
Apache::Request->args() returns an Apache::Request::Table object, while
Apache::RequestRec->args() returns the unparsed query string.
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: New to ModPerl 2
Posted by jonathan vanasco <jv...@mastersofbranding.com>.
On Nov 14, 2004, at 4:06 PM, Kurt Hansen wrote:
> Markus Wichitill wrote:
>> Apache::Request 2.0 (libapreq2), like mod_perl 2.0, is officially
>> still in development, but mostly done.
>>
>> http://httpd.apache.org/apreq/
>
> I second the advice to use libapreq2 if your code is based on
> libapreq1. I'm almost done with the conversion.
Thanks to both then!
I was under the impression that it is 'more correct' to not use the
request object in mod_perl2 and instead approach the application
development differently.
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: New to ModPerl 2
Posted by Kurt Hansen <kh...@charityweb.net>.
Markus Wichitill wrote:
> jonathan vanasco wrote:
>
>> In mod_perl1, I have a handler that takes an apache request object
>> manipulates the cookie/session data into a user, then presents the
>> user with a page
>>
>> in mod_perl2, however, there is no Apache::Request (yet) -- so my
>> code simply doesn't work at all.
>
>
> Apache::Request 2.0 (libapreq2), like mod_perl 2.0, is officially
> still in development, but mostly done.
>
> http://httpd.apache.org/apreq/
I second the advice to use libapreq2 if your code is based on libapreq1.
I'm almost done with the conversion.
Note, though, that libapreq2 will require some changes in your code, but
probably less than not using libapreq. Be sure to read the
documentation, especially the notes about converting from v1, for
Apache::Request and Apache::Cookie at:
http://httpd.apache.org/apreq/docs/libapreq2/modules.html
A few things that caused me more pain than I care to admit:
1. Apache::Cookie v2 requires an Apache::RequestRec environment variable
instead of an Apache::Request variable. Using the latter caused a
segmentation fault. I believe $r in modperl2 is an Apache::RequestRec
object, so just using your old code call should work fine. I, however,
use HTML::Mason v1.27 which converted $r into an Apache::Request object
which caused me much confusion.
2. Name and Value of a cookie cannot be changed. You'll have to create a
new Apache::Cookie if you want to change either.
3. Expires method works differently between v1 and v2 of
Apache::Cookie->new. An empty variable for -expires will default to
"now" in v2 which means the cookie won't be set since it expires
immediately. In v1, an empty -expires created a session cookie. To get
the same behavior in v2, just don't supply an -expires parameter in new.
Take care,
Kurt Hansen
khansen@charityweb.net
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: New to ModPerl 2
Posted by Markus Wichitill <ma...@gmx.de>.
jonathan vanasco wrote:
> In mod_perl1, I have a handler that takes an apache request object
> manipulates the cookie/session data into a user, then presents the user
> with a page
>
> in mod_perl2, however, there is no Apache::Request (yet) -- so my code
> simply doesn't work at all.
Apache::Request 2.0 (libapreq2), like mod_perl 2.0, is officially still in
development, but mostly done.
http://httpd.apache.org/apreq/
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html