Do I need an exporter if I am going for a clean OO in Perl?

The docs (Exporter and perlmodlib) say:

As a rule, if a module is trying to be object oriented, then do not export anything.

But then perlmodlib also says:

The standard, included modules are expected to behave in a clearly defined pollution namespace since they use the Exporter Module.

So, I wonder if you go OO and don't export anything, do you really need an exporter? If you do not, does this mean that none of the standard modules is strictly OO in this sense, or does this mean that they EXPORT_OK some things, because you need to do this if someone wants to inherit from your module ? (Is this true?) Or do you need an exporter to be able to use MyModule; ... = new MyModule use MyModule; ... = new MyModule ?

+4
source share
1 answer

You're right. If everything will be called OBJECT :: sub () or $ obj-> sub (), you should be fine.

For inheritance you will need to use @ISA, and for this you do not need an exporter.

In addition, the second quotation that you indicated concerns exported data poured into the module.

If you use: use libname (); against lib, which exports using Exporter, you are guaranteed not to export anything. This can be used to prevent namespace pollution. If you explicitly export by function name, these are the only functions you get.

+7
source

All Articles