如何检查 Perl-CGI 应用程序中的所有错误(例如使用 Perl 编译器或类似 lint 的工具、免费开源工具进行检查?)

发布于 2024-11-17 13:33:01 字数 10579 浏览 0 评论 0 原文

我有一个任务关键型 Perl-CGI 服务器端应用程序,需要时常扩展或增强。

是否有一个工具可以检查应用程序的所有执行路径,即所有 Perl 文件、所有函数、所有 if-else、switch-case 等可能性。

作为一种解释性语言,修改代码期间引入的错误并不总是显而易见。如果人们认为一切正常,如果在进行更改后,Perl 程序在进行一些测试检查后运行正常,那么可能会被误导。

全面的测试套件可能是一个解决方案,但这始终是针对程序定制的,并且在时间紧张时需要额外的时间来实现。

相反,我认为一个有效的工具将是通用的“毯子”练习/解析/任何执行路径,例如检查未声明的变量,更改函数/子例程名称,例如由于重构等。

我有 ActiveState Komodo IDE,它做得很好在检测错误方面,但作为一个商业工具,我并不总是能够在我工作的所有环境中使用它。所以我更喜欢免费和开源的东西。

更新

感谢 @Nylon Smile 的 Perl::Critic - 答案如下 - 我的 Perl 设置中没有它作为标准,所以必须使用 cpan 来尝试安装它,当然:)

我我在详细的安装进度中看到了很多成功(见下文),但也有一些失败:(以及“Bailing out the Installation for Perl-Critic-1.116”,看起来不太好:(

这是每当我尝试安装或升级 Perl 模块时,我有 CentOS 5。

这给我的印象是,维护、配置、升级 Perl 是一件相当混乱的事情,不稳定,繁琐,可能会出现“但是你没有”。 ” 和“如果-你”关于你必须做什么才能使其工作:)

[root]# cpanm Perl::Critic
--> Working on Perl::Critic
Fetching http://search.cpan.org/CPAN/authors/id/E/EL/ELLIOTJS/Perl-Critic-1.116.tar.gz ... OK
Configuring Perl-Critic-1.116 ... OK
==> Found dependencies: PPI, B::Keywords, PPI::Document, List::MoreUtils, PPIx::Utilities::Statement, PPI::Token::Whitespace,        PPI::Node, Pod::Spell, PPI::Token::Quote::Single, Perl::Tidy, String::Format, PPI::Document::File, Task::Weaken, Module::Plugg       able, IO::String, version, PPIx::Utilities::Node, Readonly, Exporter, Exception::Class, PPIx::Regexp, Config::Tiny, Email::Add       ress, Test::Deep
--> Working on PPI
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/PPI-1.215.tar.gz ... OK
Configuring PPI-1.215 ... OK
==> Found dependencies: File::Remove, Test::Object, Storable, Test::NoWarnings, Params::Util, Test::SubCalls, Task::Weaken, Li       st::MoreUtils, IO::String, Clone, Class::Inspector
--> Working on File::Remove
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/File-Remove-1.49.tar.gz ... OK
Configuring File-Remove-1.49 ... OK
==> Found dependencies: File::Spec, Cwd
--> Working on File::Spec
Fetching http://search.cpan.org/CPAN/authors/id/S/SM/SMUELLER/PathTools-3.33.tar.gz ... OK
Configuring PathTools-3.33 ... OK
Building and testing PathTools-3.33 ... FAIL
! Installing File::Spec failed. See /root/.cpanm/build.log for details.
! Bailing out the installation for File-Remove-1.49. Retry with --prompt or --force.
--> Working on Test::Object
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/Test-Object-0.07.tar.gz ... OK
Configuring Test-Object-0.07 ... OK
Building and testing Test-Object-0.07 ... OK
Successfully installed Test-Object-0.07
--> Working on Storable
Fetching http://search.cpan.org/CPAN/authors/id/A/AM/AMS/Storable-2.25.tar.gz ... OK
Configuring Storable-2.25 ... OK
Building and testing Storable-2.25 ... FAIL
! Installing Storable failed. See /root/.cpanm/build.log for details.
--> Working on Test::NoWarnings
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/Test-NoWarnings-1.02.tar.gz ... OK
Configuring Test-NoWarnings-1.02 ... OK
==> Found dependencies: Test::Tester
--> Working on Test::Tester
Fetching http://search.cpan.org/CPAN/authors/id/F/FD/FDALY/Test-Tester-0.107.tar.gz ... OK
Configuring Test-Tester-0.107 ... OK
Building and testing Test-Tester-0.107 ... OK
Successfully installed Test-Tester-0.107
Building and testing Test-NoWarnings-1.02 ... OK
Successfully installed Test-NoWarnings-1.02
--> Working on Params::Util
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/Params-Util-1.04.tar.gz ... OK
Configuring Params-Util-1.04 ... OK
Building and testing Params-Util-1.04 ... OK
Successfully installed Params-Util-1.04
--> Working on Test::SubCalls
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/Test-SubCalls-1.09.tar.gz ... OK
Configuring Test-SubCalls-1.09 ... OK
==> Found dependencies: Hook::LexWrap
--> Working on Hook::LexWrap
Fetching http://search.cpan.org/CPAN/authors/id/C/CH/CHORNY/Hook-LexWrap-0.24.tar.gz ... OK
Configuring Hook-LexWrap-0.24 ... OK
Building and testing Hook-LexWrap-0.24 ... OK
Successfully installed Hook-LexWrap-0.24
Building and testing Test-SubCalls-1.09 ... OK
Successfully installed Test-SubCalls-1.09
--> Working on Task::Weaken
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/Task-Weaken-1.04.tar.gz ... OK
Configuring Task-Weaken-1.04 ... OK
Building and testing Task-Weaken-1.04 ... OK
Successfully installed Task-Weaken-1.04
--> Working on List::MoreUtils
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/List-MoreUtils-0.32.tar.gz ... OK
Configuring List-MoreUtils-0.32 ... OK
Building and testing List-MoreUtils-0.32 ... FAIL
! Installing List::MoreUtils failed. See /root/.cpanm/build.log for details.
--> Working on IO::String
Fetching http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/IO-String-1.08.tar.gz ... OK
Configuring IO-String-1.08 ... OK
Building and testing IO-String-1.08 ... OK
Successfully installed IO-String-1.08
--> Working on Clone
Fetching http://search.cpan.org/CPAN/authors/id/R/RD/RDF/Clone-0.31.tar.gz ... OK
Configuring Clone-0.31 ... OK
Building and testing Clone-0.31 ... FAIL
! Installing Clone failed. See /root/.cpanm/build.log for details.
--> Working on Class::Inspector
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/Class-Inspector-1.25.tar.gz ... OK
Configuring Class-Inspector-1.25 ... OK
Building and testing Class-Inspector-1.25 ... OK
Successfully installed Class-Inspector-1.25
! Bailing out the installation for PPI-1.215. Retry with --prompt or --force.
--> Working on B::Keywords
Fetching http://search.cpan.org/CPAN/authors/id/F/FL/FLORA/B-Keywords-1.10.tar.gz ... OK
Configuring B-Keywords-1.10 ... OK
Building and testing B-Keywords-1.10 ... OK
Successfully installed B-Keywords-1.10
--> Working on PPIx::Utilities::Statement
Fetching http://search.cpan.org/CPAN/authors/id/E/EL/ELLIOTJS/PPIx-Utilities-1.001000.tar.gz ... OK
Configuring PPIx-Utilities-1.001000 ... OK
==> Found dependencies: PPI, Readonly, Exception::Class, PPI::Document::Fragment, PPI::Dumper, PPI::Document, Test::Deep
--> Working on Readonly
Fetching http://search.cpan.org/CPAN/authors/id/R/RO/ROODE/Readonly-1.03.tar.gz ... OK
Configuring Readonly-1.03 ... OK
Building and testing Readonly-1.03 ... OK
Successfully installed Readonly-1.03
--> Working on Exception::Class
Fetching http://search.cpan.org/CPAN/authors/id/D/DR/DROLSKY/Exception-Class-1.32.tar.gz ... OK
Configuring Exception-Class-1.32 ... OK
==> Found dependencies: Devel::StackTrace, Class::Data::Inheritable
--> Working on Devel::StackTrace
Fetching http://search.cpan.org/CPAN/authors/id/D/DR/DROLSKY/Devel-StackTrace-1.27.tar.gz ... OK
Configuring Devel-StackTrace-1.27 ... OK
Building and testing Devel-StackTrace-1.27 ... OK
Successfully installed Devel-StackTrace-1.27
--> Working on Class::Data::Inheritable
Fetching http://search.cpan.org/CPAN/authors/id/T/TM/TMTM/Class-Data-Inheritable-0.08.tar.gz ... OK
Configuring Class-Data-Inheritable-0.08 ... OK
Building and testing Class-Data-Inheritable-0.08 ... OK
Successfully installed Class-Data-Inheritable-0.08
Building and testing Exception-Class-1.32 ... OK
Successfully installed Exception-Class-1.32
--> Working on Test::Deep
Fetching http://search.cpan.org/CPAN/authors/id/R/RJ/RJBS/Test-Deep-0.108.tar.gz ... OK
Configuring Test-Deep-0.108 ... OK
Building and testing Test-Deep-0.108 ... OK
Successfully installed Test-Deep-0.108
Building and testing PPIx-Utilities-1.001000 ... FAIL
! Installing PPIx::Utilities::Statement failed. See /root/.cpanm/build.log for details.
--> Working on Pod::Spell
Fetching http://search.cpan.org/CPAN/authors/id/S/SB/SBURKE/Pod-Spell-1.01.tar.gz ... OK
Configuring Pod-Spell-1.01 ... OK
Building and testing Pod-Spell-1.01 ... OK
Successfully installed Pod-Spell-1.01
--> Working on Perl::Tidy
Fetching http://search.cpan.org/CPAN/authors/id/S/SH/SHANCOCK/Perl-Tidy-20101217.tar.gz ... OK
Configuring Perl-Tidy-20101217 ... OK
Building and testing Perl-Tidy-20101217 ... OK
Successfully installed Perl-Tidy-20101217
--> Working on String::Format
Fetching http://search.cpan.org/CPAN/authors/id/D/DA/DARREN/String-Format-1.16.tar.gz ... OK
Configuring String-Format-1.16 ... OK
Building and testing String-Format-1.16 ... OK
Successfully installed String-Format-1.16
--> Working on Module::Pluggable
Fetching http://search.cpan.org/CPAN/authors/id/S/SI/SIMONW/Module-Pluggable-3.9.tar.gz ... OK
Configuring Module-Pluggable-3.9 ... OK
Building and testing Module-Pluggable-3.9 ... OK
Successfully installed Module-Pluggable-3.9
--> Working on version
Fetching http://search.cpan.org/CPAN/authors/id/J/JP/JPEACOCK/version-0.91.tar.gz ... OK
Configuring version-0.91 ... OK
Building and testing version-0.91 ... OK
Successfully installed version-0.91
--> Working on Exporter
Fetching http://search.cpan.org/CPAN/authors/id/F/FE/FERREIRA/Exporter-5.63.tar.gz ... OK
Configuring Exporter-5.63 ... OK
Building and testing Exporter-5.63 ... OK
Successfully installed Exporter-5.63 (upgraded from 5.58)
--> Working on PPIx::Regexp
Fetching http://search.cpan.org/CPAN/authors/id/W/WY/WYANT/PPIx-Regexp-0.020.tar.gz ... OK
Configuring PPIx-Regexp-0.020 ... OK
==> Found dependencies: PPI::Document, List::MoreUtils
Building and testing PPIx-Regexp-0.020 ... FAIL
! Installing PPIx::Regexp failed. See /root/.cpanm/build.log for details.
--> Working on Config::Tiny
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/Config-Tiny-2.14.tar.gz ... OK
Configuring Config-Tiny-2.14 ... OK
Building and testing Config-Tiny-2.14 ... OK
Successfully installed Config-Tiny-2.14
--> Working on Email::Address
Fetching http://search.cpan.org/CPAN/authors/id/R/RJ/RJBS/Email-Address-1.892.tar.gz ... OK
Configuring Email-Address-1.892 ... OK
Building and testing Email-Address-1.892 ... OK
Successfully installed Email-Address-1.892
! Bailing out the installation for Perl-Critic-1.116. Retry with --prompt or --force.
23 distributions installed
[root]#

更新 2

有一个 Perl 到 C 编译器,所以大概必须检查所有执行路径才能生成 C 代码, 或者至少如果没有,错误的 C 代码可以通过 C 编译器传递,该编译器会发现问题:

I have a mission critical Perl-CGI server-side application that I need to extend or enhance from time to time.

Is there a tool that will check all the execution paths of the application, i.e. all Perl files, all functions, all if-else, switch-case etc possibilities.

Being an interpreted language, errors introduced during modifying code don't always become apparent. One can be misled if one thinks that everything is OK, if after doing the changes, the Perl program runs OK after doing some tests to check.

A comprehensive test suite might be a solution, but this is always going to be custom to the program and takes additional time to implement, when time is scarce.

Rather, I think an effective tool would be generic to "blanket" exercise/parse/whatever every execution path e.g. checking for undeclared variables, change to function/subroutine names e.g. due to refactoring etc.

I have ActiveState Komodo IDE which does a good job at detecting errors but being a commercial tool, I won't always be able to use it in all the environments I work in. So I would prefer something free and open source.

Update

Thanks @Nylon Smile for Perl::Critic - the answer below - I didn't have it as standard in my Perl setup so had to use cpan to try to install it, of course :)

I'm seeing lots of Successes in the verbose install progress (see below), but a few failures too :( and also a "Bailing out the installation for Perl-Critic-1.116" which doesn't look good :(

This is not uncommon whenever I try to install or upgrade Perl modules. I have CentOS 5.

It leaves me with the impression that maintaining, configuring, upgrading Perl is a rather messy affair, flakey, fiddly, probably with "but-you-didn't" and "if-you" regarding what you have to do to make it work :)

[root]# cpanm Perl::Critic
--> Working on Perl::Critic
Fetching http://search.cpan.org/CPAN/authors/id/E/EL/ELLIOTJS/Perl-Critic-1.116.tar.gz ... OK
Configuring Perl-Critic-1.116 ... OK
==> Found dependencies: PPI, B::Keywords, PPI::Document, List::MoreUtils, PPIx::Utilities::Statement, PPI::Token::Whitespace,        PPI::Node, Pod::Spell, PPI::Token::Quote::Single, Perl::Tidy, String::Format, PPI::Document::File, Task::Weaken, Module::Plugg       able, IO::String, version, PPIx::Utilities::Node, Readonly, Exporter, Exception::Class, PPIx::Regexp, Config::Tiny, Email::Add       ress, Test::Deep
--> Working on PPI
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/PPI-1.215.tar.gz ... OK
Configuring PPI-1.215 ... OK
==> Found dependencies: File::Remove, Test::Object, Storable, Test::NoWarnings, Params::Util, Test::SubCalls, Task::Weaken, Li       st::MoreUtils, IO::String, Clone, Class::Inspector
--> Working on File::Remove
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/File-Remove-1.49.tar.gz ... OK
Configuring File-Remove-1.49 ... OK
==> Found dependencies: File::Spec, Cwd
--> Working on File::Spec
Fetching http://search.cpan.org/CPAN/authors/id/S/SM/SMUELLER/PathTools-3.33.tar.gz ... OK
Configuring PathTools-3.33 ... OK
Building and testing PathTools-3.33 ... FAIL
! Installing File::Spec failed. See /root/.cpanm/build.log for details.
! Bailing out the installation for File-Remove-1.49. Retry with --prompt or --force.
--> Working on Test::Object
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/Test-Object-0.07.tar.gz ... OK
Configuring Test-Object-0.07 ... OK
Building and testing Test-Object-0.07 ... OK
Successfully installed Test-Object-0.07
--> Working on Storable
Fetching http://search.cpan.org/CPAN/authors/id/A/AM/AMS/Storable-2.25.tar.gz ... OK
Configuring Storable-2.25 ... OK
Building and testing Storable-2.25 ... FAIL
! Installing Storable failed. See /root/.cpanm/build.log for details.
--> Working on Test::NoWarnings
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/Test-NoWarnings-1.02.tar.gz ... OK
Configuring Test-NoWarnings-1.02 ... OK
==> Found dependencies: Test::Tester
--> Working on Test::Tester
Fetching http://search.cpan.org/CPAN/authors/id/F/FD/FDALY/Test-Tester-0.107.tar.gz ... OK
Configuring Test-Tester-0.107 ... OK
Building and testing Test-Tester-0.107 ... OK
Successfully installed Test-Tester-0.107
Building and testing Test-NoWarnings-1.02 ... OK
Successfully installed Test-NoWarnings-1.02
--> Working on Params::Util
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/Params-Util-1.04.tar.gz ... OK
Configuring Params-Util-1.04 ... OK
Building and testing Params-Util-1.04 ... OK
Successfully installed Params-Util-1.04
--> Working on Test::SubCalls
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/Test-SubCalls-1.09.tar.gz ... OK
Configuring Test-SubCalls-1.09 ... OK
==> Found dependencies: Hook::LexWrap
--> Working on Hook::LexWrap
Fetching http://search.cpan.org/CPAN/authors/id/C/CH/CHORNY/Hook-LexWrap-0.24.tar.gz ... OK
Configuring Hook-LexWrap-0.24 ... OK
Building and testing Hook-LexWrap-0.24 ... OK
Successfully installed Hook-LexWrap-0.24
Building and testing Test-SubCalls-1.09 ... OK
Successfully installed Test-SubCalls-1.09
--> Working on Task::Weaken
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/Task-Weaken-1.04.tar.gz ... OK
Configuring Task-Weaken-1.04 ... OK
Building and testing Task-Weaken-1.04 ... OK
Successfully installed Task-Weaken-1.04
--> Working on List::MoreUtils
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/List-MoreUtils-0.32.tar.gz ... OK
Configuring List-MoreUtils-0.32 ... OK
Building and testing List-MoreUtils-0.32 ... FAIL
! Installing List::MoreUtils failed. See /root/.cpanm/build.log for details.
--> Working on IO::String
Fetching http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/IO-String-1.08.tar.gz ... OK
Configuring IO-String-1.08 ... OK
Building and testing IO-String-1.08 ... OK
Successfully installed IO-String-1.08
--> Working on Clone
Fetching http://search.cpan.org/CPAN/authors/id/R/RD/RDF/Clone-0.31.tar.gz ... OK
Configuring Clone-0.31 ... OK
Building and testing Clone-0.31 ... FAIL
! Installing Clone failed. See /root/.cpanm/build.log for details.
--> Working on Class::Inspector
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/Class-Inspector-1.25.tar.gz ... OK
Configuring Class-Inspector-1.25 ... OK
Building and testing Class-Inspector-1.25 ... OK
Successfully installed Class-Inspector-1.25
! Bailing out the installation for PPI-1.215. Retry with --prompt or --force.
--> Working on B::Keywords
Fetching http://search.cpan.org/CPAN/authors/id/F/FL/FLORA/B-Keywords-1.10.tar.gz ... OK
Configuring B-Keywords-1.10 ... OK
Building and testing B-Keywords-1.10 ... OK
Successfully installed B-Keywords-1.10
--> Working on PPIx::Utilities::Statement
Fetching http://search.cpan.org/CPAN/authors/id/E/EL/ELLIOTJS/PPIx-Utilities-1.001000.tar.gz ... OK
Configuring PPIx-Utilities-1.001000 ... OK
==> Found dependencies: PPI, Readonly, Exception::Class, PPI::Document::Fragment, PPI::Dumper, PPI::Document, Test::Deep
--> Working on Readonly
Fetching http://search.cpan.org/CPAN/authors/id/R/RO/ROODE/Readonly-1.03.tar.gz ... OK
Configuring Readonly-1.03 ... OK
Building and testing Readonly-1.03 ... OK
Successfully installed Readonly-1.03
--> Working on Exception::Class
Fetching http://search.cpan.org/CPAN/authors/id/D/DR/DROLSKY/Exception-Class-1.32.tar.gz ... OK
Configuring Exception-Class-1.32 ... OK
==> Found dependencies: Devel::StackTrace, Class::Data::Inheritable
--> Working on Devel::StackTrace
Fetching http://search.cpan.org/CPAN/authors/id/D/DR/DROLSKY/Devel-StackTrace-1.27.tar.gz ... OK
Configuring Devel-StackTrace-1.27 ... OK
Building and testing Devel-StackTrace-1.27 ... OK
Successfully installed Devel-StackTrace-1.27
--> Working on Class::Data::Inheritable
Fetching http://search.cpan.org/CPAN/authors/id/T/TM/TMTM/Class-Data-Inheritable-0.08.tar.gz ... OK
Configuring Class-Data-Inheritable-0.08 ... OK
Building and testing Class-Data-Inheritable-0.08 ... OK
Successfully installed Class-Data-Inheritable-0.08
Building and testing Exception-Class-1.32 ... OK
Successfully installed Exception-Class-1.32
--> Working on Test::Deep
Fetching http://search.cpan.org/CPAN/authors/id/R/RJ/RJBS/Test-Deep-0.108.tar.gz ... OK
Configuring Test-Deep-0.108 ... OK
Building and testing Test-Deep-0.108 ... OK
Successfully installed Test-Deep-0.108
Building and testing PPIx-Utilities-1.001000 ... FAIL
! Installing PPIx::Utilities::Statement failed. See /root/.cpanm/build.log for details.
--> Working on Pod::Spell
Fetching http://search.cpan.org/CPAN/authors/id/S/SB/SBURKE/Pod-Spell-1.01.tar.gz ... OK
Configuring Pod-Spell-1.01 ... OK
Building and testing Pod-Spell-1.01 ... OK
Successfully installed Pod-Spell-1.01
--> Working on Perl::Tidy
Fetching http://search.cpan.org/CPAN/authors/id/S/SH/SHANCOCK/Perl-Tidy-20101217.tar.gz ... OK
Configuring Perl-Tidy-20101217 ... OK
Building and testing Perl-Tidy-20101217 ... OK
Successfully installed Perl-Tidy-20101217
--> Working on String::Format
Fetching http://search.cpan.org/CPAN/authors/id/D/DA/DARREN/String-Format-1.16.tar.gz ... OK
Configuring String-Format-1.16 ... OK
Building and testing String-Format-1.16 ... OK
Successfully installed String-Format-1.16
--> Working on Module::Pluggable
Fetching http://search.cpan.org/CPAN/authors/id/S/SI/SIMONW/Module-Pluggable-3.9.tar.gz ... OK
Configuring Module-Pluggable-3.9 ... OK
Building and testing Module-Pluggable-3.9 ... OK
Successfully installed Module-Pluggable-3.9
--> Working on version
Fetching http://search.cpan.org/CPAN/authors/id/J/JP/JPEACOCK/version-0.91.tar.gz ... OK
Configuring version-0.91 ... OK
Building and testing version-0.91 ... OK
Successfully installed version-0.91
--> Working on Exporter
Fetching http://search.cpan.org/CPAN/authors/id/F/FE/FERREIRA/Exporter-5.63.tar.gz ... OK
Configuring Exporter-5.63 ... OK
Building and testing Exporter-5.63 ... OK
Successfully installed Exporter-5.63 (upgraded from 5.58)
--> Working on PPIx::Regexp
Fetching http://search.cpan.org/CPAN/authors/id/W/WY/WYANT/PPIx-Regexp-0.020.tar.gz ... OK
Configuring PPIx-Regexp-0.020 ... OK
==> Found dependencies: PPI::Document, List::MoreUtils
Building and testing PPIx-Regexp-0.020 ... FAIL
! Installing PPIx::Regexp failed. See /root/.cpanm/build.log for details.
--> Working on Config::Tiny
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/Config-Tiny-2.14.tar.gz ... OK
Configuring Config-Tiny-2.14 ... OK
Building and testing Config-Tiny-2.14 ... OK
Successfully installed Config-Tiny-2.14
--> Working on Email::Address
Fetching http://search.cpan.org/CPAN/authors/id/R/RJ/RJBS/Email-Address-1.892.tar.gz ... OK
Configuring Email-Address-1.892 ... OK
Building and testing Email-Address-1.892 ... OK
Successfully installed Email-Address-1.892
! Bailing out the installation for Perl-Critic-1.116. Retry with --prompt or --force.
23 distributions installed
[root]#

Update 2

There is a Perl to C compiler, so presumably this would have to examine all execution paths to produce C code, or at least if not, the erroneous C code could be passed through a C compiler that would pick up on the problems:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寻找我们的幸福 2024-11-24 13:33:01

Perl::Critic (perlcritic.com)将为您做一些工作。该模块对源代码进行静态分析。它基于《Perl Best Practices》一书,会发现一些 bug,并会参考该书的页码给你很多风格上的建议。

Perl::Critic (perlcritic.com) will do some of the work for you. The module does a static analysis of your source code. It's based on the book "Perl Best Practices" and will find some bugs and will give you many advices on the style with reference to the page number of the book.

来世叙缘 2024-11-24 13:33:01

我认为,如果你首先增强设计,你会得到最大的效果。

您可以尽可能地进行防御性编码,例如:

  • 尽可能静态地编码,以便与 Perl::Critic 和编译器等工具配合。这使得能够在编译时检测错误。

  • 书籍“Perl 最佳实践 ' 和 'Perl Hacks'(均来自 O'Reilly)有一些将代码部分从运行时检查转移到编译时检查的技巧.

