sub foo { my $self = shift; unless (ref $self) { # Complain return undef } # Do stuff return $some_useful_value }