In this entry, I'd like to discuss an OOP technique of having a class with plugins, where the plugins specify plugins for the objects used ("has-a") by instances of the class.
This occured to me in Test-Run, where I implemented several classes which I called "Structs" (like in C) which wrapped around a hash ref using accessors. The instances of these classes were referenced by the main class ("Test::Run::Core"). I graudually moved more and more methods into the helper classes, if I saw they only referred to their own data.
Now, I have some plugins of the Test::Run::Core class. It happened to me at least once now, that after I moved a few methods to the helper classes, the plugin broke, because the method in question was no longer present in the main class. I had to find a way to extend the helper classes, and it made me thinking that I'd like to have some plugins for it too.
Plugins in Perl, at least as implemented by Catalyst and Test-Run, are done by creating an empty class (let's say MyPluggableClass), adding all the plugins, in front to @MyPluggableClass::ISA, and adding the master class which the plugins enhance at the end. So @MyPluggableClass::ISA will look something like:
( qw(Plugin::Foo Plugin::Bar Plugin::Quux MasterClass) )
Now, I'd like a way for plugins of the Test::Run main class, to add plugins to its helper classes. I already have some code to traverse the inheritance tree and collect an array from the individual methods (shamelessly borrowed from a similar paradigm in Class::Std). Using it, I can collect all the plugins, append the master class at the end, and initialise a new instance of the helper class.
I can even abstract this functionality into its own meta class. So my questions are:
I think one big monolithic class is not the way to go, so I'd appreciate any comments.