Quoting Scott Prelewicz <suppressed>:
> Based on a user config option, at a point in my script I want to either
> call a format_html function or redirect to another url. In both cases, I
> have tosend out the cookie. Where should I put this if.else, and how do
> I do this, namely how do I send a cookie and redirect?
If you want to send a cookie, you need to use the header_add method
(header_props clobbers all previously set headers, so don't use it).
$webapp->header_add(-cookie=>[$cookie]);
Then later when you want to redirect you can use the following:
$self->header_add(-location => $location);
$self->header_type('redirect');
Again, use header_add. If you are using header_props, then your previously set
cookie will be clobbered. So just use header_add.
I use the following method in my super class to simplify redirection. In your
case it would simplify your code to the follwoing:
sub some_runmode {
my $self = shift;
$self->header_add(-cookie=>[$cookie]);
return $self->redirect($location);
}
Here is my 'redirect' method (You will need to remove the call to
$self->log->debug(), since that is another wrapper that I commonly use and is
not part of the base CGI::Application module)
sub redirect {
my $self = shift;
my $location = shift;
$self->header_add(-location => $location);
$self->header_type('redirect');
$self->log->debug('redirecting to ', $location);
return "";
}
Pretty simple stuff, but I find it simplifies and clarifies my code.
Cheers,
Cees
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.