You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Kurt George Gjerde <ku...@intermedia.uib.no> on 2003/03/06 10:33:15 UTC

[mp2] $r->args

Stan and all,

I'll just send in things as I discover them. Nothing urgent; just file it
and look at it when time permits. Hope that's ok.


Under ModPerl::Registry (in script handled by Registry), $r->args is not
properly updated when the QUERY_STRING changes. Have to reload a couple of
times. Looks like a cache thing(?).

Changing http://example.com/?name=Janet to .../?name=Brian, $r->args still
contains "name=Janet".

On the other hand, is the availability of $r in registry scripts just a
side-effect? (should $r be available or not).


Best,
-Kurt.
__________
kurt george gjerde <ku...@intermedia.uib.no>
intermedia uib, university of bergen

I don't work here.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] $r->args

Posted by Stas Bekman <st...@stason.org>.
Stas Bekman wrote:
> Kurt George Gjerde wrote:
> 
>> Stan and all,
>>
>> I'll just send in things as I discover them. Nothing urgent; just file it
>> and look at it when time permits. Hope that's ok.
>>
>>
>> Under ModPerl::Registry (in script handled by Registry), $r->args is not
>> properly updated when the QUERY_STRING changes. Have to reload a 
>> couple of
>> times. Looks like a cache thing(?).
>>
>> Changing http://example.com/?name=Janet to .../?name=Brian, $r->args 
>> still
>> contains "name=Janet".
>>
>> On the other hand, is the availability of $r in registry scripts just a
>> side-effect? (should $r be available or not).
> 
> 
> Hmm, interesting. You must have created a closure. I'm sure if you show 
> a sample code this will be easier to understand.
> 
> Based on your side-effect comment, I think what you do is:
> 
> test.pl:
> --------
> $r->content_type('text/plain');
> $r->print($r->args);
> 
> whereas you should do:
> 
> test.pl:
> --------
> my $r = shift;
> $r->content_type('text/plain');
> $r->print($r->args);
> 
> why? because what registry does is wrapping the code into a function 
> handler, passing $r as an argument. However it's also in the scope of 
> the code that calls this function, so it looks like it work. However if 
> you change your code to:
> 
> test.pl:
> --------
> use warnings;
> $r->content_type('text/plain');
> $r->print($r->args);
> 
> you will see a warning:
> 
> Variable "$r" will not stay shared at 
> /home/stas/apache.org/temp/ModPerl-Registry/t/cgi-bin/args.pl line 5.
> 
> I think there is a similar potential problem in mp1, but I haven't checked.
> 
> In any case I'll make sure that $r is not in scope. when handler is called.
> 
> Also make sure you have warnings enabled globally, this will prevent a 
> lot of problems early.
> 
> PerlSwitches -wT
> 
> in httpd.conf.

The following patch will make sure that your script will complain under 'use 
strict' and it'll fail in any case, if it doesn't get its own $r . The problem 
doesn't exist in Apache::Registry, but does exist in Apache::PerlRun, I'll 
patch it.

Index: lib/ModPerl/RegistryCooker.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/ModPerl-Registry/lib/ModPerl/RegistryCooker.pm,v
retrieving revision 1.33
diff -u -r1.33 RegistryCooker.pm
--- lib/ModPerl/RegistryCooker.pm       2 Mar 2003 23:23:57 -0000       1.33
+++ lib/ModPerl/RegistryCooker.pm       8 Mar 2003 03:44:38 -0000
@@ -628,12 +628,12 @@
  # args: $self - registry blessed object
  #       $eval - a ref to a scalar with the code to compile
  # rtrn: success/failure
+# note: $r must not be in scope of compile(), scripts must do
+#       my $r = shift; to get it off the args stack
  #########################################################################

  sub compile {
      my($self, $eval) = @_;
-
-    my $r = $self->{REQ};

      $self->debug("compiling $self->{FILENAME}") if DEBUG && D_COMPILE;



__________________________________________________________________
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


Re: [mp2] $r->args

Posted by Stas Bekman <st...@stason.org>.
Kurt George Gjerde wrote:
> On Sat, 8 Mar 2003, Stas Bekman wrote:
> 
> 
>>test.pl:
>>--------
>>my $r = shift;
>>$r->content_type('text/plain');
>>$r->print($r->args);
>>
>>why? because what registry does is wrapping the code into a function handler,
>>passing $r as an argument. However it's also in the scope of the code that
>>calls this function, so it looks like it work. However if you change your code to:
> 
> 
> The  $r=shift  did the trick. I wasn't aware that the code was wrapped
> into a handler until I studied the RegistryCooker source yesterday. Sorry.

No prob. It won't work with the latest cvs without:

my $r = shift;

or

$r = Apache->request; # with PerlOptions +GlobalRequest

.

It's good that you caught it ;)

__________________________________________________________________
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


Re: [mp2] $r->args

Posted by Kurt George Gjerde <ku...@intermedia.uib.no>.
On Sat, 8 Mar 2003, Stas Bekman wrote:

> test.pl:
> --------
> my $r = shift;
> $r->content_type('text/plain');
> $r->print($r->args);
>
> why? because what registry does is wrapping the code into a function handler,
> passing $r as an argument. However it's also in the scope of the code that
> calls this function, so it looks like it work. However if you change your code to:

The  $r=shift  did the trick. I wasn't aware that the code was wrapped
into a handler until I studied the RegistryCooker source yesterday. Sorry.

Thanks,
-Kurt.
__________
kurt george gjerde <ku...@intermedia.uib.no>
intermedia uib, university of bergen

Working for bandwidth.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] $r->args

Posted by Stas Bekman <st...@stason.org>.
Kurt George Gjerde wrote:
> Stan and all,
> 
> I'll just send in things as I discover them. Nothing urgent; just file it
> and look at it when time permits. Hope that's ok.
> 
> 
> Under ModPerl::Registry (in script handled by Registry), $r->args is not
> properly updated when the QUERY_STRING changes. Have to reload a couple of
> times. Looks like a cache thing(?).
> 
> Changing http://example.com/?name=Janet to .../?name=Brian, $r->args still
> contains "name=Janet".
> 
> On the other hand, is the availability of $r in registry scripts just a
> side-effect? (should $r be available or not).

Hmm, interesting. You must have created a closure. I'm sure if you show a 
sample code this will be easier to understand.

Based on your side-effect comment, I think what you do is:

test.pl:
--------
$r->content_type('text/plain');
$r->print($r->args);

whereas you should do:

test.pl:
--------
my $r = shift;
$r->content_type('text/plain');
$r->print($r->args);

why? because what registry does is wrapping the code into a function handler, 
passing $r as an argument. However it's also in the scope of the code that 
calls this function, so it looks like it work. However if you change your code to:

test.pl:
--------
use warnings;
$r->content_type('text/plain');
$r->print($r->args);

you will see a warning:

Variable "$r" will not stay shared at 
/home/stas/apache.org/temp/ModPerl-Registry/t/cgi-bin/args.pl line 5.

I think there is a similar potential problem in mp1, but I haven't checked.

In any case I'll make sure that $r is not in scope. when handler is called.

Also make sure you have warnings enabled globally, this will prevent a lot of 
problems early.

PerlSwitches -wT

in httpd.conf.

__________________________________________________________________
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