Is it proper to get and especially set Perl module's global variables directly?
- by DVK
I was wondering what the best practice in Perl is regarding getting - or, more importantly, setting - a global variable of some module by directly accessing $Module::varName in case the module didn't provide getter/setter method for it.
The reason it smells bad to me is the fact that it sort of circumvents encapsulation. Just because I can do it in Perl, I'm not entirely certain I should (assuming there actually is an alternative such as adding a getter/setter to the module).
I'm asking this because I'm about to request an addition of a getter/setter for a global variable in one of the core Perl modules, and I would like to avoid it soundly and unanimously rejected on the grounds of "Why the heck do you need one when you can access the variable in the package directly?" - in case doing the latter is actually considered perfectly OK by the community.