How to subscribe to events emitted from a plugin? #1890
Answered
by
guest20
michaelfung
asked this question in
Q&A
-
I want to emit some event, say foo, inside a plugin:
How can I subscribe to the foo event at some other parts of the app? |
Beta Was this translation helpful? Give feedback.
Answered by
guest20
Dec 19, 2021
Replies: 1 comment 1 reply
-
You want the plugin to register a helper that makes # inside a plugin module:
sub register ($self, $app, $conf) {
...
$app->helper(pluginName => sub { $self }); #elsewhere:
$c->pluginName->on(...) ... it might be a bit late if the plugin emits an event during register though |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
michaelfung
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You want the plugin to register a helper that makes
$self
available. If it's not your plugin you can just sub-class it and add the helper yourself.... it might be a bit late if the plugin emits an event during register though