sub onlyAcceptFooObjects { my ($foo) = @_; (defined($foo) && ref($foo) && $foo->isa("Foo")) || die "This method only accepts Foo objects"; # ... }