in reply to Re: Restoring CGI.pm object
in thread Restoring CGI.pm object

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.

Replies are listed 'Best First'.
Re^3: Restoring CGI.pm object
by ccn (Vicar) on Oct 27, 2008 at 18:01 UTC
    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
Re^3: Restoring CGI.pm object
by jettero (Monsignor) on Oct 27, 2008 at 17:56 UTC
    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 .

        You can localize changes to the hash...
        sub my_restornator { local %ENV; %ENV = restore_env(); # do things with the restored CGI object # goes back the way it was after this brace: }

        If you're really clever, you could possibly make a restoredCGI object, I'm a little unsure on the details. Can it be done with Autoloader + local? Dunno for sure.

        -Paul