Skip to content

Instantly share code, notes, and snippets.

@wki
Created March 17, 2010 06:12
Show Gist options
  • Save wki/334969 to your computer and use it in GitHub Desktop.
Save wki/334969 to your computer and use it in GitHub Desktop.
Just a simple Catalyst Debugger
# real location of this library:
# /some/perl-search/path/Devel/CatDebug.pm
#
# debug your application like this:
# $ PERL5LIB=./lib perl -d:CatDebug ./script/name_or_your_app_server.pl
#
package DB;
our $stack_depth = 0;
our $must_show = 0;
sub DB {
$must_show = 0 if ($must_show > $stack_depth);
return if (!$must_show);
($package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash)
= caller(1);
print STDERR "[$stack_depth] in $subroutine ($filename $line)\n"
if ($must_show);
}
sub sub {
if ($sub =~ m{\A Catalyst::Engine::HTTP::_handler}xms) {
$must_show = $stack_depth + 1;
}
if ($must_show) {
my $p = join(', ',
map {
if (tied($_)) {
'<tied: ' . ref(tied($_)) . '>'
} elsif (ref($_)) {
# we need something like this because
# stringification might cause endless loops...
'<' . ref($_) . '>'
} elsif (defined($_)) {
# this seems to have negative side effects:
#s{(.*)}{'$1'}xms
# if (!m{\A (?: -?[\d.]+ | \*[\w:]* ) \z}xms);
m{\A (?: -?[\d.]+ | \*[\w:]* ) \z}xms
? $_
: "'$_'";
} else {
'-undef-'
}
}
@_);
print STDERR "[$stack_depth] calling $sub($p)\n"
}
local $stack_depth = $stack_depth + 1;
# if we are interested in return values we might use:
#
# if (wantarray) {
# my @result = &$sub;
# return @result;
# } elsif (defined wantarray) {
# my $result = &$sub;
# return $result;
# } else {
# &$sub;
# return;
# }
&$sub;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment