I realize the code above is just a demo and not a full implementation, but just a note on coding and error handling as appropriate here. I'd rewrite some of the above like this:
eval { require $_; my $plugin = $_->new or die "failed to instantiate\n"; $plugins{$pluginName} = $plugin; } or logger("failed to load plugin: $@");
Plugins can and will fail, so treat them with some skepticism :) -- this is actually a benefit of decoupling that you can afford to keep the main application running even if a plugin failed. In terms of development, if you expose a mechanism to rescan the plugin repository, you can reattempt to load a failing plugin without restarting your application. (Theoretically you could also implement plugin unload routines, but that's harder.)
Plugins are a great opportunity to use either interfaces or traits. Getting compile-time (or at least, plugin load-time) verification that it conforms to the plugin interface is nice.
In reply to Re^2: Plugin Programming
by gaal
in thread Plugin Programming
by theirpuppet
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |