I think I would put the dispatched functions in a separate namespace:
It's no longer necessary to munge the function names, and the functions are easily factored out to a separate module (which could, of course, also be done with the original approach).c:\@Work\Perl>perl -wMstrict -le "my @args = qw(hi there); ;; for my $do_this (qw(Title Description Object Fooble Properties)) { my $code = Dispatcher->can($do_this); ;; if (!$code) { print qq{Missing Handler for '$do_this'}; next; } ;; $code->(@args); } ;; { package Dispatcher; ;; sub Title { print qq{title handler: @_}; } sub Description { print qq{description handler: @_}; } sub Object { print qq{object handler: @_}; } sub Properties { print qq{properties handler: @_}; } } " title handler: hi there description handler: hi there object handler: hi there Missing Handler for 'Fooble' properties handler: hi there
Give a man a fish: <%-{-{-{-<
In reply to Re^2: '100 elsif's vs hash of coderef's
by AnomalousMonk
in thread '100 elsif's vs hash of coderef's
by Wiggins
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |