Erik Hensema has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dynamic loading of object-oriented plugins
by dragonchild (Archbishop) on Oct 24, 2001 at 01:34 UTC | |
|
Re: Dynamic loading of object-oriented plugins
by jackdied (Monk) on Oct 24, 2001 at 02:43 UTC | |
|
Re: Dynamic loading of object-oriented plugins
by chromatic (Archbishop) on Oct 24, 2001 at 08:30 UTC | |
|
Re: Dynamic loading of object-oriented plugins
by tomhukins (Curate) on Oct 24, 2001 at 02:36 UTC |