in reply to Automating dispatch tables
Actually Chip recently pointed out on p5p that the second one is not the right way to handle this. In reality you are much better off avoiding can() and doing:
eval { $ref->$method() }; # updated: forgot the $method :-( die $@ if $@ and $@!~/^Undefined subroutine/;
This is because for all kinds of reasons can() is not 100% safe. For instance if the method needs to be autoloaded can() will return false, but calling the sub wont.
IMO the first one is also not the greatest way to write that.
$dispatch{$method}->() if $dispatch{$method};
First they ignore you, then they laugh at you, then they fight you, then you win.
-- Gandhi
|
|---|