Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在Perl中使用接口模块_Perl_Interface_Perl Module_Cpan - Fatal编程技术网

无法在Perl中使用接口模块

无法在Perl中使用接口模块,perl,interface,perl-module,cpan,Perl,Interface,Perl Module,Cpan,我是Perl的初学者。我正在尝试使用,但无法使其工作。我已按照上的说明安装了模块。 我正在使用EPIC-Eclipse。我试图在同一个网站上实现给出的示例。示例如下: 这是一个可反弹的界面 package Bouncable; use Class::Interface; &interface; # this actually declares the interface sub bounce; sub getBounceBack; 1; packa

我是Perl的初学者。我正在尝试使用,但无法使其工作。我已按照上的说明安装了模块。 我正在使用EPIC-Eclipse。我试图在同一个网站上实现给出的示例。示例如下: 这是一个可反弹的界面

  package Bouncable;

  use Class::Interface;
  &interface;   # this actually declares the interface

  sub bounce;
  sub getBounceBack;

  1;
  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类,它实现了Bounchable接口

  package Bouncable;

  use Class::Interface;
  &interface;   # this actually declares the interface

  sub bounce;
  sub getBounceBack;

  1;
  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.

感谢您的帮助!谢谢

模块不喜欢在其行的前面留空白

可弹跳

use strict;
package Bouncable;

use Class::Interface;
interface;   # this actually declares the interface

sub bounce;
sub getBounceBack;

1;
下午四点

use strict;
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;

模块不喜欢在其行的前面有空格

可弹跳

use strict;
package Bouncable;

use Class::Interface;
interface;   # this actually declares the interface

sub bounce;
sub getBounceBack;

1;
下午四点

use strict;
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;

在我看来,这是一个复制粘贴或Windows换行问题。在接口模块第395行中,替换仅删除空格而不是空格。随后立即出现上述错误消息

$line =~ s/\ +$//;
应该由

$line =~ s/\s+$//;

这只是我最好的猜测,我无法在这里查看。如果这不起作用,请联系此模块的维护人员

在我看来,这是一个复制粘贴或Windows换行问题。在接口模块第395行中,替换仅删除空格而不是空格。随后立即出现上述错误消息

$line =~ s/\ +$//;
应该由

$line =~ s/\s+$//;

这只是我最好的猜测,我无法在这里查看。如果这不起作用,请联系此模块的维护人员

你能在eclipse之外运行它吗?另外,在命令提示下,如果键入
perldoc Class::Interface
,会发生什么?哦,别忘了
使用strict;使用警告示例将其禁用,但您应该始终使用它,并且不能在命令提示符下运行它。我也犯了同样的错误。当我键入perldoc Class::Interface时,我得到了上面问题中提到的doc页面,我已经查看了模块代码,您需要删除
use Class::
Interface
行前面的空白,我可能建议您使用更现代的模块,比如Moosecan,您可以在eclipse之外运行它吗?另外,在命令提示下,如果键入
perldoc Class::Interface
,会发生什么?哦,别忘了
使用strict;使用警告示例将其禁用,但您应该始终使用它,并且不能在命令提示符下运行它。我也犯了同样的错误。当我输入perldoc Class::Interface时,我得到了上面问题中提到的doc页面,我已经查看了模块代码,您需要删除
use Class::
Interface
行前面的空白,我可能建议您根据模块代码使用更现代的模块,如MooseAs,在上述两个模块中,我们不需要在接口和实现之前加一个“&”吗?根据模块代码,我们不需要在接口和实现之前加一个“&”吗?