Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Is there an eligant way to make methods in perl really private?

You're got some good answers above. Here's a different approach.

You can get the delayed effect of private methods by adopting a simple convention: Start all private methods with an underscore, and teach people not to invoke these methods from outside of the class hierarchy1. To enforce this, it's a simple matter to spider your code base looking for references to private methods that are not preceded by "$self->".

Having a script that traverses the code base looking for certain patterns can be very useful. In team settings, I've set up scripts to look for special code patterns (e.g., "TBD" or "FIXME" comments, correct copyright strings, etc.) The scripts ran every night, and produced a report (an HTML page) that we would check every morning. It also gave us an easy way to chart our code growth over time.

The question you'll need to ask yourself is whether you can live with the delay. I've found that the convention was good enough.

1 Purists will note that this really enforced "protected" methods.

In reply to Re: REALLY Private Methods in perl: Is Perl Flexible enough to be made Inflexible? by dws
in thread REALLY Private Methods in perl: Is Perl Flexible enough to be made Inflexible? by penguin

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (7)
    As of 2020-04-03 21:08 GMT
    Find Nodes?
      Voting Booth?
      The most amusing oxymoron is:

      Results (32 votes). Check out past polls.