简体   繁体   English

Perl Par :: Packer找不到模块问题

[英]Perl Par::Packer Can't find module issue

I have a perl program that uses WWW::Mechanize::Firefox on windows 7 32bit with strawberry perl. 我有一个Perl程序,在带有草莓perl的Windows 7 32bit上使用WWW::Mechanize::Firefox

It works fine with the command C:\\>perl testcase.pl . 使用命令C:\\>perl testcase.pl When I compile it with C:\\>pp -o testcase.exe testcase.pl it compiles with no errors. 当我使用C:\\>pp -o testcase.exe testcase.pl编译时,它不会出现错误。

When I run the testcase.exe it gives me the error: 当我运行testcase.exe时,出现以下错误:

Failed to connect to , Can't locate object method "setup" via package "MozRepl::Client" at MozRepl.pm line 224

The code I am using for testcase.pl is: 我用于testcase.pl的代码是:

#!perl
use MozRepl;
use WWW::Mechanize::Firefox;
use warnings;
system('start firefox');
sleep(5);
$mech = WWW::Mechanize::Firefox->new;

Also note that a program without WWW::Mechanize::Firefox and MozRepl does work fine. 还要注意,没有WWW::Mechanize::FirefoxMozRepl确实可以正常工作。 The problem has obviously been narrowed down to PAR::Packer not liking MozRepl , any idea what it might be? 问题显然已经缩小到PAR::Packer不喜欢MozRepl ,知道这可能是什么吗?

PAR::Packer sometimes has a hard time identifying which modules need to be included in a PAR package in order to fulfill all of the requirements of the program you are trying to package. PAR :: Packer有时很难确定PAR软件包中需要包含哪些模块才能满足您要打包的程序的所有要求。

It copes OK if the dependancies are loaded via plain 'use', or 'require' statements where the module to be loaded is a literal string, but it won't have much chance if the module is being loaded dynamically with something like: 如果依赖关系是通过普通的“ use”或“ require”语句加载的,那么可以解决问题,其中要加载的模块是文字字符串,但是如果使用以下方式动态加载模块,则机会不大:

require $myModuleToLoad;

Browsing the source code of MozRepl and related modules shows that they make heavy use of plugins loaded dynamically. 浏览MozRepl和相关模块的源代码表明,它们大量使用了动态加载的插件。 I suspect that some of these are not being packaged. 我怀疑其中一些没有包装。

You can manually specify module(s) to be included in the PAR package by adding -M Module::Name to the pp command line for each of the modules to be added (replacing Module::Name with the actual module name of course). 您可以通过为每个要添加的模块在pp命令行中添加-M Module::Name来手动指定要包含在PAR包中的模块(将Module :: Name替换为实际的模块名称) 。

The hard part might be identifying which modules to include. 困难的部分可能是确定要包括哪些模块。 One way to do this is to temporarily add something like this to the end of your script: 一种方法是在脚本末尾临时添加如下代码:

END { print "$_ -> $INC{$_}\n" foreach sort keys %INC; }

then run your script normally, not through PAR. 然后正常运行脚本,而不是通过PAR。 It should list all the modules that were loaded. 它应该列出所有已加载的模块。 You can compare that with the actual modules present in the PAR package and add the missing ones using the -M option to pp. 您可以将其与PAR软件包中的实际模块进行比较,并使用-M选项将缺失的模块添加到pp。

You can see the modules inside your PAR file by opening it with an unzipping tool, such as 7zip. 通过使用7zip之类的解压缩工具打开PAR文件,可以看到其内部的模块。 Or in Linux: 或在Linux中:

unzip -l {parfile}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM