文章目录

  • 一、关于 CPAN
    • CPAN 安装工具
  • 二、metacpan
    • 使用示例
  • 三、使用 CPAN
    • 使用 cpan 安装第三方库
    • 检查模块是否已安装
    • 查看模块信息
  • 四、使用 CPANM
    • mac 上使用 brew 安装 CPANM
    • 使用 cpanm 安装库

Perl 学习交流QQ群,欢迎加入:909619846


一、关于 CPAN

CPAN(Comprehensive Perl Archive Network : 全面的Perl存档网络)

  • CPAN 官网
    https://www.cpan.org
  • perl-cpan
    https://www.perl.org/about/whitepapers/perl-cpan.html

CPAN 安装工具

CPAN 安装工具有以下几种:

  • CPAN.pm ( cpan)是原始客户端。
    它随Perl一起提供,因此您已经拥有了它.它具有最多的功能.尽管实际上每个人都接受默认安装,但它具有许多配置选项以自定义其工作方式.它可以轻松地与 local :: lib 集成.
  • cpanminus (cpanm) 尝试进行零配置自动为大多数用户执行正确操作的客户端。
    它还可以在资源有限的系统(例如 VPS )上很好地运行.
    它不随Perl一起提供,但易于安装.它可以与 local :: lib 轻松集成.
    它的最大局限性是缺乏配置.如果您想做一些不寻常的事情,它可能不支持.
  • CPANPLUS (cpanp)是一种尝试使Perl程序可以使用的CPAN API使用,而不是您在命令行中使用的应用。
    cpanp shell更像是一种概念证明,我不知道使用它的任何真正优势.

其中 CPANM 是目前最常用的一种

  • metacpan 对 cpanm 的描述
    https://metacpan.org/dist/App-cpanminus/view/bin/cpanm

二、metacpan

https://metacpan.org


使用示例

这里我们搜索 restful,第一个得到 Mojolicious::Plugin::RESTful - A Mojolicious Plugin for RESTful HTTP Actions
https://metacpan.org/pod/Mojolicious::Plugin::RESTful

点击左边 Tools – Install Instructions

我们可以得到两种安装方式: cpanmcpan,下面具体介绍下这两个安装工具的使用


三、使用 CPAN

Mac 预装了 cpan,终端输入 cpan,第一次会提示你一些配置信息

第一次使用

$ cpan
Loading internal logger. Log::Log4perl recommended for better logging CPAN.pm requires configuration, but most of it can be done automatically.If you answer 'no' below, you will enter an interactive dialog for each
configuration option instead.Would you like to configure as much as possible automatically? [yes] yesUse of uninitialized value $what in concatenation (.) or string at /System/Library/Perl/5.30/App/Cpan.pm line 679, <STDIN> line 1.<install_help>Warning: You do not have write permission for Perl library directories.To install modules, you need to configure a local Perl library directory or escalate your privileges.
CPAN can help you by bootstrapping the local::lib module or by configuring itself to use 'sudo' (if available).
You may also resolve this problem manually if you need to customize your setup.What approach do you want?  (Choose 'local::lib', 'sudo' or 'manual')[local::lib] Autoconfiguration complete.Attempting to bootstrap local::lib...Writing /Users/xx/.cpan/CPAN/MyConfig.pm for bootstrap...
commit: wrote '/Users/xx/.cpan/CPAN/MyConfig.pm'
Fetching with LWP: http://www.cpan.org/authors/01mailrc.txt.gz
Reading '/Users/xx/.cpan/sources/authors/01mailrc.txt.gz'
............................................................................DONE
Fetching with LWP: http://www.cpan.org/modules/02packages.details.txt.gz
Reading '/Users/xx/.cpan/sources/modules/02packages.details.txt.gz'Database was generated on Wed, 10 Aug 2022 08:29:03 GMT
..............New CPAN.pm version (v2.34) available.[Currently running version is v2.22]You might want to tryinstall CPANreload cpanto both upgrade CPAN.pm and run the new version without leaving   the current session...............................................................DONE
Fetching with LWP:
http://www.cpan.org/modules/03modlist.data.gz
Reading '/Users/xx/.cpan/sources/modules/03modlist.data.gz'
DONE
Writing /Users/xx/.cpan/Metadata
Fetching with LWP:
http://www.cpan.org/authors/id/H/HA/HAARG/local-lib-2.000029.tar.gz
Fetching with LWP:
HASH(0x7fc8d6af25c8)authors/id/H/HA/HAARG/CHECKSUMS
Fetching with LWP:
HASH(0x7fc8d6af25c8)authors/id/H/HA/HAARG/CHECKSUMS.gz
Fetching with LWP:
http://www.cpan.org/authors/id/H/HA/HAARG/CHECKSUMS
Checksum for /Users/xx/.cpan/sources/authors/id/H/HA/HAARG/local-lib-2.000029.tar.gz ok
Configuring H/HA/HAARG/local-lib-2.000029.tar.gz with Makefile.PL
Attempting to create directory /Users/xx/perl5
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for local::lib
Writing MYMETA.yml and MYMETA.jsonHAARG/local-lib-2.000029.tar.gz/usr/bin/perl Makefile.PL --bootstrap -- OK
Running make for H/HA/HAARG/local-lib-2.000029.tar.gz
cp lib/local/lib.pm blib/lib/local/lib.pm
cp lib/lib/core/only.pm blib/lib/lib/core/only.pm
cp lib/POD2/DE/local/lib.pod blib/lib/POD2/DE/local/lib.pod
cp lib/POD2/PT_BR/local/lib.pod blib/lib/POD2/PT_BR/local/lib.pod
Manifying 4 pod documentsHAARG/local-lib-2.000029.tar.gz/usr/bin/make -- OK
Running make test for HAARG/local-lib-2.000029.tar.gz
PERL_DL_NONLAZY=1 "/usr/bin/perl" "-I/Users/xx/perl5/lib/perl5" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/bad_variables.t ...... ok
t/carp-mismatch.t ...... ok
t/classmethod.t ........ ok
t/de-dup.t ............. ok
t/lib-core-only.t ...... ok
t/pipeline.t ........... ok
t/shell.t .............. ok
t/stackable.t .......... ok
t/subroutine-in-inc.t .. ok
t/taint-mode.t ......... ok
All tests successful.
Files=10, Tests=245,  5 wallclock secs ( 0.06 usr  0.03 sys +  2.21 cusr  1.59 csys =  3.89 CPU)
Result: PASSHAARG/local-lib-2.000029.tar.gz/usr/bin/make test -- OK
Running make install for HAARG/local-lib-2.000029.tar.gz
Manifying 4 pod documents
Installing /Users/xx/perl5/lib/perl5/POD2/PT_BR/local/lib.pod
Installing /Users/xx/perl5/lib/perl5/POD2/DE/local/lib.pod
Installing /Users/xx/perl5/lib/perl5/local/lib.pm
Installing /Users/xx/perl5/lib/perl5/lib/core/only.pm
Installing /Users/xx/perl5/man/man3/lib::core::only.3pm
Installing /Users/xx/perl5/man/man3/POD2::DE::local::lib.3pm
Installing /Users/xx/perl5/man/man3/local::lib.3pm
Installing /Users/xx/perl5/man/man3/POD2::PT_BR::local::lib.3pm
Appending installation info to /Users/xx/perl5/lib/perl5/darwin-thread-multi-2level/perllocal.podHAARG/local-lib-2.000029.tar.gz/usr/bin/make install  -- OKlocal::lib is installed. You must now add the following environment variables
to your shell configuration files (or registry, if you are on Windows) and
then restart your command line shell and CPAN before installing modules:PATH="/Users/xx/perl5/bin${PATH:+:${PATH}}"; export PATH;
PERL5LIB="/Users/xx/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB;
PERL_LOCAL_LIB_ROOT="/Users/xx/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT;
PERL_MB_OPT="--install_base \"/Users/xx/perl5\""; export PERL_MB_OPT;
PERL_MM_OPT="INSTALL_BASE=/Users/xx/perl5"; export PERL_MM_OPT;commit: wrote '/Users/xx/.cpan/CPAN/MyConfig.pm'You can re-run configuration any time with 'o conf init' in the CPAN shell
Terminal does not support AddHistory.To fix enter>  install Term::ReadLine::Perlcpan shell -- CPAN exploration and modules installation (v2.22)
Enter 'h' for help.cpan[1]>  # 这里进入了交互模式

使用 cpan 安装第三方库

安装包位于目录: ~/.cpan/build
相关配置文件为:~/.cpan/FTPstats.yml

方式一:进入交互模式,安装

$ cpan
# $ perl -MCPAN -e shell  效果同上
...
cpan[1]> install Switch
cpan[2]> exit # 退出交互模式

