我如何开始一个新的 Perl 模块分发? [英] How do I start a new Perl module distribution?
问题描述
我正在尝试建立一个用 Perl 编写的大型项目.IBM MakeMaker 教程 到目前为止非常有帮助,但我不明白如何将所有模块链接到主程序中.在我的项目根目录中,我有 MANIFEST
、Makefile.PL
、README
、一个 bin
目录和一个 lib
目录.在我的 bin
目录中,我有我的主脚本 (Main.pl
).在 lib
目录中,我有我的每个模块,分为各自的目录(即 Utils::Util1
和 Utils::Utils2
> 在 utils
目录等中).在每个模块目录下,还有一个t
目录,里面有tests
I'm trying to set up a large-ish project, written in Perl. The IBM MakeMaker tutorial has been very helpful so far, but I don't understand how to link all the modules into the main program. In my project root, I have MANIFEST
, Makefile.PL
, README
, a bin
directory, and a lib
directory. In my bin
directory, I have my main script (Main.pl
). In the lib
directory, I have each of my modules, divided up into their own respective directories (i.e. Utils::Util1
and Utils::Utils2
in the utils
directory, etc). In each module directory, there is also a t
directory, containing tests
我的 MANIFEST
文件包含以下内容:
My MANIFEST
file has the following:
bin/Main.pl
lib/Utils/Util1.pm
lib/Utils/Util2.pm
lib/Utils/t/Utils1.t
lib/Utils/t/Utils2.t
Makefile.PL
MANIFEST
README
Makefile.PL
如下:
use ExtUtils::MakeMaker;
WriteMakefile(
'NAME'=>'Foo',
'VERSION_FROM'=>'bin/Main.pl',
'PREREQ_PM'=>{
"XML::Simple"=> 2.18}, #The libraries that we need and their
#minimum version numbers
'EXE_FILES' =>[("bin/Main.pl")]
);
在我制作并运行后,程序崩溃,抱怨找不到Utils::Util1
,当我运行'make test
时,它说没有定义测试
.任何人都可以提出任何建议吗?我从来没有用perl做过这样的大型项目,我需要添加更多的模块
After I make and run, the program crashes, complaining that it cannot find Utils::Util1
, and when I run 'make test
, it says no tests defined
. Can anyone make any suggestions? I have never done a large scale project like this in perl, and I will need to add many more modules
推荐答案
试试这个结构:
bin/Main.pl
lib/Utils/Util1.pm
lib/Utils/Util2.pm
Makefile.PL
MANIFEST
README
t/Utils1.t
t/Utils2.t
正如 ysth 所说,make
不会安装您的模块,它只是在 blib
目录中构建它们.(在您的情况下,它只是将它们复制到那里,但如果您有 XS 代码,它将使用 C 编译器编译.)使用 make install
安装您的模块以供常规脚本使用.
As ysth said, make
does not install your modules, it just builds them in a blib
directory. (In your case it just copies them there, but if you had XS code, it would be compiled with a C compiler.) Use make install
to install your modules for regular scripts to use.
如果你想在 make
和 make install
之间运行你的脚本,你可以这样做:
If you want to run your script between make
and make install
, you can do:
perl -Mblib bin/Main.pl
-Mblib
指示 perl 将适当的目录临时添加到搜索路径中,以便您可以尝试卸载的模块.(make test
会自动做到这一点.)
The -Mblib
instructs perl to temporarily add the appropriate directories to the search path, so you can try out an uninstalled module. (make test
does that automatically.)
这篇关于我如何开始一个新的 Perl 模块分发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!