Perl代码中的依赖关系(Dependencies in Perl code)

编程入门 行业动态 更新时间:2024-10-28 00:23:52
Perl代码中的依赖关系(Dependencies in Perl code)

我被分配了一些用旧的Perl Legacy代码编写的web应用程序,让它在我们的服务器上运行以便以后扩展它。 该代码是10年前由一位自学成才的独立开发人员编写的......

这些代码有很奇怪的东西 - 他们不害怕在第一行上do lib-param.pl ,后来在文件中do /lib-pl/lib-param.pl - 这是一个不同的文件。

包括a.pl与方法b()和c()以及后来包括d.pl与方法c()和e()似乎也很受欢迎...包似乎是未知的,所以你只需找到&c ()稍后在代码中的某处。

有趣的问题:

有没有可以在perl文件之间绘制关系的工具? 显示其他文件使用的文件列表? MySQL数据库和表格相同吗? 它可以显示哪些模式/表由哪些文件使用? 是否有一个IDE知道调用哪个c() - a.pl中的那个或d.pl中的那个? 你会如何开始尝试理解代码?

我倾向于浏览每个文件并重构它,但不允许这样做 - 只有严格的最低限度才能使代码正常工作。 (但由于代码从不uses strict ,我不知道我是不是......)

I've been assigned to pick up a webapplication written in some old Perl Legacy code, get it working on our server to later extend it. The code was written 10 years ago by a solitary self-taught developer...

The code has weird stuff going on - they are not afraid to do lib-param.pl on line one, and later in the file do /lib-pl/lib-param.pl - which is offcourse a different file.

Including a.pl with methods b() and c() and later including d.pl with methods c() and e() seems to be quite popular too... Packages appear to be unknown, so you'll just find &c() somewhere in the code later.

Interesting questions:

Is there a tool that can draw relations between perl-files? Show a list of files used by each other file? The same for MySQL databases and tables? Can it show which schema's/tables are used by which files? Is there an IDE that knows which c() is called - the one in a.pl or the one in d.pl? How would you start to try to understand the code?

I'm inclined to go through each file and refactor it, but am not allowed to do that - only the strict minimum to get the code working. (But since the code never uses strict, I don't know if I'm gonna...)

最满意答案

不使用严格是一个错误 - 不要继续它。 将d.pl的内容移动到D.pm (或者可能是更好的名称),如果代码是程序性的,则使用Sub::Exporter将这些Sub::Exporter返回到调用包中。 strict是词法,你可以只打开一个包。 比如你的新package D; 。 要找出要调用的代码,请使用Devel :: SimpleTrace。

perl -MDevel::SimpleTrace ./foo.pl

现在任何警告都会附带一个完整的后退日志 - 代码周围的警告并运行它。

我认为应该删除MySQL问题。 Schema Table映射与perl无关,这个问题似乎不合适。

Not using strict is a mistake -- don't continue it. Move the stuff in d.pl to D.pm (or perhaps a better name alltogether), and if the code is procedural use Sub::Exporter to get those subs back into the calling package. strict is lexical, you can turn it on for just one package. Such as your new package D;. To find out which code is being called, use Devel::SimpleTrace.

perl -MDevel::SimpleTrace ./foo.pl

Now any warnings will be accompanied by a full back-log -- sprinkle warnings around the code and run it.

I think the MySQL question should be removed, from this. Schema Table mappings have nothing to do with perl, it seems an out of place distraction on this question.

更多推荐

本文发布于:2023-07-14 17:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1106062.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   关系   Perl   Dependencies   code

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!