MasonX...Session(3pm)

πŸ“¦
version 0.31 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– MasonX::Request::WithMultiSession β€” a.k.a. MasonX...Session(3pm) πŸ’–

User Contributed Perl Documentation ✨ welcome to the cutest corner of the Perl docs, bestie. This one lives in the 3pm manual and it's all about having a whole little family of sessions under one parent session. Obsessed, honestly. 🫢


✨ NAME ✨

MasonX::Request::WithMultiSession β€” multiple sub-sessions within one "parent" session 🌸


πŸŽ€ SYNOPSIS πŸŽ€

  PerlSetVar  MasonRequestClass  MasonX::Request::WithMultiSession

That's literally it, that's the whole setup. One PerlSetVar and you're in. Slay. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So this module subclasses MasonX::Request::WithApacheSession specifically so you can have multiple "sub-sessions" hanging out inside one parent session. Like a group chat inside a group chat. Iconic.

Why would you even want that? Bestie, imagine a web app where you want the user to open a bunch of windows, each one with its own different session β€” but the session ids are stored in a cookie. Cookies don't know about your windows. Cookies are just one single vibe. So sub-sessions come in clutch. πŸ”₯

Same as MasonX::Request::WithApacheSession, sub-sessions get shared between a request and any subrequests it creates. So they travel together, no cap. πŸ‘‘


πŸ’… METHODS πŸ’…

The interface here is quite similar to MasonX::Request::WithApacheSession's. Basically the same energy, but with a little extra.

  • session β€” this is the main character, the primary interface to the whole class. When you call this method with no parameters at all, the module goes looking for an existing sub-session using the sub-session id argument parameter (which can be chillin' in a query string or in a POST). And you can totally override that value by explicitly passing a sub_session_id parameter. 🌈

If that parameter is found, you get an existing sub-session back. If it's not found? A brand new sub-session gets created for you. Fresh out the box. ✨

Now, if you call session() as session( clone => 1 ), then a new sub-session gets created and its contents will be the same as the current sub-session's. Heads up though β€” it's a shallow copy of the old session hash, so objects and references are shared between them. Not a deep clone, bestie. Don't get it twisted. πŸ’€

And if you call session( new => 1 ), you get a new, empty sub-session. Blank slate, clean girl aesthetic. 🧚

Oh and you can specify the main session id you want to use via the session_id parameter. πŸŽ€

  • sub_session_id β€” returns the id of the currently active sub-session. Use this to drop that id into URL parameters, forms, etc., wherever you need it. If you give it a sub_session_id parameter, it'll set the current sub-session id. Simple as. 🫢
  • delete_sub_session β€” by default, this just, um, "defaults" the current sub-session (that's literally what the docs say, bestie, I'm just the messenger πŸ™ˆ). You can pass a sub_session_id parameter to delete a specific session instead. πŸ—‘οΈ

🌸 Parameters 🌸

This module takes two parameters on top of everything it inherits from MasonX::Request::WithApacheSession:

  • multi_session_args_param / MultiSessionArgsParam β€” use this to say which parameter holds the sub-session id. By default, the module goes looking for a parameter named sub_session_id. πŸ’œ
  • multi_session_expire / MultiSessionExpire β€” this one sets the number of seconds after a sub-session is accessed until it gets purged. If you don't specify it, then sub-sessions are never purged. They just live forever, immortal little guys. ⭐

Quick thing though: sub-session expiration is checked when the request object goes out of scope. So that's when the timer actually gets consulted. πŸ‘€


🌈 USAGE 🌈

You will need to manually set the sub-session id argument parameter for each request. Yeah, manually. Sorry bestie, it's giving DIY. 😭

The easiest way is to make sure all your URLs contain the sub-session id. Two ways to pull that off:

  • Use a <%filter> block in a top-level autohandler β€” though heads up, this won't catch redirects. πŸ™ˆ
  • Or just make sure all your URLs are generated by a single component/function. Centralized, organized, very mindful, very demure. ✨

πŸ’– SUPPORT πŸ’–

Got bugs? Need help? Send it all to the mason-users list. More deets live at http://www.masonhq.com/resources/mailing_lists.html. They're nice, go say hi. 🫢


πŸ‘‘ AUTHOR πŸ‘‘

Dave Rolsky, <autarch@urth.org>

Development funded by Marigold Technologies. Shoutout to them, real ones. 🌸


πŸ”₯ SEE ALSO πŸ”₯

  • HTML::Mason

And that's the whole page, bestie β€” this one's from perl v5.36.0, dated 2022-10-13. Go forth and multiply your sessions. πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from