我熟悉使用package.json
与node.js,Gemfile
为Ruby,Podfile
为Objective-C,等。定义perl项目所需的包和版本
什么是Perl的等效文件,语法是什么?
我已经安装了几个使用cpanm的软件包,并希望将软件包名称和版本保存在可由团队成员执行的单个文件中。
我熟悉使用package.json
与node.js,Gemfile
为Ruby,Podfile
为Objective-C,等。定义perl项目所需的包和版本
什么是Perl的等效文件,语法是什么?
我已经安装了几个使用cpanm的软件包,并希望将软件包名称和版本保存在可由团队成员执行的单个文件中。
对于简单的使用情况,编写cpanfile
是一个不错的选择。示例文件可能看起来像
requires 'Marpa::R2', '2.078';
requires 'String::Escape', '2010.002';
requires 'Moo', '1.003001';
requires 'Eval::Closure', '0.11';
on test => sub {
requires 'Test::More', '0.98';
};
也就是说,它实际上是一个Perl脚本,而不是数据格式。依赖关系然后可以安装,如
$ cd /path/to/your/module
$ cpanm --installdeps .
这不会安装您的模块!但它确保所有的依赖性得到满足,所以我们可以这样做:
use lib '/path/to/your-module/lib'; # add the location as a module search root
use Your::Module; # works! yay
这通常是足够的,例如,对于你想让其他人修改的git仓库。
如果你想创建一个可以分发和易于安装压缩包,我建议Dist::Zilla
(虽然它是面向对CPAN版本)。取而代之的是cpanfile
我们使用dist.ini
:
name = Your-Module
version = 1.2.3
author = Your Self <[email protected]>
license = GPL_3
copyright_holder = Your Self
[@Basic]
[Prereqs]
Marpa::R2 = 2.078
String::Escape = 2010.002
Moo = 1.003001
Eval::Closure = 0.11
[Prereqs/TestRequires]
Test::More = 0.98
然后:
DIST ::吉拉需要创造出一种安装模块需要Makefile.PL
和其他基础设施的照顾。
然后,您可以分发该压缩包,并像cpanm Your-Module-1.2.3.tar.gz
一样安装它。依赖关系已解决,您的软件包将被复制到永久位置,并且您现在可以在任何脚本中使用use Your::Module
,而无需指定位置。
请注意,你要坚持标准的目录布局Perl模块:
./
lib/
Your/
Module.pm # package Your::Module
Module/
Helper.pm # package Your::Module::Helper
t/ # tests to verify the module works on the target syste,
foo.t
bar.t
xt/ # optional: Author tests that are not run on installation
baz.t
bin/ # optional: scripts that will later end up in the target system's $PATH
command-line-tool
我通常使用['[AutoPrereqs]'](http://p3rl.org/Dist::Zilla::Plugin::AutoPrereqs)而不是['[Prereqs]'](http://p3rl.org/Dist::Zilla::Plugin::Prereqs)。 –
Makefile.PL
通常(以及其他一些文件; Perl的软件包的时间比您提到的任何其他语言的时间长,并且在此处有一些不合理的地方)。
Module Starter是一个明智的方式来开始编写一个包。它有一个getting started指南。
[cpanfile](http://search.cpan.org/~miyagawa/Module-CPANfile-1.0002/lib/cpanfile .pod),http://stackoverflow.com/q/17696492/223226 –