fergal has asked for the wisdom of the Perl Monks concerning the following question:

Update 2:The latest bleaperl has a patch that allows
perl -Mdiagnostics=t-,-w badly_behaved_script
-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

use Devel::Verbose; a_sub(); sub a_sub { will_warn(); print STDERR "-------------\n"; will_die(); } sub will_warn { warn("something funny"); } sub will_die { die("something awful"); }
this will give output something like
Trace begun at line 11
main::will_warn at line 5
main::a_sub at line 3
something funny at line 11.
Trace begun at line 14
main::will_die at line 7
main::a_sub at line 3
something awful at 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).

Have I reinvented a wheel? Just checking before I post to CPAN. It's based on Devel::StackTrace and Exception::Class.

Carp does something similar but you have to explicitly use it in your code, whereas I can do perl -MDevel::Verbose and I will get full stack traces from all warn()s and die()s, without changing a line of code in