[Pdx-pm] Poll: traits
Kris Bosland
krisb at ring.org
Sat Nov 19 14:07:55 PST 2005
On Sat, 19 Nov 2005, Ovid wrote:
> sub fuse {
> my ($self, $time) = @_;
> $self->set_igniter($time);
> $self->explode;
> }
>
> Where does the set_igniter() method come from? It might be provided in
> the TBomb trait, but if you want to have a variety of applicable
> igniters, you can add this:
>
> our @REQUIRES = qw(set_igniter);
>
> Now, TBomb does not have to provide its own implementation, but you
> can't use it unless *something* provides that. Again, it fails at
> compile time.
>
Hey, something I have been thinking of recently is to try to
figure out some way to create an interface test widget in between two
classes or libraries. Some kind of mirrored thing that:
1. Tests that the library you use acts like you expect
2. Provides a reciprocal dummy object that can test your library
independantly.
Something like:
package BombInterface;
use TestInterface;
interface("fuse","Boom!");
Then,
BombInterface->testInterface() does:
ok_defined(my $b = Bomb->new());
ok($b->fuse(),"Boom!");
and
my $b = BombInterface->stubInterface()
$b->fuse(); #"Boom!"
can be used in the tests of the class using Bomb.
-Kris
More information about the Pdx-pm-list
mailing list