# 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 object!" unless ref $IO; foreach my $method (@required_methods) { croak("The IO object passed to 'new ShoppingCart' does not implement the necessary methods!") unless $IO->can($method); } $self->{IO} = $IO; } ...