Question

I'm a beginner in Perl. I am trying to use CPAN Interface module, but I'm not able to make it work. I have installed the module as per instructions on this page. I'm using EPIC- Eclipse. I'm trying to implement the example given on the same website. The example is as follows: This is Bouncable interface.

  package Bouncable;

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

  sub bounce;
  sub getBounceBack;

  1;

and this is the Ball class which implements the Bouncable interface.

  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;

The code is pretty much straight-forward and simple. But im stuck with the following error, and I can't get rid of it.

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.

Any help is appreciated! Thanks

Was it helpful?

Solution

The module doesn't like white space at the front of its lines

Bouncable.pm

use strict;
package Bouncable;

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

sub bounce;
sub getBounceBack;

1;

Ball.pm

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;

OTHER TIPS

From my point of view its a copy&paste or Windows linebreak problem. In the interface module line 395 the substitution remove only spaces not whitespaces. The mentioned error message follows immediatly.

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

should be replaced by

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

It's only my best guess, can't check it out here. If this doen't work contact the maintainer of this module.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top