I have a rather complex data structure I’ve implemented in Perl. This has been broken up into about 20 classes. Basically, any time you want to use one of these classes, you need to use all of them.
Right now, if someone wants to use this data structure, they need to do something like:
use Component::Root;
use Component::Foo;
use Component::Bar;
use Component::Baz;
use Component::Flib;
use Component::Zen;
use Component::Zen::Foo;
use Component::Zen::Bar;
use Component::Zen::Baz;
... # 15 more of these...
use Component::Last;
to be able to manipulate all parts of it. How can I write a module that does this for the user, so all they have to do is
use Component;
to get all of the other modules imported?
In this particular case, the modules are all classes and don’t have exports.
If these are just classes (i.e. they don’t export any functions or variables when you
usethem), then all that really matters is that they have been loaded.Just create
Component.pm:You don’t need
Exporteror anything like it.However, instead of having a module that is nothing but
usestatements, it probably makes more sense to put thoseusestatements into the class of the root node, or into the module that creates the data structure. That is, people will want to say:or
depending on how your data structure is normally created. It might be a bit confusing for people to write:
but it really depends on what your API looks like. If there are a number of classes that people might be calling
newon, thenuse Componentmight be the way to go.