יובל קוג'מן (Yuval Kogman) > Devel-STDERR-Indent-0.04 > Devel::STDERR::Indent

Download:
Devel-STDERR-Indent-0.04.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
Report a bug
Module Version: 0.04   Source   Latest Release: Devel-STDERR-Indent-0.06

NAME ^

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

SYNOPSIS ^

        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;
                }
        }

DESCRIPTION ^

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.

EXPORTS ^

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

indent ^

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

$STRING ^

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

VERSION CONTROL ^

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.