I'm not 100% it IS what is he doing. It doesn't hurt to explain it in more detail for others even if he does.
Anyway here's some code that implements the method checking:
# in package ShoppingCart
@required_methods = qw(GetNext GetFirst Reset ...);
sub initialize {
my $self = shift;
my $IO = shift;
croak "The first parameter to 'new ShoppingCart' must be an IO objec
+t!"
unless ref $IO;
foreach my $method (@required_methods) {
croak("The IO object passed to 'new ShoppingCart' does not impleme
+nt the necessary methods!")
unless $IO->can($method);
}
$self->{IO} = $IO;
}
...
The test is not compile time, but currently it's the best you can get. AFAIK of course.
Jenda |