I have this routine which I use through the app to make cookies for certain things

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" ?


In reply to Re: Re: Cookies with CGI::Application by Anonymous Monk
in thread Cookies with CGI::Application by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.