in reply to how to clear cgi object from session?

hmm seems to have lost my own reply. Yes, well i'm using CGI::Session, and I wanted to know whether there was a way to clean up my saved cgi object (CGI.pm). Could it be $session->clear($cgi)? let's take another sample:
main.pl : my $cgi = New CGI; my $session = new CGI::Session(); $cgi->param("name", "Barney"); $session->save_param($cgi); #saves cgi object into session $cgi->redirect(URI => "body.pl?sessionid=".$session->id);
then on body.pl :
my $cgi = New CGI; my $sessionid = $cgi->param("sessionid"); my $session = new CGI::Session($sessionid); $session->load_param($cgi); $cgi->param("name"); #we still have barney around. $session->clear($cgi); #ASSUMPTION - CLEAN UP CGI $cgi->redirect(URI => "car.pl?sessionid=".$session->id);
Then on car.pl :
my $cgi = New CGI; my $sessionid = $cgi->param("sessionid"); my $session = new CGI::Session($sessionid); $session->load_param($cgi); print $cgi->param("name"); #should not have anything anymore

Replies are listed 'Best First'.
Re^2: how to clear cgi object from session?
by almut (Canon) on Sep 14, 2007 at 13:04 UTC

    It should just work if you call $session->clear() (without passing the $cgi object). As I already said, this would clear all parameters, though. In case you have other stuff stored in the session which you don't want to have cleared, you could do $session->clear([$cgi->param()]) instead, which would clear nothing but the parameters of the current CGI object.

    BTW, save_param($cgi) does not store the CGI object itself. It calls the param() method on the object passed in. This method, when called without an argument, returns a list of all parameters, which are then stored in the session. (In theory, the API of CGI::Session could likewise accept clear($cgi), to then call param() on the CGI object, etc... — but that's not how it's implemented.)  HTH.