perl - WWW::Mechanize::GZip 触发 __DIE__ 信号......为什么?

标签 perl gzip mechanize die

我花了一段时间才找到我的代码突然出现的问题,但 WWW::Mechanize::GZip 似乎以某种方式触发了我的 $SIG{ 模具 } 处理程序。考虑这个代码:

use strict;
use WWW::Mechanize::GZip;

$SIG{__DIE__} = sub {
   print "WTF???  WHY IS THIS BEING TRIGGERED?\n";
};

my $mech = WWW::Mechanize::GZip->new();
$mech->get( 'http://ammoseek.com/' );

print $mech->content(), "\n";

知道为什么会发生这种情况吗?我能做些什么来防止它?

谢谢,

-麦克风

最佳答案

您可以通过 $SIG{__DIE__} 了解死亡原因/死亡原因的详细信息。处理程序打印:

  • 错误消息(处理程序中的 $_[0])
  • 从处理程序中的堆栈跟踪(例如通过调用 Carp::cluck )

  • 或者,使用 onerror => \&func WWW::Mechanize::GZip 构造函数的参数以创建自定义错误处理程序(假设错误不是来自 Compress::Zlib)。来自 WWW::Mechanize POD

    onerror => \&func

    Reference to a die-compatible function, such as Carp::croak, that is called when there's a fatal error.

    If this is set to undef, no errors will ever be shown.

    If this value is not passed, Mech uses Carp::croak if Carp is installed, or CORE::die if not.



    由于 WWW::Mechanize::GZip 是 WWW::Mechanize 的直接子类,您可以使用相同的参数来构造它。

    关于perl - WWW::Mechanize::GZip 触发 __DIE__ 信号......为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2976344/

    相关文章:

    perl - 是否有一个 Perl 模块来监控电子邮件队列?

    c - 在rtems操作系统中解压tar.gz

    python - 使用 python Mechanize 修复网页的字符编码

    Ruby 在大表中选择按钮的最快方法

    json - Perl 无法加载 SSLeay.dll,因为未安装 LWP::Protocol::https

    Perl Getopt::Long 支持参数空格

    ios - 在 xcode 中使用 GZIP 压缩 CSV 文件

    python - 使用 Mechanize 处理非标准 401 header

    regex - Perl - 在逗号上拆分字符串。忽略空格

    Java - 使用 Deflater 写入 GZIP 文件