A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Trace the execution of subroutines under mod_perl

1) First try one of these to trace every line (doesn't actually capture subroutine names):

Debug::TraceDebug::LTraceDevel::Trace, or others.

2) Then if you want to filter the list, try:

perl PERL5DB='sub DB::DB {my @c=caller;return if $c[1] =~ m|/opt/foo/bar| || $c[1] =~ m|/qux/| || $c[1] =~ m|Useless|; print STDERR qq|@c[1,2] ${"::_<$c[1]"}[$c[2]]|}' perl -d path/to/test/file.t

(thanks Brian)

3) Here's one I came up with using Moose:

use Moose;
use Scalar::Util;
use Data::Dumper;
for my $func qw(list all the subroutine names here) {
    around $func => sub {
        my $orig = shift;
        my $self = shift;
        warn "Running __PACKAGE__::${func} with:\n";
        my $i = 0;
        foreach my $param (@_) {
            $i++;
            # don't display class it$self
            next if blessed $param and $param->isa(__PACKAGE__);
            if (blessed $param) {
                # try not to dump out huge objects
                warn "\t$i = $param\n";
            } else {
                warn "\t$i = ".Dumper($param);
            }
        }
        # call the original sub
        $self->$orig(@_);
    }
}

4) Simple way to log all parameters:

my $r=\@_; $logger->debug('entering ', sub { $logger->dump(args => $r) });

5) Simple way to log method name only, without potentially verbose parameters:

$logger->info("entering ".( caller(0) )[3]);

6) Log4perl configuration

Use %M to log the method name, then just log anything, e.g. "entering".