我想为我自己的"默认使用"制作一个模块,例如:
use My::perldefs;
Run Code Online (Sandbox Code Playgroud)
具有以下内容(主要基于tchrist的帖子.)
use 5.014;
use strict;
use features qw(switch say state);
no warnings;
use warnings qw(FATAL closed threads internal debugging pack substr malloc
unopened portable prototype inplace io pipe unpack regexp
deprecated exiting glob digit printf utf8 layer
reserved parenthesis taint closure semicolon);
no warnings qw(exec newline);
use utf8;
use open qw(:std :utf8);
use charnames qw(:full);
use feature qw(unicode_strings);
use Encode qw(encode decode);
use Unicode::Normalize qw(NFD NFC);
use Carp qw(carp croak confess cluck);
use autodie; …Run Code Online (Sandbox Code Playgroud) 我想创建几个模块,这些模块将用于我项目中的几乎所有脚本和模块.这些可以在我的每个脚本中使用 d,如下所示:
#!/usr/bin/perl
use Foo::Bar;
use Foo::Baz;
use Foo::Qux;
use Foo::Quux;
# Potentially many more.
Run Code Online (Sandbox Code Playgroud)
是否可以将所有这些use语句移动到一个新模块Foo::Corge,然后只需要use Foo::Corge在我的每个脚本和模块中移动?
我有很多独立的脚本.他们唯一共享的是,他们使用()一大组CPAN模块(每个模块都导出几个函数).我想集中这个模块列表.我发现了几种方法.哪一个是最好的?
我可以创建SharedModules.pm来导入所有内容,然后使用Exporter手动将所有内容导出到main ::.
我可以创建以"package main"开头的SharedModules.pm 所以它会直接导入main ::.它似乎工作.这是不好的做法,为什么?
我可以要求()一个似乎将所有内容导入main ::的sharedmodules.pl.我不喜欢这种方法,因为在mod_perl下,require()不能很好地工作.
第二个看起来对我来说最好,但是我想知道为什么例如Modern :: Perl不能那样工作.
我想创建一个Base类,每次使用它时都会导出以下模块:
use 5.018;
use Data::Dumper;
use Warning;
#etc etc
Run Code Online (Sandbox Code Playgroud)
类似的问题: