in reply to A function to check if subroutine exists?
sub UNIVERSAL::native_can { my ($obj,$meth) = @_; $obj = ref($obj) || $obj; local @{"${obj}::ISA"}; return $obj->can($meth); } my $obj = Class::Child->new; # Class::Child inherits 'foo' from Class::Parent print $obj->can('foo') ? 1 : 0; # 1 print $obj->native_can('foo') ? 1 : 0; # 0
|
|---|