in reply to Can you override lexically scoped variables when sub-classing a module.

Why are you opposed to changing the original code? Is this a third party provided file so that your changes will be wiped out by the latest update? If so, that might be a good reason - PROVIDED that you document a hack using PadWalker very carefully with lots of asterisks and capital letters or other PAY ATTENTION TO ME signs in the code that uses. Anything private to a third party module is likely to get renamed, reengineered, restructured, or otherwise disappeared. Despite your goal of not touching third party code, your hack may still break with the next release of the third party code.

If this is internal company code, then you really are better off getting permission to change "my" to "our", even though it is major hassle. The problem with hacks like using PadWalker is that they are virtually impossible for the next programmer to discover who has your job after you. Anyone reading the source code of the file with the "my" variable will reasonably expect that variable not to be vulnerable to being messed with by outside modules. They will be going nuts trying to figure out what in the original module is making it change (nothing of course) they will NEVER think to look elsewhere outside of the file in the many company scripts to find your module playing hack with PadWalker. "my" is like a contract with future maintainers that outsiders won't muck with this.

Of course if the pesky module with "my" is yours and yours alone, then again why NOT change it to "our"?

  • Comment on Re: Can you override lexically scoped variables when sub-classing a module.

Replies are listed 'Best First'.
Re^2: Can you override lexically scoped variables when sub-classing a module.
by learnedbyerror (Monk) on Oct 11, 2012 at 22:01 UTC

    I'm not opposed to changing the original code. It is a 3rd party and I have a request out. Eventually, it will get done, just not as fast as I would like. I have been looking at Padwalker and considering it. However, my gut is telling me that this isn't a "good" path for all of the reasons that you pointed out.

    Given your feedback and the feedback from the other monks, I think I am going to create a patched local copy and then sub-class it. This will minimize the impact on the maintenance to reverse out when changed.

    Thanks! lbe