Questions about registering and calling plugins #1645
-
|
Within a Mojolicious (not lite) application I have a plugin class Mojolicious::Plugin::PhotoArchive which I want to use from a controller Dirlist.pm, invoked by an application Pas.pm; it builds web pages displaying the photographs from a given directory. I have two questions about how to write it and how to call it from the controller. Firstly how the plugin is added. Careful examination of the Mojoilicious code tells me that the "plugin" method calls both the "new" and "register" methods from my plugin class, but that nothing is done to make the plugin available to the caller unless I do it. Is this correct? Using some other plugins as examples I have coded my "register" method thus: Secondly how to call the plugin. Careful inspection using the Perl debugger shows that my plugin is available to the controller: but if I call it thus I'm sure that's not how it works, and that I'm down a rabbit hole of misunderstanding. Can someone put me right on these two points? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
While your first point is correct (most plugins don't care about their instances anyway, but you can do as you say) you've missed the point of helpers entirely in the second. You've found where the coderefs are stored however they're used by calling them as methods on the controller or application (via a generic controller). When done that way they have access to the application. I'm interested in how you came to be this misguided as clearly you have the effort to walk the debugger more deeply into mojo than I've ever taken it. Have you read the tutorial https://docs.mojolicious.org/Mojolicious/Guides/Tutorial#Helpers ? We recommend reading it and all the guides in the order listed here https://docs.mojolicious.org/#TUTORIAL |
Beta Was this translation helpful? Give feedback.
While your first point is correct (most plugins don't care about their instances anyway, but you can do as you say) you've missed the point of helpers entirely in the second.
You've found where the coderefs are stored however they're used by calling them as methods on the controller or application (via a generic controller). When done that way they have access to the application.
I'm interested in how you came to be this misguided as clearly you have the effort to walk the debugger more deeply into mojo than I've ever taken it. Have you read the tutorial https://docs.mojolicious.org/Mojolicious/Guides/Tutorial#Helpers ? We recommend reading it and all the guides in the order listed here h…