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

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

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.06   Source  

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 very usefl to indent traces, but often too much trouble.

This module makes automates the indentation. When you call the indent function the indentation level is increased for as long as you keep the value you got back. Once that goes out of scope the indentation level is decreased again.

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

Instantiates a new indentation guard and calls enter on it before returning it.

Parameters are passed to new:

        indent "foo"; # will print enter/leave messages too

METHODS ^

new

Creates the indentation helper, but does not install it yet.

If given a single argument it is assumed to be for the message attribute.

emit

Output a warning with the previous installed hook.

format

Indent a message.

warn

Calls format and then emit.

enter

Calls install the hook and outputs the optional message.

leave

Calls uninstall the hook and outputs the optional message.

install

Installs the hook in $SIG{__WARN__}.

uninstall

Uninstalls the hook restoring the previous value.

ATTRIBUTES ^

message

If supplied will be printed in enter prefixed by enter_string and in leave prefixed by leave_string.

indent_string

Defaults to ' ' (four spaces).

enter_string

Defaults to ' -> '.

leave_string

Defaults to ' <- '.

VERSION CONTROL ^

http://nothingmuch.woobling.org/code

syntax highlighting: