- COPYRIGHT AND LICENSE
Devel::TrackGlobalScalar - Track those pesky global variables
At the VERY start of your script:
use Devel::TrackGlobalScalar [qw($/ $|)], track_source => 1;
Then, somewhen deep inside the codebase:
$/ = \32768;
and back in your code base, all readline()s suddenly read exactly 32768 bytes and you do not know where $/ was mucked with.
So to a place where you know the readline() call behaves different than expected, you add a debugging line like this:
print STDERR tied($/)->get_source();
Or more comprehensively like this:
Nobody likes global variables. They incur action at a distance. It can be horrible to find out where they were modified when all you have is the action. Particularly in the millions of lines of Perl we work with at booking.com.
This module tries to mitigate the problem by providing a mechanism to track all accesses to global scalars.
Doing this requires some ugly hacks, so don't leave this in production code!
When loading the module, the first parameter must be a string indicating the global you want to track or an array reference containing multiple such strings. Thereafter, you can pass any of two named options:
- track_source (default: 1)
When enabled, all writing accesses to the chosen globals are tracked for later reporting.
- report_write_access (default: 0)
Always shows a stack trace on writing access to the globals.
Given the name of the signal handler you care about, returns the backtrace from its origin.
Dumps all tracked globals' origin backtraces to STDERR. Includes those variables for which the last access was actually undef(). (Except for falling out of scope due to a
local. In this case, we revert to the previous backtrace.)
This module was originally developed for booking.com. With approval from booking.com, this module was generalized and put on CPAN, for which the author would like to express his gratitude.
(C) 2012 Steffen Mueller. All rights reserved. This code is available under the same license as Perl version 5.8.1 or higher. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.