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 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.
indent
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
Instantiates a new indentation guard and calls enter on it before returning it.
enter
Parameters are passed to new:
new
indent "foo"; # will print enter/leave messages too
Creates the indentation helper, but does not install it yet.
If given a single argument it is assumed to be for the message attribute.
message
Output a warning with the previous installed hook.
Indent a message.
Calls format and then emit.
format
emit
Calls install the hook and outputs the optional message.
install
Calls uninstall the hook and outputs the optional message.
uninstall
Installs the hook in $SIG{__WARN__}.
$SIG{__WARN__}
Uninstalls the hook restoring the previous value.
If supplied will be printed in enter prefixed by enter_string and in leave prefixed by leave_string.
enter_string
leave
leave_string
Defaults to ' ' (four spaces).
' '
Defaults to ' -> '.
' -> '
Defaults to ' <- '.
' <- '
http://nothingmuch.woobling.org/code
4 POD Errors
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
=back without =over
Unknown directive: =over1
'=item' outside of any '=over'
To install Devel::STDERR::Indent, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Devel::STDERR::Indent
CPAN shell
perl -MCPAN -e shell install Devel::STDERR::Indent
For more information on module installation, please visit the detailed CPAN module installation guide.