sub bake {
my $cookie = shift;
my @args = @_;
use CGI;
my $query = new CGI;
# Make a new cookie
my $new_cookie = $query->cookie(@args);
# Get the cookies already baked
my $cookies = $cookie->param('cookies');
my @new_cookies;
push(@new_cookies, $new_cookie);
push(@new_cookies, @$cookies) if $cookies;
$cookie->param('cookies', ¥@new_cookies);
}
Then, to retrieve the cookies before I out put:
sub return_cookies {
my $cookie = shift ;
my $cookies = $cookie->param('cookies');
$cookie->debug("SET @$cookies") if $cookies;
return @$cookies if $cookies;
}
The strange thing is of course, that this particular part worked fine for a day. I did not touch it, but made several changed to the main app. This leads me to believe it is not a problem with the cookie setting/retreiving function, but someplace else. And since &return_cookies returns exactly what I expect, I am totally lost.
I just discovered something strange. I am using CGI::Application so I have various run modes:
sub top {
my $app = shift;
# Reset the cookies
$app->cookie->bake(-name=>'site', -value=>$app->query->param('site
+'), -expires=>'1h');
$app->cookie->bake(-name=>'keyword_or', -value=>'', -expires=>'-1h
+');
$app->param('template', $app->get_template('top.html'));
return ($app->output);
}
sub results {
my $app = shift;
# Do stuff to the keyword
&manage_keyword($app) if ($app->query->param('do_search'));
return ($app->output);
}
sub manage_keyword {
my $app = shift;
my $keyword_or = $app->query->param('keyword_or');
$keyword_combined ||= $app->query->cookie('keyword_or');
....
$app->cookie->bake(-name=>'keyword_or', -value=>"$keyword_or") if
+$keyword_or;
.....
}
For some reason, even though the run_mode is results, the
$app->cookie->bake(-name=>'keyword_or', -value=>'', -expires=>'-1h');
in run_mode "top" seems to be deleting my cookie. If I comment that out, it works fine. Why the hang is it even paying attention to "top" ?
|