BerntB has asked for the wisdom of the Perl Monks concerning the following question:

A quick and simple question: Which is the present default module for doing simple plugins?

It is for an open source project on non-servers, hopefully including Windows, so a module should be lightweight on dependencies.

  • Comment on What is present best practices for lightweight plugins?

Replies are listed 'Best First'.
Re: What is present best practices for lightweight plugins?
by Corion (Patriarch) on Apr 02, 2012 at 10:34 UTC

    I would consider require for a (very) basic plugin system. If you need anything more than that, I recommend Module::Pluggable and instantiating each plugin as separate object.

    For plugin configuration, I haven't seen any good mechanism. I would look at how Dist::Zilla handles it but any plugin mechanism will either have static configuration and a ->visit method that either cancels all following plugins or modifies the visited object or will need some real programming anyway, and when you need real programming, doing it in Perl instead of a configuration file is advisable.


      I'll go Module::Pluggable. The code is easy to read and it satisfies the needs without any dependencies at all (good for my use case).

Re: What is present best practices for lightweight plugins?
by Rhandom (Curate) on Apr 03, 2012 at 13:59 UTC
    Be careful about using Module::Pluggable. Each time you run your script Module::Pluggable has to search through the entire INC path, and as part of that searching it will load every matching module. So, you get a win in that you can abstract out parts of your code or use separate distributions. But you also get a heavy penalty in that you might be loading large chunks of code unrelated to your current task at hand.

    If you don't care to allow for arbitrary extension by third parties, then I'd use something like autouse or AutoRole to mix in known functionality.

    If you want third party extensions but without the bloat, then a mapping of method name to module name is a way to go.

    Alternately you could use a hybrid approach and scan @INC for module names - but don't load them unless a method that maps to a module is called.

    However, with all that said, Module::Pluggable might be doing exactly what you want. I haven't had any of my personal projects ever fall into that category.
    my @a=qw(random brilliant braindead); print $a[rand(@a)];

      Thanks, good advice.

      This is for a server so startup is no problem. (-: And I wish that the code gets so popular it has memory problems with the number of plugins... :-)