【发布时间】:2013-10-23 17:20:33
【问题描述】:
我是 Perl 的新手,并且已将 Moose 作为 Perl OO 的源代码,但我在使其工作时遇到了一些问题。具体来说,超类的方法似乎没有被继承。 为了测试这一点,我创建了三个文件,其中包含以下内容:
thingtest.pl
use strict;
use warnings;
require "thing_inherited.pm";
thing_inherited->hello();
东西.pm
package thing;
use strict;
use warnings;
use Moose;
sub hello
{
print "poo";
}
sub bye
{
print "naaaa";
}
1;
最后,thing_inherited.pm
package thing_inherited;
use strict;
use warnings;
use Moose;
extends "thing";
sub hello
{
bye();
}
1;
所以人们通常期望方法 bye 作为子类的一部分被继承,但我却得到了这个错误......
Undefined subroutine &thing_inherited::bye called at thing_inherited.pm line 11.
如果我在这里做错了什么,谁能解释一下?谢谢!
edit:在这样做时,我遇到了另一个难题:从我的超类调用我的基类中应该被超类覆盖的方法没有被覆盖。 说我有
sub whatever
{
print "ignored";
}
在我的基类中并添加了
whatever();
在我的 bye 方法中,调用 bye 不会产生被覆盖的结果,只会打印“ignored”。
【问题讨论】:
标签: perl oop inheritance moose