|more useful options|
Using caller to determine the namespace of an anonymous subroutineby rrwo (Friar)
|on Feb 23, 2006 at 21:56 UTC||Need Help??|
rrwo has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to figure out how to determine the package that an anonymous subroutine belongs to by using the caller function.
The difficulty I'm having is that when classes use something like Class::Accessor to create accessors for classes, the namespace of the methods is Class::Accessor (or whatever class created them) rather than the actual class it belongs to.
I've not found any clear documentation on this. From a bit of netsurfing I saw an article refer to the package that caller returned being the package that the subroutine was compiled in. Which sounds like an accurate description of what this is.
So my question is: is there a way for Perl to determine the actual package that called a subroutine, rather than the package where the call to the subroutine was compiled?
Some cample code to illustrate my question is below. The code prints "Creator::__ANON__" as the namespace, rather than "TracedCreatee::foo".
The purpose of this question is for improving Class::Tie::InsideOut, which is a proof-of-concept package for using tied hashes to implement inside-out objects. A downside in that is one cannot use Class::Accessor to create methods.