使用父母“出口商”与使用出口商的“进口”; [英] use parent 'Exporter' vs. use Exporter 'import';

查看:160
本文介绍了使用父母“出口商”与使用出口商的“进口”;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  package Some :: Module; 
使用strict;
使用5.10.1;

使用父出口商;
我们的@EXPORT_OK = qw(some_func);






 一些::模块; 
使用strict;
使用5.10.0;

use Exporter'import';
我们的@EXPORT_OK = qw(some_func);


解决方案

没有,真的。出口商最初被设想为基层工作;之后它被增强,允许你只是导入它的导入方法。现在没有理由继承。



如果您正在编写可能与Perl 5.8.2及更早版本一起使用的代码,则需要足够的出口商版本:

 使用出口商5.57'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);

解决方案

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';

这篇关于使用父母“出口商”与使用出口商的“进口”;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