I'm trying to develop an application which is able to dynamically load plugins. These plugins are objects (packages).
I've got some code working, but I've got the feeling it's not the prettiest of all scripts :-/
Basically my in the main package I load the plugins by calling require. The plugins then register themselves to the main package by calling this function:
sub register_plugin { push @callbacks, shift; }
A plugin basically looks like this:
register_plugin("foo"); package foo; sub new { return bless {}; } sub hello { print "Hello!\n"; } 1;
Then this works from main:
foreach $callback (@callbacks) { $bar = $callback->new(); $bar->hello(); }
I think it's quite ugly to return the package name as a string to main. Isn't there some other way, preferably using a reference or something like that?
In reply to Dynamic loading of object-oriented plugins by Erik Hensema
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |