要搜索没有安装到 所指定路径的模块,使用 lib 编译指令:

    注意:use lib 必须置于试图使用 Magic::Foo 之前。

    及其命令行工具 module-starter 创建模块发行套件的基本框架,以便发布到 CPAN 上。它包含基本的代码布局、POD 指令、文档片断、基本测试、Makefile.PLMANIFEST 文件、以及 READMEChanges 记录的开头。

    1. $ module-starter --module=Magic::Foo --module=Magic::Foo::Internals \
    2. --author="Andy Lester" --email="andy@perl.org" --verbose
    3. Created Magic-Foo
    4. Created Magic-Foo/lib/Magic
    5. Created Magic-Foo/lib/Magic/Foo
    6. Created Magic-Foo/lib/Magic/Foo/Internals.pm
    7. Created Magic-Foo/t
    8. Created Magic-Foo/t/pod.t
    9. Created Magic-Foo/t/boilerplate.t
    10. Created Magic-Foo/t/00-load.t
    11. Created Magic-Foo/.cvsignore
    12. Created Magic-Foo/Makefile.PL
    13. Created Magic-Foo/Changes
    14. Created Magic-Foo/README
    15. Created Magic-Foo/MANIFEST
    16. Created starter directories and files

    如果你想创建 XS 模块,即 Perl 代码与外部 C 代码的接口,那么你将需要使用原始的模块开始工具 h2xsh2xs 已包含到每个 Perl 发行中,但它可能并没有 Module::Starter 那么新。除非你需要 XS 代码,否则使用 Module::Starter

    Dist::Zilla 是一个相当好用的 Perl 模块,它使创建、打包、以及发行模块的过程变得十分容易。如果你打算将编写的模块发布到 CPAN 上,那么使用Dist::Zilla 将为你节省许多时间。

    初始化 Dist::Zilla 配置

    根据向导提供你的姓名、Email、选择版权许可、以及 PAUSE 帐号(发布模块到 CPAN 时需要)即可。

    Dist::Zilla 默认将配置文件保存在 ~/.dzil/config.ini 文件中,所以后续你也可以通过修改此文件来变更相应信息。

    创建模块

    执行以下命令可以创建一个新的模块,如 Foo::Bar:

    1. [DZ] writing files to /home/xiaodong/code/Foo-Bar
    2. [DZ] dist minted in ./Foo-Bar

    这将创建如下目录结构及文件:

    其中,dist.ini 为该模块的配置文件,Bar.pm 为模块源文件。

    打包模块

    1. $ dzil build
    2. [DZ] beginning to build WebService-TaobaoIP
    3. [DZ] guessing dist's main_module is lib/WebService/TaobaoIP.pm
    4. [DZ] extracting distribution abstract from lib/WebService/TaobaoIP.pm
    5. [DZ] writing WebService-TaobaoIP in WebService-TaobaoIP-0.03
    6. defined(@array) is deprecated at /usr/share/perl5/Log/Log4perl/Config.pm line
    7. 864.
    8. (Maybe you should just omit the defined()?)
    9. [DZ] writing archive to WebService-TaobaoIP-0.03.tar.gz

    执行该命令后,模块就会被打包成 .tar.gz 格式。

    发布模块

    如果你要将模块发布到 CPAN 上,只需执行:

    根据提示,回答 将发布模块,N 将终止发布过程。

    其他功能

    Dist::Zilla 不愧为一站式工具,除上述基本功能之外,还包括添加模块到现有发行、执行测试、列出模块依赖等特性。

    有关 Dist::Zilla 的更多用法,可参考其。