我有一个 perl 包ServerSocket.pm
,如下所示:
package Functions::ServerSocket;
use strict;
use warnings;
use ZeroMQ qw/:all/;
use Functions::Testd qw(get_interface_address);
# Next lines are needed to export subroutines
use base 'Exporter';
use vars qw/ @EXPORT_OK /;
@EXPORT_OK = qw(start_socket receive_msg send_msg end_msg close_socket term_ctxt send_ip);
{....................}
# Send a message
sub send_msg {
# Retrieve message
my $msg = shift;
# If $sender is not undef, sending the first part of output with socket identity
if (defined($sender)){
select_recipient();
}
ZeroMQ::Raw::zmq_send($socket, $msg, ZMQ_SNDMORE);
chomp($msg);
print "MSG: \"$msg\" sent.\n";
}
{................................}
我在另一个名为的包中使用了这个包Testd.pm
:package Functions::Testd;
use strict;
use warnings;
use Functions::ServerSocket qw(send_msg close_socket term_ctxt end_msg);
use Scalar::Util qw(looks_like_number);
use Socket;
require 'sys/ioctl.ph';
{...............}
sub stop_daemon {
# Killing all remaining process
killing_child();
# Printing to the FIFO the last log.
send_msg("Daemon stopped.\n");
send_msg("DAEMON_STOPPED\n");
end_msg();
# Removing the socket. Do it only when you're sure you don't have any more output to send.
remove_socket();
print "Daemon stopped.\n";
STDOUT->flush();
exit 0;
}
{..............}
对我来说一切都很好,我使用了这种方法数百次。但是这次我得到了这个错误:
Undefined subroutine &Functions::Testd::send_msg called at Functions/Testd.pm line 80.
我找到的唯一解决方案是编写带有完整路径的子例程,即&Functions::ServerSocket::send_msg
. 为什么会这样?从 ServerSocket 导出到 Testd 的所有函数都会发生同样的错误。我也在其他包和脚本中导入 ServerSocket 函数,一切正常。只有 Testd 似乎无法导入它们。
如果您需要,我可以发布整个包裹。
正如有人问的那样,这是调试器中 M 的输出:
'/usr/lib/perl/5.14/auto/POSIX/autosplit.ix' => '/usr/lib/perl/5.14/auto/POSIX/autosplit.ix'
'/usr/lib/perl/5.14/auto/POSIX/load_imports.al' => '/usr/lib/perl/5.14/auto/POSIX/load_imports.al'
'AutoLoader.pm' => '5.71 from /usr/share/perl/5.14/AutoLoader.pm'
'B.pm' => '1.29 from /usr/lib/perl/5.14/B.pm'
'Carp.pm' => '1.20 from /usr/share/perl/5.14/Carp.pm'
'Class/Struct.pm' => '0.63 from /usr/share/perl/5.14/Class/Struct.pm'
'Config.pm' => '/usr/lib/perl/5.14/Config.pm'
'Config_git.pl' => '/usr/lib/perl/5.14/Config_git.pl'
'Config_heavy.pl' => '/usr/lib/perl/5.14/Config_heavy.pl'
'Cwd.pm' => '3.36 from /usr/lib/perl/5.14/Cwd.pm'
'DynaLoader.pm' => '1.13 from /usr/lib/perl/5.14/DynaLoader.pm'
'Errno.pm' => '1.13 from /usr/lib/perl/5.14/Errno.pm'
'Exporter.pm' => '5.64_03 from /usr/share/perl/5.14/Exporter.pm'
'Exporter/Heavy.pm' => '5.64_03 from /usr/share/perl/5.14/Exporter/Heavy.pm'
'Fcntl.pm' => '1.11 from /usr/lib/perl/5.14/Fcntl.pm'
'File/Basename.pm' => '2.82 from /usr/share/perl/5.14/File/Basename.pm'
'File/Find.pm' => '1.19 from /usr/share/perl/5.14/File/Find.pm'
'File/Spec.pm' => '3.33 from /usr/lib/perl/5.14/File/Spec.pm'
'File/Spec/Unix.pm' => '3.33 from /usr/lib/perl/5.14/File/Spec/Unix.pm'
'File/stat.pm' => '1.05 from /usr/share/perl/5.14/File/stat.pm'
'FindBin.pm' => '1.50 from /usr/share/perl/5.14/FindBin.pm'
'Functions/Help.pm' => 'Functions/Help.pm'
'Functions/Launcher.pm' => 'Functions/Launcher.pm'
'Functions/ServerSocket.pm' => 'Functions/ServerSocket.pm'
'Functions/Setup.pm' => 'Functions/Setup.pm'
'Functions/Shell.pm' => 'Functions/Shell.pm'
'Functions/ShellSocket.pm' => 'Functions/ShellSocket.pm'
'Functions/Testd.pm' => 'Functions/Testd.pm'
'Getopt/Long.pm' => '2.38 from /usr/share/perl/5.14/Getopt/Long.pm'
'IO.pm' => '1.25_04 from /usr/lib/perl/5.14/IO.pm'
'IO/Dir.pm' => '1.08 from /usr/lib/perl/5.14/IO/Dir.pm'
'IO/File.pm' => '1.15 from /usr/lib/perl/5.14/IO/File.pm'
'IO/Handle.pm' => '1.31 from /usr/lib/perl/5.14/IO/Handle.pm'
'IO/Pipe.pm' => '1.14 from /usr/lib/perl/5.14/IO/Pipe.pm'
'IO/Seekable.pm' => '1.1 from /usr/lib/perl/5.14/IO/Seekable.pm'
'IO/Socket.pm' => '1.32 from /usr/lib/perl/5.14/IO/Socket.pm'
'IO/Socket/INET.pm' => '1.31 from /usr/lib/perl/5.14/IO/Socket/INET.pm'
'IO/Socket/UNIX.pm' => '1.23 from /usr/lib/perl/5.14/IO/Socket/UNIX.pm'
'JSON.pm' => '2.53 from JSON.pm'
'JSON/PP.pm' => '2.27200 from /usr/share/perl/5.14/JSON/PP.pm'
'JSON/backportPP.pm' => 'JSON/backportPP.pm'
'List/Util.pm' => '1.23 from /usr/lib/perl/5.14/List/Util.pm'
'POSIX.pm' => '1.24 from /usr/lib/perl/5.14/POSIX.pm'
'Proc/Daemon.pm' => '0.14 from Proc/Daemon.pm'
'Proc/Spawn.pm' => '1.03 from Proc/Spawn.pm'
'Scalar/Util.pm' => '1.23 from /usr/lib/perl/5.14/Scalar/Util.pm'
'SelectSaver.pm' => '1.02 from /usr/share/perl/5.14/SelectSaver.pm'
'Socket.pm' => '2.005 from /usr/local/lib/perl/5.14.2/Socket.pm'
'Symbol.pm' => '1.07 from /usr/share/perl/5.14/Symbol.pm'
'Term/ANSIColor.pm' => '3.00 from /usr/share/perl/5.14/Term/ANSIColor.pm'
'Term/Cap.pm' => '1.12 from /usr/share/perl/5.14/Term/Cap.pm'
'Term/ReadLine.pm' => '1.07 from /usr/share/perl/5.14/Term/ReadLine.pm'
'Tie/Hash.pm' => '1.04 from /usr/share/perl/5.14/Tie/Hash.pm'
'Time/HiRes.pm' => '1.972101 from /usr/lib/perl/5.14/Time/HiRes.pm'
'XSLoader.pm' => '0.13 from /usr/share/perl/5.14/XSLoader.pm'
'ZeroMQ.pm' => '0.21 from /usr/local/lib/perl/5.14.2/ZeroMQ.pm'
'ZeroMQ/Constants.pm' => '/usr/local/lib/perl/5.14.2/ZeroMQ/Constants.pm'
'ZeroMQ/Context.pm' => '/usr/local/lib/perl/5.14.2/ZeroMQ/Context.pm'
'ZeroMQ/Message.pm' => '/usr/local/lib/perl/5.14.2/ZeroMQ/Message.pm'
'ZeroMQ/Poller.pm' => '/usr/local/lib/perl/5.14.2/ZeroMQ/Poller.pm'
'ZeroMQ/Raw.pm' => '/usr/local/lib/perl/5.14.2/ZeroMQ/Raw.pm'
'ZeroMQ/Socket.pm' => '/usr/local/lib/perl/5.14.2/ZeroMQ/Socket.pm'
'_h2ph_pre.ph' => '/usr/lib/perl/5.14/_h2ph_pre.ph'
'asm-generic/ioctl.ph' => '/usr/lib/perl/5.14/asm-generic/ioctl.ph'
'asm-generic/ioctls.ph' => '/usr/lib/perl/5.14/asm-generic/ioctls.ph'
'asm/ioctl.ph' => '/usr/lib/perl/5.14/asm/ioctl.ph'
'asm/ioctls.ph' => '/usr/lib/perl/5.14/asm/ioctls.ph'
'base.pm' => '2.16 from /usr/share/perl/5.14/base.pm'
'bits/ioctl-types.ph' => '/usr/lib/perl/5.14/bits/ioctl-types.ph'
'bits/ioctls.ph' => '/usr/lib/perl/5.14/bits/ioctls.ph'
'bits/predefs.ph' => '/usr/lib/perl/5.14/bits/predefs.ph'
'bits/wordsize.ph' => '/usr/lib/perl/5.14/bits/wordsize.ph'
'bytes.pm' => '1.04 from /usr/share/perl/5.14/bytes.pm'
'constant.pm' => '1.21 from /usr/share/perl/5.14/constant.pm'
'features.ph' => '/usr/lib/perl/5.14/features.ph'
'gnu/stubs-64.ph' => '/usr/lib/perl/5.14/gnu/stubs-64.ph'
'gnu/stubs.ph' => '/usr/lib/perl/5.14/gnu/stubs.ph'
'linux/ioctl.ph' => '/usr/lib/perl/5.14/linux/ioctl.ph'
'overload.pm' => '1.13 from /usr/share/perl/5.14/overload.pm'
'perl5db.pl' => '1.33 from /usr/share/perl/5.14/perl5db.pl'
'strict.pm' => '1.04 from /usr/share/perl/5.14/strict.pm'
'sys/cdefs.ph' => '/usr/lib/perl/5.14/sys/cdefs.ph'
'sys/ioctl.ph' => '/usr/lib/perl/5.14/sys/ioctl.ph'
'sys/ttydefaults.ph' => '/usr/lib/perl/5.14/sys/ttydefaults.ph'
'threads.pm' => '1.83 from /usr/lib/perl/5.14/threads.pm'
'vars.pm' => '1.02 from /usr/share/perl/5.14/vars.pm'
'warnings.pm' => '1.12 from /usr/share/perl/5.14/warnings.pm'
'warnings/register.pm' => '1.02 from /usr/share/perl/5.14/warnings/register.pm'