Perl 从CPAN自动安装缺少的模块
如果我想发布一个Perl脚本,那么最好的方法是什么来轻松地安装用户系统上缺少的任何必需模块?如果有一种方法甚至可以在Perl丢失或“太旧”时安装/升级Perl本身,那么就需要额外的积分。通常这会以类似CPAN的包创建结束。 因此,当您需要安装所有依赖项时,请键入Perl 从CPAN自动安装缺少的模块,perl,deployment,cpan,Perl,Deployment,Cpan,如果我想发布一个Perl脚本,那么最好的方法是什么来轻松地安装用户系统上缺少的任何必需模块?如果有一种方法甚至可以在Perl丢失或“太旧”时安装/升级Perl本身,那么就需要额外的积分。通常这会以类似CPAN的包创建结束。 因此,当您需要安装所有依赖项时,请键入makeinstalldeps 看 也可能对你和一些例子有用 Makefile.PL允许您定义DEP和所需的perl版本。 你也可以加上 use 5.010; 为了运行所需的最低版本的perl,请将其添加到脚本中。有关详细信息,请参阅。
makeinstalldeps
看
也可能对你和一些例子有用
Makefile.PL
允许您定义DEP和所需的perl版本。
你也可以加上
use 5.010;
为了运行所需的最低版本的perl,请将其添加到脚本中。有关详细信息,请参阅。为什么不使用创建可执行文件的pp(PAR Packager)。在目标机器上不需要Perl或任何东西。自动安装软件是让最终用户和系统管理员对您非常生气的最佳方式。忘掉这种方法吧
您只需将所有依赖项随应用程序发行版一起发布,通常使用
inc
目录。如果您查看cpanminus,只需执行一个文件即可安装:
curl-Lhttp://cpanmin.us |perl---自我升级
这可能就是你想要的行为;这是通过App::Fatpacker完成的。请查看:
一个取自的半自动脚本,适用于具有中级bash技能和几乎0级perl技能的人员:
#!/usr/bin/env perl
use strict ; use warnings ;
use 5.10.0 ;
use ExtUtils::Installed;
# quick and dirty check for prerequisites perl modules:
# courtesy of:http://stackoverflow.com/a/9340304/65706
# if you have a calling bash script call by :
# perl "/path/to/isg_pub_preq_checker.pl"
# export ret=$?
# test $ret -ne 0 && doExit 1 "[FATAL] perl modules not found!!!"
my $PrintOkCheck = 1 ;
# check that all the required modules are installed
my ( $ret , $msg ) = doCheckRequiredModules();
unless ( $ret == 0 ) {
print "$msg" ;
# give some time for the user to react
print "printing all installed modules :" ;
my $c = 9 ;
for ( my $i=0;$i<=$c;$i++){
print ( ( $c-$i) . '.') ;
sleep 1 ;
}
print "\n" ;
doListAllInstalledModules();
print "\n" ;
}
exit(0);
sub doListAllInstalledModules {
my $instmod = ExtUtils::Installed->new();
foreach my $module ($instmod->modules()) {
my $version = $instmod->version($module) || "???";
print "found module:$module -- v$version\n";
}
}
#eof sub
sub doCheckRequiredModules {
my @modules = qw(
YAML::Any
Test::More
Spreadsheet::XLSX
Test::Deep
File::Copy::Recursive
IO::HTML
Test::More
Filter::Util::Call
Algorithm::Diff
Text::Diff
Test::Base
Test::CPAN::Meta::YAML
Test::YAML::Valid
Test::YAML::Meta
Test::YAML
Data::Printer
ExtUtils::Installed
Sub::StrictDecl
Spreadsheet::WriteExcel
Mojolicious::Plugin::RenderFile
JSON
Carp::Always
Mojolicious::Plugin::PDFRenderer
Redis::Client
);
for(@modules) {
eval "use $_";
if ($@) {
#flush the screen
print "\033[2J";
print "\033[0;0H";
my $msg = "\n\n\n [FATAL] did not found the following prerequisite perl module: $_ \n\n" ;
$msg .= "\n # == START copy paste == " ;
$msg .= "\n#you must install it otherwise the application will not work" ;
$msg .= "\n#the module could be installef by running the following commands:" ;
# if the user knows already the difference between the running the cmd
# with sudo or he / she probably knows already how-to install perl modules
$msg .= "\n# as a start configure the cpan to install dependancies first \n" ;
$msg .= "\n" . 'perl -MCPAN -e \'my $c = "CPAN::HandleConfig"; $c->load(doit => 1, autoconfig => 1); $c->edit(prerequisites_policy => "follow"); $c->edit(build_requires_install_policy => "yes"); $c->commit\'' . "\n" ;
$msg .= "\n#than install the $_ module by running: \n" ;
$msg .= "\nsudo perl -MCPAN -e 'install $_'\n\n\n" ;
$msg .= "\n # == STOP copy paste == \n\n\n" ;
$msg .= "\n # == START copy paste == " ;
$msg .= "\n# if you seem to be stuck in circular reference kind of loop try even :\n" ;
$msg .= "\nsudo perl -MCPAN -e 'CPAN::Shell->force(qw( install $_));'\n" ;
$msg .= "\n # == STOP copy paste == " ;
$msg .= "\n# You may end-up now with Ctrl + C \n\n\n" ;
return ( 1, "$msg") if $@;
} else {
say "[INFO ] == ok == check for prerequisite perl module : $_" if $PrintOkCheck == 1 ;
}
}
#eof foreach module
return ( 0 , "all required modules found" ) ;
}
#eof sub
# ??!!
#perl -MCPAN -e 'install Module::Signature'
# the following modules have been or might be part of the installable modules
#PDF::WebKit
#HTML::TreeBuilder
#HTML::TreeBuilder::XPath
#HTML::TableExtract
#HTML::ElementTable
#/usr/bin/env perl
严格使用;使用警告;
使用5.10.0;
使用ExtUtils::Installed;
#快速检查perl模块的先决条件:
#承蒙:http://stackoverflow.com/a/9340304/65706
#如果您有一个调用bash脚本的调用方:
#perl“/path/to/isg_pub_preq_checker.pl”
#导出ret=$?
#test$ret-ne 0&&doExit 1“[致命]找不到perl模块!!!”
我的$PrintOkCheck=1;
#检查是否安装了所有必需的模块
my($ret,$msg)=doCheckRequiredModules();
除非($ret==0){
打印“$msg”;
#给用户一些时间做出反应
打印“打印所有安装的模块:”;
我的$c=9;
对于(my$i=0;$inew();
foreach my$模块($instmod->modules()){
我的$version=$instmod->version($module)| |?“?”;
打印“找到的模块:$module--v$version\n”;
}
}
#eof接头
子doCheckRequiredModules{
my@modules=qw(
YAML::有吗
测试::更多
电子表格::XLSX
测试::深度
文件::复制::递归
IO::HTML
测试::更多
过滤器::Util::调用
算法::Diff
文本::Diff
测试::基本
测试::CPAN::元::YAML
测试::YAML::有效
测试::YAML::Meta
测试:YAML
数据:打印机
ExtUtils::已安装
Sub::StrictDecl
电子表格::WriteExcel
Mojolicious::Plugin::RenderFile
JSON
鲤鱼:总是
Mojolicious::Plugin::PDFRenderer
Redis::客户端
);
对于(@模块){
评估“使用美元”;
如果($@){
#冲洗屏幕
打印“\033[2J”;
打印“\033[0;0H”;
my$msg=“\n\n\n[FATAL]未找到以下必备perl模块:$\u\n\n”;
$msg.=“\n#==开始复制粘贴==”;
$msg.=“\n#您必须安装它,否则应用程序将无法工作”;
$msg.=“\n#可以通过运行以下命令来安装模块:”;
#如果用户已经知道运行cmd和
#使用sudo或他/她可能已经知道如何安装perl模块
$msg.=“\n#首先配置cpan以首先安装依赖项\n”;
$msg.=“\n”''perl-MCPAN-e\'my$c=“CPAN::HandleConfig”;$c->load(doit=>1,autoconfig=>1);$c->edit(先决条件策略=>“遵循”);$c->edit(构建需要安装策略=>“是”);$c->commit\”。\n;
$msg.=“\n#然后通过运行:\n”安装$uu模块;
$msg.=“\nsudo perl-MCPAN-e'install$\n\n\n”;
$msg.=“\n#==停止复制粘贴==\n\n\n”;
$msg.=“\n#==开始复制粘贴==”;
$msg.=“\n#如果您似乎陷入循环引用类型的循环中,请尝试偶数:\n”;
$msg.=“\nsudo perl-MCPAN-e'CPAN::Shell->force(qw(install$);”\n”;
$msg.=“\n#==停止复制粘贴==”;
$msg.=“\n#您现在可以使用Ctrl+C\n\n\n键结束”;
如果$@,则返回(1,“$msg”);
}否则{
如果$PrintOkCheck==1,则说“[INFO]==ok==check以检查必备的perl模块:$\”;
}
}
#eof foreach模块
返回值(0,“找到所有必需的模块”);
}
#eof接头
# ??!!
#perl-MCPAN-e“安装模块::签名”
#以下模块已经或可能是可安装模块的一部分
#PDF::WebKit
#HTML::TreeBuilder
#HTML::TreeBuilder::XPath
#HTML::TableExtract
#HTML::ElementTable
这不是我心目中的“无痛”!我想分发一个perl脚本文件,允许用户只运行该脚本一次