in reply to Ironclad protection of instance data

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
  • Comment on Re: Ironclad protection of instance data

Replies are listed 'Best First'.
Re^2: Ironclad protection of instance data
by skyknight (Hermit) on Jul 04, 2004 at 04:20 UTC
    This sounds like a Murphy's Law variant: If there is more than one day to do it, and one of those ways is wrong, then Perl will make it possible.

      Kind of puts me in mind of an situation back in the '80s when Volvo decided to make the sidelights on their cars be on whenever the ignition was on.

      They did this as a consequence of a law change in Sweden that required all vehicles to switch their sidelights on when moving. That law came about as a consequence of the fact that in a large part of Sweden has 3 months or so of 24 hour twilight/darkness each year, which meant that laws written in terms of "Vehicles shall switch their lights on 'at night' or 'after dark'" etc. were always open to legal (mis)interpretation.

      Later, when drivers in other countries drove their Volvo's around during the daytime, (besides getting perpetually flashed "Your lights are on idiot!", by other road users taking the p***:), they found themselves in court if a sidelight bulb blew--EVEN IF IT WAS BRIGHT SUNLIGHT.

      Laws, like rules, are written to achieve a particular end. In this case, the lights are there to ensure the vehicle can be seen in low-light visibility.

      The law is an ass because often as not, there is no room allowed for interpretation. To be seen at night, the vehicle must have lights. To do any good, the lights must work. If they don't work, an offense has been commited.

      If the working light would not have affected the visibility of the vehicle, should the errent owner be prosecuted?


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
      "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon