Re: [htmltmpl] H-T strangeness with CGI-Session
Brought to you by:
samtregar
From: Cees H. <ce...@si...> - 2004-03-26 21:27:06
|
Puneet Kishor wrote: > The problem is thus -- I am storing only the identifying info and a > descriptive text. But the AofH in the Session file is showing additional > info that looks suspiciously like the loop_context_vars. Here is an > excerpt from my Session file -- > > "rolodex" => [{"ROLODEXVAL" => 3330,"__last__" => 0,"ROLODEXTEXT" => > "Puneet Kishor (My Org, Inc.)","__counter__" => undef,"__first__" => > 0,"__odd__" => 0,"__inner__" => 0}], This is probably because you are passing a reference to a data structure to both CGI::Session and HTML::Template. In other words they both get the exact in memory data structure. HTML::Template is adding things to the hashes that are stored in the array ref, and CGI::Session doesn't save it's parameters to the session until it goes out of scope (probably at the end of the request) so it sees the changes that HTML::Template made to the data. There are a couple of things you can do to solve it. - Don't pass the same data structure to both CGI::Session and HTML::Template. Make a copy of the data before passing it by dereferencing the data (see the dclone() method in the Storable module for copying complex data structures if you have a deep data structure). - Or you can make CGI::Session save it's data right away by making it go out of scope, or calling close or flush to sync the data to the session store. Although HTML::Template is causing this problem, I don't think you cna call it a bug. Although many modules will make a copy of the data that is passed in if they intend to make any changes, that can be very expensive if there is a lot of data (which there tends to be when dealing with templates). Cheers, Cees |