http://www.perlmonks.org?node_id=477121

I shot myself in the foot (but only slightly) the other day and thought I'd share with you all.

I was testing a piece of code something like:

my $foo = $obj->foo() or die; my $bar = $foo->bar() or die; ... baz() or die; my @quux = $bar->quux(); for my $quux (@quux) { ... }
but many of the classes and subs called were not available. So I thought: no problem, I'll wrap a test framework around the code that provides a sub quux to return sample data and a sub AUTOLOAD to make sure things that need to return true. Since some of the things that need to return true are constructors, I'll make it sub AUTOLOAD { bless {} }.

And I got it running; the real subs that existed got called; the sub quux that provided fake data got called; everything else was effectively a noop. But there was a problem with the output, and I needed to run it in the debugger, and ran into a mystery that stumped me for a little while. You can try it yourself; run perl -d -we'sub AUTOLOAD { bless {} } foo()' and note that "s" stepping into foo seems ineffective; you can do it over and over again without terminating. And using "n" gets you a "100 levels deep in subroutine calls!" warning.

In retrospect, the problem was simply solved by an additional sub declaration: