CGI::Session::delete() really just does this:
my $cgi = CGI->new();
my $cookie = $cgi->cookie( -name=>$self->name, -value => 1, -expires=>
+ '-1d');
And then later it sends the header including this cookie definition back to the browser. (example later in this post)
The cookie isn't really managed by perl, it is managed by the browser. By telling the browser that the cookie was supposed to expire a day ago you can cause it to be deleted.
This is done with the http headers that you send back with your response.
It is easier to do this using one of the standard modules instead of writing the "Set-Cookie" header manually.
Basic Example:
my $cgi= CGI->new();
my $cookie = $cgi->cookie( -name=>$name, -value => 1, -expires=> '-1d'
+);
print $query->header(-cookie => $cookie, type => 'text/html');
print "This text is sent to the browser, and at the same time the cook
+ie is cleared\n";
Note that this is setting what the value of the cookie will be -after- the browser gets this response.
If you want to remove the cookie for -this- invocation you could modify the value of $ENV{HTTP_COOKIE}. For example, this would remove all cookies for -this- run - but not future ones.
delete $ENV{HTTP_COOKIE};
I'm sure there is a module for modifying the current cookie definitions, but I can't think of one offhand and am too tired to search at the moment :)
Hope this helped.
|