... ways to *ensure* (for my own benefit) that other classes don't use private methods of other classes

Do you mean that you want to ensure that your class (being a parent class) doesn't accidentally call a private method in a subclass? If you're talking about method calls that look like

$self->_private(@args)
then maybe I have something for you.

I don't ever call private methods using method lookup, since I know which package it will be in, namely the current package. I also name private methods with a leading underscore, and thus my code looks like this:

_private($self => @args)
This way, I don't ever have to be afraid to refactor a parent class and add a private method. If you use method lookup, you'll risk accidentally picking up a private method in the subclass, thus needlessly breaking distant code.

This is a paradigm that has worked well for me. It's simple, it doesn't require anything out of the ordinary, and works well enough (but YMMV).

If you talk about what Java calls protected methods (methods that are designed to be used by subclasses too, but no one else), then that's a whole different story.

lodin


In reply to Re: Howto keep private methods private? ('function' lookup) by lodin
in thread Howto keep private methods private? by perl-diddler

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.