Nothing can be truely ironclad since you are using perl and no matter what you do, someone could probably get around it (although some solutions require walking the op-tree which is just silly).

But seriously, I would have to agree with dws in that you may be restricting yourself too much. I have dealt with this issue myself in the past, and have created a module (Devel::StrictObjectHash) to solve it. I took a slightly different approach than you are suggestion, which is not to restrict access to instance data, but instead to verify that it is not accessed incorrectly.

Devel::StrictObjectHash allows you to use hash-ref based Perl OO and with a few lines of up-front configuration (and no extra code in your classes) check that your instance data is protected from misuse during development and testing. Once you are satisfied, you can remove the configuration and allow your code to run unhindered. It allows the 3 common styles of access (public, protected and private) and is flexible with hash-key naming conventions as well. If you are interested and/or have any questions let me know and I will be happy to help.

-stvn

In reply to Re: Ironclad protection of instance data by stvn
in thread Ironclad protection of instance data by friedo

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.