方式二:直接使用 cpan install 安装

$ cpan install Switch$ cpan install XML::LibXML

检查模块是否已安装

perl -e 'use XML::LibXML'

不报错即代表安装成功


查看模块信息

 $ cpan -i Switch

四、使用 CPANM

mac 上使用 brew 安装 CPANM

$ brew install cpanminus

安装成功校验

查看版本信息

$ cpanm  -V
cpanm (App::cpanminus) version 1.9018 (/usr/local/bin/cpanm)
perl version 5.030003 (perl)%Config:archname=darwin-thread-multi-2levelinstallsitelib=/Library/Perl/5.30installsitebin=/usr/local/bininstallman1dir=/usr/share/man/man1installman3dir=/usr/share/man/man3sitearchexp=/Library/Perl/5.30/darwin-thread-multi-2levelsitelibexp=/Library/Perl/5.30vendorarch=/Network/Library/Perl/5.30/darwin-thread-multi-2levelvendorlibexp=/Network/Library/Perl/5.30archlibexp=/System/Library/Perl/5.30/darwin-thread-multi-2levelprivlibexp=/System/Library/Perl/5.30%ENV:@INC:FatPacked::140563055820376=HASH(0x7fd76302be58)/Library/Perl/5.30/darwin-thread-multi-2level/Library/Perl/5.30/Network/Library/Perl/5.30/darwin-thread-multi-2level/Network/Library/Perl/5.30/Library/Perl/Updates/5.30.3/System/Library/Perl/5.30/darwin-thread-multi-2level/System/Library/Perl/5.30/System/Library/Perl/Extras/5.30/darwin-thread-multi-2level/System/Library/Perl/Extras/5.30

查看帮助

