in reply to Can caller() or the call stack be tricked?

As noted above a goto allows you to omit your sub from the call stack. There's a price to pay though; control flow never returns to your sub.

use Carp qw(cluck); sub foo { cluck(1) }; sub bar { goto \&foo; carp "here" }; sub baz { bar() }; baz(); # bar() is not shown in the stack trace, # but "here" never gets carped!

For more powerful call stack trickery there's Sub::Uplevel (pure Perl, but slows down all uses of caller in your application) and Scope::Upper (even more powerful).

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Replies are listed 'Best First'.
Re^2: Can caller() or the call stack be tricked?
by Ralesk (Pilgrim) on Jul 08, 2013 at 21:56 UTC

    As long as things after the bar(); call inside sub baz still get to run, I don’t mind. bar — in our case package OOModule; sub debug { ...; } — really only needs to invoke main::debug with a string somehow and doesn’t need to manipulate things afterwards. It seems that goto &{quack} is just about right for this.