如果您无法避免动态生成的代码,那么好的测试套件是无可替代的。我更喜欢一些手动编写的测试与自动生成的测试相结合 测试::LectroTestDevel::Cover 将帮助您了解您的测试覆盖范围。

我不知道有任何工具像您所要求的那样,但这种工具的运行时间很容易令人无法接受。所有可能的代码路径的组合通常太多而不实用。

I think, you will get the most effect, if you first enhance the design.

You could code as defensively as possible, for example:

  • Code as statically as possible in order to cooperate with tools like Perl::Critic and the compiler. This enables the detection of errors at compile time.

  • The books 'Perl Best Practices' and 'Perl Hacks' (both from O'Reilly) have some tricks for moving code parts from runtime checking to compiletime checking.

If you cannot avoid dynamically generated code, there is no substitute for a good test suite. I prefer some manually written tests combined with automatically generated tests from Test::LectroTest. Devel::Cover will help you to get a feeling of your test coverage.

I don't know of any tool like the one you ask for, but the runtime of such a tool could easily be unacceptible. The combinatorics of all possible code paths is often too much to be practical.

萌吟 2024-11-24 13:33:01
  • 如果您还没有使用它(我假设您已经使用,但只是确定一下),使用 strict; use warnings; 将为您发现很多错误,尤其是那些可能由粗心编辑引入的错误,尽管它不进行任何代码路径分析。

  • 对于代码路径部分,我不知道有什么会自动为所有执行路径生成测试,但是 Devel::Cover 将提供代码覆盖率指标,以帮助确定您自己编写的测试是否缺少任何执行路径。

  • If you're not already using it (I assume you are, but just making sure), use strict; use warnings; will find a lot of errors for you, especially of the sorts likely to be introduced by careless edits, although it doesn't do any code path analysis.

  • For the code path portion, I'm not aware of anything that will automatically generate tests for all execution paths, but Devel::Cover will provide code coverage metrics to help determine whether the tests you've written yourself are missing any execution paths.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文