Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How to identify calling class whilst in inherited method

by Marcello (Hermit)
on Dec 19, 2003 at 12:46 UTC ( #315784=note: print w/replies, xml ) Need Help??


in reply to How to identify calling class whilst in inherited method

More interestingly,

I have a similar problem, but I want to know which class AND which method called the method in a baseclass. Does anybody know how to use caller() to get this data? I remember running into problems when using an eval() in the calling method.

Thanks.

Marcel

Update: Think I've found it:
sub GetCaller { my $self = shift; my $i = 0; my $result; while (1) { my ($package, $filename, $line, $subroutine) = caller($i++); if (defined($package) && ($package ne "main")) { $result = $subroutine; } else { last; } }; return $result; }
I ignore "main" because this is always a startup script.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://315784]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2020-05-29 07:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (167 votes). Check out past polls.

    Notices?