developer tip

설치된 CPAN 모듈 목록은 어떻게 얻습니까?

copycodes 2020. 10. 4. 11:43
반응형

설치된 CPAN 모듈 목록은 어떻게 얻습니까?


노력하는 것 말고

perldoc <module name>

개별적으로 내 마음에 드는 CPAN 모듈이나 파일 시스템을 살펴보고 디렉토리를 살펴보면 어떤 모듈이 설치되어 있는지 알 수 없습니다.

설치된 모든 CPAN 모듈의 큰 목록을 얻는 가장 쉬운 방법은 무엇입니까? 명령 줄 또는 기타에서.


이에 대한 답변은 Perl FAQ에서 찾을 수 있습니다 perldoc -q installed. 요컨대, 이 스레드에서 이전에 다룬 두 가지 변형 을 사용 ExtUtils::Installed하거나 사용 File::Find하는 것으로 귀결됩니다.

"내 시스템에 설치된 모듈을 어떻게 찾습니까?" FAQ 항목을 찾을 수 있습니다. perlfaq3에서. perlfaq 에서 모든 FAQ 답변 목록을 볼 수 있습니다.


perldoc perllocal

편집 : CPAN FAQ 에 (약간) 더 많은 정보가 있습니다.


perldoc -q installed

cpan -l트릭 할 것이라고 주장 하지만 나를 위해 작동하지 않습니다. 다른 옵션 :

cpan -a

설치된 패키지의 멋진 목록을 뱉어 내고 파일에 쓰는 좋은 부작용이 있습니다.


perldoc perllocal이 CPAN을 통해 설치된 모듈에 대해서만보고한다는 점은 주목할 가치가 있습니다. 누군가 수동으로 모듈을 설치하면 찾을 수 없습니다. 또한 여러 사람이 모듈을 설치하고 perllocal.pod가 소스 제어를받는 경우 사람들이 충돌을 잘못 해결하고 목록을 손상시킬 수 있습니다 (예를 들어 여기에서 발생했습니다).

유감스럽게도 솔루션은 File :: Find 또는 이와 유사한 것으로 @INC를 통해 걷는 것처럼 보입니다. 그러나 이는 모듈 만 찾는 것이 아니라 배포판에서 관련 모듈도 찾습니다. 예를 들어 Test :: Harness의 실제 배포 이름과 함께 TAP :: Harness 및 TAP :: Parser를보고합니다 (버전 3 이상이 있다고 가정). 잠재적으로 배포 이름과 일치시키고 일치하지 않는 이름을 버릴 수 있지만 로컬에서 빌드되고 설치된 모듈을 버릴 수 있습니다.

brian d foy의 backpan 인덱싱 작업에는 .pm 파일에 코드를 전달하는 코드가 있어야하며 배포를 유추하려고 시도하지만 패키지에있는 내용이 반드시 설치되어 있지 않기 때문에 때때로 실패합니다 (Devel :: Cover 참조). :: Inc 예).


ExtUtils-Installed를 시도해 볼 수 있지만 .packlists 만 보이 므로 사람들 @INC이 손 으로 물건을 옮긴 모듈을 놓칠 수 있습니다 .

내가 쓴 응용 프로그램 - 모듈 - 리스터를 비 쉘 웹 호스팅 계정에 CGI 스크립트로이 작업을 수행하고 싶어 친구. 모듈 파일을 가져 와서 서버가 CGI 스크립트로 취급 할 파일 이름으로 업로드하면됩니다. 표준 라이브러리 외부에는 종속성이 없습니다. 그대로 사용하거나 코드를 훔치십시오.

모듈 및 해당 버전 목록을 출력합니다.

타이 :: 사이클 1.15
타이 :: IxHash 1.21
타이 :: 토글 1.07
타이 :: ToObject 0.03
시간 :: CTime 99.062201
시간 :: DaysInMonth 99.1117
시간 :: 에포크 0.02
시간 :: 퍼지 0.34
시각 :: JulianDay 2003.1125
시간 :: ParseDate 2006.0814
시간 :: 시간대 2006.0814

이 기능을 cpan도구 의 기능으로 추가하려고 했기 때문에 그렇게 할 것입니다. 지금은이, [시간 통과] 그리고 -l에 스위치를 cpan. 릴리스하기 전에 몇 가지 다른 작업이 있지만 github에 있습니다. 그것을 기다리지 않으려면 -a목록에 Pod를 배치하지만 스위치를 사용하여 자동 번들을 만들 수 있습니다.

행운을 빕니다;


$ for M in `perldoc -t perllocal|grep Module |sed -e 's/^.*" //'`; do V=`perldoc -t perllocal|awk "/$M/{y=1;next}y" |grep VERSION |head -n 1`; printf "%30s %s\n" "$M" "$V"; done |sort
              Class::Inspector     *   "VERSION: 1.28"
                    Crypt::CBC     *   "VERSION: 2.33"
               Crypt::Rijndael     *   "VERSION: 1.11"
                    Data::Dump     *   "VERSION: 1.22"
                   DBD::Oracle     *   "VERSION: 1.68"
                           DBI     *   "VERSION: 1.630"
                   Digest::SHA     *   "VERSION: 5.92"
           ExtUtils::MakeMaker     *   "VERSION: 6.84"
                       install     *   "VERSION: 6.84"
               IO::SessionData     *   "VERSION: 1.03"
               IO::Socket::SSL     *   "VERSION: 2.016"
                          JSON     *   "VERSION: 2.90"
                  MIME::Base64     *   "VERSION: 3.14"
                  MIME::Base64     *   "VERSION: 3.14"
                   Mozilla::CA     *   "VERSION: 20141217"
                   Net::SSLeay     *   "VERSION: 1.68"
                        parent     *   "VERSION: 0.228"
                  REST::Client     *   "VERSION: 271"
                    SOAP::Lite     *   "VERSION: 1.08"
                  Task::Weaken     *   "VERSION: 1.04"
                 Term::ReadKey     *   "VERSION: 2.31"
                Test::Manifest     *   "VERSION: 1.23"
                  Test::Simple     *   "VERSION: 1.001002"
                  Text::CSV_XS     *   "VERSION: 1.16"
                     Try::Tiny     *   "VERSION: 0.22"
                   XML::LibXML     *   "VERSION: 2.0108"
         XML::NamespaceSupport     *   "VERSION: 1.11"
                XML::SAX::Base     *   "VERSION: 1.08"

트릭을 수행하는 스크립트는 다음과 같습니다.

 use ExtUtils::Installed;

 my $inst = ExtUtils::Installed->new();
 my @modules = $inst->modules();
 foreach $module (@modules){
        print $module ." - ". $inst->version($module). "\n";
 }

=head1 ABOUT

This scripts lists installed cpan modules using the ExtUtils modules

=head1 FORMAT

Prints each module in the following format
<name> - <version>

=cut

이를 위해 CPAN 'r'명령을 사용하고 싶습니다. 이전 스타일로 CPAN 셸에 들어갈 수 있습니다.

sudo perl -MCPAN -e shell

또는 대부분의 최신 시스템에는 'cpan'명령이 있으므로이 명령은 셸로 이동합니다.

sudo cpan

(일반 사용자로 실행할 수 있도록 cpan을 설정 한 경우를 제외하고는 일반적으로 'sudo'를 사용하여 루트로 실행하거나 'su-'를 사용하여 루트로 설정해야합니다. 이 컴퓨터에 루트가없는 경우에도 CPAN 셸을 사용하여이 정보를 찾을 수 있지만 모듈을 설치할 수 없으며 처음에 약간의 설정을 거쳐야 할 수 있습니다. 실행하십시오.)

그런 다음 cpan 셸에 들어가면 'r'명령을 사용하여 설치된 모든 모듈과 해당 버전을보고 할 수 있습니다. 따라서 "cpan>"프롬프트에서 'r'을 입력합니다. 설치된 모든 모듈과 버전이 나열됩니다. 사용하다 '?' 더 많은 도움을 받으려면


* nix에서 할 수있는 정말 엉뚱한 방법이 있습니다.별로 신경 쓰지 않는 것 (예 : warnings :: register 등)을 얻을 수 있지만 다음을 통해 액세스 할 수있는 모든 .pm 파일 목록을 제공해야합니다. 펄.


for my $path (@INC) {
    my @list = `ls -R $path/**/*.pm`;
    for (@list) {
        s/$path\///g;
        s/\//::/g;
        s/\.pm$//g;
        print;
    }
}


instmodsh터미널에서 명령 을 사용하여 시스템에 설치된 펄 모듈의 목록을 얻을 수 있습니다 . 출력을 향상시키기 위해 세 가지 옵션을 묻습니다.

   l            - List all installed modules
   m <module>   - Select a module
   q            - Quit the program

perl -MFile::Find=find -MFile::Spec::Functions -Tlwe 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC'

답변은 Perl FAQ 목록 에서 찾을 수 있습니다 .

Perl과 함께 제공되는 훌륭한 문서를 훑어 봐야합니다.

