简体   繁体   中英

searching cpan.org from the commandline

I'm wondering if there's a feature to CPAN that allows the user to search all the modules available at CPAN.org.

I could probably just write something that sends the get request and spits back the answers...just wondering if there is already a built in utility...it would be really great.

I like how in debian or ubuntu linux, there is this thing "apt-cache search", or "aptitude search", that shows you which packages are already installed, and which packages are potentially available for you system. It would be a really great thing if there was something like this for perl modules/CPAN.

You can run Perl's CPAN module interactively:

# perl -MCPAN -e shell
Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v1.9800)
Enter 'h' for help.

cpan[1]> i /JSON::XS/
Reading '/home/alt/.cpan/Metadata'
  Database was generated on Wed, 06 Mar 2013 23:07:32 GMT
Module  < Catalyst::Action::Deserialize::JSON::XS (BOBTFISH/Catalyst-Action-REST-1.06.tar.gz)
Module  < Catalyst::Action::Serialize::JSON::XS (BOBTFISH/Catalyst-Action-REST-1.06.tar.gz)
Module  < JSON::XS               (MLEHMANN/JSON-XS-2.33.tar.gz)
Module  < JSON::XS::Boolean      (MLEHMANN/JSON-XS-2.33.tar.gz)
Module  < JSON::XS::VersionOneAndTwo (LBROCARD/JSON-XS-VersionOneAndTwo-0.31.tar.gz)
Module  < Mojo::JSON::XS         (YSYROTA/Mojo-JSON-Any-0.990104.tar.gz)
Module  < Mojo::JSON::XS::_Bool  (VTI/Mojo-JSON-Any-0.990103.tar.gz)
Module  < Sledge::Plugin::JSON::XS (TOKUHIROM/Sledge-Plugin-JSON-XS-0.05.tar.gz)
8 items found

There's also the cpan script that may be in your path. So, instead of typing

perl -MCPAN -eshell

you can just type

cpan

And that drops you into the CPAN shell.

Then, from the CPAN> prompt, you type i /ModuleName/ to search for modules. What would be really nice is to have the cpan script handle the i /ModuleName/ but for now, only -L is available which lists a particular module author's modules.

Yes, there is. What have you tried?

Here's the CPAN manual describing everything you can do from the command line.

Specifically, after you run cpan in interactive mode, m Module::Name will search for a module.

In my opinion, entering the cpan shell is not really "from the commandline".

I needed the ability to pipe the output of cpan to other external commands (grep/awk/sed/etc)

To that end this syntax works

echo 'm /keyword/' | cpan

examples:

-sh-4.2$ echo 'm /SFTP/' | cpan | grep   Recursive
Module  < Net::SFTP::Recursive   (GEOTIGER/Net-SFTP-Recursive-0.12.tar.gz)

or 
-sh-4.2$ echo 'm /SFTP.*Recursive/' | cpan

cpan shell -- CPAN exploration and modules installation (v1.9800)
Enter 'h' for help.

cpan[1]> Reading '/home/myuser/.cpan/Metadata'
  Database was generated on Thu, 14 Oct 2021 17:17:03 GMT
Module id = Net::SFTP::Recursive
    CPAN_USERID  GEOTIGER (Geo Tiger <tiger.geo@gmail.com>)
    CPAN_VERSION undef
    CPAN_FILE    G/GE/GEOTIGER/Net-SFTP-Recursive-0.12.tar.gz
    INST_FILE    (not installed)
cpan[2]> Lockfile removed.

Of course it would be quite easy to create a script to do this

cat << EOF > cpancmd
#!/bin/ksh
echo "\$*" | cpan
EOF
chmod 755 cpancmd
./cpancmd m /SFTP/ | grep Recursive

Or using more specific scripts or aliases to target sub commands "i" or "m" etc..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM