Perl:您可以将“使用”模块或设置应用于包含脚本吗?

时间:2015-06-19 13:36:02

标签: perl

例如,我的每个脚本都位于顶部:

use warnings; use strict; use v5.10;
use Tools;

我的“工具”包中有许多我一直使用的功能。我宁愿只是包含它并让它对包含脚本使用warnings,strict和5.10,因为无论如何我必须为每个脚本use。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:4)

您可以使用Import::Into和自定义import方法在导入类中打开内容。例如:

package Tools;

use strict;
use warnings;
use feature ':5.10';

use Import::Into;

sub import {
    my $target = caller;
    strict->import::into( $target );
    warnings->import::into( $target );
    feature->import::into( $target, ':5.10' );

    # other imports, etc
}

我写了一篇关于在这里使用Import :: Into的更详细的帖子:Removing Perl Boilerplate with Import::Into

相关问题