我正在尝试使用 Lincoln Stein 的Network Programming With Perl中的一组 IO 模块,并遇到以下错误:
Can't locate object method "blocking" via package "IO::LineBufferedSessionData"
at /mxhome/charrison/private/perl/IO/SessionData.pm line 22.
我从 Addison/Wesley 站点为本书下载的模块集合不包含 blocking() 子例程,经过一番挖掘后,我发现它希望调用 IO::Socket 中的 blocking() 子例程的证据或者 IO::File,或者 IO::Handle.... 实际上在 IO::Handle 中有一个 blocking() 方法。
这是 IO::SessionData 模块的顶部部分,包括它正在吐槽的那一行:
package IO::SessionData;
# file: IO/SessionData.pm
# Figure 13.5: The IO::SessionData Module Code
use strict;
use Carp;
use IO::SessionSet;
use Errno 'EWOULDBLOCK';
use vars '$VERSION';
$VERSION = 1.00;
use constant BUFSIZE => 3000;
# Class method: new()
# Create a new IO::SessionData object. Intended to be called from within
# IO::SessionSet, not directly.
sub new {
my $pack = shift;
my ($sset,$handle,$writeonly) = @_;
# make the handle nonblocking
#######################################################################
$handle->blocking(0); # <=== THIS IS THE CALL IT FAILS ON
#######################################################################
my $self = bless {
outbuffer => '',
sset => $sset,
handle => $handle,
write_limit => BUFSIZE,
writeonly => $writeonly,
choker => undef,
choked => undef,
},$pack;
$self->readable(1) unless $writeonly;
return $self;
}
我不知道这是否足以解决问题。我对模块或面向对象的 Perl 了解甚少。我猜作者打算blocking
在某个超类中调用一个方法(例如 IO::Handle?)。这本书写于 2001 年,也许有些规则已经改变。或者文本可能有错误。任何人都可以提出解决方案,或要求提供更多信息吗?
更新 1:confess
这是在有问题的阻塞()调用之前 生成的堆栈跟踪:
/Users/chap/private/wdi/server$ ./server_template -v
at /Users/chap/private/wdi/lib/IO/SessionData.pm line 21.
IO::SessionData::new('IO::LineBufferedSessionData', 'IO::LineBufferedSet=HASH(0x7fcbe19bd450)', 'IO::Socket::INET=GLOB(0x7fcbe18a8070)', undef) called at /Users/chap/private/wdi/lib/IO/LineBufferedSessionData.pm line 21
IO::LineBufferedSessionData::new('IO::LineBufferedSessionData', 'IO::LineBufferedSet=HASH(0x7fcbe19bd450)', 'IO::Socket::INET=GLOB(0x7fcbe18a8070)', undef) called at /Users/chap/private/wdi/lib/IO/SessionSet.pm line 46
IO::SessionSet::add('IO::LineBufferedSet=HASH(0x7fcbe19bd450)', 'IO::Socket::INET=GLOB(0x7fcbe18a8070)') called at /Users/chap/private/wdi/lib/IO/SessionSet.pm line 136
IO::SessionSet::wait('IO::LineBufferedSet=HASH(0x7fcbe19bd450)') called at /Users/chap/private/wdi/lib/IO/LineBufferedSet.pm line 24
IO::LineBufferedSet::wait('IO::LineBufferedSet=HASH(0x7fcbe19bd450)') called at ./server_template line 221
如您所见,new() 正在内部被调用。(我的应用程序在堆栈的底部;其他所有内容都来自本书。)