I used the recommended goto SUB way. Here’s what happens.

There are two programs, in both debug is a fancy little debug message printer. In one of them, _debug is an actual sub that does a little more than this, it also sends the debug message to a server for central logging. In the other app, _debug is just an alias, so any case of _debug will still work: *_debug = \&debug;

Now, in the app that has the actual sub _debug { ... } declared, Perl will tell me ‘Ambiguous use of &{_debug} resolved to &_debug’, for a line which contains the following: goto &{_debug};

What exactly might be so ambiguous about this?


Relevant code pieces for easier understanding:

package OO::SubModule; sub new { my ($class, $args) = @_; my $self = { ( defined $args ? %$args : () ) }; bless($self, $class); ## Some boilerplate debug callback that we can override during const +ruction $self->{debug_cb} //= sub { my $self = shift; carp("DEBUG ".join(", +", map { defined $_ ? $_ : "undef" } @_)); }; return $self; } sub _debug { my $self = $_[0]; goto &{$self->{debug_cb}}; } ## You can say $self->_debug("booya") to do $self->{debug_cb}->("booya +") without it ending up in the call stack
## both apps $oosub = OO::SubModule->new({ debug_cb => sub { my $self = shift; my ($str) = @_; goto &{_debug}; }, }); ## Any occurrence of $self->_debug("booya") within OO::SubModule reall +y does _debug("booya") of the main app, this way ## Without getting in the call stack, right?

In reply to Re: Can caller() or the call stack be tricked? by Ralesk
in thread Can caller() or the call stack be tricked? by Ralesk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.