Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use parent 'Exporter' vs. use Exporter 'import';

What do I gain if I use the first example instead of the second example?

package Some::Module;
use strict;
use 5.10.1;

use parent 'Exporter';
our @EXPORT_OK = qw(some_func);

package Some::Module;
use strict;
use 5.10.0;

use Exporter 'import';
our @EXPORT_OK = qw(some_func);
like image 448
sid_com Avatar asked Oct 24 '25 18:10

sid_com


2 Answers

Nothing, really. Exporter was originally envisioned to work as a base class; later it was enhanced to allow you to just import its import method. There is no reason to inherit from it now.

If you are writing code that may be used with Perl 5.8.2 and earlier, you should require a sufficient version of Exporter:

use Exporter 5.57 'import';
like image 138
ysth Avatar answered Oct 26 '25 09:10

ysth


use Exporter 'import' works in Exporter 5.57+, which has been bundled with Perl since Perl 5.8.3. If you need to support the older versions of Exporter which were bundled with earlier releases of Perl, then you should inherit from Exporter instead.

(Exporter is a dual-life module, so users of older versions of Perl can technically upgrade Exporter without upgrading all of Perl; however older versions of the cpan tool sometimes have issues upgrading dual-life modules, so upgrading Exporter may be potentially tricky for them.)

If you don't care about archaic releases of Perl, by all means use Exporter 'import'. Exporter isn't really written in an object-/class-oriented fashion, so there's no real reason to inherit from it. (Unlike my own exporter module, Exporter::Tiny which is designed with inheritance/overriding in mind!)

like image 21
tobyink Avatar answered Oct 26 '25 10:10

tobyink



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!