nacredata has asked for the wisdom of the Perl Monks concerning the following question:

Ok, so far, and it's not been too long, I love Mason. But I'm stuck on Session values.

My httpd.conf file declares %session a MasonGlobal. My root level autohandler checks/sets cookies and ties the %session and logs in. That all works great and users stay logged in across the various pages.

But when I try and assign a value to that global %session value somewhere other than the autohandler where it is localized (as the Mason book strongly suggests), the value is not saved to the next page. So I guess the global %session is not tied, just the local autohandler %session.

How do I get a value into that localized %session, and thus to the underlying MySQL session table, from another module??

I tried creating a method in that autohandler and passing values back it, but that didn't seem to work.

thanks.

  • Comment on Mason Sessions - problem Storing values

Replies are listed 'Best First'.
Re: Mason Sessions - problem Storing values
by perrin (Chancellor) on Apr 20, 2005 at 00:45 UTC
    Apache::Session only saves the data when it gets destroyed. If you put it in a global, it never gets destroyed. The session modules for Mason on CPAN work around this by explicitly destroying %session. I'd suggest you use one of them instead of building your own.
      I am looking at the MasonX-Request-WithApacheSession module now, and will use it if I don't figure this out soon. I do like to understand things as best I can, though, which is worth some struggle. The items I add in that autohandler -- user permission level and group -- ARE saved, and the other info I want saved is visible at the end of that autohandler if I insert a print $session{SQLstatement} before the close of the autohandler. So that session value is not masked by the local *session; declaration in the init section, but they are also not saved as they are only around for that one request, while the above values persist. I do want to understand what is going on here with scoping, even if I use the module. thanks.
        I don't really understand your description of what you're doing, but you should go and read the Apache::Session docs. They make it pretty clear that you have to make sure the object gets destroyed. Your "print $session{SQLstatement}" will not affect anything one way or the other.
      So, anyway, I got it to work by making the tied %session lexically scoped in the autohandler and then passing a reference down to all other components. But I'm still curious how they got it to work with the global -- teh book specifically discusses a global, localized in the autohandler but available elsewhere as a global. If nothing else, that section of the book may need a little flushing out in the next edition. Thanks for the offers of help.