http://www.perlmonks.org?node_id=1068785


in reply to Recommendations for adding plugin/addon capability to a program

I would probably use the existing class-hierarchy capabilities of the Perl language, and perhaps the very-goodness of UNIVERSAL::require.

Your system would stipulate that all plugins must inherit from some base-class (perhaps “among others”) via a use base statement.   It would also require that the modules live in some specified location.   When a new plugin was requested, it would attempt to require the appropriate module, then, if successful in doing that, would perhaps call some class-method to initialize it.

Okay, for a brass-tacks example of what I am talking about, peruse http://search.cpan.org/~mkanat/RPC-Any-1.00/lib/RPC/Any/Server.pm#HOW_RPC_METHODS_ARE_CALLED which describes a similar “plugin” notion in the context of an RPC-server which loads request-handling modules on demand.   There are many others.   Study the source-code of “live examples” to see exactly how they did it.