Where in my Dancer app should I use modules that are needed for objects restored from the session?

StackOverflow https://stackoverflow.com/questions/21891282

  •  13-10-2022
  •  | 
  •  

Question

I use some Moose objects that I retrieve from Redis. I wrote code that figures out the right classes and and loads them on demand. Now I store those in the session as well, and when they get restored (by the Session engine and not my own Redis retrieval code) it happens that the required module has not been loaded yet.

After giving it some thought I figured out that this is because I keep restarting the Dancer app in testing after making changes to the route handlers, but my session is still valid. In production that will most likely not happen. There, the modules have been loaded at some point, especially because you need to retrieve the object before putting it in the session.

However, I would like to fix that, so dynamical loading should not be necessary any more, and I cannot run into that problem of can't call method foo on an undefined value because the module has not been loaded yet. But where would I sensibly put all those uses? There is only a handful of those so it's not a big deal to load them upfront.

I thought the main .pm-file that is used by the app.pl file might make sense. Or maybe the app.pl itself, though that seems wrong. Is there a best practice for this?

Was it helpful?

Solution

~/lib/your app name here.pm file would by my suggesting of placing your use module code since this is often the file used to handle routes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top