$ cpanm -h
Usage: cpanm [options] Module [...]Options:-v,--verbose              Turns on chatty output-q,--quiet                Turns off the most output--interactive             Turns on interactive configure (required for Task:: modules)-f,--force                force install-n,--notest               Do not run unit tests--test-only               Run tests only, do not install-S,--sudo                 sudo to run install commands--installdeps             Only install dependencies--showdeps                Only display direct dependencies--reinstall               Reinstall the distribution even if you already have the latest version installed--mirror                  Specify the base URL for the mirror (e.g. http://cpan.cpantesters.org/)--mirror-only             Use the mirror's index file instead of the CPAN Meta DB-M,--from                 Use only this mirror base URL and its index file--prompt                  Prompt when configure/build/test fails-l,--local-lib            Specify the install base to install modules-L,--local-lib-contained  Specify the install base to install all non-core modules--self-contained          Install all non-core modules, even if they're already installed.--auto-cleanup            Number of days that cpanm's work directories expire in. Defaults to 7Commands:--self-upgrade            upgrades itself--info                    Displays distribution info on CPAN--look                    Opens the distribution with your SHELL-U,--uninstall            Uninstalls the modules (EXPERIMENTAL)-V,--version              Displays software versionExamples:cpanm Test::More                                          # install Test::Morecpanm MIYAGAWA/Plack-0.99_05.tar.gz                       # full distribution pathcpanm http://example.org/LDS/CGI.pm-3.20.tar.gz           # install from URLcpanm ~/dists/MyCompany-Enterprise-1.00.tar.gz            # install from a local filecpanm --interactive Task::Kensho                          # Configure interactivelycpanm .                                                   # install from local directorycpanm --installdeps .                                     # install all the deps for the current directorycpanm -L extlib Plack                                     # install Plack and all non-core deps into extlibcpanm --mirror http://cpan.cpantesters.org/ DBI           # use the fast-syncing mirrorcpanm -M https://cpan.metacpan.org App::perlbrew          # use only this secure mirror and its indexYou can also specify the default options in PERL_CPANM_OPT environment variable in the shell rc:export PERL_CPANM_OPT="--prompt --reinstall -l ~/perl --mirror http://cpan.cpantesters.org"Type `man cpanm` or `perldoc cpanm` for the more detailed explanation of the options.

使用 cpanm 安装库

直接使用 cpanm xx:xxx 就可以安装了,如

cpanm Mojolicious::Plugin::RESTful

你可以在 metacpan 上查看库的信息,然后进行安装
https://metacpan.org


2022-08-11(三)伊织

Perl 学习交流QQ群,欢迎加入:909619846
更多博主的 Perl 文章:https://so.csdn.net/so/search?q=Perl&t=blog&u=lovechris00

Perl 6 - CPAN相关推荐

  1. 杰瑞学Perl之CPAN(1)

    CPAN(Comprehensive Perl Archive Network:全面的Perl存档网络)是查找任何Perl有关的东西的中心仓库.它包含从整个Perl社区收集来的智慧:成百上千的 Per ...

  2. 烂泥:perl中CPAN的安装

    本文首发于烂泥行天下 最近一直在学习nagios监控的知识,因为使用SNMP方式进行监测.而nagios的SNMP监测文件是pl结尾的perl脚本,所以需要安装CPAN. 下面就安装CPAN的安装记录 ...

  3. perl 正则表达式 引擎_Perl 5引擎概述

    perl 正则表达式 引擎 正如我在" 我的DeLorean运行Perl "中所述,切换到Perl极大地提高了我的开发速度和可能性. 在这里,我将更深入地研究Perl 5的设计,以 ...

  4. 编程网站 Perl.com 被劫,售价 19 万美元

    整理 | 郑丽媛 出品 | CSDN(ID:CSDNnews) 1987 年诞生的 Perl,尽管近年来不如 Python 和 Rust 这类年轻的编程语言时常活跃在大众视野,但 33 年后的如今依旧 ...

  5. Perl语言学习总结

    Perl ------practical extraction and report language <一>.实用性摘录与报表语言: <二>.常用到的与perl有关的网站:h ...

  6. 什么是Perl语言?

    perl Perl 最初的设计者为 拉里·沃尔(Larry Wall),它于1987年12月18日发表.Perl借取了C.sed.awk.shell scripting以及很多其他程序语言的特性. P ...

  7. perl 模块使用范例

    已有模块: 说明: 以下例子代码的测试是在FreeBSD & Solaris下进行的,Perl版本为5.005_03. (1) LWP::Simple, get()  (2) Time::Hi ...

  8. Perl模块使用 = 简短例子代码集合(转帖)

    一些常用模块的简单描述 http://www.perldoc.com/perl5.6/pod/perlmodlib.html 在perl 中使用模块: 模块的下载地址:http://www.cpan. ...

  9. [经验总结]Perl模块使用 = 简短例子代码集合

    [原创] Perl模块使用 => 简短例子代码集合! http://www.chinaunix.net 作者:deathcult发表于:2003-09-04 14:59:54 [发表评论] [查 ...

  10. Perl常用模块使用例子

    一些常用模块的简单描述 http://www.perldoc.com/perl5.6/pod/perlmodlib.html 在perl 中使用模块: 模块的下载地址:http://www.cpan. ...

最新文章

  1. 初识微信小程序第一弹
  2. 房地产萧条的两个标志
  3. 微控制器和微处理器的区别
  4. 【NLP】用BERT进行机器阅读理解
  5. Mac下PyCharm CE 配置PyQt5环境
  6. 1.11 多于空间维度的向量组
  7. [有奖励]GeneralUpdate开源项目招募开发者
  8. svm解决兵王问题_机器学习: svm
  9. 知名开源操作系统两大老板闹翻,一位联合创始人被迫退出,道一声:再见
  10. FMPlayer组件说明
  11. 国人常用密码TOP100 FROM THISITE
  12. 利用EnableQ服务政府民意调查
  13. el-progress入门学习
  14. 实现微信浏览器内打开App Store链接
  15. Redis的持久化操作---RDBAOF
  16. LeetCode刷题|36有效的数独
  17. PS轻松制作四种扁平化风格图标
  18. python云计算1_python云计算1
  19. 中断API之enable_irq
  20. 【华为昇腾社区、鹏城实验室】中国软件开源创新大赛·赛道二:任务挑战赛(模型王者挑战赛黄金赛段)

热门文章

  1. Java 二维码及条形码处理
  2. 华硕笔记本开机直接进入bios解决方法
  3. 记一次失败的git截图工具使用经历——shareX
  4. 自学量化投资之旅-学习第一个策略EMV指标
  5. el-upload限制文件大小(图片尺寸)
  6. Urchin = Analytics Google的免费网站统计系统发布
  7. android红外线开发实例,Android实例-红外线操作(XE10.2+小米5)
  8. dubbo admin安装中易踩坑点及解决方法
  9. 2016秋招面经(蘑菇街+BT+网易杭研+CVTE+唯品会)
  10. 使用anysdk打包android渠道