Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Dancer2 hooks and perl modules

by MrCromeDome (Deacon)
on Dec 22, 2020 at 20:37 UTC ( [id://11125637]=note: print w/replies, xml ) Need Help??


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.

Cheers!

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11125637]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-26 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found