Perl: Makefile.PL, File::ShareDir::Install, chicken and eggs

时间:2016-04-15 14:48:43

标签: perl packaging

The File::ShareDir::Install module represents a practical way of carrying around auxiliary files with a Perl distribution/module. I feel however a bit puzzled on how to include it in the dependencies of my project.

I tried to install my package on a fresh machine (actually a docker container with base OS + Perl + CPAN) and I got the error:

Can't locate File/ShareDir/Install.pm in @INC ... at Makefile.PL line 7.

According to the documentation (perldoc File::ShareDir::Install), the pattern should be, in my Makefile.PL:

use ExtUtils::MakeMaker;
use File::ShareDir::Install;

install_share 'share';
install_share dist => 'dist-share';
install_share module => 'My::Module' => 'other-share';

WriteMakefile( ... );       # As you normaly would

package MY;
use File::ShareDir::Install qw(postamble);

However, by doing so I need File::ShareDir::Install to be pre-installed on my system as requirement to run the Makefile.PL script. Declaring it as dependency will not work, for obvious reasons!

Should I instruct my users to explicitly instasll File::ShareDir::Install before my module? Would it be possible to install it programmatically, within Makefile.PL, by directly calling the CPAN module?

2 个答案:

答案 0 :(得分:4)

这是CONFIGURE_REQUIRES的用途:

  

适用于6.52及更高版本。

     

运行Makefile.PL本身所需的模块哈希,但不运行您的发行版。

     

这将进入META.yml的configure_requires字段和META.json的prereqs字段的配置。

     

如果未指定此属性,则默认为{ "ExtUtils::MakeMaker" => 0 }

     

格式与PREREQ_PM相同。

因此,您需要添加WriteMakefile参数:

CONFIGURE_REQUIRES => {
  "ExtUtils::MakeMaker" => '6.52',
  "File::ShareDir::Install" => 0,
},

然后使用cpancpanm安装模块的人将自动安装File :: ShareDir :: Install。

答案 1 :(得分:-1)

构建分发

  1. 建立File::ShareDir::Install构建时依赖项。

    CONFIGURE_REQUIRES => {
       'ExtUtils::MakeMaker'     => '6.52',
       'File::ShareDir::Install' => 0,
    },    
    
  2. 在构建发行版的机器上安装File :: ShareDir :: Install。

  3. 构建发行版。

    这将创建一个META.yml,其中包含File :: ShareDir :: Install作为构建时依赖项。

  4. 安装发行版

    正常使用cpancpanmcpancpanm将从META.yml中提取构建时依赖项,并在运行Makefile.PL之前安装它们。