in reply to Re^2: A caller() by any other name
in thread A caller() by any other name
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; }
|
|---|