Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to identify calling class whilst in inherited method

by Marcello (Hermit)
on Dec 19, 2003 at 12:46 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://315784]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-20 03:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found