I'm not sure if I'm just reiterating kennethk's solution in the language of lexicals-in-closures rather than globals, but couldn't you do something like:
package A; my $self; my $b = bless \do { my $o } => 'B'; sub foo { $self = shift; $b->bar; } sub caller { return $self; } package B; sub bar { print "Called by ", (caller)[0]->caller, "\n"; } package main; my $a = bless \do { my $o } => 'A'; print "About to call via $a\n"; $a->foo;

UPDATE: On further thought, you could even confine the messiness of those caller->caller semantics to one place by defining a function like

sub called_by { return ( caller 1 )[0]->caller; }


In reply to Re^3: A caller() by any other name by JadeNB
in thread A caller() by any other name by Bloodnok

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.