Steffen Müller > Devel-TrackSIG > Devel::TrackGlobalScalar

Download:
Devel-TrackSIG-0.03.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.03   Source  

NAME ^

Devel::TrackGlobalScalar - Track those pesky global variables

SYNOPSIS ^

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:

  Devel::TrackGlobalScalar->dump_all_sources;

DESCRIPTION ^

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!

Import Options

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.

get_source

Given the name of the signal handler you care about, returns the backtrace from its origin.

dump_all_sources

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.)

AUTHOR ^

Steffen Mueller, smueller@cpan.org

ACKNOWLEDGMENT ^

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.

COPYRIGHT AND LICENSE ^

 (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.
syntax highlighting: