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

[suggestion] Plugin hook system improvements

Quote Reply
[suggestion] Plugin hook system improvements
I already posted the following suggestion to Alex, but I also post to the forum, so anybody could tell opinion or idea about it. I hope I understood the codings correctly, if not please correct me.

Here it is:

Developing a plugin right now, but I've faced a problem.
It seems, that if I replaced the original subroutine (using GT::Plugins->action ( STOP ); ) within a PRE hook, then only another POST hook is possible to run, and I'm not able to have another PRE hook to run before the original (or replaced) code.
It seems we can have only 1 PRE and only 1 POST hook of the same hook.

Here is an example what I would like. Example from the plugin.cfg:
Code:
...
[
'handle_page',
'PRE',
'Plugins::Extended_link::handle_page_pre_hook',
'1'
],
[
'handle_page',
'PRE',
'Plugins::Extended_link::handle_page_replacing_original',
'1'
],
...
----------------------------------
In the example above, the following will happen:
a) "handle_page_pre_hook" will run before original code
b) "handle_page_replacing_original" will NOT run, because there was already a PRE hook for "handle_page" hook.
c) The original code will run instead of "handle_page_replacing_original".

If we would modify type of "handle_page_replacing_original" hook to POST, then:
a) "handle_page_pre_hook" will run first
b) original code will RUN
c) "handle_page_replacing_original" will RUN, too

This makes me such problem, that I can not replace the original code, and still to have a PRE hook for the same hook.

1.) SUGGESTION: - REPLACE hook feature
The only solution would be, if you would extend the feature of the plugin system, and add a "REPLACE" feature.
So we will have: PRE, REPLACE, POST hook types

The REPLACE name explains itself, I think.
We would be able to REPLACE the original code, and still make possible to run PRE hooks before, and POST hooks after the REPLACEd subroutine.
(I know about the GT::Plugins->action ( STOP ) feature, this suggestion is to improve this feature)
------------------------------------------------------
2.) SUGGESTION: - multiple PRE and POST hooks of the same hook, and executing order between the hooks with same name & type

It seems we can have only 1 PRE and only 1 POST hook of the same hook. Is it true?

If yes, would be fine to be able to have multiple PRE & POST hooks of the same hook. Also the executing order of the same PRE or POST hooks would be important.
Example:
Code:
...
[
'handle_page',
'PRE',
'Plugins::Extended_link::timing',
'1', # hook is Enabled
'1' # Executing order. This is executed 1st
],
[
'handle_page',
'PRE',
'Plugins::Extended_link::page_display',
'1', # hook is Enabled
'2' # Executing order. This is executed 2nd
],
...

The 5. array element, would be loaded as the $hook->[4] in sub load_cfg.
It would define the executing order of the hooks with same name & type.
------------------------------------------------------

I think (if I was right and understood the workflow correctly), these suggestions would definitely help developing of new plugins, and would increase flexibility of the current Plugin System.

I plan to base my future plugins on this suggestion.
I've faced now with a problem, that seems is caused by the limitations of current plugin system.(?)
I would need to use the hook with same name & type, and it seems it is not possible.
If GT staff will decide to implement these suggestions, I would wait until developing of these suggestions is finished.

I think it would be very useful to lead the developments of the plugin system in this way.

Opinions, and comments are welcome.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...