in reply to Getting name of sub from a hash-based dispatch table?
Far better, IMHO, would it be to put this attribute into the dispatch-table like so:
%query=('action1'=>[\&handler1,'public'], 'action2'=>[\&handler2, 'public'], 'action3'=>[\&_do_not_advertise_this_function_externally,'priva +te'], # and so on );
Now you will have to dereference one level deeper to get the sub-reference and the attribute, but that seems a small loss given that you now have the attribute handy in the dispatch-table.
If ever you want to change the public/private atribute, all you have to do is change this atribute in the dispatch-table. In your system, you would have to change the dispatch table and the actual subroutine name itself (and if you ever call such a subroutine directly from somewhere else in your code, you will have broken your program, unless you change the subroutine-call as well -- messy, messy).
With the "attribute" solution you can even change the public/private programatically if necessary. [Whole new vistas of enormous possibilities unfold before your inner eye]
CountZero
"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
|
|---|