[Israel.pm] How can I know if my function is called in a script orfrom embedding Perl in C ?

Gaal Yahas gaal at forum2.org
Mon Apr 16 04:47:21 PDT 2007


On Mon, Apr 16, 2007 at 01:56:22PM +0300, Levenglick Dov-RM07994 wrote:
> > I have a module/function that is intended to be embeded in C. When
> > testing it from scripts I want it to print debug information.
> > Is there a simple way to know how my code is being executed ?
> >  I know I cna set a flag (environment or inside Perl), but I am looking
> > for a "cleaner" way.
>  
> You can try caller()  or any of the libraries associated with it:
> Devel::DumpStack
> Devel::StackTrace 
> However, Devel::CallerItem  seems most promising

I wouldn't use Devel::CallerItem; it's from 1995 and doesn't seem to
offer something the OP needs that can't be obtained by caller.

But really, I'm not sure looking at the callstack is the best approach
here. The OP wanted elegance, but this isn't it. Especially if the call
stack is examined every function entry!

Perhaps the module can ask for an init function to be called. This can set
a global flag inside the module. Sure, the init sub (invoked once) can use
callstack inspection to avoid asking its caller to pass an explicit value.

-- 
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/



More information about the Perl mailing list