perldoc perltoc

시도 man perllocalperldoc perllocal.


다음 명령을 시도하십시오

instmodsh


Linux / Unix에서는 다음과 같은 간단한 명령을 사용합니다.

perl -e 'print qx/find $_ -name "*.pm"/ foreach ( @INC );' 

모든 폴더를 스캔하고 @INC* .pm 파일을 찾습니다.


I wrote a perl script just yesterday to do exactly this. The script returns the list of perl modules installed in @INC using the '::' as the separator. Call the script using -

perl perlmod.pl

OR

perl perlmod.pl <module name> #Case-insensitive(eg. perl perlmod.pl ftp)

As of now the script skips the current directory('.') since I was having problems with recursing soft-links but you can include it by changing the grep function in line 17 from

  grep { $_ !~ '^\.$' } @INC

to just,

@INC

The script can be found here.


Here is yet another command-line tool to list all installed .pm files:

Find installed Perl modules matching a regular expression

  • Portable (only uses core modules)
  • Cache option for faster look-up's
  • Configurable display options

Here's a Perl one-liner that will print out a list of installed modules:

perl -MExtUtils::Installed -MData::Dumper -e  'my ($inst) = ExtUtils::Installed->new(); print Dumper($inst->modules());'

Just make sure you have Data::Dumper installed.


To walk through the @INC directory trees without using an external program like ls(1), one could use the File::Find::Rule module, which has a nice declarative interface.

Also, you want to filter out duplicates in case previous Perl versions contain the same modules. The code to do this looks like:

#! /usr/bin/perl -l

use strict;
use warnings;
use File::Find::Rule;

my %seen;
for my $path (@INC) {
    for my $file (File::Find::Rule->name('*.pm')->in($path)) {
        my $module = substr($file, length($path)+1);
        $module =~ s/.pm$//;
        $module =~ s{[\\/]}{::}g;
        print $module unless $seen{$module}++;
    }
}

At the end of the run, you also have all your module names as keys in the %seen hash. The code could be adapted to save the canonical filename (given in $file) as the value of the key instead of a count of times seen.


the Perl cookbook contains several iterations of a script "pmdesc" that does what you want. Google-search for "Perl Cookbook pmdesc" and you'll find articles on other Q&A Sites, several code listings on the net, a discussion of the solution, and even some refinements.


cd /the/lib/dir/of/your/perl/installation
perldoc $(find . -name perllocal.pod)

Windows users just do a Windows Explorer search to find it.


The following worked for me.

$ perldoc perllocal | grep Module
$ perldoc perllocal | grep -E 'VERSION|Module'

Try "perldoc -l":

$ perldoc -l Log::Dispatch /usr/local/share/perl/5.26.1/Log/Dispatch.pm


All those who can't install perldoc, or other modules, and want to know what modules are available (CPAN or otherwise), the following works for linux and Mingw32/64:

grep -RhIP '^package [A-Z][\w:]+;' `perl -e 'print join " ",@INC'` | sed 's/package //' | sort | uniq

Yes, it's messy. Yes, it probably reports more than you want. But if you pipe it into a file, you can easily check for, say, which dbm interfaces are present:

 grep -RhIP '^package [A-Z][\w:]+;' `perl -e 'print join " ",@INC'` | sed 's/package //' | sort | uniq > modules-installed
 cat modules-installed | grep -i dbm 

AnyDBM_File;
Memoize::AnyDBM_File;
Memoize::NDBM_File;
Memoize::SDBM_File;
WWW::RobotRules::AnyDBM_File;

Which is why I ended up on this page (disappointed)

(I realise this doesn't answer the OP's question exactly, but I'm posting it for anybody who ended up here for the same reason I did. That's the problem with stack*** it's almost imposisble to find the question you're asking, even when it exists, yet stack*** is nearly always google's top hit!)


Use perldoc -q installed for more information or Just type

perldoc <Module::Name>

As you enter your Perl script you have all the installed modules as .pm files below the folders in @INC so a small bash script will do the job for you:

#!/bin/bash

echo -e -n "Content-type: text/plain\n\n"

inc=`perl -e '$, = "\n"; print @INC;'`

for d in $inc
do
   find $d -name '*.pm'
done

For Linux the easiest way to get is,

dpkg -l | grep "perl"

This works for me

perl -e 'print join("\n",@INC,"")'

This is what I do: perl -M{cpan_module}
If you don't receive any errors there is a good chance that the module is installed.

참고URL : https://stackoverflow.com/questions/115425/how-do-i-get-a-list-of-installed-cpan-modules

반응형