Gossamer Forum
Home : Gossamer Threads Inc. : Discussion :

Plugin System

Quote Reply
Plugin System
Sorry if this is the wrong place for this post. It isn't totally product specific so I thought here was ok.

Anyway, I notice that the way plugin hooks are run sometimes varies from:

GT::Plugins->dispatch($CFG->{admin_root_path} . '/Plugins', \&sub_routine);


GT::Plugins->dispatch($CFG->{admin_root_path} . '/Plugins', \&sub_routine, $args);


GT::Plugins->dispatch($CFG->{admin_root_path} . '/Plugins', sub { return sub_routine($args) }, $args);

I was just wondering what the reason for the difference was.

At first I thought it was to do with passing in arguments to the function but $args is passed into the sub routine whichever way you call it due to how the code ref is compiled in GT::Plugins.

I've got a feeling that this will turn out to be a really dumb question Blush

Last edited by:

Paul: Oct 2, 2002, 10:32 AM
Quote Reply
Re: [Paul] Plugin System In reply to
Ugh I guess this should have gone in the plugin authors forum.
Quote Reply
Re: [Paul] Plugin System In reply to

In your first and second example, $args is only passed through in the second one. That's why it's different. The third one is used mainly when doing something Object Oriented related and usually looks more like:

$PLG->dispatch('GMail::Messages::get_attachlist', sub { GMail::Messages->get_attachlist(@_) }, $id);

and this is used to preserve OO inheritance. We fixed GT::Plugins to provide an OO dispatch feature, so the above is depreciated and won't be used any more.

Hope that helps,

Gossamer Threads Inc.
Quote Reply
Re: [Alex] Plugin System In reply to
Thanks for clearing that up.

Regarding the OO usage, here is what I found in GForum:

GT::Plugins->dispatch($CFG->{admin_root_path} . '/Plugins/GForum', "post_normalize", sub { return _plg_normalize(@_) }, $p);

Isn't that really the same as:

GT::Plugins->dispatch($CFG->{admin_root_path} . '/Plugins/GForum', "post_normalize", \&_plg_normalize }, @_);

I was confused as to why the same arguments were passed in twice.

I can't find a good example. It's basically with something like above except @_ is passed into the subroutine as well as into the dispatch method but the dispatch method then passes the argument back into the main function, but that is already done with:

sub { return _plg_normalize(@_) }

Let me know if I'm making no sense, I'm having trouble explaining Blush

Last edited by:

Paul: Oct 8, 2002, 8:53 AM