ymakkapati has asked for the wisdom of the Perl Monks concerning the following question:

I am new to Perl. I have perl5 on my Centos7. I am trying to make `perlcritic`command work on my Centos. I installed perlcritic with the command "cpan Perl::Critic" and tried to run ./perlcritic. I kept installing the dependent modules of perlcritic, and adding the libraries to the @INC. For Clone module, there is no lib. If I move just the Clone.pm to @INC (/usr/share/perl5), I get an error"Can't locate loadable object for module Clone in @INC (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.24.1 /usr/local/share/perl/5.24.1 /usr/lib/x86_64-linux-gnu/perl5/5.24 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.24 /usr/share/perl/5.24 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/PPI/Element.pm line 25." If I move whole Clone module to /usr/share/perl5 ,then I still get error saying"Cannot locate Clone.pm". It would be great if there is any doc for completely installing perlcritic and making it work. --Thanks in advance

Replies are listed 'Best First'.
Re: perlcritic on Linux
by haukex (Archbishop) on Apr 11, 2019 at 19:10 UTC

    Welcome to Perl and the Monastery, ymakkapati.

    Based on those paths, it sounds like you're trying to install a module into the system Perl using cpan, which is generally not recommended, because it can create conflicts with the packages installed into the system Perl using the package manager, and in case of problems, cleaning this up can become quite difficult. Also, Perl modules should always be installed using their recommended installation procedure, not by copying files into the @INC directories.

    Although I am not a CentOS expert (hippo is our resident expert, I believe), I think you should be able to install Perl::Critic (which includes the perlcritic command) by installing the RPM package perl-Perl-Critic using your system's package manager, and I'd also install perl-core to get all the Perl core modules installed as well. Assuming the RPM's dependencies are configured correctly, you should get all the required dependencies installed automatically as well.

    If you don't want to modify the system Perl, then the recommended alternatives are: You can install a copy of Perl into your home directory using e.g. perlbrew, into which you can install any CPAN modules you like using cpanm (which I'd recommend) or cpan. The other alternative is local::lib, which lets you install modules to your home directory, but still allows you to use the system Perl (I believe the RPM package for that is perl-local-lib).

    By the way, you said "I ... tried to run ./perlcritic". That probably won't work, since the ./ means "run the executable that is in the current directory", which won't find the perlcritic installed in your PATH - you should run the command as simply "perlcritic" (without the ./).

      Thanks for the response. I will try to install the rpm package for perl_critic and let you know. Worked, thanks a lot.