|Do you know where your variables are?|
Automatic stack traces for warns and diesby fergal (Chaplain)
|on Jul 30, 2004 at 23:16 UTC||Need Help??|
fergal has asked for the wisdom of the Perl Monks concerning the following question:
Update 2:The latest bleaperl has a patch that allows
-w adds stack traces to warnigns and -t turns off the explanations. No need for a new module.
Update:I should have been more clear in my question, I'm not asking "how do I do this?", I already know how to do it. I'm asking "is this readily available already?" because it's pretty amazing that after all these years, there is no standard, easy way to force Perl to give a stacktrace when it dies.
In particular I want to be able to say to someone who's using my code and having problems, "run it again with perl -MDevel::Verbose and send me the output" and they'll be able to get it from CPAN and the code should work just as before, except with much more info when it dies.
Most languages will give you a stack trace when they die or at least you can set a flag so that this happens, Perl lacks this feature and I couldn't find a module that provides it. So for quite a while now I have been using my own module that works like this
this will give output something like
Trace begun at t.pl line 11 main::will_warn at t.pl line 5 main::a_sub at t.pl line 3 something funny at t.pl line 11. ------------- Trace begun at t.pl line 14 main::will_die at t.pl line 7 main::a_sub at t.pl line 3 something awful at t.pl line 14.It's very careful not to interefere with the original dieing and warning behaviour (it's not perfect in this respect but it's close).
Carp does something similar but you have to explicitly use it in your code, whereas I can do perl -MDevel::Verbose some_script.pl and I will get full stack traces from all warn()s and die()s, without changing a line of code in some_script.pl.