You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Gene Dascher <ge...@multiservice.com> on 2001/03/15 13:07:11 UTC

%ENV

Is the ENV hash sanitized and repopulated between the time the Perl*Auth
handlers are run and the requested cgi is executed?  I am setting an ENV key
in one of my handlers that I'd like to use in a cgi that resides in a
protected directory.  Is it possible to retain that variable throughout the
entire process, or will it always get wiped out?

Example:
I use my browser to call a cgi that is in a protected directory.  In the
PerlAuthenHandler, I set $ENV{'TEST_VAR'} = 1.  I can pull the value of
$ENV{'TEST_VAR'} in the PerlAuthzHandler, but when I try and fetch the value
in the cgi that I called, the key 'TEST_VAR' does not exist.

Thanks,

Gene Dascher


Re: %ENV

Posted by darren chamberlain <dl...@users.sourceforge.net>.
Gene Dascher (gedascher@multiservice.com) said something to this effect on 03/15/2001:
> Well, with the subprocess_env(), I can see the key that I set in my cgi now,
> but the value that I set the key to is a Hash reference that I need to use
> in my cgi.  Unfortunately, all I get now is ENV{'TEST_VAR'} =
> HASH(0x860a278), and I can't pull my values out.

I'm running into this as well, but with a different Apache::Table
object. It seems that Apache::Table stringifies its values, which
makes it useless for applications like this.

The only Apache piece that doesn't stringify is pnotes, which is
only available to Perl handlers.

Another option is:

    my $value_to_save = {
        a => 1,
        b => 2,
        c => [ 3, 4, 5 ],
    };

    my $d = Data::Dumper->new([ $value_to_save ]);
    $d->Indent(0)->Purity(1)->Terse(1)->Deepcopy(1);

    $r->subprocess_env('TEST_VAR' => $d->Dump);

And then in whatever you use the value in:

    my $restored_value = eval $r->subprocess_env('TEST_VAL');

$r->subprocess_env('TEST_VAL') looks something like (as a string):

    {"a" => 1,"b" => 2,"c" => [3,4,5]}

You could also use Storable, but that is not a part of the
default install like Data::Dumper is, so I avoid it if I can.

(darren)

-- 
Make no laws whatever concerning speech, and speech will be free; so soon
as you make a declaration on paper that speech shall be free, you will have
a hundred lawyers proving that "freedom does not mean abuse, nor liberty
license"; and they will define and define freedom out of existence.  
    -- Voltarine de Cleyre (19th Century French anarchist)

RE: %ENV

Posted by Gene Dascher <ge...@multiservice.com>.
Well, with the subprocess_env(), I can see the key that I set in my cgi now,
but the value that I set the key to is a Hash reference that I need to use
in my cgi.  Unfortunately, all I get now is ENV{'TEST_VAR'} =
HASH(0x860a278), and I can't pull my values out.

Thanks for the help; it looks like we are headed in the right direction.
Now, is there any way to set an ENV key to a hash or hash reference and use
that later on in a cgi program?

Thanks,

Gene

-----Original Message-----
From: darren chamberlain [mailto:dlc@users.sourceforge.net]
Sent: Thursday, March 15, 2001 6:19 AM
To: modperl
Subject: Re: %ENV


Gene Dascher (gedascher@multiservice.com) said something to this effect on
03/15/2001:
> Is the ENV hash sanitized and repopulated between the time the Perl*Auth
> handlers are run and the requested cgi is executed?  I am setting an ENV
key
> in one of my handlers that I'd like to use in a cgi that resides in a
> protected directory.  Is it possible to retain that variable throughout
the
> entire process, or will it always get wiped out?
>
> Example:
> I use my browser to call a cgi that is in a protected directory.  In the
> PerlAuthenHandler, I set $ENV{'TEST_VAR'} = 1.  I can pull the value of
> $ENV{'TEST_VAR'} in the PerlAuthzHandler, but when I try and fetch the
value
> in the cgi that I called, the key 'TEST_VAR' does not exist.

Try fiddling with $r->subprocess_env; I've had good results that way. e.g.:

    $r->subprocess_env('TEST_VAR', 1);

I haven't tried using %ENV, but I was under the impression it was
tied to the same internal Apache::Table object as
$r->subprocess_env, which means that setting $ENV{'TEST_VAR'}
should work as well.

Make sure you are setting this in the parent request, if you are
in a subrequest:

    $r = ($r->is_main) ? $r : $r->main;

(darren)
--
The world is coming to an end!  Repent and return those library books!


Re: %ENV

Posted by darren chamberlain <dl...@users.sourceforge.net>.
Gene Dascher (gedascher@multiservice.com) said something to this effect on 03/15/2001:
> Is the ENV hash sanitized and repopulated between the time the Perl*Auth
> handlers are run and the requested cgi is executed?  I am setting an ENV key
> in one of my handlers that I'd like to use in a cgi that resides in a
> protected directory.  Is it possible to retain that variable throughout the
> entire process, or will it always get wiped out?
> 
> Example:
> I use my browser to call a cgi that is in a protected directory.  In the
> PerlAuthenHandler, I set $ENV{'TEST_VAR'} = 1.  I can pull the value of
> $ENV{'TEST_VAR'} in the PerlAuthzHandler, but when I try and fetch the value
> in the cgi that I called, the key 'TEST_VAR' does not exist.

Try fiddling with $r->subprocess_env; I've had good results that way. e.g.:

    $r->subprocess_env('TEST_VAR', 1);

I haven't tried using %ENV, but I was under the impression it was
tied to the same internal Apache::Table object as
$r->subprocess_env, which means that setting $ENV{'TEST_VAR'}
should work as well.

Make sure you are setting this in the parent request, if you are
in a subrequest:

    $r = ($r->is_main) ? $r : $r->main;

(darren)
-- 
The world is coming to an end!  Repent and return those library books!