macosperlzshcpan

Install perlcritic on macOS Ventura


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;
}

Solution

  • 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)