在perl中,有没有办法让子例程在调用时打印它们的名称和参数?
我需要快速了解在一堆意大利面条代码 perl 模块中调用了哪些子例程。
我可以编写一个脚本来遍历所有模块,并添加代码以在每个子例程开始时打印出子例程名称和参数。
但是有没有办法覆盖内部 perl“子例程”机制本身来做到这一点?
该代码在 mod_perl 下运行,因此我无法轻松使用调试器。
I need to quickly understand which subroutines are being called in a mess of spaghetti code perl modules.
I could write a script to go through all the modules and add code to print out the subroutine name and arguments at the start of every subroutine.
But is there a way to override the internal perl 'subroutine' mechanism itself to do this?
The code is running under mod_perl so I can't easily use a debugger.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Devel:Trace 将显示子例程调用和参数。它还将显示执行的每一行代码,这可能比您需要的更详细。
Devel::DumpTrace 将更加详细,显示值< /strong> 变量也是如此。
Devel:Trace will show subroutine calls and arguments. It will also show every line of code that is executed, which may be more verbose than you need.
Devel::DumpTrace will be even more verbose, showing the values of variables as well.
您可以通过 NYTProf 运行代码当通过 mod_perl 在 Apache 下运行
You can run the code through NYTProf when when running under Apache via mod_perl
我知道您说您“无法轻松使用调试器”,因为您在 mod_perl 下运行,但是有一些选项可以实现此处描述的操作:
http://perl.apache.org/docs/1.0/guide/debug.html#Non_Interactive_Perl_Debugging_under_mod_perl
I know you say you "can't easily use the debugger" because you're running under mod_perl, but there are some options for doing just that described here:
http://perl.apache.org/docs/1.0/guide/debug.html#Non_Interactive_Perl_Debugging_under_mod_perl
您可以使用
Moose::方法修饰符
。我对Moose
不太了解,但从手册中我可以看到你可以做到。就这样吧。这会产生类似“
请注意我只是一个初学者,所以要小心该代码”的内容。
You could use
Moose::MethodModifiers
. I don't know much aboutMoose
, but from the manual I can see you can do it. Here goes.This produces something like
Please note I'm only a beginner so be cautious about that code.