in reply to Dancer2 hooks and perl modules

You need to package your module as a plugin to write your own hooks. See Hooks in the Dancer2::Plugin docs for more information.

More simply, if you just want to add code in the before hook of each app, write the code in a subroutine in a module, use that module in both apps, then call the sub from the before hook of each app.

Also, if you create a module with the name package A;, use Dancer2; is sufficient. Save yourself a few characters and don't be redundant with use Dancer2 appname =>'A'; And, that's one less thing to maintain if you ever rename that module.


Replies are listed 'Best First'.
Re^2: Dancer2 hooks and perl modules
by clemep8 (Acolyte) on Dec 23, 2020 at 19:58 UTC
    Yeah, I can call hook theHook => sub \&theSub; in each app for each hook, but was hoping for something a little more automatic and less redundant...The docs seemed to indicate there was an optional apps property for hook that allowed defining the hook in multiple apps simultaneously, but it doesn't seem to work.