in reply to Are there reasons to instantiate the CGI object more than once?
For a GET, I beleive you can construct multiple CGI.pm objects without this blocking issue.
You can use an alternate constructor for CGI.pm to create more than one without worrying about blocking by passing an empty anon hash:
Why you would do it is another issue. I have found that a second, temporary CGI.pm object is useful for doing things like generating URLs that need lots of query string data for either HTTP redirects, or for creating links in generated HTML. CGI.pm is good at escaping and decoding the data, so why not make use of it?use strict; use warnings; use CGI; ... # first one, processes POST data if present my $q = new CGI(); ... # passing the anon hash causes this CGI.pm object # to read its params from the hash instead of # the environment my $q2 = new CGI({});
use strict; use warnings; use CGI; ... my $q = new CGI(); ... if( $someRedirectCondition ) { my $q2 = new CGI({}); $q2->param('copy' => $q->param('copy') ); $q2->param('foo' => 'bar'); $q2->param('qux' => 'baz'); ... my $uri = "http://some.domain/and/a/path?" . $q2->query_string(); print $q2->redirect( -uri => $uri ); exit 0; }
|
|---|