Friday, May 22, 2009


The next module in the modules I haven't talked about series is Devel::STDERR::Indent. This is a simple utility module for indenting tracing output.

If you're doing high level tracing with warn then every call to warn invokes $SIG{__WARN__}. Devel::STDERR::Indent wraps this hook and indents the output according to its current level of nesting. This is especially handy for recursive code, where the same trace message is emitted for different parts of the flow.

To raise the indentation level you create a guard:

use Devel::STDERR::Indent qw(indent);

sub foo {
    my $h = indent();
    warn "in foo";

For as long as $h is in scope, the indentation level will be one level deeper.

No comments: