My idea is it that it is a "bad thing" to code into the name of the subroutine the fact whether or not the subroutine should be externally "advertised".

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


In reply to Re: Getting name of sub from a hash-based dispatch table? by CountZero
in thread Getting name of sub from a hash-based dispatch table? by theguvnor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.