[Melbourne-pm] Invalid use of Exporter as a parent of a class

Adriano Ferreira a.r.ferreira at gmail.com
Sun Dec 2 06:01:46 PST 2012

As a matter of fact, the Exporter documentation gives arguments for
this approach (not inheriting from Exporter:


Exporting Without Inheriting from Exporter

By including Exporter in your @ISA you inherit an Exporter's import()
method but you also inherit several other helper methods which you
probably don't want. To avoid this you can do

  package YourModule;
  use Exporter qw( import );

which will export Exporter's own import() method into YourModule.
Everything will work as before but you won't need to include Exporter
in @YourModule::ISA.

Note: This feature was introduced in version 5.57 of Exporter,
released with perl 5.8.3.


But as someone else in the thread mentioned, Sub::Exporter can be even
nicer and even more if combined with lexical & compile-time exports.
(Though it can look overkill to make something that looks ordinary as


On Wed, Nov 28, 2012 at 4:47 AM, Bradley Dean <bjdean at bjdean.id.au> wrote:
> Greetings folks,
> I've found myself having a conversation about why Exporter shouldn't be
> included in the base of a class-defining perl module. This is my position,
> such that this would be very bad code:
>   # Bad code, don't inherit from Exporter in a class
>   package My::Class;
>   use base qw(Foo Bar Exporter);
>   ...
> I can't think of any good reason to do this - but my partner-in-discussion
> has invoked "Damian Conway's methods" (Hi Damian, sorry to cause teeth
> grinding if this does so) so I thought I'd see if I was missing something.
> To my mind the only reason that someone would be tempted to inherit from
> Exporter in a class was if you also wanted to export functions - and even
> then the problems of then creating invalid inherited 'methods' from
> Exporter would make this a horrible solution.
> So then, thoughts?
> Cheerio,
>  Brad
> --
> Bradley Dean
> Email: bjdean at bjdean.id.au Skype: skype at bjdean.id.au
> Mobile(Aus): +61-413014395 WWW: http://bjdean.id.au/
> _______________________________________________
> Melbourne-pm mailing list
> Melbourne-pm at pm.org
> http://mail.pm.org/mailman/listinfo/melbourne-pm

More information about the Melbourne-pm mailing list