Like others in this thread I'm pretty firmly in the camp of "let the user do what they want, even if they want to do something dumb". I dont see a lot of point in enforcing privacy rules in a perl object structure. In fact, i dont see a lot of point in subroutines doing "check if I'm being used correctly" logic. And for more than one reason:

First is that such checks involve a fairly expensive overhead, second is that such checks usually just mean that instead of getting a run-time error from perl when i actually have done something wrong I get a run time error from the checker code telling me I might have done something wrong, but often with less information about what it is and why it was wrong. Lastly I find often that such checks are overly restrictive based on misunderstandings of how perl works. (The classic example is using ref to check type.)

For instance your logic for protected methods assumes that there will never need to be an interface compatible object that needs to be written that can't inherit from your base class but must work as though it does. I can work around your defense with some craftyness, but that craftyness is unnecessary if you leave off with the run-time protections and let me make my own decisions about how I use your code.

About the only time I think such logic is called for is when the action of the sub/object is "dangerous" in some way and must be used in a guarded fashion.

---
$world=~s/war/peace/g


In reply to Re: Closure objects with public, private, and protected fields by demerphq
in thread Closure objects with public, private, and protected fields by gargle

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.