【发布时间】:2013-04-11 07:11:08
【问题描述】:
我不知道为什么我无法访问子包:
mbzdb:
#!/usr/bin/perl -w
use lib "./lib";
use MbzDb::Instance;
my $instance = new MbzDb::Instance();
$instance->startFromCommandLine();
lib/MbzDb/Instance.pm:
#!/usr/bin/perl -w
package MbzDb::Instance;
use strict;
use warnings;
use Getopt::Long;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(new startFromCommandLine);
sub new {
my $class = shift;
return bless {}, $class;
}
sub startFromCommandLine {
my $self = shift;
}
如果我在lib/MbzDb.pm 中使用相同的代码,则导出工作正常。我做错了什么?
给出的错误是:
无法在 ./mbzdb 第 6 行通过包“MbzDb::Instance”找到对象方法“new”(也许您忘记加载“MbzDb::Instance”?)。
【问题讨论】:
-
如果注释掉 use lib,同样的代码在 lib/Mbzdb.pm 中是否有效?
-
如果我删除
use lib "./lib";则无法找到该模块。如果我删除它并将.pms 移动到另一个位置,我会得到同样的错误。 -
嗯,MbzDb下没有其他lib目录(即lib/Mbzdb/lib?
-
不,没有其他目录。
-
以防万一..
return 1模块末尾有return 1吗?另一个注意事项:导出new会导致大错误,我认为您不需要导出它
标签: perl perl-module