perl Graphics命令在命令行中起作用,但没有用作CGI
我们有一个旧的perl脚本,该脚本生成一个PNG图形文件,以在内部网页中显示线条绘制。我们将该Perl脚本用作Apache Web服务器中的CGI。多年来工作正常。最近,我们希望将Apache Web服务器从Windows 7计算机移动到Windows 10计算机。问题开始了。 Perl脚本无法使用Chart :: Lines程序模块生成图形文件。当我以某种方式将Perl脚本从CGI转换为普通的Perl脚本并在命令行中运行时,它可以正常工作。
我已经将问题跟踪到C:\ Strawberry \ perl \ site \ lib \ cart \ base.pm中的一条线:
sub _draw_right_legend {
.
.
# draw the point
$self->{'gd_obj'}->line(int(($x3+$x2)/2), $y2, int(($x3+$x2)/2), $y2, gdBrushed);
.
.
}
当Perl脚本以CGI运行时,“ Gdbrushed”的使用似乎可以触发问题。该程序将在该线路上终止。不幸的是,当我检查Apache Web服务器中的日志文件时,我什么都没看。如上所述,perl脚本的简单词在命令行中效果很好。这意味着我看不到任何错误消息。
如果我用“ $ color”替换“ gdbrushed”,则CGI脚本不会崩溃。但是,该语句应该绘制的观点不会出现在图形文件中。 ($颜色是在同一子例程中定义的,用于绘制线路)。这意味着这确实不是解决方案。
目前,我通过评论该行并跳过该“点”来解决这个问题。但是我想找到一个更好的解决方案。
请注意,当我尝试安装gd.pm和Chart ::行以PERL时,正常过程无法安装(因为安装程序无法在CPAN中找到GD.PM或Chart :: Lines)。我最终使用了残酷的力量方法将整个Perl程序文件夹从“已知的好” Apache Web服务器(Windows 7)复制到新服务器(Windows 10)。这可能与这个问题有关。但是我在Chart :: Lines中使用的所有其他内容都在起作用,除了绘制“点”。
更新1:修复了GD和图表安装的问题。不幸的是,这并不能解决本文中提到的问题。图表程序试图提取点时仍会崩溃。我在Apache Web服务器中找到了错误消息。log:
Insecure dependency in eval while running with -T switch at C:/Strawberry/perl/site/lib/GD.pm line 87.
gd.pm中的语句触发错误是:
sub AUTOLOAD {
# This AUTOLOAD is used to 'autoload' constants from the constant()
# XS function. If a constant is not found then control is passed
# to the AUTOLOAD in AutoLoader.
my($constname);
($constname = $AUTOLOAD) =~ s/.*:://;
undef $!;
my $val = constant($constname);
if ($! != 0) {
if ($! =~ /Invalid/) {
$AutoLoader::AUTOLOAD = $AUTOLOAD;
goto &AutoLoader::AUTOLOAD;
}
else {
my($pack,$file,$line) = caller;
die "Your vendor has not defined GD macro $pack\:\:$constname, used at $file line $line $!.\n";
}
}
eval "sub $AUTOLOAD { $val }"; <-- This triggers the error
goto &$AUTOLOAD;
}
似乎问题可能与我的程序使用GDBrushed常数有关。并以某种方式使用该常数触发了GD.PM中的此错误。我不知道为什么。
更新2:我发现当错误发生时,$ autoLoad中有“ gd :: gdbrushed”。这意味着此错误可能与该常数的使用有关。
We have an old Perl script that generates a PNG graphic file to show a line-chart in an internal web page. We use that Perl script as a CGI in an Apache web server. It works fine for many years. Recently we want to move the Apache web server from a Windows 7 computer to a Windows 10 computer. And the problem starts. The Perl script cannot use Chart::Lines program module to generate the graphic file. Somehow when I convert the Perl script from a CGI into a plain Perl script and run in a command line, it works fine.
I have tracked down the problem to a line in C:\Strawberry\perl\site\lib\Chart\Base.pm:
sub _draw_right_legend {
.
.
# draw the point
$self->{'gd_obj'}->line(int(($x3+$x2)/2), $y2, int(($x3+$x2)/2), $y2, gdBrushed);
.
.
}
Seem like the use of "gdBrushed" can trigger the problem when the Perl script is running as a CGI. The program will terminate itself right at that line. Unfortunately, when I check the log file in Apache web server, I don't see anything. As mentioned above, the plain-version of the Perl script works fine in command line. This means I cannot see any error message.
If I replace "gdBrushed" with "$color", the CGI script won't crash. But the point that the statement is supposed to draw doesn't appear in the graphic file. ($color is defined inside the same sub routine, and it is used to draw a line). This means this is really not a solution.
For now, I get around this problem by commenting out that line and skip drawing that "point". But I would like to find a better solution.
Please note that when I tried to install GD.pm and Chart::Lines to Perl, the normal process failed to install (because the installation program cannot find GD.pm or Chart::Lines in CPAN any more). I ended up using the brutal force approach to copy the entire Perl program folder from a "known good" Apache web server (Windows 7) to the new server (Windows 10). This may have to do with this problem. But everything else that I use in Chart::Lines is working, except for drawing that "point".
UPDATE 1: Fixed the problem with installation of GD and Chart. Unfortunately this doesn't fix the problem mentioned in this post. The Chart program still crashes when it tries to draw points. I find the error message in error.log in Apache web server:
Insecure dependency in eval while running with -T switch at C:/Strawberry/perl/site/lib/GD.pm line 87.
The statement in GD.pm that triggers the error is:
sub AUTOLOAD {
# This AUTOLOAD is used to 'autoload' constants from the constant()
# XS function. If a constant is not found then control is passed
# to the AUTOLOAD in AutoLoader.
my($constname);
($constname = $AUTOLOAD) =~ s/.*:://;
undef $!;
my $val = constant($constname);
if ($! != 0) {
if ($! =~ /Invalid/) {
$AutoLoader::AUTOLOAD = $AUTOLOAD;
goto &AutoLoader::AUTOLOAD;
}
else {
my($pack,$file,$line) = caller;
die "Your vendor has not defined GD macro $pack\:\:$constname, used at $file line $line $!.\n";
}
}
eval "sub $AUTOLOAD { $val }"; <-- This triggers the error
goto &$AUTOLOAD;
}
Seem like the problem may have to do with my program using gdBrushed constant. And somehow using that constant triggers this error in GD.pm. And I don't know why.
UPDATE 2: I find that when the error happens, $AUTOLOAD has "GD::gdBrushed" in it. This means this error is likely related to the use of that constant.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论