在macOS Ventura上安装perlcritic。

huangapple go评论94阅读模式
英文:

Install perlcritic on macOS Ventura

问题

I'm on macOS Ventura 13.3.1 and I'm trying to get perlcritic working.

  1. perl --version

给出:

  1. This is perl 5, version 36, subversion 0 (v5.36.0) built for darwin-thread-multi-2level
  2. ...

当我输入:

  1. cpan Perl::Critic

我得到:

  1. Loading internal logger. Log::Log4perl recommended for better logging
  2. Reading '/Users/baduker/.cpan/Metadata'
  3. Database was generated on Sun, 07 May 2023 10:41:02 GMT
  4. Perl::Critic is up to date (1.150).

然而,当我尝试:

  1. perlcritic -1 list.pl

我得到:

  1. zsh: command not found: perlcritic

我还尝试了使用 brew

  1. brew install perlcritic

但是 brew 找不到它,建议使用 perltidy

  1. Warning: No available formula with the name "perlcritic". Did you mean perltidy?
  2. ==> Searching for similarly named formulae and casks...
  3. ==> Formulae
  4. perltidy
  5. To install perltidy, run:
  6. brew install perltidy

附加调试信息:

  1. which perl
  2. /opt/homebrew/bin/perl

运行 perl -V:installsitebin 给出:

  1. installsitebin='/opt/homebrew/Cellar/perl/5.36.0/bin';

问题: 如何在 macOS 上使 perlcritic 工作?

PS. list.pl 看起来像这样:

  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Path::Tiny;
  5. use autodie;
  6. my $dir = path("/tmp"); # /tmp
  7. my $file = $dir->child("test");
  8. my $content = $file->slurp_utf8();
  9. my $file_handle = $file->openr_utf8();
  10. while( my $line = $file_handle->getline() ) {
  11. print $line;
  12. }
英文:

I'm on macOS Ventura 13.3.1 and I'm trying to get perlcritic working.

  1. perl --version

Gives me:

  1. This is perl 5, version 36, subversion 0 (v5.36.0) built for darwin-thread-multi-2level
  2. ...

When I type:

  1. cpan Perl::Critic

I get:

  1. Loading internal logger. Log::Log4perl recommended for better logging
  2. Reading '/Users/baduker/.cpan/Metadata'
  3. Database was generated on Sun, 07 May 2023 10:41:02 GMT
  4. Perl::Critic is up to date (1.150).

However, when I try:

  1. perlcritic -1 list.pl

I get:

  1. zsh: command not found: perlcritic

I've also tried using brew

  1. brew install perlcritic

But brew can't find it and suggests perltidy:

  1. Warning: No available formula with the name "perlcritic". Did you mean perltidy?
  2. ==> Searching for similarly named formulae and casks...
  3. ==> Formulae
  4. perltidy
  5. To install perltidy, run:
  6. brew install perltidy

Additional debugging info:

  1. which perl
  2. /opt/homebrew/bin/perl

Running perl -V:installsitebin gives:

  1. installsitebin='/opt/homebrew/Cellar/perl/5.36.0/bin';

Question: How do I get perlcirtic working on macOS?


PS. list.pl looks like this:

  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Path::Tiny;
  5. use autodie;
  6. my $dir = path("/tmp"); # /tmp
  7. my $file = $dir->child("test");
  8. my $content = $file->slurp_utf8();
  9. my $file_handle = $file->openr_utf8();
  10. while( my $line = $file_handle->getline() ) {
  11. print $line;
  12. }

答案1

得分: 1

根据评论中的反馈,修复很容易。

运行:

  1. perl -V:installsitebin

以确认安装情况。

在我的情况下,perlcritic 被安装了,但出于某种原因,opt/homebrew/Cellar/perl/5.36.0/bin 没有添加到 PATH

注意:我使用 brew 安装的 perl

修复方法:

  1. export PATH=$PATH:/opt/homebrew/Cellar/perl/5.36.0/bin/

然后,运行 perlcritic -1 list.pl 会产生如下输出:

  1. No package-scoped "$VERSION" variable found at line 0, column 0. See page 404 of PBP. (Severity: 2)
英文:

Based on the feedback in the comments, the fix is easy.

Run:

  1. perl -V:installsitebin

To confirm the installation.

In my case, perlciritic gets installed, but, for some reason, opt/homebrew/Cellar/perl/5.36.0/bin doesn't get added to PATH.

Note: I use brew perl installation.

The fix:

  1. export PATH=$PATH:/opt/homebrew/Cellar/perl/5.36.0/bin/

Then, running perlcritic -1 list.pl produces, for example:

  1. No package-scoped "$VERSION" variable found at line 0, column 0. See page 404 of PBP. (Severity: 2)

huangapple
  • 本文由 发表于 2023年5月7日 19:38:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76193687.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定