perl - How can I get the calling method which inherit from other package -


i want calling method's name. try caller, works fine in cases. result not expected when method inherit parent package. following example:

package caller; sub output_caller { #output calling method's name     @stacks = caller(1);     print $stacks[3]; }  package foo; sub foo {     caller::output_caller(); }  package bar; use base 'foo';  bar->foo(); 

the output

foo::foo  

which expected

bar::foo 

is possible bar::foo?

use carp qw(confess) gets close. return

at c:\src_test\perl\testmost\callertest.pl line 11.     foo::foo('bar') called @ c:\src_test\perl\testmost\callertest.pl line 18 foo::foo 

from modified script

package caller; sub output_caller { #output calling method's name     @stacks = caller(1);     print $stacks[3]; }  package foo; use carp qw(cluck); sub foo {     cluck();     caller::output_caller(); }  package bar; use base 'foo';  bar->foo(); 

Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -