分发 Perl 应用程序

发布于 2024-09-12 02:10:33 字数 251 浏览 6 评论 0原文

我最近创建了一个小型 Perl 应用程序,它使用了一些需要通过 CPAN 安装的非核心模块。

有没有一种方法可以分发应用程序,并能够检查是否安装了所需的模块,如果没有安装,则从 CPAN 中提取它们?我想我正在寻找类似于 CPAN 自动依赖项安装功能的东西。

我考虑过使用 module-starter 和 Module::Install 创建一个类似模块的目录结构,然后定制构建文件以将应用程序安装到 /bin...但我不确定这是否是一个鞋拔子解决方案。

I recently created a little Perl application that utilizes a few non-core modules that will need to be installed via CPAN.

Is there a way to distribute the application with the ability to check to see if the required modules are installed and pull them from CPAN if they aren't? I suppose I am looking for something similar to the CPAN auto-dependency-install feature.

I thought about using module-starter and Module::Install to create a module-like directory structure and then tailor the Build file to install the application to /bin... but I'm not sure if this is a shoe-horn solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

骷髅 2024-09-19 02:10:33

这不是一个鞋拔子解决方案,而是正确的做法。由于特殊情况,您应该让专门的工具处理依赖关系,例如在安装说明中写入:

  1. 解压存档。
  2. 在未归档的目录中运行cpan .

您无需更改构建文件即可将程序安装在 bin 目录中,默认情况下会这样做。

It's not a shoe-horn solution, but the Right Thing to do. You should let a specialised tool handle the dependencies because of the corner cases, e.g. write in the installation instructions:

  1. Unpack the archive.
  2. Run cpan . in the unarchived directory.

You need not change the Build file to install programs in the bin directory, it does this by default.

眼眸印温柔 2024-09-19 02:10:33
BEGIN {
    eval "use evil::module";
    if($@) { `sudo perl -MCPAN -e 'install evil::module'`; exit ; }
}
  1. 您可以轻松检查某个模块是否存在,并a)尝试安装它并退出/重新启动应用程序b)croak/die。 (就像上面的代码片段中的那样)

  2. 您还可以附加要打包的模块,将它们解压到某个目录,并将该目录推送到开始块中的@INC。

BEGIN {
    eval "use evil::module";
    if($@) { `sudo perl -MCPAN -e 'install evil::module'`; exit ; }
}
  1. You can easily check if certain module is present and a)try to install it and exit/restart application b)croak/die. (sth like in the code snippet above)

  2. You can also attach the modules you want to package, extract them to a certain directory, and push the dir to @INC in the begin block.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文