in reply to Howto keep private methods private?
... 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
then maybe I have something for you.$self->_private(@args)
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:
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._private($self => @args)
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
|
|---|