
Devel::STDERR::Indent - Indents STDERR to aid in print-debugging recursive algorithms.

use Devel::STDERR::Indent qw/indent/;
sub factorial {
my $h = indent; # causes indentation
my $n = shift;
warn "computing factorial $n"; # indented based on call depth
if ($n == 0) {
return 1
} else {
my $got = factorial($n - 1);
warn "got back $got, multiplying by $n";
return $n * $got;
}
}

When debugging recursive code it's useful, but often too much trouble to have your traces indented.
This module makes it easy - call the indent function, and keep the thing you got back around until the sub exits.
This will wrap $SIG{__WARN__} with something that adds as many repetitions of $Devel::STDERR::Indent::STRING as there are live instances of the class (minus one):
s/^/$STRING x ($count - 1)/ge
When the handle is destroyed (due to garbage collection), $count is decremented.

All exports are optional, and may be accessed fully qualified instead.

Returns an object which you keep around for as long as you want another indent level:
my $h = $indent;
# ... all warnings are indented by one additional level
$h = undef; # one indentation level removed

The string to repeat (defaults to "\t").

This module is maintained using Darcs. You can get the latest version from http://nothingmuch.woobling.org/Devel-STDERR-Indent/, and use darcs send to commit changes.