How would I determine a callers object ref ?

M

MadDan

From within any sub, I can easily determine the call stack - with,
AFAICT, one proviso: when called by an method, I don't seem to be able
to determine the object ref. for the caller.

Any ideas/help greatly appreciated.

TIA,
 
A

Anno Siegel

MadDan said:
AFAICT, one proviso: when called by an method, I don't seem to be able
to determine the object ref. for the caller.

Please define what you mean by "object ref. for the caller".

The object (or class) a method was called through is in its first
parameter, you don't need caller() to access that. The ref() function
gives you the class an object was blessed into.

Anno
 
B

Brian McCauley

MadDan said:
AFAICT, one proviso: when called by an method, I don't seem to be able
to determine the object ref. for the caller.

Any ideas/help greatly appreciated.

Because of the way OO is implemented in Perl the concept simply does
not apply.
 
M

MadDan

Hi Anno,

Anno Siegel wrote:
Please define what you mean by "object ref. for the caller".

The object (or class) a method was called through is in its first
parameter, you don't need caller() to access that. The ref() function
gives you the class an object was blessed into.

.... and caller() returns the class to which the calling method belongs.
I was wondering whether there is any means of determing the instance,
c/w class, of the calling method - short of extending the interface and
have the caller provide its own ref as an argument to the called
method.

<snip>
 
A

Anno Siegel

MadDan said:
Hi Anno,

Anno Siegel wrote:


... and caller() returns the class to which the calling method belongs.

Not really. caller() returns the package that was in effect when the
calling code was compiled. For a method invoking another method this is
usually the class the calling method belongs to, but it doesn't have to
be so. In any case, what caller() reports is determined at compile-time,
it doesn't matter how the code is reached at run time.
I was wondering whether there is any means of determing the instance,
c/w class, of the calling method - short of extending the interface and
have the caller provide its own ref as an argument to the called
method.

With "instance of the calling method", I suppose you mean the object
through which the calling method was activated. caller() knows nothing
about that, even if it *seems* to know its class.

Anno
 
B

Bo Lindbergh

From within any sub, I can easily determine the call stack - with,
AFAICT, one proviso: when called by an method, I don't seem to be able
to determine the object ref. for the caller.[/QUOTE]

perldoc -f caller
.... and search for "from within the DB package".


/Bo Lindbergh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top