CPAN

最後更新: 2019-10-28

介紹

 

CPAN (Comprehensive Perl Archive Network)

Search: http://search.cpan.org

cpan - easily interact with CPAN from the command line

 


Debian

 

CPAN 是依賴 build-essential package.

apt-get install build-essential

 

Centos6

yum groupinstall "Development Tools"

在 Default 的最少安裝後, 它會安裝 95 個 Package, Total download size: 82 M, Installed size: 235 M

安裝 cpan

yum install cpan

# 好多 package 都會叫你要裝 YAML

yum install perl-YAML

Check version

cpan -v

/usr/bin/cpan script version 1.9, CPAN.pm version 1.9402

 


進入 cpan 的 shell

 

# perl -MCPAN -e shell

Are you ready for manual configuration? [yes] no

# 安裝 Package

cpan> install File::Scan::ClamAV

相當於

cpan -i File::Scan::ClamAV

# Check Package Version

perl -MCGI -e 'print $CGI::VERSION'

 


Useful Opts

 

-n, --notest       # Skip the testing of modules.

Use this only when you just want to save time for installing hundreds of distributions to the same perl and architecture

you've already tested to make sure it builds fine.

# Show the "Changes" files for the specified modules

-C module

# Show the module details.

-D module

# recompile dynamically loaded modules

cpan -r

 


Tools

 

cpanm

 from App::cpanminus is a script to get, unpack, build and install modules from CPAN.

local::lib

 enables you to install modules into a specified directory, without requiring root or administrator access.

perlbrew

 A tool to manage multiple perl installations in your $HOME directory. They are completely isolated perl

 


cpanm

 

Install cpanm to make installing other modules easier

# Centos6 沒有 perl-App-cpanminu Package

yum install cpan

cpan -i App::cpanminus

# Usage

cpanm Module::Name

 


Create an autobundle

 

easily re-install all CPAN modules to my newly installed perl

autobundle writes a bundle file into the "$CPAN::Config->{cpan_home}/Bundle" directory.

The file contains a list of all modules that are both available from CPAN and currently installed within @INC.

The name of the bundle file is based on the current date and a counter.

Old System

# -a  Creates the CPAN.pm autobundle with CPAN::Shell->autobundle.

cpan -a

Creating autobundle in /Bundle
CPAN: Storable loaded ok (v2.20)
Going to read '/root/.cpan/Metadata'
  Database was generated on Mon, 28 Oct 2019 06:17:03 GMT

Package namespace         installed    latest  in CPAN file
App::cpanminus               1.7044    1.7044  MIYAGAWA/App-cpanminus-1.7044.tar.gz
Archive::Tar                   1.58      2.32  BINGOS/Archive-Tar-2.32.tar.gz
...

Wrote bundle file
    /root/.cpan/Bundle/Snapshot_2019_10_28_00.pm

New System

# install modules ( sole -i is optional )

# copy "Snapshot_2019_10_28_00.pm" to "~/.cpan/Bundle" in New System

cpan Bundle::Snapshot_2019_10_28_00.pm

 


設定

 

# 保存 setting

cpan[1]> o conf commit

commit: wrote '/usr/share/perl5/CPAN/Config.pm'

# To reconfigure CPAN

o conf init

 


Force install

 

cpan -fi pkg_name

 


Troubleshoot

 

[1] imapsync --tests 見 Error

...
ok 846 - get_options cgi context: no CGI param => undef
Undefined subroutine CGI::multi_param
 at /usr/bin/imapsync line 15095
# Tests were run but no plan was declared and done_testing() was not seen.

原因

CGI version > 4.08       # Centos6 的  "perl-CGI" Version 只有 3.51-144.el6

Fix

# yum remove perl-HTML-Parser perl-libwww-perl  perl-CGI

cpanm install CGI

 


ExtUtils::Embed

 

ExtUtils::Embed is a dual-lifed module, meaning it's distributed as part of the perl distribution as well as in a second distribution.

cpanm is trying to install ExtUtils::Embed by installing the perl distribution instead of the ExtUtils-Embed distribution.

cpanm is wisely unwilling to upgrade perl itself.

 


 

Creative Commons license icon Creative Commons license icon