Is it proper to get and especially set Perl module's global variables directly?

Posted by DVK on Stack Overflow See other posts from Stack Overflow or by DVK
Published on 2010-05-27T16:24:09Z Indexed on 2010/05/27 16:31 UTC
Read the original article Hit count: 480

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.

© Stack Overflow or respective owner

Related posts about best-practices

Related posts about perl