You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Tosh Cooey <to...@1200group.com> on 2010/01/15 19:41:45 UTC

$r->subprocess_env('REQUEST_URI') returns undef ?

From:
http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_subprocess_env_

subprocess_env

Get/set the Apache subprocess_env table, or optionally set the value of 
a named entry.

When the $key argument (string) is passed, it returns the corresponding 
value (if such exists, or undef. The following two lines are equivalent:

   $val = $r->subprocess_env($key);
   $val = $r->subprocess_env->get($key);


Ok... Seems simple enough...

In my module if I do the following:

$r->subprocess_env;
my $uri = $ENV{REQUEST_URI};

The I get the URI.

But if I change the above to:

my $uri = $r->subprocess_env('REQUEST_URI');

I get undef.

Confused.

Tosh

-- 
McIntosh Cooey - Twelve Hundred Group LLC - http://www.1200group.com/

Re: $r->subprocess_env('REQUEST_URI') returns undef ?

Posted by Tosh Cooey <to...@1200group.com>.
Ah... I assumed that $r->subprocess_env in VOID context was an expensive 
operation as it populated $ENV (from what I had read) as one should try 
to avoid it.  I also find it non-intuitive that:

$r->subprocess_env;       # void context
my $uri = $r->subprocess_env('REQUEST_URI');

is the same as

$r->subprocess_env;
my $uri = $ENV{REQUEST_URI};

But that's obviously just my lack of intuitiveness.

Yes, $r->uri is about a billion times more useful, thank-you again 
David, and thanks for your help Torsten!

Tosh


Torsten Förtsch wrote:
> On Friday 15 January 2010 19:41:45 Tosh Cooey wrote:
>> When the $key argument (string) is passed, it returns the corresponding 
>> value (if such exists, or undef. The following two lines are equivalent:
>>
>>    $val = $r->subprocess_env($key);
>>    $val = $r->subprocess_env->get($key);
>>
>>
>> Ok... Seems simple enough...
>>
>> In my module if I do the following:
>>
>> $r->subprocess_env;
>> my $uri = $ENV{REQUEST_URI};
>>
>> The I get the URI.
>>
>> But if I change the above to:
>>
>> my $uri = $r->subprocess_env('REQUEST_URI');
>>
>> I get undef.
>>
> Tosh, do you know what VOID context means in perl?
> 
> @list=function()      # this list context
> $scalar=function()    # this is scalar context
> function()            # this is void context: the return value is ignored
> 
> Now, in void context and only then subprocess_env() calls
> 
>        ap_add_common_vars(r);
>        ap_add_cgi_vars(r);
> 
> These 2 functions add such things like REQUEST_URI to the environment.
> 
> So, if you do it like this:
> 
>        $r->subprocess_env;       # void context
>        my $uri = $r->subprocess_env('REQUEST_URI');
> 
> it is very likely that you get the REQUEST_URI.
> 
> But as David pointed out, $r->uri is the much better way.
> 
> Torsten
> 

-- 
McIntosh Cooey - Twelve Hundred Group LLC - http://www.1200group.com/

Re: $r->subprocess_env('REQUEST_URI') returns undef ?

Posted by Torsten Förtsch <to...@gmx.net>.
On Friday 15 January 2010 19:41:45 Tosh Cooey wrote:
> When the $key argument (string) is passed, it returns the corresponding 
> value (if such exists, or undef. The following two lines are equivalent:
> 
>    $val = $r->subprocess_env($key);
>    $val = $r->subprocess_env->get($key);
> 
> 
> Ok... Seems simple enough...
> 
> In my module if I do the following:
> 
> $r->subprocess_env;
> my $uri = $ENV{REQUEST_URI};
> 
> The I get the URI.
> 
> But if I change the above to:
> 
> my $uri = $r->subprocess_env('REQUEST_URI');
> 
> I get undef.
> 
Tosh, do you know what VOID context means in perl?

@list=function()      # this list context
$scalar=function()    # this is scalar context
function()            # this is void context: the return value is ignored

Now, in void context and only then subprocess_env() calls

       ap_add_common_vars(r);
       ap_add_cgi_vars(r);

These 2 functions add such things like REQUEST_URI to the environment.

So, if you do it like this:

       $r->subprocess_env;       # void context
       my $uri = $r->subprocess_env('REQUEST_URI');

it is very likely that you get the REQUEST_URI.

But as David pointed out, $r->uri is the much better way.

Torsten

Re: $r->subprocess_env('REQUEST_URI') returns undef ?

Posted by Tosh Cooey <to...@1200group.com>.
Not at all, I have no idea what they are, and ignorance is bliss!

Ah... Blessed ignorance...

Tosh


craig@animalhead.com wrote:
> If $r scares you, are $c = $r->connection() and $s = $r->server() truly 
> terrifying :-)
> 
> cmac
> 
> On Jan 15, 2010, at 4:08 PM, Tosh Cooey wrote:
> 
>> It's probably obvious, but $r kinda scares me.  I guess I saw 
>> subprocess_env in the docs and so that's where I stopped... What a 
>> couple centimeters more would have done...
>>
> 
> 

-- 
McIntosh Cooey - Twelve Hundred Group LLC - http://www.1200group.com/

Re: $r->subprocess_env('REQUEST_URI') returns undef ?

Posted by cr...@animalhead.com.
If $r scares you, are $c = $r->connection() and $s = $r->server()  
truly terrifying :-)

cmac

On Jan 15, 2010, at 4:08 PM, Tosh Cooey wrote:

> It's probably obvious, but $r kinda scares me.  I guess I saw  
> subprocess_env in the docs and so that's where I stopped... What a  
> couple centimeters more would have done...
>


Re: $r->subprocess_env('REQUEST_URI') returns undef ?

Posted by Tosh Cooey <to...@1200group.com>.
It's probably obvious, but $r kinda scares me.  I guess I saw 
subprocess_env in the docs and so that's where I stopped... What a 
couple centimeters more would have done...

Thank-you David!!

Tosh


Ihnen, David wrote:
> At the risk of being kind of obvious, did you try $r->uri?
> 
> http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_uri_
> 
> David
> 
> -----Original Message-----
> From: Tosh Cooey [mailto:tosh@1200group.com] 
> Sent: Friday, January 15, 2010 10:42 AM
> To: modperl@perl.apache.org
> Subject: $r->subprocess_env('REQUEST_URI') returns undef ?
> 
> From:
> http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_subprocess_env_
> 
> subprocess_env
> 
> Get/set the Apache subprocess_env table, or optionally set the value of 
> a named entry.
> 
> When the $key argument (string) is passed, it returns the corresponding 
> value (if such exists, or undef. The following two lines are equivalent:
> 
>    $val = $r->subprocess_env($key);
>    $val = $r->subprocess_env->get($key);
> 
> 
> Ok... Seems simple enough...
> 
> In my module if I do the following:
> 
> $r->subprocess_env;
> my $uri = $ENV{REQUEST_URI};
> 
> The I get the URI.
> 
> But if I change the above to:
> 
> my $uri = $r->subprocess_env('REQUEST_URI');
> 
> I get undef.
> 
> Confused.
> 
> Tosh
> 

-- 
McIntosh Cooey - Twelve Hundred Group LLC - http://www.1200group.com/

RE: $r->subprocess_env('REQUEST_URI') returns undef ?

Posted by "Ihnen, David" <di...@amazon.com>.
At the risk of being kind of obvious, did you try $r->uri?

http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_uri_

David

-----Original Message-----
From: Tosh Cooey [mailto:tosh@1200group.com] 
Sent: Friday, January 15, 2010 10:42 AM
To: modperl@perl.apache.org
Subject: $r->subprocess_env('REQUEST_URI') returns undef ?

From:
http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_subprocess_env_

subprocess_env

Get/set the Apache subprocess_env table, or optionally set the value of 
a named entry.

When the $key argument (string) is passed, it returns the corresponding 
value (if such exists, or undef. The following two lines are equivalent:

   $val = $r->subprocess_env($key);
   $val = $r->subprocess_env->get($key);


Ok... Seems simple enough...

In my module if I do the following:

$r->subprocess_env;
my $uri = $ENV{REQUEST_URI};

The I get the URI.

But if I change the above to:

my $uri = $r->subprocess_env('REQUEST_URI');

I get undef.

Confused.

Tosh

-- 
McIntosh Cooey - Twelve Hundred Group LLC - http://www.1200group.com/