Home : Products : Gossamer Links : Development, Plugins and Globals :

Products: Gossamer Links: Development, Plugins and Globals: Re: [Ian] Hook Arguments: Edit Log

Here is the list of edits for this post
Re: [Ian] Hook Arguments
Just a quick followup on how argument parsing and hooks work in our plugin system:

In any of our products, we can wrap a subroutine call with GT::Plugin::dispatch function. By doing this, it makes end users able to do one of the following:

1. Run some custom code before the subroutine is called
2. Change the input arguments to the subroutine
3. Override the subroutine (i.e. don't run it)
4. Run some custom code after the subroutine.
5. Change the output of a subroutine

So wherever you see:

my $results = GT::Plugins->dispatch($CFG->{admin_root_path} . '/Plugins', 'hook_name', \&subroutine, $arg1, $arg2);

It means that it is going to run subroutine() function with $args as arguments. You are able to run code before or after it by placing a hook on hook_name.

For a PRE hook, you are passed in whatever the subroutine() was going to take, in the example above, you'd get $arg1, and $arg2. Your PRE hook can modify these or leave them alone. If you don't override the main function, it must return the same type of arguments so that subroutine() can run as normal (as the return of your hook is passed into subroutine()).

For a POST hook, you are passed in whatever subroutine() returned. You must take care to return something of the same type, as your hooks return value will be placed in $results.

Hope that helps clear up the logic a bit. If you can wrap your head around this, it makes creating hooks much easier. You can scan the code for GT::Plugins->dispatch() and see what exactly you are getting passed in, and the hook name, and what you need to return.

Cheers,

Alex
--
Gossamer Threads Inc.

Last edited by:

Alex: Jun 5, 2002, 10:40 AM

Edit Log: