如何在 Perl 应用程序中用“承认"替换所有“死"? [英] How can I replace all 'die's with 'confess' in a Perl application?

查看:62
本文介绍了如何在 Perl 应用程序中用“承认"替换所有“死"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个大型 Perl 应用程序中工作,并且希望在每次调用 'die' 时获取堆栈跟踪.我知道 Carp 模块,但我不想搜索/替换每个实例死"与忏悔".此外,我想要 Perl 模块或 Perl 解释器本身错误的完整堆栈跟踪,显然我无法更改它们以使用 Carp.

I'm working in a large Perl application and would like to get stack traces every time 'die' is called. I'm aware of the Carp module, but I would prefer not to search/replace every instance of 'die' with 'confess'. In addition, I would like full stack traces for errors in Perl modules or the Perl interpreter itself, and obviously I can't change those to use Carp.

那么,有没有办法让我在运行时修改die"函数,使其表现得像confess"?或者,是否有 Perl 解释器设置会从die"中抛出完整的堆栈跟踪?

So, is there a way for me to modify the 'die' function at runtime so that it behaves like 'confess'? Or, is there a Perl interpreter setting that will throw full stack traces from 'die'?

推荐答案

使用 Devel::SimpleTraceCarp::Always 他们会做你想做的要求您无需付出任何努力.它们具有全局效果,这意味着它们可以很容易地添加到命令行上,例如使用-MDevel::SimpleTrace.

Use Devel::SimpleTrace or Carp::Always and they'll do what you're asking for without any hard work on your part. They have global effect, which means they can easily be added for just one run on the commandline using e.g. -MDevel::SimpleTrace.

这篇关于如何在 Perl 应用程序中用“承认"替换所有“死"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