dash2 has asked for the wisdom of the Perl Monks concerning the following question:
I want to build a script with a nice API for plugins that lets people simply download a plugin, and it starts working automatically. (My end users aren't programmer types. They need stuff to be simple.) The plugins will extend, or replace, functions of the main script.
My current thoughts on architecture are as follows:
- any pluginable functions will call &replace() at their start and &extend() at the end.
- &replace() will search for plugins in the plugin directory. Plugins that want to replace the particular function will respond to the main plugin interface, and replace the main function with their own version.
- &extend() will do something similar, but as the main function has been called already, it will add to functionality rather than replace it.
Now this would work, but does it not kind of suck?
This inheritance works even without needing object-orientation, which is nice.package MyPlugin; our @ISA = qw(TheMainPackageIReplace); ...
This would be most cool. I wouldn't have subroutine calls everywhere. I wouldn't have to specify which functions are pluginable. They all could be! And it uses the perl package system so I can use version numbers etc. for dependencies.
My problem is with point 3. Normally we use() a particular package, which then inherits from whatever. Now in this case, it's the reverse: we want to use "whatever package is available that fulfils this role". So if MainPackage is available, we use MainPackage; if MyPlugin is available, we use MyPlugin which inherits from MainPackage.
Now you see the problem? I don't know how to fix it so that the script knows which package to use(). Almost, I want to call the plugin something consistent and have it replace a default "plugin" which would inherit all its methods from the MainPackage ancestor. But this seems like it's going to involve a heavy overhead in resolving method calls by going up the inheritance tree. Plus, what about different plugins replacing different functions - ie multiple inheritance?
I seem to be trying to go against the way packages work. They inherit everything to one descendant from multiple ancestors. I want to hand function calls down to multiple descendants from one ancestor! Is there a better way? Or a neat solution? or even just a clever hack?
cheers
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: plugins and inheritance
by Corion (Patriarch) on Feb 27, 2001 at 17:36 UTC | |
|
Re: plugins and inheritance
by jeroenes (Priest) on Feb 27, 2001 at 20:17 UTC | |
by dash2 (Hermit) on Feb 27, 2001 at 20:26 UTC | |
|
Re: plugins and inheritance
by tomhukins (Curate) on Feb 27, 2001 at 18:45 UTC | |
by dash2 (Hermit) on Feb 27, 2001 at 20:22 UTC | |
by tomhukins (Curate) on Feb 28, 2001 at 04:07 UTC | |
|
(tye)Re: plugins and inheritance
by tye (Sage) on Feb 27, 2001 at 20:42 UTC | |
by dash2 (Hermit) on Mar 08, 2001 at 17:36 UTC | |
|
Re: plugins and inheritance
by baku (Scribe) on Feb 28, 2001 at 01:32 UTC | |
by idsfa (Vicar) on Aug 29, 2003 at 15:18 UTC |