in reply to UNIVERSAL->cando , shortcut for testing and running methods?
No need to make up new operatorsadd a method to every single class when a sub will do just fine.
sub cando { my $o = shift; my $m = shift; return if !eval { $o->can($m) }; return $o->$m(@_); } my $home = cando($self, 'home') // cando($self, 'house', 1) // confess(q{Can't determine home});
Keep in mind neither your operatormethod nor this sub will work right if home returns undef.
|
|---|