This Perl extension assists in removing global variables, allowing for better code organization and maintenance.
Globals introduce complexity as they increase the number of things that one needs to keep in their head at a given time, causing confusion such as "What the heck is $FROBOZZ supposed to be again?" If one piece of code accidentally uses $THNEE = 34 instead of $THNEE == 34, then another piece of code miles distant could break, and one would have to hunt through the entire program for the bug, which can be time-consuming.
The standard remedy for rampant global variables is to write subroutines that return the information that the global is supposed to contain. Devel::WarnGlobal provides a more efficient way to manage these variables. Once the 'get' function is written, one can tie that variable to the function, and the variable will always return the value of the function. This feature can be useful while testing, as it serves to verify that the new 'get' function is correctly written.
Devel::WarnGlobal can provide warnings whenever the global is accessed, assisting in tracing down uses of the given global. These warnings are on by default, and one can turn them on and off with the warn() method on the tied object, ensuring that access controls can be put into set_clown() to make sure that get_clown() will always return a valid clown. If 'die_on_write' is set, Devel::WarnGlobal will die if an attempt is made to write to a value with no 'set' method defined.
As a convenience, Devel::WarnGlobal allows for the tying of variables in the 'use' line via Devel::WarnGlobal::Scalar. This extension provides an easy, efficient, and effective way to eliminate globals, making it a highly recommended tool to simplify the management of global variables.
Version 0.05: N/A