|Subject:||CGI objects access global data|
(Tested with v3.05 under apache on Linux.) Consider two scripts: # a use CGI; use Storable qw(nstore); my $q = new CGI(); nstore($q, "/tmp/stash"); print $q->header(-content_type => 'text/plain'), $q->self_url(); # b use CGI; use Storable qw(retrieve); my $q = new CGI(); my $q2 = retrieve("/tmp/stash"); print $q->header(-content_type => 'text/plain'), $q->self_url(), "\n", $q2->self_url(); Invoking a, then b, we get the results,and then This is broken -- the latter should print The reason is the CGI::url() extracts information from $ENV. So q2 thinks that its URL is the URL under which the script was invoked, not the URL under which it was saved. (Why does it matter? Well, I came across this in a case where I wanted to stash some data to be able to reinvoke a script via POST later on. I can imagine other cases where the same thing might arise.) I guess the easiest fix is to save the bits of %ENV that matter in the CGI object, rather than accessing the global %ENV.