NAME

Tie::WarnGlobal::Scalar - Perl extension aiding elimination of globals

SYNOPSIS

use Tie::WarnGlobal::Scalar;

tie $MY_READONLY, 'Tie::WarnGlobal::Scalar', { name => '$MY_READONLY', get => \&get_function, die_on_write => 1 };
tie $MY_GLOBAL, 'Tie::WarnGlobal::Scalar', { get => \&get_function, set => \&set_function, warn => 0 };

my $tied = tied $MY_GLOBAL;
$tied->warn(1);
## ...
$tied->warn(0);

$tied->die_on_write(1);
## ...
$tied->die_on_write(0);

DESCRIPTION

Globals are elusive things. If you inherit (or write) a program with all kinds of global package variables, it can be hard to find them, and time-consuming to replace them all at once.

Tie::WarnGlobal::Scalar is a partial answer. Once you've written a routine that returns the value that was originally in your global variable, you can tie that variable to the function, and the variable will always return the value of the function. This can be valuable while testing, since it serves to verify that you've written your new 'get'-function correctly.

In order to trace down uses of the given global, Tie::WarnGlobal::Scalar can provide warnings whenever the global is accessed. These warnings are on by default; they are controlled by the 'warn' parameter. Also, one can turn warnings on and off with the warn() method on the tied object. If 'die_on_write' is set, Tie::WarnGlobal::Scalar will die if an attempt is made to write to a value with no 'set' method defined. (Otherwise, the 'set' method will produce a warning, but will have no effect on the value.)

AUTHOR

Stephen Nelson, steven@jubal.com

SEE ALSO

perl(1), perltie(1), Tie::Watch(3), Tie::WarnGlobal(3).