【发布时间】:2013-10-08 12:20:44
【问题描述】:
我是 Perl 的初学者。我正在尝试使用CPAN Interface module,但我无法使其工作。我已经按照this page 上的说明安装了模块。 我正在使用 EPIC-Eclipse。我正在尝试实现在同一网站上给出的示例。示例如下: 这是 Bouncable 界面。
package Bouncable;
use Class::Interface;
&interface; # this actually declares the interface
sub bounce;
sub getBounceBack;
1;
这是实现 Bouncable 接口的 Ball 类。
package Ball;
use Class::Interface;
&implements( 'Bouncable' );
sub bounce {
my $self = shift;
print "The ball is bouncing @ ".$self->getBounceBack." strength"
}
sub getBounceBack {
return 10;
}
1;
代码非常简单明了。但是我遇到了以下错误,我无法摆脱它。
Ball tries to implement non existing interface Bouncable -- Interface Bouncable does not use the interface module. at D:/Eclipse projects/PerlTrial/Bouncable.pm line 4.
Compilation failed in require at (eval 3) line 1.
BEGIN failed--compilation aborted at (eval 3) line 1.
at D:/Eclipse projects/PerlTrial/Ball.pm line 4.
任何帮助表示赞赏!谢谢
【问题讨论】:
-
你能在 Eclipse 之外运行它吗?同样在命令提示符下,如果您键入
perldoc Class::Interface会发生什么? -
哦,别忘了
use strict; use warnings;示例将其关闭,但您应该始终使用它 -
也无法从命令提示符运行它。我犯了同样的错误。当我输入 perldoc Class::Interface 时,我得到了我在上面的问题中提到的文档页面
-
我查看了模块代码,您需要删除
use Class::和interface行前的空格我可能建议您使用更现代的模块,例如 Moose
标签: perl interface perl-module cpan