在macOS Ventura上安装perlcritic。

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

Install perlcritic on macOS Ventura

问题

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

perl --version

给出:

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

...

当我输入:

cpan Perl::Critic

我得到:

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

然而,当我尝试:

perlcritic -1 list.pl

我得到:

zsh: command not found: perlcritic

我还尝试了使用 brew

brew install perlcritic

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

Warning: No available formula with the name "perlcritic". Did you mean perltidy?
==> Searching for similarly named formulae and casks...
==> Formulae
perltidy

To install perltidy, run:
  brew install perltidy

附加调试信息:

which perl
/opt/homebrew/bin/perl

运行 perl -V:installsitebin 给出:

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

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

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

#!/usr/bin/perl
use strict;
use warnings;

use Path::Tiny;
use autodie;

my $dir = path("/tmp"); # /tmp

my $file = $dir->child("test");

my $content = $file->slurp_utf8();

my $file_handle = $file->openr_utf8();

while( my $line = $file_handle->getline() ) {
    print $line;
}
英文:

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

perl --version

Gives me:

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

...

When I type:

cpan Perl::Critic

I get:

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

However, when I try:

perlcritic -1 list.pl

I get:

zsh: command not found: perlcritic

I've also tried using brew

brew install perlcritic

But brew can't find it and suggests perltidy:

Warning: No available formula with the name "perlcritic". Did you mean perltidy?
==> Searching for similarly named formulae and casks...
==> Formulae
perltidy

To install perltidy, run:
  brew install perltidy

Additional debugging info:

which perl
/opt/homebrew/bin/perl

Running perl -V:installsitebin gives:

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

Question: How do I get perlcirtic working on macOS?


PS. list.pl looks like this:

#!/usr/bin/perl
use strict;
use warnings;

use Path::Tiny;
use autodie;

my $dir = path("/tmp"); # /tmp

my $file = $dir->child("test");

my $content = $file->slurp_utf8();

my $file_handle = $file->openr_utf8();

while( my $line = $file_handle->getline() ) {
    print $line;
}

答案1

得分: 1

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

运行:

perl -V:installsitebin

以确认安装情况。

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

注意:我使用 brew 安装的 perl

修复方法:

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

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

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:

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:

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

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

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:

确定