in reply to Restoring CGI.pm object

You can store your %ENV in $cgi params before saving.
Something like this:

$cgi->param(-name=>"ENV-$_",-value=> $ENV{$_} for keys %ENV;

And restore them back upon CGI restoring

foreach my $p ($cgi->param()) { if ($p =~ /^ENV-(.*)/) { $ENV{$1} = $cgi->param($p); $cgi->delete($p); } }

Replies are listed 'Best First'.
Re^2: Restoring CGI.pm object
by Haloric (Novice) on Oct 27, 2008 at 17:51 UTC
    Thanks - although doesn't that affect my $ENV{} in the restoring process ?

    I would like it if I could refer to the original $cgi->remote_addr() method, and have it work, and not affect the current environment.

      Since remote_addr is exactly
      sub remote_addr { return $ENV{'REMOTE_ADDR'} || '127.0.0.1'; }
      the easiest way to isolate stored ENV is to use local %ENV
      If you check the source for CGI, you'll find that those functions read from the ENV vars populated by your webserver.

      -Paul

        Ah, thats no use to me then. Thanks for pointing that out.

        I will have to use some other way, don't really want to trash my own ENV with values from a previous request.

        Think I will just store a hash of all the ENV values in the original request then, and restore that hash, don't need the $cgi object in that case, since all it does for me is break up the params .