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