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

Scott Penrose scottp at dd.com.au
Wed Nov 28 00:22:46 PST 2012


I prefer the second method of Exporter

         package YourModule;
         require Exporter;
         @ISA = qw(Exporter);
         @EXPORT_OK = qw(munge frobnicate);  # symbols to export on request

       or

         package YourModule;
         use Exporter 'import'; # gives you Exporter's import() method directly
         @EXPORT_OK = qw(munge frobnicate);  # symbols to export on request

So instead of inheriting Export, you just create an 'import' sub that is used to do the 'importing'.

Especially if you are doing mixed modules. 

Slight disagreement with the others on the list about having both, in that we often create a module like 'use CGI' which can be both an object (if you don't export anything) or import methods. 

In fact Exporter module above is the same, you can inherit it, or just import the 'import' method. 

Scott

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5928 bytes
Desc: not available
URL: <http://mail.pm.org/pipermail/melbourne-pm/attachments/20121128/5e22e523/attachment.bin>


More information about the Melbourne-pm mailing list