Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How would I determine a callers object ref ?

Reply
Thread Tools

How would I determine a callers object ref ?

 
 
MadDan
Guest
Posts: n/a
 
      11-24-2005
>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,

 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      11-24-2005
MadDan <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> >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.


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
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      11-24-2005

MadDan wrote:
> >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.


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

 
Reply With Quote
 
MadDan
Guest
Posts: n/a
 
      11-25-2005
Hi Anno,

Anno Siegel wrote:
<snip>
> 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>

 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      11-25-2005
MadDan <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> Hi Anno,
>
> Anno Siegel wrote:
> <snip>
> > 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.


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
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
 
Reply With Quote
 
Bo Lindbergh
Guest
Posts: n/a
 
      11-26-2005
In article <(E-Mail Removed) .com>,
"MadDan" <(E-Mail Removed)> wrote:

> >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.


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


/Bo Lindbergh
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
passing ref to ptr again as ref to ptr.... osama178@gmail.com C++ 22 04-30-2008 10:42 AM
passing ref to ptr again as ref to ptr.... osama178@gmail.com C++ 6 04-29-2008 08:09 AM
passing ref to ptr again as ref to ptr.... osama178@gmail.com C++ 0 04-24-2008 08:23 PM
strong ref from weak ref? Navindra Umanee Ruby 2 02-12-2005 05:06 PM



Advertisments