waba has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks,
I'm doing perl OO for $work. Under normal circumstances I'd use a modern framework (Object::InsideOut, Moose, ...), but for various (politic) reasons this isn't possible here. So, I have to stick to whatever can be found in the perl 5.8.8 core modules and use classic blessed hashes for the implementation.
As my hierarchy of classes is expected to grow huge over the time, I'd like to protect their internals from each other. For example, my base class has a 'session' data member which is expected to be private as it is not part of the documented interface. This is all fine and nifty, but there is nothing guaranteeing against a sub-sub-sub-class trying to stuff its own 'session' in the same blessed hash and introducing a subtle bug - and a world of pain.
So far I've guarded against this using a __PACKAGE__ prefix, but I've recently stumbled upon what seems to be a hidden treasure: the fields pragma. It has the following features:
Of these, I'm primarily interested by 1, although 2 is pretty nice as well, and 3 is always a bonus. However, is there any known pitfalls with this pragma? I've found this resource about it only, and its main criticism was that fields are "bizarre". Anyone has got some real-world experience with it?
|
|---|