From: "Lazarev, Roman" <[EMAIL PROTECTED]>
   Date: Fri, 6 Jul 2001 09:38:00 -0400 

   The question that I'm trying to answer is - how to implement this "plug-in
   mechanism" in perl? 

"There's more that one way to do it," but this comes quickly to mind:
Write a package implementing a known set of functions for each "plug-in".
Require the package at runtime based on the data.

# Tests for valid package that is in the plug-in directory.
# You might want to extend to testing if the current user has permissions
# to use a given plug-in, etc.
If ($data{package_name} =~ /^\w+$/ &&
    -f "$PATH_TO_PLUGINS/$data{package_name}.pm") {
   # runtime require and import
   eval "use $data{package_name} qw(functions needed in this module)";
}

Defects:
Can't use multiple plug-ins simultaneously.  (Try something
object-oriented or carry the package name around for each function
invocation.)

If the plug-in package is extremely complex, then there will be a
noticable delay the first time it is required.  (Preload all
plug-ins at startup time and use package names to keep straight
which to use where.)

--kag

Reply via email to