Welcome, Guest. Please login or register.
Did you miss your activation email?


Login with username, password and session length

Search

 
Advanced search

8043 Posts in 1856 Topics- by 2099 Members - Latest Member: roi
Calendar Script CommunityCustomizationHacks and Mods (Moderators: scott, DanO, Marty)Using same hook for two or more plugins?
Pages: [1]   Go Down
Print
Author Topic: Using same hook for two or more plugins?  (Read 1592 times)
0 Members and 1 Guest are viewing this topic.
Tanus
New Member
*

Karma: 0
Offline Offline

Posts: 15


WWW
« on: January 03, 2008, 09:53:17 AM »

As I understand the code in the procedure 'handleCustomFunction' and other posts in the forum, it is so that you will have a problem if two plugins use the same hook.

For instance 'display_before_getEvents' are used by MetaCalendar (v1). However the code in MetaCalendar follows any good practices for programming and does handle what it is supposed to do and nothing else. I.e. it returns immediately if it is any other calendar that is called. The issue arises as soon as you need to write a new plugin that needs to use the same hook.

I know that this in most cases are solved case by case, but has anyone looked into making a general solution? And how to do it?

I am thinking along lines of first call the first (uppermost) plugin in the hierarchy, and then number two, three and so on if defined...
(The reason for asking is that I am considering making a plugin for export to iCalendar based on a search - something similar to the CSXport-plugin...)

« Last Edit: January 03, 2008, 09:58:24 AM by Tanus » Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #1 on: January 03, 2008, 02:22:56 PM »

** has anyone looked into making a general solution? **

Not that I've read. Until now people have just made their own hook for their new function when an conflict was found.

** I am thinking along lines of first call the first (uppermost) plugin in the hierarchy, and then number two, three and so on **

That might be a possibility... as long as none of the latter calls duplicates the functions of a previous one and the variable values haven't been changed by the previously called function.

JMO

Dan O.
Logged
Tanus
New Member
*

Karma: 0
Offline Offline

Posts: 15


WWW
« Reply #2 on: January 05, 2008, 08:28:48 AM »

Quote
That might be a possibility... as long as none of the latter calls duplicates the functions of a previous one and the variable values haven't been changed by the previously called function.
Yes, that must be a prerequisite. For plugins not altering the database this should be OK as long as the code uses alters only local variables. For plugins manipulating the database one need more caution, and you will probably as a minimum need to order the plugins in the right order, or even remove the routine in question.

However, if I should rewrite my own 'handleCustomFunction', I guess I need to make a loop in there and I will possibly need to undef the first routine, before performing require on the next with the same name of the next plugin? Am I right? I am not into all details of perl, but I guess 'undef' is the right keyword? (As far as I can see from perldoc...)
Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #3 on: January 06, 2008, 05:20:59 PM »

** I guess I need to make a loop in there and I will possibly need to undef the first routine, before performing require on the next with the same name of the next plugin? Am I right? **

I've never looked into the code that deeply I'm afraid.

** I guess 'undef' is the right keyword? **

undef can be used to undefine a variable or an array in Perl. Is that where the included code is stored?

Dan O.


« Last Edit: January 07, 2008, 05:13:38 PM by DanO » Logged
Tanus
New Member
*

Karma: 0
Offline Offline

Posts: 15


WWW
« Reply #4 on: January 06, 2008, 05:29:30 PM »

Not really. However according to perldoc, undef might also be used to undefine a subroutine as well, but I have not found any other sources on it or any examples. I will see if I can find some time and investigate a little bit on it, I will post back with the result...
Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #5 on: January 07, 2008, 05:31:37 PM »

I found one discussion that might give you some ideas?

LINK > Undefining subroutines and inheritance

JFYI

Dan O.
Logged
Pages: [1]   Go Up
Print
Jump to: