NAME
Devel::WarnGlobal::Scalar - Track down and eliminate scalar globals
VERSION
version 0.09
SYNOPSIS
use Devel::WarnGlobal::Scalar;
tie $MY_READONLY, 'Devel::WarnGlobal::Scalar', { name => '$MY_READONLY', get => \&get_function, die_on_write => 1 };
tie $MY_GLOBAL, 'Devel::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.
Devel::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, Devel::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, Devel::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.)
NAME
Devel::WarnGlobal::Scalar - Track down and eliminate scalar globals
AUTHOR
Stephen Nelson, stephenenelson@mac.com
SEE ALSO
perl(1), perltie(1), Tie::Watch(3), Devel::WarnGlobal(3).
AUTHOR
Stephen Nelson <stephenenelson@mac.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Stephen Nelson.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.