CPAN(3perl)

🌸 CPAN 🌸

okay bestie, welcome to CPAN(3perl) β€” from the Perl Programmers Reference Guide. this is the whole CPAN module, the one that does querying, downloading, and building of perl modules from CPAN sites. buckle up, it's a long one πŸ’–


✨ NAME ✨

CPAN β€” query, download and build perl modules from CPAN sites πŸ¦‹


πŸŽ€ SYNOPSIS πŸŽ€

Interactive mode, the vibe:

perl -MCPAN -e shell

--or--

cpan

Basic commands, the receipts:

# Modules:

cpan> install Acme::Meta                       # in the shell

CPAN::Shell->install("Acme::Meta");            # in perl

# Distributions:

cpan> install NWCLARK/Acme-Meta-0.02.tar.gz    # in the shell

CPAN::Shell->
  install("NWCLARK/Acme-Meta-0.02.tar.gz");    # in perl

# module objects:

$mo = CPAN::Shell->expandany($mod);
$mo = CPAN::Shell->expand("Module",$mod);      # same thing

# distribution objects:

$do = CPAN::Shell->expand("Module",$mod)->distribution;
$do = CPAN::Shell->expandany($distro);         # same thing
$do = CPAN::Shell->expand("Distribution",
                          $distro);            # same thing

πŸ’… DESCRIPTION πŸ’…

so the CPAN module basically automates β€” or at minimum simplifies β€” the make and install of perl modules and extensions. it's giving personal assistant energy fr fr. it comes with some very primitive searching capabilities and it knows how to use LWP, HTTP::Tiny, Net::FTP, plus certain external download clients, all to fetch distributions off the net 🌈

those get fetched from one or more mirrored CPAN (Comprehensive Perl Archive Network) sites and unpacked in a dedicated directory ✨

the CPAN module also supports named and versioned bundles of modules. bundles make handling sets of related modules way simpler. see Bundles below πŸ‘‘

the package contains a session manager and a cache manager. the session manager keeps track of what has been fetched, built, and installed in the current session. the cache manager keeps track of the disk space occupied by the make processes and deletes excess space using a simple FIFO mechanism 🧚

every method it provides is accessible both in a programmer style and in an interactive shell style πŸ’œ

🐚 CPAN::shell([$prompt, $command]) Starting Interactive Mode 🐚

get into interactive mode by running

perl -MCPAN -e shell

or

cpan

which drops you into a readline interface. if Term::ReadKey and either Term::ReadLine::Perl or Term::ReadLine::Gnu are installed, then history and command completion are supported πŸ”₯

once you're at the command line, type h for a one-page help screen. the rest should be self-explanatory, iykyk ✨

the function call shell takes two optional arguments: one is the prompt, the second is the default initial command line (that second one only works if a real ReadLine interface module is installed) 🫢

the most common uses of the interactive modes are:

πŸ” Searching for authors, bundles, distribution files and modules

there are corresponding one-letter commands a, b, d, and m for each of the four categories, and another one, i, for any of the mentioned four. each of the four entities is implemented as a class with slightly differing methods for displaying an object πŸ‘‘

arguments to these commands are either strings exactly matching the identification string of an object, or regular expressions matched case-insensitively against various attributes of the objects. the parser only recognizes a regular expression when you enclose it with slashes πŸ’…

the principle is that the number of objects found influences how an item is displayed. if the search finds one item, the result is displayed with the rather verbose method as_string, but if more than one is found, each object is displayed with the terse method as_glimpse ✨

examples:

cpan> m Acme::MetaSyntactic
Module id = Acme::MetaSyntactic
    CPAN_USERID  BOOK (Philippe Bruhat (BooK) <[...]>)
    CPAN_VERSION 0.99
    CPAN_FILE    B/BO/BOOK/Acme-MetaSyntactic-0.99.tar.gz
    UPLOAD_DATE  2006-11-06
    MANPAGE      Acme::MetaSyntactic - Themed metasyntactic variables names
    INST_FILE    /usr/local/lib/perl/5.10.0/Acme/MetaSyntactic.pm
    INST_VERSION 0.99
cpan> a BOOK
Author id = BOOK
    EMAIL        [...]
    FULLNAME     Philippe Bruhat (BooK)
cpan> d BOOK/Acme-MetaSyntactic-0.99.tar.gz
Distribution id = B/BO/BOOK/Acme-MetaSyntactic-0.99.tar.gz
    CPAN_USERID  BOOK (Philippe Bruhat (BooK) <[...]>)
    CONTAINSMODS Acme::MetaSyntactic Acme::MetaSyntactic::Alias [...]
    UPLOAD_DATE  2006-11-06
cpan> m /lorem/
Module  = Acme::MetaSyntactic::loremipsum (BOOK/Acme-MetaSyntactic-0.99.tar.gz)
Module    Text::Lorem            (ADEOLA/Text-Lorem-0.3.tar.gz)
Module    Text::Lorem::More      (RKRIMEN/Text-Lorem-More-0.12.tar.gz)
Module    Text::Lorem::More::Source (RKRIMEN/Text-Lorem-More-0.12.tar.gz)
cpan> i /berlin/
Distribution    BEATNIK/Filter-NumberLines-0.02.tar.gz
Module  = DateTime::TimeZone::Europe::Berlin (DROLSKY/DateTime-TimeZone-0.7904.tar.gz)
Module    Filter::NumberLines    (BEATNIK/Filter-NumberLines-0.02.tar.gz)
Author          [...]

these examples illustrate several aspects: the first three queries target modules, authors, or distros directly and yield exactly one result. the last two use regular expressions and yield several results. the last one targets all of bundles, modules, authors, and distros simultaneously. when more than one result is available, they are printed in one-line format πŸ’–

πŸ“¦ get, make, test, install, clean modules or distributions

these commands take any number of arguments and investigate what is necessary to perform the action. argument processing goes like this:

known module name in format Foo/Bar.pm   module
other embedded slash                     distribution
  - with trailing slash dot              directory
enclosing slashes                        regexp
known module name in format Foo::Bar     module

if the argument is a distribution file name (recognized by embedded slashes), it is processed. if it's a module, CPAN determines the distribution file in which this module is included and processes that, following any dependencies named in the module's META.yml or Makefile.PL (this behavior is controlled by the configuration parameter prerequisites_policy). if an argument is enclosed in slashes it is treated as a regular expression: it is expanded and if the result is a single object (distribution, bundle or module), this object is processed πŸ‘‘

example:

install Dummy::Perl                   # installs the module
install AUXXX/Dummy-Perl-3.14.tar.gz  # installs that distribution
install /Dummy-Perl-3.14/             # same if the regexp is unambiguous

get downloads a distribution file and untars or unzips it, make builds it, test runs the test suite, and install installs it πŸ¦‹

any make or test is run unconditionally. an

install <distribution_file>

is also run unconditionally. but for

install <module>

CPAN checks whether an install is needed and prints module up to date if the distribution file containing the module doesn't need updating ✨

CPAN also keeps track of what it has done within the current session and doesn't try to build a package a second time regardless of whether it succeeded or not. it does not repeat a test run if the test has been run successfully before. same for install runs πŸ’…

the force pragma may precede another command (currently: get, make, test, or install) to execute the command from scratch and attempt to continue past certain errors. see the section below on the force and the fforce pragma πŸ”₯

the notest pragma skips the test part in the build process.

example:

cpan> notest install Tk

a clean command results in a

make clean

being executed within the distribution file's working directory 🧚

πŸ“– readme, perldoc, look module or distribution

readme displays the README file of the associated distribution. Look gets and untars (if not yet done) the distribution file, changes to the appropriate directory and opens a subshell process in that directory. perldoc displays the module's pod documentation in html or plain text format 🌸

πŸ“‚ ls author / ls globbing_expression

the first form lists all distribution files in and below an author's CPAN directory as stored in the CHECKSUMS files distributed on CPAN. the listing recurses into subdirectories πŸ‘‘

the second form limits or expands the output with shell globbing, like in the following examples:

ls JV/make*
ls GSAR/*make*
ls */*make*

the last example is very slow and outputs extra progress indicators that break the alignment of the result 😭

note that globbing only lists directories explicitly asked for, for example FOO/* will not list FOO/bar/Acme-Sthg-n.nn.tar.gz. this may be regarded as a bug that may be changed in some future version πŸ’€

πŸ’” failed

the failed command reports all distributions that failed on one of make, test or install for some reason in the currently running shell session πŸ™ˆ

πŸ’Ύ Persistence between sessions

if the YAML or the YAML::Syck module is installed, a record of the internal state of all modules is written to disk after each step. the files contain a signature of the currently running perl version for later perusal ✨

if the configurations variable build_dir_reuse is set to a true value, then CPAN.pm reads the collected YAML files. if the stored signature matches the currently running perl, the stored state is loaded into memory such that persistence between sessions is effectively established πŸ”₯

πŸ’ͺ The force and the fforce pragma

to speed things up in complex installation scenarios, CPAN.pm keeps track of what it has already done and refuses to do some things a second time. a get, a make, and an install are not repeated. a test is repeated only if the previous test was unsuccessful. the diagnostic message when CPAN.pm refuses to do something a second time is one of Has already been "unwrapped|made|tested successfully" or something similar. another situation where CPAN refuses to act is an install if the corresponding test was not successful πŸ‘‘

in all these cases, the user can override this stubborn behaviour by prepending the command with the word force, for example:

cpan> force get Foo
cpan> force make AUTHOR/Bar-3.14.tar.gz
cpan> force test Baz
cpan> force install Acme::Meta

each forced command is executed with the corresponding part of its memory erased πŸ’…

The "fforce" pragma is like the "force get" but on steroids bestie β€” it wipes the whole memory first and then does whatever action you asked for, which basically restarts the entire get/make/test/install situation from absolute zero. Fresh slate. Factory reset. We love a clean slate πŸ’…

πŸŽ€ Lockfile πŸŽ€

Interactive sessions keep a lockfile, and by default it lives at ~/.cpan/.lock. Batch jobs can just vibe without a lockfile and never bother each other. Iconic. Multiprocessing behavior.

When another process is holding the lockfile, the shell will offer to run in downgraded mode. Heads up though: this is an experimental feature and it has not been tested very well yet 😭. In that downgraded second shell: no writing to the history file, no using the metadata file, and you get a different prompt. So like, it's giving "guest mode".

πŸ¦‹ Signals πŸ¦‹

CPAN.pm installs signal handlers for SIGINT and SIGTERM. While you're chilling in the cpan-shell, the intent is that you can hit ^C any time and bounce right back to the cpan-shell prompt. A SIGTERM makes the cpan-shell clean up and leave the shell loop. And if you wanna fake a SIGTERM, you can send two consecutive SIGINTs β€” which usually just means pressing ^C twice. Two taps and it's gone ✨

CPAN.pm ignores SIGPIPE. If the user sets inactivity_timeout, then a SIGALRM is used during the run of the perl Makefile.PL or perl Build.PL subprocess. A SIGALRM is also used during module version parsing, and that one is controlled by version_timeout.

πŸ’– CPAN::Shell πŸ’–

The commands available in the shell interface are methods in the package CPAN::Shell. When you enter the shell command, your input gets split by the Text::ParseWords::shellwords() routine, which acts like most shells do. The first word is read as the method to be invoked, and all the rest of the words are treated as that method's arguments. Continuation lines? Supported β€” just end a line with a literal backslash \. Periodt.

🌸 autobundle 🌸

autobundle writes a bundle file into the $CPAN::Config->{cpan_home}/Bundle directory. That file contains a list of all the modules that are both available from CPAN and currently installed within @INC. Duplicates of each distribution are suppressed. The bundle file's name is based on the current date and a counter, like Bundle/Snapshot_2012_05_21_00.pm. You can reinstall it by running cpan Bundle::Snapshot_2012_05_21_00, or by installing Bundle::Snapshot_2012_05_21_00 from the CPAN shell.

Return value: the path to the file that got written. Baby's got receipts.

🧚 hosts 🧚

Note: this feature is still in alpha state and may change in future versions of CPAN.pm

This command gives you a statistical overview over recent download activities. The data for it is collected in the YAML file FTPstats.yml inside your cpan_home directory. If no YAML module is configured, or YAML isn't installed, or if ftpstats_size is set to a value <=0, then no stats are provided. Sorry bestie, no data, no drama.

πŸ‘‘ install_tested πŸ‘‘

Installs all distributions that have been tested successfully but have not yet been installed. See also is_tested.

⭐ is_tested ⭐

Lists all build directories of distributions that have been tested successfully but have not yet been installed. See also install_tested. They're a matching set, fr fr 🫢

🌈 mkmyconfig 🌈

mkmyconfig() writes your own CPAN::MyConfig file into your ~/.cpan/ directory, so you can save your very own preferences instead of the system-wide ones. Main character customization energy.

πŸ’€ r [Module|/Regexp/]... πŸ’€

Scans the current perl installation for modules that have a newer version available on CPAN and hands you a list of them. Called with no argument, all potential upgrades get listed; called with arguments, the list is filtered down to the modules and regexps you gave as arguments.

The listing looks something like this:

  Package namespace         installed    latest  in CPAN file
  CPAN                        1.94_64    1.9600  ANDK/CPAN-1.9600.tar.gz
  CPAN::Reporter               1.1801    1.1902  DAGOLDEN/CPAN-Reporter-1.1902.tar.gz
  YAML                           0.70      0.73  INGY/YAML-0.73.tar.gz
  YAML::Syck                     1.14      1.17  AVAR/YAML-Syck-1.17.tar.gz
  YAML::Tiny                     1.44      1.50  ADAMK/YAML-Tiny-1.50.tar.gz
  CGI                            3.43      3.55  MARKSTOS/CGI.pm-3.55.tar.gz
  Module::Build::YAML            1.40      1.41  DAGOLDEN/Module-Build-0.3800.tar.gz
  TAP::Parser::Result::YAML      3.22      3.23  ANDYA/Test-Harness-3.23.tar.gz
  YAML::XS                       0.34      0.35  INGY/YAML-LibYAML-0.35.tar.gz

It suppresses duplicates in the in CPAN file column, so distributions with tons of upgradeable modules only show up once. Slay.

Note that the list is not sorted. So don't come for the ordering, it's not that kind of party.

πŸ”₯ recent EXPERIMENTAL COMMAND πŸ”₯

The recent command downloads a list of recent uploads to CPAN and displays them slowly. While the command is running, a $SIG{INT} exits the loop after the current item has been displayed.

Note: This command requires XML::LibXML installed.
Note: This whole command is currently just a hack and will probably change in future versions of CPAN.pm, but the general approach will likely remain.
Note: See also smoke.

πŸŽ€ recompile πŸŽ€

recompile() is a special command that takes no argument and runs the make/test/install cycle with brute force over all installed dynamically loadable extensions (a.k.a. XS modules), with 'force' in effect. The whole point of this command is to finish a network installation. Picture it: you've got a common source tree for two different architectures. You decide to do a completely independent fresh installation. You start on one architecture with help from a Bundle file produced earlier. CPAN installs the entire Bundle for you, but when you try to repeat the job on the second architecture, CPAN responds with a "Foo up to date" message for all the modules 😭. So you invoke CPAN's recompile on the second architecture and boom β€” you're done.

Another popular use for recompile is as a rescue in case your perl breaks binary compatibility. If one of the modules CPAN uses is itself depending on binary compatibility (meaning you can't run CPAN commands at all), then you should try the CPAN::Nox module for recovery. Save that one for emergencies bestie πŸ’œ

πŸ“ report Bundle|Distribution|Module πŸ“

The report command temporarily turns on the test_report config variable, then runs the force test command with whatever arguments you gave it. The force pragma reruns the tests and repeats every step that might have failed before. Round two, but make it thorough.

⚠️ smoke EXPERIMENTAL COMMAND ⚠️

* WARNING: this command downloads and executes software from CPAN to your computer of completely unknown status. You should never do this with your normal account and better have a dedicated well separated and secured machine to do this. *

Okay so smoke takes the list of recent uploads to CPAN as provided by the recent command and tests them all. While the command is running, $SIG{INT} is defined to mean that the current item shall be skipped.

Note: This whole command is currently just a hack and will probably change in future versions of CPAN.pm, but the general approach will likely remain.
Note: See also recent.

πŸ¦‹ upgrade [Module|/Regexp/]... πŸ¦‹

The upgrade command first runs an r command with the arguments you gave it, and then installs the newest versions of all the modules that got listed by that. Two-for-one, we love an efficient queen.


πŸ’… The four "CPAN::*" Classes: Author, Bundle, Module, Distribution πŸ’…

Even though it might be considered internal, the class hierarchy does matter, both for users and for programmers. CPAN.pm deals with those four classes up there, and all of them share a set of methods. Classical single polymorphism is in effect. A metaclass object registers all objects of all kinds and indexes them with a string. The strings that reference objects have a separated namespace (well β€” not completely separated, let's be honest):

          Namespace                         Class

    words containing a "/" (slash)      Distribution
     words starting with Bundle::          Bundle
           everything else            Module or Author

Modules know their associated Distribution objects. They always refer to the most recent official release. Developers may mark their releases as unstable development versions β€” by inserting an underscore into the module version number, which will also be reflected in the distribution name when you run 'make dist' β€” so the really hottest and newest distribution is not always the default. If a module Foo is circulating on CPAN in both version 1.23 and 1.23_90, CPAN.pm offers you a convenient way to install version 1.23 by saying

    install Foo

That would install the complete distribution file (say BAR/Foo-1.23.tar.gz) with all its accompanying material. But if you'd like to install version 1.23_90, you need to know where the distribution file lives on CPAN relative to the authors/id/ directory. If the author is BAR, this might be BAR/Foo-1.23_90.tar.gz; so you would have to say

    install BAR/Foo-1.23_90.tar.gz

The first example is driven by an object of the class CPAN::Module, the second by an object of class CPAN::Distribution. Different class, different rules πŸ’…

🌿 Integrating local directories 🌿

Note: this feature is still in alpha state and may change in future versions of CPAN.pm

Distribution objects are normally distributions from the CPAN, but there's a slightly degenerate case for Distribution objects too: projects held on your local disk. These distribution objects have the same name as the local directory and they end with a dot. A dot all by itself is also allowed, and it means the current directory at the time CPAN.pm was used. All actions β€” make, test, install, the whole squad β€” are applied directly to that directory.

This gives the command cpan . a genuinely interesting touch: while the normal mantra of installing a CPAN module without CPAN.pm is one of

    perl Makefile.PL                 perl Build.PL
           ( go and get prerequisites )
    make                             ./Build
    make test                        ./Build test
    make install                     ./Build install

the command cpan . does all of this at once. It figures out which of the two mantras is appropriate, fetches and installs all prerequisites, takes care of them recursively, and finally finishes the installation of the module in the current directory β€” be it a CPAN module or not. It's giving "one command to rule them all" 😭✨

The typical usage case is for private modules, or for working copies of projects from remote repositories that are sitting on the local disk.

πŸ’œ Redirection πŸ’œ

The usual shell redirection symbols " | " and ">" are recognized by the cpan shell only when surrounded by whitespace. So piping to a pager or redirecting output into a file works somewhat like in a normal shell, with the stipulation that you must type extra spaces. Spaces are not optional here bestie, the shell is picky πŸ™ˆ

πŸŽ€ Plugin support EXPERIMENTAL πŸŽ€

Plugins are objects that implement any of currently eight methods:

  pre_get
  post_get
  pre_make
  post_make
  pre_test
  post_test
  pre_install
  post_install

The plugin_list configuration parameter holds a list of strings of the form

  Modulename=arg0,arg1,arg2,arg3,...

e.g.:

  CPAN::Plugin::Flurb=dir,/opt/pkgs/flurb/raw,verbose,1

okay bestie, so like… at run time, every single plugin in that list gets instantiated as a singleton object β€” and the way it does that is basically running the equivalent of this lil pseudo code situation:

my $plugin = <string representation from config>;
<generate Modulename and arguments from $plugin>;
my $p = $instance{$plugin} ||= Modulename->new($arg0,$arg1,...);

Those generated singletons? They stay from the moment they're made all the way to the end of the shell session, no cap. And <plugin_list> can be reconfigured literally whenever, at any point, at run time. πŸ¦‹

While the cpan shell is running, it checks all activated plugins at each of the 8 reference points listed above, and runs the respective method if that object actually implements it. The method gets called with the active CPAN::Distribution object passed in as an argument. ✨


🌸 CONFIGURATION 🌸

So when you use the CPAN module for the first time, a configuration dialogue pops up and tries to figure out a couple of site specific options. The result of that little chat gets stored in a hash reference $CPAN::Config, inside the file CPAN/Config.pm. πŸ’…

Default values defined in CPAN/Config.pm can be overridden in a user specific file: CPAN/MyConfig.pm. Bestie, you want to put that file in "$HOME/.cpan/CPAN/MyConfig.pm", because "$HOME/.cpan" gets added to the search path of the CPAN module before the use() or require() statements. Also the mkmyconfig command will literally write this file for you, so… slay. πŸŽ€

Now if you want to keep your own CPAN/MyConfig.pm somewhere else, you should load it before loading CPAN.pm, like:

perl -I/tmp/somewhere -MCPAN::MyConfig -MCPAN -eshell
--or--
perl -I/tmp/somewhere -MCPAN::MyConfig -S cpan

And once you're in the shell, you can change your config however you like, bestie. πŸ‘‘

The o conf command has various bells and whistles, and honestly? It's giving main character energy:

completion support

If you have a ReadLine module installed, you can hit Tab at any point of the commandline and o conf will offer you completion for the built-in subcommands and/or config variable names. Obsessed. πŸ’–

displaying some help: o conf help

Displays a short help. Simple as that.

displaying current values: o conf [KEY]

Displays the current value(s) for this config variable. Without KEY, it displays all subcommands and config variables.

Example:

o conf shell

If KEY starts and ends with a slash, the string in between is treated as a regular expression, and only keys matching that regexp get displayed.

Example:

o conf /color/

changing of scalar values: o conf KEY VALUE

Sets the config variable KEY to VALUE. The empty string can be specified as usual in shells, with '' or "".

Example:

o conf wget /usr/bin/wget

changing of list values: o conf KEY SHIFT|UNSHIFT|PUSH|POP|SPLICE|LIST

If a config variable name ends with "list", it is a list. o conf KEY shift removes the first element of the list, o conf KEY pop removes the last element of the list. o conf KEYS unshift LIST prepends a list of values to the list, o conf KEYS push LIST appends a list of valued to the list. πŸ“

Likewise, o conf KEY splice LIST passes the LIST to the corresponding splice command.

Finally, any other list of arguments is taken as a new list value for the KEY variable, discarding the previous value. Bye to the old one, periodt.

Examples:

o conf urllist unshift http://cpan.dev.local/CPAN
o conf urllist splice 3 1
o conf urllist http://cpan1.local http://cpan2.local ftp://ftp.perl.org

reverting to saved: o conf defaults

Reverts all config variables to the state in the saved config file. Undo button vibes. πŸ™ˆ

saving the config: o conf commit

Saves all config variables to the current config file (that's CPAN/Config.pm or CPAN/MyConfig.pm that was loaded at start). πŸ’Ύ

The configuration dialog can be started any time later again by issuing the command o conf init in the CPAN shell. And if you only want a subset of the configuration dialog, you can run it by issuing o conf init WORD, where WORD is any valid config variable or a regular expression. 🧚

✨ Config Variables ✨

The following keys in the hash reference $CPAN::Config are currently defined:

  • allow_installing_module_downgrades β€” allow or disallow installing module downgrades yes we're going backwards on purpose bestie
  • allow_installing_outdated_dists β€” allow or disallow installing modules that are indexed in the cpan index pointing to a distro with a higher distro-version number
  • applypatch β€” path to external prg
  • auto_commit β€” commit all changes to config variables to disk
  • build_cache β€” size of cache for directories to build modules
  • build_dir β€” locally accessible directory to build modules
  • build_dir_reuse β€” boolean if distros in build_dir are persistent
  • build_requires_install_policy β€” to install or not to install when a module is only needed for building. yes|no|ask/yes|ask/no
  • bzip2 β€” path to external prg
  • cache_metadata β€” use serializer to cache metadata
  • check_sigs β€” if signatures should be verified
  • cleanup_after_install β€” remove build directory immediately after a successful install and remember that for the duration of the session
  • colorize_debug β€” Term::ANSIColor attributes for debugging output
  • colorize_output β€” boolean if Term::ANSIColor should colorize output
  • colorize_print β€” Term::ANSIColor attributes for normal output
  • colorize_warn β€” Term::ANSIColor attributes for warnings
  • commandnumber_in_prompt β€” boolean if you want to see current command number
  • commands_quote β€” preferred character to use for quoting external commands when running them. Defaults to double quote on Windows, single tick everywhere else; can be set to space to disable quoting
  • connect_to_internet_ok β€” whether to ask if opening a connection is ok before urllist is specified
  • cpan_home β€” local directory reserved for this package
  • curl β€” path to external prg
  • dontload_hash β€” DEPRECATED let her rest 😴
  • dontload_list β€” arrayref: modules in the list will not be loaded by the CPAN::has_inst() routine
  • ftp β€” path to external prg
  • ftp_passive β€” if set, the environment variable FTP_PASSIVE is set for downloads
  • ftp_proxy β€” proxy host for ftp requests
  • ftpstats_period β€” max number of days to keep download statistics
  • ftpstats_size β€” max number of items to keep in the download statistics
  • getcwd β€” see below fr fr it has its own little section
  • gpg β€” path to external prg
  • gzip β€” location of external program gzip
  • halt_on_failure β€” stop processing after the first failure of queued items or dependencies
  • histfile β€” file to maintain history between sessions
  • histsize β€” maximum number of lines to keep in histfile
  • http_proxy β€” proxy host for http requests
  • inactivity_timeout β€” breaks interactive Makefile.PLs or Build.PLs after this many seconds inactivity. Set to 0 to disable timeouts.
  • index_expire β€” refetch index files after this many days
  • inhibit_startup_message β€” if true, suppress the startup message
  • keep_source_where β€” directory in which to keep the source (if we do)
  • load_module_verbosity β€” report loading of optional modules used by CPAN.pm
  • lynx β€” path to external prg
  • make β€” location of external make program
  • make_arg β€” arguments that should always be passed to 'make'
  • make_install_make_command β€” the make command for running 'make install', for example 'sudo make'
  • make_install_arg β€” same as make_arg for 'make install'
  • makepl_arg β€” arguments passed to 'perl Makefile.PL'
  • mbuild_arg β€” arguments passed to './Build'
  • mbuild_install_arg β€” arguments passed to './Build install'
  • mbuild_install_build_command β€” command to use instead of './Build' when we are in the install stage, for example 'sudo ./Build'
  • mbuildpl_arg β€” arguments passed to 'perl Build.PL'
  • ncftp β€” path to external prg
  • ncftpget β€” path to external prg
  • no_proxy β€” don't proxy to these hosts/domains (comma separated list) not me ghosting a proxy on purpose ✨
  • pager β€” location of external program more (or any pager)
  • password β€” your password if you CPAN server wants one
  • patch β€” path to external prg
  • patches_dir β€” local directory containing patch files
  • perl5lib_verbosity β€” verbosity level for PERL5LIB additions
  • plugin_list β€” list of active hooks (see Plugin support above and the CPAN::Plugin module)
  • prefer_external_tar β€” per default all untar operations are done with Archive::Tar; by setting this variable to true the external tar command is used if available
  • prefer_installer β€” legal values are MB and EUMM: if a module comes with both a Makefile.PL and a Build.PL, use the former (EUMM) or the latter (MB); if the module comes with only one of the two, that one will be used no matter the setting
  • prerequisites_policy β€” what to do if you are missing module prerequisites ('follow' automatically, 'ask' me, or 'ignore'). For 'follow', also sets PERL_AUTOINSTALL and PERL_EXTUTILS_AUTOINSTALL for "--defaultdeps" if not already set
  • prefs_dir β€” local directory to store per-distro build options
  • proxy_user β€” username for accessing an authenticating proxy
  • proxy_pass β€” password for accessing an authenticating proxy
  • pushy_https β€” use https to cpan.org when possible, otherwise use http to cpan.org and issue a warning
  • randomize_urllist β€” add some randomness to the sequence of the urllist
  • recommends_policy β€” whether recommended prerequisites should be included
  • scan_cache β€” controls scanning of cache ('atstart', 'atexit' or 'never')
  • shell β€” your favorite shell main character choice tbh
  • show_unparsable_versions β€” boolean if r command tells which modules are versionless
  • show_upload_date β€” boolean if commands should try to determine upload date
  • show_zero_versions β€” boolean if r command tells for which modules $version==0
  • suggests_policy β€” whether suggested prerequisites should be included
  • tar β€” location of external program tar
  • tar_verbosity β€” verbosity level for the tar command
  • term_is_latin β€” deprecated: if true Unicode is translated to ISO-8859-1 (and nonsense for characters outside latin range) ma'am this is not it
  • term_ornaments β€” boolean to turn ReadLine ornamenting on/off
  • test_report β€” email test reports (if CPAN::Reporter is installed)
  • trust_test_report_history β€” skip testing when previously tested ok (according to CPAN::Reporter history)
  • unzip β€” location of external program unzip
  • urllist β€” arrayref to nearby CPAN sites (or equivalent locations)
  • urllist_ping_external β€” use external ping command when autoselecting mirrors
  • urllist_ping_verbose β€” increase verbosity when autoselecting mirrors
  • use_prompt_default β€” set PERL_MM_USE_DEFAULT for configure/make/test/install
  • use_sqlite β€” use CPAN::SQLite for metadata storage (fast and lean) fast AND lean, she ate πŸ’…
  • username β€” your username if you CPAN server wants one
  • version_timeout β€” stops version parsing after this many seconds. Default is 15 secs. Set to 0 to disable.
  • wait_list β€” arrayref to a wait server to try (See CPAN::WAIT)
  • wget β€” path to external prg
  • yaml_load_code β€” enable YAML code deserialisation via CPAN::DeferredCode
  • yaml_module β€” which module to use to read/write YAML files

okay bestie. You can set and query each of these options interactively in the cpan shell with the o conf or the o conf init command as specified below. πŸ’…

  • "o conf <scalar option>" β€” prints the current value of the scalar option
  • "o conf <scalar option> <value>" β€” Sets the value of the scalar option to value
  • "o conf <list option>" β€” prints the current value of the list option in MakeMaker's neatvalue format.
  • "o conf <list option> [shift|pop]" β€” shifts or pops the array in the list option variable
  • "o conf <list option> [unshift|push|splice] <list>" β€” works like the corresponding perl commands.
  • interactive editing: o conf init [MATCH|LIST] β€” Runs an interactive configuration dialog for matching variables. Without argument runs the dialog over all supported config variables. To specify a MATCH the argument must be enclosed by slashes.

Examples:

o conf init ftp_passive ftp_proxy
o conf init /color/

Note: this method of setting config variables often provides more explanation about the functioning of a variable than the manpage. the interactive dialog is spilling the tea fr fr


🧭 CPAN::anycwd($path): Note on config variable getcwd 🌸

CPAN.pm changes the current working directory a lot and needs to determine its own current working directory. By default it uses Cwd::cwd, but if for some reason this doesn't work on your system, configure alternatives according to the following table:

  • cwd β€” Calls Cwd::cwd
  • getcwd β€” Calls Cwd::getcwd
  • fastcwd β€” Calls Cwd::fastcwd
  • getdcwd β€” Calls Cwd::getdcwd
  • backtickcwd β€” Calls the external command cwd.

πŸ”— Note on the format of the urllist parameter ✨

urllist parameters are URLs according to RFC 1738. We do a little guessing if your URL is not compliant, but if you have problems with "file" URLs, please try the correct format. Either:

file://localhost/whatever/ftp/pub/CPAN/

or

file:///home/ftp/pub/CPAN/

πŸ’Ώ The urllist parameter has CD-ROM support πŸŽ€

The "urllist" parameter of the configuration table contains a list of URLs used for downloading. If the list contains any "file" URLs, CPAN always tries there first. This feature is disabled for index files. So the recommendation for the owner of a CD-ROM with CPAN contents is: include your local, possibly outdated CD-ROM as a "file" URL at the end of urllist, e.g.

o conf urllist push file://localhost/CDROM/CPAN

CPAN.pm will then fetch the index files from one of the CPAN sites that come at the beginning of urllist. It will later check for each module to see whether there is a local copy of the most recent version. local first, queen behavior πŸ‘‘

And here's the thing about urllist that catches literally everyone off guard 🫢 β€” the site that you successfully fetched the last file from automatically gets a preference token, and it gets tried first for the next request. So if you add a new site at runtime, surprise, bestie, the previously-preferred site might get tried all over again. Which means: if you want a site to be disallowed for the next transfer, you have to explicitly remove it from urllist. No vibes-based hoping. Explicit removal only. πŸ’…

✨ Maintaining the urllist parameter ✨

Okay so if you've got YAML.pm (or literally any other YAML module you've configured in yaml_module) installed, CPAN.pm is out here collecting little statistical receipts about your recent downloads πŸ“Š. You can peep the stats with the hosts command, or go snooping directly by looking into the FTPstats.yml file sitting in your cpan_home directory. Ngl, kind of nosy of it, but it's useful.

If you want those statistics to actually be interesting? The recommendation is that randomize_urllist be set β€” that sprinkles some amount of randomness into the URL selection and keeps things from being all stale and same-y. 🌈

🌸 The requires and build_requires dependency declarations 🌸

Since CPAN.pm version 1.88_51, modules declared as build_requires by a distribution are treated differently depending on the config variable build_requires_install_policy. Here's the tea:

  • Set build_requires_install_policy to no β†’ the module is not installed. It's only built and tested, then kept in the list of tested-but-uninstalled modules. It stays available during the build of the dependent module because the path to the blib/arch and blib/lib directories gets integrated into the PERL5LIB environment variable. Cute, right? πŸŽ€
  • Set build_requires_install_policy to yes β†’ both modules declared as requires and those declared as build_requires are treated alike. No favourites here.
  • Set it to ask/yes or ask/no β†’ CPAN.pm asks the user and sets the default accordingly. Consent-based dependency management, we love to see it. πŸ’–

πŸ’… Configuration of the allow_installing_* parameters πŸ’…

These allow_installing_* parameters get evaluated during the make phase. Set to yes, and they allow the testing and the installation of the current distro β€” otherwise they have, and I quote, no effect. Set to no, and they may abort the build (which means preventing testing and installing, bestie 😭), depending on what's chillin' in the blib/ directory. And what is blib/? It's the directory that holds all the files that would usually be installed in the install phase. Iconic little staging area.

  • allow_installing_outdated_dists β€” compares the blib/ directory with the CPAN index. If it finds something in there that belongs, according to the index, to a different dist, it aborts the current build. πŸ’€
  • allow_installing_module_downgrades β€” compares the blib/ directory with already installed modules, actually their version numbers as determined by ExtUtils::MakeMaker or equivalent. If a to-be-installed module would downgrade an already installed module, the current build gets aborted. Not today, downgrades.
Okay now for an interesting twist πŸŒ€ (the manpage's words, not mine): it happens when a distroprefs document demands the installation of an outdated dist via goto while allow_installing_outdated_dists forbids it. Without additional provisions, allow_installing_outdated_dists would win and the distroprefs would lose. Rude. So the proper arrangement in such a case is to write a second distroprefs document for the distro that goto points to and overrule the cpanconfig there. Like so:
---
match:
  distribution: "^MAUKE/Keyword-Simple-0.04.tar.gz"
goto: "MAUKE/Keyword-Simple-0.03.tar.gz"
---
match:
  distribution: "^MAUKE/Keyword-Simple-0.03.tar.gz"
cpanconfig:
  allow_installing_outdated_dists: yes

πŸ¦‹ Configuration for individual distributions (Distroprefs) πŸ¦‹

(Note: this feature has been introduced in CPAN.pm 1.8854 β€” vintage, but in a chic way. πŸ‘‘

So distributions on CPAN usually behave according to what we call the CPAN mantra. Or, since the advent of Module::Build, we should honestly be talking about two mantras:

perl Makefile.PL     perl Build.PL
make                 ./Build
make test            ./Build test
make install         ./Build install

Beautiful. Chanted like a little incantation. ✨

But some modules just cannot be built with this mantra. They try to get some extra data from the user via the environment, or extra arguments, or interactively β€” which totally disturbs the installation of large bundles like Phalanx100, or modules with many dependencies like Plagger. Messy.

The distroprefs system of CPAN.pm addresses this problem by letting the user specify extra informations and recipes in YAML files, in order to either:

  • pass additional arguments to one of the four commands,
  • set environment variables,
  • instantiate an Expect object that reads from the console, waits for some regular expressions and enters some answers,
  • temporarily override assorted CPAN.pm configuration variables,
  • specify dependencies the original maintainer forgot, or
  • disable the installation of an object altogether.

See the YAML and Data::Dumper files that come with the CPAN.pm distribution in the distroprefs/ directory for examples. πŸ‘‘ go look, they're right there

πŸŽ€ Filenames πŸŽ€

The YAML files themselves must have the .yml extension β€” everything else is ignored (for two exceptions, peep Fallback Data::Dumper and Storable below, don't worry, I got you). The containing directory can be specified in CPAN.pm in the prefs_dir config variable. Try o conf init prefs_dir in the CPAN shell to set and activate the distroprefs system. One command, system activated, slay.

Every YAML file may contain arbitrary documents according to the YAML specification, and every document is treated as an entity that can specify the treatment of a single distribution. One doc, one distro, very demure.

Filenames can be picked arbitrarily β€” genuinely anything you want, no naming schema, live your truth. CPAN.pm always reads all files (in alphabetical order) and takes the key match (see below in Language Specs) as a hashref containing match criteria that determine if the current distribution matches the YAML document or not.

🌈 Fallback Data::Dumper and Storable 🌈

If neither your configured yaml_module nor YAML.pm is installed, CPAN.pm falls back to using Data::Dumper and Storable, and looks for files with the extensions .dd or .st in the prefs_dir directory. Those files are expected to contain one or more hashrefs. For Data::Dumper generated files, this is expected to be done with by defining $VAR1, $VAR2, etc. The YAML shell would produce these with the command:

ysh < somefile.yml > somefile.dd

For Storable files, the rule is that they must be constructed such that Storable::retrieve(file) returns an array reference, and the array elements represent one distropref object each. The conversion from YAML would look like so:

perl -MYAML=LoadFile -MStorable=nstore -e '
    @y=LoadFile(shift);
    nstore(\@y, shift)' somefile.yml somefile.st

In bootstrapping situations it is usually sufficient to translate only a few YAML files to Data::Dumper for crucial modules like YAML::Syck, YAML.pm and Expect.pm. And if you prefer Storable over Data::Dumper, remember to pull out a Storable version that writes an older format than all the other Storable versions that will need to read them. ⚠️ Version-matching matters here, fr fr.

⭐ Blueprint ⭐

The following example contains all supported keywords and structures with the exception of eexpect, which can be used instead of expect:

---
comment: "Demo"
match:
  module: "Dancing::Queen"
  distribution: "^CHACHACHA/Dancing-"
  not_distribution: "\.zip$"
  perl: "/usr/local/cariba-perl/bin/perl"
  perlconfig:
    archname: "freebsd"
    not_cc: "gcc"
  env:
    DANCING_FLOOR: "Shubiduh"
disabled: 1
cpanconfig:
  make: gmake
pl:
  args:
    - "--somearg=specialcase"

  env: {}

  expect:
    - "Which is your favorite fruit"
    - "apple\n"

make:
  args:
    - all
    - extra-all

  env: {}

  expect: []

  commandline: "echo SKIPPING make"

test:
  args: []

  env: {}

  expect: []

install:
  args: []

  env:
    WANT_TO_INSTALL: YES

  expect:
    - "Do you really want to install"
    - "y\n"

patches:
  - "ABCDE/Fedcba-3.14-ABCDE-01.patch"

depends:
  configure_requires:
    LWP: 5.8
  build_requires:
    Test::Exception: 0.25
  requires:
    Spiffy: 0.30

πŸ’œ Language Specs πŸ’œ

Every YAML document represents a single hash reference. The valid keys in this hash are as follows:

  • comment [scalar] β€” a comment. That's it. That's the key. A lil note for your future self. πŸŽ€
  • cpanconfig [hash] β€” temporarily override assorted CPAN.pm configuration variables.

Supported are: build_requires_install_policy, check_sigs, make, make_install_make_command, prefer_installer, test_report. Please report as a bug when you need another one supported. πŸ‘‘ (they're asking!!)

  • depends [hash] * EXPERIMENTAL FEATURE * β€” all three types, namely configure_requires, build_requires, and requires are supported in the way specified in the META.yml specification. The current implementation merges the specified dependencies with those declared by the package maintainer. In a future implementation this may be changed to override the original declaration. ⚠️ so don't build your whole personality on the current behaviour
  • disabled [boolean] β€” specifies that this distribution shall not be processed at all. Her ass is NOT being installed. πŸ’€
  • features [array] * EXPERIMENTAL FEATURE * β€” experimental implementation to deal with optional_features from META.yml. Still needs coordination with installer software and currently works only for META.yml declaring dynamic_config=0. Use with caution. 🚨 (caution!!! for real)
  • goto [string] β€” the canonical name of a delegate distribution to install instead. Useful when a new version, although it tests OK itself, breaks something else, or a developer release or a fork is already uploaded that is better than the last released version. Redirection, but make it fashion. ✨
  • install [hash] β€” processing instructions for the make install or ./Build install phase of the CPAN mantra. See below under Processing Instructions.
  • make [hash] β€” processing instructions for the make or ./Build phase of the CPAN mantra. See below under Processing Instructions.
  • match [hash] β€” a hashref with one or more of the keys distribution, module, perl, perlconfig, and env that specify whether a document is targeted at a specific CPAN distribution or installation. Keys prefixed with not_ negates the corresponding match.
    • The corresponding values are interpreted as regular expressions. The distribution related one will be matched against the canonical distribution name, e.g. AUTHOR/Foo-Bar-3.14.tar.gz.
    • The module related one will be matched against all modules contained in the distribution until one module matches.
    • The perl related one will be matched against $^X (but with the absolute path).

patches [array]

Bestie, this one is a list β€” an array of patches sitting on CPAN or on your local disk, and they get applied in order by an external patch program. πŸ’…

Whether the value for the -p parameter is 0 or 1 gets figured out by reading the patch beforehand. Sneaky, but it works.

The path to each patch is either:

  • an absolute path on the local filesystem, or
  • relative to a patch directory that you specified in the patches_dir configuration variable, or
  • written in the format of a canonical distro name.

For examples, go peek at the distroprefs/ directory inside the CPAN.pm distribution β€” those examples are not installed by default, so don't go looking for them in your normal install and get confused. πŸ™ˆ

Note!!! If the applypatch program is installed and CPAN::Config knows about it and a patch was written by the makepatch program, then CPAN.pm lets applypatch apply the patch. Both makepatch and applypatch are available from CPAN in the JV/makepatch-* distribution. ✨

pl [hash]

Processing instructions for the perl Makefile.PL or perl Build.PL phase of the CPAN mantra. Scroll down to Processing Instructions below, it's all there. 🫢

test [hash]

Processing instructions for the make test or ./Build test phase of the CPAN mantra. Same deal β€” see below under Processing Instructions.


Processing Instructions πŸ› οΈ

args [array]

Arguments to be added to the command line.

commandline

A full commandline to run via system(). During execution, the environment variable PERL is set to $^X (but with an absolute path). And heads up: if commandline is specified, args is not used. Pick one, babe. πŸ’…

eexpect [hash]

Extended "expect". This is a hash reference with four allowed keys: mode, timeout, reuse, and talk.

You must install the Expect module to use eexpect. CPAN.pm does not install it for you. It's not gonna hold your hand on this one. 😭

  • mode may have the values deterministic β€” for when all questions come in the order written down β€” or anyorder β€” for when the questions may come in any order. The default mode is deterministic.
  • timeout denotes a timeout in seconds. Floating-point timeouts are OK. With mode=deterministic, the timeout denotes the timeout per question; with mode=anyorder it denotes the timeout per byte received from the stream or questions.
  • talk is a reference to an array that contains alternating questions and answers. Questions are regular expressions and answers are literal strings. The Expect module watches the stream from the execution of the external program (perl Makefile.PL, perl Build.PL, make, etc.).

For mode=deterministic, the CPAN.pm injects the corresponding answer as soon as the stream matches the regular expression. Iconic behaviour, honestly. ✨

For mode=anyorder CPAN.pm answers a question as soon as the timeout is reached for the next byte in the input stream. In this mode you can use the reuse parameter to decide what will happen with a question-answer pair after it has been used.

In the default case (reuse=0) it is removed from the array, avoiding being used again accidentally. If you want to answer the question "Do you really want to do that" several times, then it must be included in the array at least as often as you want this answer to be given. Setting the parameter reuse to 1 makes this repetition unnecessary. Obsessed with efficiency fr fr. πŸ”₯

env [hash]

Environment variables to be set during the command.

expect [array]

You must install the Expect module to use expect. CPAN.pm does not install it for you. No cap. 😀

expect: <array> is a short notation for this eexpect:

        eexpect:
                mode: deterministic
                timeout: 15
                talk: <array>

Schema verification with Kwalify 🌈

If you have the Kwalify module installed (which is part of the Bundle::CPANxxl), then all your distroprefs files are checked for syntactic correctness. Vibe check, but for YAML. πŸ’…


Example Distroprefs Files πŸŽ€

CPAN.pm comes with a collection of example YAML files. Note that these are really just examples and should not be used without care because they cannot fit everybody's purpose. After all, the authors of the packages that ask questions had a need to ask, so you should watch their questions and adjust the examples to your environment and your needs.

You have been warned:-) 🚨

PROGRAMMER'S INTERFACE πŸ’»

If you do not enter the shell, shell commands are available both as methods (CPAN::Shell->install(...)) and as functions in the calling package (install(...)).

Before calling low-level commands, it makes sense to initialize components of CPAN you need, e.g.:

  CPAN::HandleConfig->load;
  CPAN::Shell::setup_output;
  CPAN::Index->reload;

High-level commands do such initializations automatically, bestie. No stress. 🫢

There's currently only one class that has a stable interface β€” CPAN::Shell. All commands that are available in the CPAN shell are methods of the class CPAN::Shell. The arguments on the commandline are passed as arguments to the method.

So if you take for example the shell command

  notest install A B C

the actually executed command is

  CPAN::Shell->notest("install","A","B","C");

Each of the commands that produce listings of modules (r, autobundle, u) also return a list of the IDs of all modules within the list. Little gift for your scripts. 🎁

expand($type,@things)

The IDs of all objects available within a program are strings that can be expanded to the corresponding real objects with the CPAN::Shell->expand("Module",@things) method. Expand returns a list of CPAN::Module objects according to the @things arguments given. In scalar context, it returns only the first element of the list.

expandany(@things)

Like expand, but returns objects of the appropriate type, i.e. CPAN::Bundle objects for bundles, CPAN::Module objects for modules, and CPAN::Distribution objects for distributions.

Note: it does not expand to CPAN::Author objects. 🚫

Programming Examples 🌸

This enables the programmer to do operations that combine functionalities that are available in the shell.

    # install everything that is outdated on my disk:
    perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'

    # install my favorite programs if necessary:
    for $mod (qw(Net::FTP Digest::SHA Data::Dumper)) {
        CPAN::Shell->install($mod);
    }

    # list all modules on my disk that have no VERSION number
    for $mod (CPAN::Shell->expand("Module","/./")) {
        next unless $mod->inst_file;
        # MakeMaker convention for undefined $VERSION:
        next unless $mod->inst_version eq "undef";
        print "No VERSION in ", $mod->id, "\n";
    }

    # find out which distribution on CPAN contains a module:
    print CPAN::Shell->expand("Module","Apache::Constants")->cpan_file

Or if you want to schedule a cron job to watch CPAN, you could list all modules that need updating. First a quick and dirty way:

    perl -e 'use CPAN; CPAN::Shell->r;'

If you don't want any output should all modules be up to date, parse the output of above command for the regular expression /modules are up to date/ and decide to mail the output only if it doesn't match.

If you prefer to do it more in a programmerish style in one single process, something like this may better suit you:

  # list all modules on my disk that have newer versions on CPAN
  for $mod (CPAN::Shell->expand("Module","/./")) {
    next unless $mod->inst_file;
    next if $mod->uptodate;
    printf "Module %s is installed as %s, could be updated to %s from CPAN\n",
        $mod->id, $mod->inst_version, $mod->cpan_version;
  }

If that gives too much output every day, you may want to watch only for three modules. You can write

  for $mod (CPAN::Shell->expand("Module","/Apache|LWP|CGI/")) {

as the first line instead. Or you can combine some of the above tricks:

  # watch only for a new mod_perl module
  $mod = CPAN::Shell->expand("Module","mod_perl");
  exit if $mod->uptodate;
  # new mod_perl arrived, let me know all update recommendations
  CPAN::Shell->r;

Methods in the other Classes πŸ‘‘

CPAN::Author::as_glimpse()

Returns a one-line description of the author.

CPAN::Author::as_string()

Returns a multi-line description of the author.

CPAN::Author::email()

Returns the author's email address.

CPAN::Author::fullname()

Returns the author's name.

CPAN::Author::name()

An alias for fullname.

CPAN::Bundle::as_glimpse()

Returns a one-line description of the bundle.

CPAN::Bundle::as_string()

Returns a multi-line description of the bundle.

CPAN::Bundle::clean()

Recursively runs the clean method on all items contained in the bundle.

CPAN::Bundle::contains()

Returns a list of objects' IDs contained in a bundle. The associated objects may be bundles, modules or distributions.

CPAN::Bundle::force($method,@args)

Forces CPAN to perform a task that it normally would have refused to do. Force takes as arguments a method name to be called and any number of additional arguments that should be passed to the called method.

The internals of the object get the needed changes so that CPAN.pm does not refuse to take the action. The force is passed recursively to all contained objects.

See also the section above on the force and the fforce pragma.

CPAN::Bundle::get()

Recursively runs the get method on all items contained in the bundle.

CPAN::Bundle::inst_file()

Returns the highest installed version of the bundle in either @INC or $CPAN::Config->{cpan_home}.

Note that this is different from CPAN::Module::inst_file. Don't get it twisted. πŸ’…

CPAN::Bundle::inst_version()

Like CPAN::Bundle::inst_file, but returns the $VERSION.

CPAN::Bundle::uptodate()

Returns 1 if the bundle itself and all its members are up-to-date.

CPAN::Bundle::install()

Recursively runs the install method on all items contained in the bundle.

πŸŽ€ CPAN::Bundle::make()

Runs the make method on literally every item in the bundle β€” recursively, bestie. All of them. Not one skipped. πŸ’…

🌸 CPAN::Bundle::readme()

Recursively runs the readme method on every item contained in the bundle. πŸ“–

✨ CPAN::Bundle::test()

Recursively runs the test method on all items contained in the bundle. Every single one gets tested, periodt. πŸ§ͺ


πŸ¦‹ CPAN::Distribution::as_glimpse()

Hands you back a one-line description of the distribution. Just the lil vibe summary. πŸ‘‘

πŸ’– CPAN::Distribution::as_string()

Same energy, but a multi-line description of the distribution. The full essay. πŸ“

🌈 CPAN::Distribution::author

Returns the CPAN::Author object of the maintainer who uploaded this distribution. That's your mystery uploader, identified. πŸ•΅οΈ

πŸ’… CPAN::Distribution::pretty_id()

Returns a string shaped like "AUTHORID/TARBALL", where AUTHORID is the author's PAUSE ID and TARBALL is the distribution filename. Cute lil ID card fr fr. πŸŽ€

πŸ“ CPAN::Distribution::base_id()

Returns the distribution filename without any archive suffix. E.g "Foo-Bar-0.01". Naked filename. No .tar.gz costume. 😌

🧚 CPAN::Distribution::clean()

Changes into the directory where the distribution got unpacked, then runs make clean there. Tidy up, bestie. 🧹

πŸ’œ CPAN::Distribution::containsmods()

Returns a list of IDs of modules contained in a distribution file. Heads up though β€” this only works for distributions listed in the 02packages.details.txt.gz file. Which lowkey means it's typically just the most recent version of a distribution that gets covered. 😭

πŸ”₯ CPAN::Distribution::cvs_import()

Changes into the directory where the distribution has been unpacked and runs something like

cvs -d $cvs_root import -m $cvs_log $cvs_dir $userid v$version

right there in that directory. ✨

🌸 CPAN::Distribution::dir()

Returns the directory into which this distribution has been unpacked. Its lil home. 🏠

πŸ‘‘ CPAN::Distribution::force($method,@args)

Forces CPAN to do a thing it normally would have straight-up refused to do. Force takes as arguments a method name to be called, plus any number of extra arguments that should get passed along to that called method. The internals of the object get the needed changes made so that CPAN.pm stops refusing to take the action. Also go peep the section above about the "force" and the "fforce" pragma. πŸ’ͺ

πŸ¦‹ CPAN::Distribution::get()

Downloads the distribution from CPAN and unpacks it. Does nothing if the distribution has already been downloaded and unpacked within the current session. Already got it? We move. 😌

πŸ’– CPAN::Distribution::install()

Changes into the directory where the distribution has been unpacked and runs the external command make install there. If make hasn't been run yet, it gets run first. A make test is issued in any case, and if that fails, the install is cancelled. You can dodge that cancellation by letting force run the install for you. πŸ™ˆ

This install method only has the power to install the distribution if there are no dependencies in the way. To install an object along with all its dependencies, use CPAN::Shell->install.

Note that install() gives no meaningful return value. See uptodate(). πŸ’€

🌈 CPAN::Distribution::isa_perl()

Returns 1 if this distribution file seems to be a perl distribution. Normally this is derived from the file name only, but the index from CPAN can contain a hint that lets it return true for other filenames too. πŸͺ

✨ CPAN::Distribution::look()

Changes into the directory where the distribution has been unpacked and opens a subshell there. Exiting the subshell returns. Peek around, then dip. 🫢

πŸŽ€ CPAN::Distribution::make()

First runs the get method to make sure the distribution is downloaded and unpacked. Then changes into the directory where the distribution has been unpacked and runs the external commands perl Makefile.PL or perl Build.PL and make there. The whole glow-up sequence. πŸ”₯

πŸ’œ CPAN::Distribution::perldoc()

Downloads the pod documentation of the file associated with a distribution (in HTML format) and runs it through the external command lynx specified in $CPAN::Config->{lynx}. If lynx isn't available, it converts it to plain text with the external command html2text and runs it through the pager specified in $CPAN::Config->{pager}. Backup plan built in. πŸ’…

πŸ“ CPAN::Distribution::prefs()

Returns the hash reference from the first matching YAML file that the user has deposited in the prefs_dir/ directory. The first succeeding match wins. Files in the prefs_dir/ are processed alphabetically, and the canonical distro name (e.g. AUTHOR/Foo-Bar-3.14.tar.gz) is matched against the regular expressions stored in the $root->{match}{distribution} attribute value. Additionally, all module names contained in a distribution are matched against the regular expressions in the $root->{match}{module} attribute value. The two match values are ANDed together. Each of the two attributes are optional. πŸ”

🌸 CPAN::Distribution::prereq_pm()

Returns the hash reference that has been announced by a distribution as the "requires" and "build_requires" elements. These can be declared either by the "META.yml" (if authoritative) or can be deposited after the run of "Build.PL" in the file "./_build/prereqs", or after the run of "Makfile.PL" written as the "PREREQ_PM" hash in a comment in the produced "Makefile".

Note: this method only works after an attempt has been made to "make" the distribution. Returns undef otherwise. 😭

🧚 CPAN::Distribution::readme()

Downloads the README file associated with a distribution and runs it through the pager specified in $CPAN::Config->{pager}. Cute lil read. πŸ“–

🌈 CPAN::Distribution::reports()

Downloads report data for this distribution from www.cpantesters.org and displays a subset of them. Receipts, bestie. 🧾

πŸ‘‘ CPAN::Distribution::read_yaml()

Returns the content of the META.yml of this distro as a hashref.

Note: works only after an attempt has been made to "make" the distribution. Returns undef otherwise. Also returns undef if the content of META.yml is not authoritative. (The rules about what exactly makes the content authoritative are still in flux.) πŸ’€

πŸ’– CPAN::Distribution::test()

Changes into the directory where the distribution has been unpacked and runs make test there. Vibe check time. βœ…

✨ CPAN::Distribution::uptodate()

Returns 1 if all the modules contained in the distribution are up-to-date. Relies on containsmods. 🌟

πŸŽ€ CPAN::Index::force_reload()

Forces a reload of all indices. No waiting, no excuses. πŸ”„

πŸ¦‹ CPAN::Index::reload()

Reloads all indices if they have not been read for more than $CPAN::Config->{index_expire} days. Only if they're getting a lil stale. πŸ•°οΈ

πŸ’œ CPAN::InfoObj::dump()

CPAN::Author, CPAN::Bundle, CPAN::Module, and CPAN::Distribution all inherit this method. It prints the data structure associated with an object. Useful for debugging.

Note: the data structure is considered internal and thus subject to change without notice. Don't build your whole personality on it. πŸ™ˆ

🌸 CPAN::Module::as_glimpse()

Returns a one-line description of the module in four columns:

  1. The first column contains the word "Module".
  2. The second column consists of one character: an equals sign (=) if this module is already installed and up-to-date, a less-than sign (<) if this module is installed but can be upgraded, and a space if the module is not installed.
  3. The third column is the name of the module.
  4. The fourth column gives maintainer or distribution information.

Four whole columns of information, slay. πŸ“Š

πŸ”₯ CPAN::Module::as_string()

Returns a multi-line description of the module. πŸ“

πŸ“ CPAN::Module::clean()

Runs a clean on the distribution associated with this module. ✨

πŸ’… CPAN::Module::cpan_file()

Returns the filename on CPAN that is associated with the module. πŸ—‚οΈ

🌈 CPAN::Module::cpan_version()

Returns the latest version of this module available on CPAN. Freshest drop available. πŸ†•

🧚 CPAN::Module::cvs_import()

Runs a cvs_import on the distribution associated with this module. ✨

πŸ‘‘ CPAN::Module::description()

Returns a 44 character description of this module. Only available for modules listed in The Module List (CPAN/modules/00modlist.long.html or 00modlist.long.txt.gz). Short. Snappy. Exactly 44 chars. πŸ’…

πŸ’– CPAN::Module::distribution()

Returns the CPAN::Distribution object that contains the current version of this module. 🫢

πŸ¦‹ CPAN::Module::dslip_status()

Returns a hash reference. The keys of the hash are the letters "D", "S", "L", "I", and <P>, for development status, support level, language, interface and public licence respectively. The data for the DSLIP status are collected by pause.perl.org when authors register their namespaces. The values of the 5 hash elements are one-character words whose meaning is described in the table below. There are also 5 hash elements "DV", "SV", "LV", "IV", and <PV> that carry a more verbose value of the 5 status variables.

Where the 'DSLIP' characters have the following meanings:

  • D - Development Stage (Note: NO IMPLIED TIMESCALES):
    • i - Idea, listed to gain consensus or as a placeholder
    • c - under construction but pre-alpha (not yet released)
    • a/b - Alpha/Beta testing
    • R - Released
    • M - Mature (no rigorous definition)
    • S - Standard, supplied with Perl 5
  • S - Support Level:
    • m - Mailing-list
    • d - Developer
    • u - Usenet newsgroup comp.lang.perl.modules
    • n - None known, try comp.lang.perl.modules
    • a - abandoned; volunteers welcome to take over maintenance
  • L - Language Used:
    • p - Perl-only, no compiler needed, should be platform independent
    • c - C and perl, a C compiler will be needed
    • h - Hybrid, written in perl with optional C code, no compiler needed
    • + - C++ and perl, a C++ compiler will be needed
    • o - perl and another language other than C or C++
  • I - Interface Style
    • f - plain Functions, no references used
    • h - hybrid, object and function interfaces available
    • n - no interface at all (huh?)
    • r - some use of unblessed References or ties
    • O - Object oriented using blessed references and/or inheritance
  • P - Public License
    • p - Standard-Perl: user may choose between GPL and Artistic
    • g - GPL: GNU General Public License
    • l - LGPL: "GNU Lesser General Public License" (previously known as "GNU Library General Public License")
    • b - BSD: The BSD License
    • a - Artistic license alone
    • 2 - Artistic license 2.0 or later
    • o - open source: approved by www.opensource.org
    • d - allows distribution without restrictions
    • r - restricted distribution
    • n - no license at all

CPAN::Module::force($method,@args)

Okay so this one is the "I said what I said" method πŸ’… β€” it forces CPAN to do a thing it would normally flat-out refuse to do. You hand it a method name to invoke, plus however many extra arguments you want to pass that method. The internals of the object get the needed changes made to them so that CPAN.pm stops refusing to take the action. Peep the section above on the force and the fforce pragma too, iykyk.

CPAN::Module::get()

Runs a get on the distribution that belongs to this module.

CPAN::Module::inst_file()

Hands back the filename of the module it found in @INC. Only the first file found gets reported β€” same energy as perl itself, which stops searching @INC the moment it finds a module.

CPAN::Module::available_file()

Hands back the filename of the module it found in PERL5LIB or @INC. Again, first file found wins. The glow-up this method has over inst_file is that modules which have been tested but not yet installed get included, because PERL5LIB keeps track of tested modules. bestie behavior honestly.

CPAN::Module::inst_version()

Returns the version number of the installed module, in readable format. πŸŽ€

CPAN::Module::available_version()

Returns the version number of the available module, in readable format. ✨

CPAN::Module::install()

Runs an install on the distribution that belongs to this module.

CPAN::Module::look()

Changes into the directory where the distribution for this module got unpacked, and opens a subshell right there. Exiting the subshell returns you. 🐚

CPAN::Module::make()

Runs a make on the distribution associated with this module.

CPAN::Module::manpage_headline()

If the module is installed, it takes a lil peek into the module's manpage, reads the headline, and returns it. And moreover β€” if the module got downloaded within this session, it does the equivalent thing on the downloaded module even if that one hasn't been installed yet. so considerate fr.

CPAN::Module::perldoc()

Runs a perldoc on this module.

CPAN::Module::readme()

Runs a readme on the distribution associated with this module.

CPAN::Module::reports()

Calls the reports() method on the associated distribution object.

CPAN::Module::test()

Runs a test on the distribution associated with this module.

CPAN::Module::uptodate()

Returns 1 if the module is installed and up-to-date. ✨

CPAN::Module::userid()

Returns the author's ID of the module. πŸ‘‘


Cache Manager 🧺

Right now the cache manager is literally only tracking one thing: the build directory, $CPAN::Config->{build_dir}. It's a simple FIFO mechanism β€” the absolute second the size of all the directories under build_dir gets bigger than $CPAN::Config->{build_cache} (that's in MB, bestie), it deletes complete directories below build_dir. no cap.

The contents of this cache may get used for later re-installations you intend to do manually, but CPAN itself will never trust them. Why? Because you, the user, might be using those very directories for building modules on different architectures. 😭

There's another directory β€” $CPAN::Config->{keep_source_where} β€” where the original distribution files are kept. That directory is not covered by the cache manager and must be controlled by the user. And if you choose to have the same directory as both build_dir and keep_source_where, then your sources will be deleted with that same fifo mechanism. πŸ’€

Bundles πŸŽ€

A bundle is just a perl module in the namespace Bundle:: that doesn't define any functions or methods. It usually contains nothing but documentation. that's it, that's the whole vibe.

It starts like a perl module would β€” a package declaration and a $VERSION variable. After that, the pod section looks like any other pod, with one difference: one special pod section exists that starts with (verbatim):

=head1 CONTENTS

In this pod section, each line obeys the format

    Module_Name [Version_String] [- optional text]

The only required part is the first field β€” the name of a module (like Foo::Bar, so the name of the module, not the name of the distribution file). The rest of the line is optional. The comment part is delimited by a dash, exactly like in the man page header.

The distribution of a bundle should follow the same convention as other distributions.

Bundles get treated specially in the CPAN package. If you say install Bundle::Tkkit (assuming such a bundle exists), CPAN will install all the modules in the CONTENTS section of the pod. You can install your own Bundles locally by placing a conformant Bundle file somewhere into your @INC path. The autobundle() command, which is available in the shell interface, does exactly that for you β€” it includes all currently installed modules in a snapshot bundle file. obsessed πŸ’–


PREREQUISITES ✨

CPAN is out here trying to depend on as little as possible so the user can use it even in a hostile environment. But the more goodies the environment provides, the better it works. For example, if you try this in the CPAN shell

install Bundle::CPAN

or

install Bundle::CPANxxl

you will find the shell more convenient than the bare shell you had before it. 🫢

If you have a local mirror of CPAN and can access all files with file: URLs, then you only need a perl later than perl5.003 to run this module. Otherwise, Net::FTP is strongly recommended. LWP may be required for non-UNIX systems, or if your nearest CPAN site is associated with a URL that is not ftp:.

If you have neither Net::FTP nor LWP, don't panic β€” there's a fallback mechanism implemented for an external ftp command or for an external lynx command. πŸ’œ

UTILITIES 🧰

Finding packages and VERSION πŸ”

This module presumes that all packages on CPAN

  • declare their $VERSION variable in an easy to parse manner. This prerequisite can hardly be relaxed, because it consumes far too much memory to load all packages into the running program just to determine the $VERSION variable. Currently all programs that are dealing with version use something like this
perl -MExtUtils::MakeMaker -le \
    'print MM->parse_version(shift)' filename

So if you are the author of a package and you're wondering if your $VERSION can be parsed, please try the above method. pleaseeee πŸ™

  • come as compressed or gzipped tarfiles or as zip files and contain a Makefile.PL or Build.PL (well, we try to handle a bit more, but with little enthusiasm).

Debugging πŸ›

Debugging this module is more than a bit complex, due to interference from the software producing the indices on CPAN, the mirroring process on CPAN, packaging, configuration, synchronicity, and even (gasp!) due to bugs within the CPAN.pm module itself. the audacity honestly.

For debugging the code of CPAN.pm itself in interactive mode, some debugging aid can be turned on for most packages within CPAN.pm with one of

  • o debug package... β€” sets debug mode for packages.
  • o debug -package... β€” unsets debug mode for packages.
  • o debug all β€” turns debugging on for all packages.
  • o debug number β€” which sets the debugging packages directly. Note that o debug 0 turns debugging off.

What seems like a successful strategy is the combination of reload cpan and the debugging switches. Add a new debug statement while running in the shell, then issue a reload cpan and see the new debugging messages immediately without losing the current context. main character debugging fr. ✨

o debug without an argument lists the valid package names and the current set of packages in debugging mode. o debug has built-in completion support too.

For debugging of CPAN data there's the dump command, which takes the same arguments as make/test/install and outputs each object's Data::Dumper dump. If an argument looks like a perl variable and contains one of $, @ or %, it is eval()ed and fed to Data::Dumper directly.

Floppy, Zip, Offline Mode πŸ’Ύ

CPAN.pm works nicely without network access too, bestie. If you maintain machines that are not networked at all, you should consider working with file: URLs. You'll have to collect your modules somewhere first. So you might use CPAN.pm to put together all you need on a networked machine. Then copy the $CPAN::Config->{keep_source_where} (but not $CPAN::Config->{build_dir}) directory onto a floppy. This floppy is kind of a personal CPAN. CPAN.pm on the non-networked machines works nicely with this floppy. See also below the paragraph about CD-ROM support. 🌈

Basic Utilities for Programmers πŸ› οΈ

has_inst($module)

Returns true if the module is installed. Used to load all modules into the running CPAN.pm that are considered optional. The config variable dontload_list intercepts the has_inst() call such that an optional module is not loaded despite being available. For example, the following command will prevent YAML.pm from being loaded:

cpan> o conf dontload_list push YAML

See the source for details.

use_inst($module)

Similar to has_inst() β€” it tries to load the optional library, but it also dies if the library is not available.

has_usable($module)

Returns true if the module is installed and in a usable state. Only useful for a handful of modules that are used internally. See the source for details.

instance($module)

The constructor for all the singletons used to represent modules, distributions, authors, and bundles. If the object already exists, this method returns the object; otherwise, it calls the constructor.

frontend()

frontend($new_frontend)

Getter/setter for the frontend object. The method just allows you to subclass CPAN.pm.


SECURITY πŸ”’

Okay so real talk: there's no strong security layer in CPAN.pm. CPAN.pm helps you install foreign, unmasked, unsigned code on your machine. 😭 We compare to a checksum that comes from the net, just as the distribution file itself does. But we try to make it easy to add security on demand:

Cryptographically signed modules πŸ”

Since release 1.77, CPAN.pm has been able to verify cryptographically signed module distributions using Module::Signature. The CPAN modules can be signed by their authors, thus giving more security. The simple unsigned MD5 checksums that were used before by CPAN protect mainly against accidental file corruption.

You will need to have Module::Signature installed, which in turn requires that you have at least one of Crypt::OpenPGP module or the command-line gpg tool installed.

You will also need to be able to connect over the Internet to the public key servers, like pgp.mit.edu, and their port 11731 (the HKP protocol).

The configuration parameter check_sigs is there to turn signature checking on or off.


EXPORT πŸ’…

Most functions in package CPAN are exported by default. The reason for this is that the primary use is intended for the cpan shell or for one-liners. slay.

bestie we're deep in the CPAN.pm lore now and it's still giving. buckle up. πŸŽ€


πŸ’– ENVIRONMENT πŸ’–

okay so CPAN.pm talks to your environment like it's leaving voice notes for itself. here's the tea:

  • when the CPAN shell dips into a subshell via the look command, it sets the environment variable CPAN_SHELL_LEVEL to 1, or increments that variable if it's already set. wee little counter. πŸͺ†
  • when CPAN runs, it sets the environment variable PERL5_CPAN_IS_RUNNING to the ID of the running process. it also sets PERL5_CPANPLUS_IS_RUNNING, just to stop runaway processes, which could genuinely happen with older versions of Module::Install. ✨
  • when it runs perl Makefile.PL, the environment variable PERL5_CPAN_IS_EXECUTING gets set to the full path of the Makefile.PL being executed. this is what stops runaway processes with newer versions of Module::Install. πŸ›‘
  • when the config variable ftp_passive is set, all downloads run with the environment variable FTP_PASSIVE set to that value. generally a slay idea because it influences both Net::FTP and LWP-based connections. you can get the same effect by starting the cpan shell with this environment variable already set. and for Net::FTP alone, you can always set passive mode by running libnetcfg. πŸ’…

✨ POPULATE AN INSTALLATION WITH LOTS OF MODULES ✨

populating a freshly installed perl with all your fave modules is so easy if you keep a private bundle definition file. to get a useful blueprint of one, use the autobundle command on the CPAN shell command line. this command writes a bundle definition file for every module installed for the current perl interpreter. πŸ‘‘

amin note: run this command once only, and from then on maintain the file manually under a private name, say Bundle/my_bundle.pm. then with a clever bundle file you can simply say

cpan> install Bundle::my_bundle

and then answer a few questions and go out for coffee (possibly even in a different city). β˜•οΈπŸ›«

maintaining a bundle definition file means keeping track of two things: dependencies and interactivity. CPAN.pm sometimes fails on calculating dependencies because not all modules define all MakeMaker attributes correctly, so a bundle definition file should specify prerequisites as early as possible. on the other hand it's annoying that so many distributions need some interactive configuring. so what you can try to accomplish in your private bundle file is to have the packages that need to be configured early in the file and the gentle ones later, so you can go out for coffee after a few minutes and leave CPAN.pm to churn away unattended. 🫢


πŸ”₯ WORKING WITH CPAN.pm BEHIND FIREWALLS πŸ”₯

shoutout to Graham Barr for contributing the following paragraphs about the interaction between perl and various firewall configurations. for further info on firewalls, it's recommended to consult the documentation that comes with the ncftp program. if you can't get through the firewall with a simple Perl setup, it's likely you can configure ncftp so that it works through your firewall. 🧱

Three basic types of firewalls

firewalls can be categorized into three basic types. no cap.

http firewall

this is when the firewall machine runs a web server, and to access the outside world you must do so via that web server. if you set environment variables like http_proxy or ftp_proxy to values beginning with http://, or in your web browser you've got proxy information set, then you know you're running behind an http firewall. 🌐

to access servers outside these types of firewalls with perl (even for ftp), you need LWP or HTTP::Tiny.

ftp firewall

this is where the firewall machine runs an ftp server. this kind of firewall will only let you access ftp servers outside the firewall. usually you do it by connecting to the firewall with ftp, then entering a username like user@outside.host.com. πŸ“‘

to access servers outside these types of firewalls with perl, you need Net::FTP.

One-way visibility

one-way visibility means these firewalls try to make themselves invisible to users inside the firewall. an FTP data connection is normally created by sending your IP address to the remote server and then listening for the return connection. but the remote server won't be able to connect to you because of the firewall. for these types of firewall, FTP connections need to be done in a passive mode.

there are two that the author can think of. 🫣

SOCKS

if you're using a SOCKS firewall, you'll need to compile perl and link it with the SOCKS library. this is what's normally called a 'socksified' perl. with this executable you'll be able to connect to servers outside the firewall as if it weren't even there. 🧦

IP Masquerade

this is when the firewall is implemented in the kernel (via NAT, or networking address translation) β€” it lets you hide a whole network behind one IP address. with this firewall no special compiling is needed, since you can access hosts directly.

for accessing ftp servers behind such firewalls you usually need to set the environment variable FTP_PASSIVE or the config variable ftp_passive to a true value. πŸ’…

Configuring lynx or ncftp for going through a firewall

if you can go through your firewall with e.g. lynx, presumably with a command such as

/usr/local/bin/lynx -pscott:tiger

then you'd configure CPAN.pm with the command

o conf lynx "/usr/local/bin/lynx -pscott:tiger"

that's all. similarly for ncftp or ftp, you'd configure something like

o conf ncftp "/usr/bin/ncftp -f /home/scott/ncftplogin.cfg"

your mileage may vary… 😌


🌸 FAQ 🌸

1) I installed a new version of module X but CPAN keeps saying, I have the old version installed

probably you do have the old version installed. this can happen if a module installs itself into a different directory in the @INC path than it was previously installed in. ngl this isn't really a CPAN.pm problem β€” you'd have the same problem installing the module manually. the easiest way to prevent this behaviour is to add the argument UNINST=1 to the make install call, and that is why many people add this argument permanently by configuring

o conf make_install_arg UNINST=1

2) So why is UNINST=1 not the default?

because there are people who have their precise expectations about who may install where in the @INC path and who uses which @INC array. in fine tuned environments UNINST=1 can cause damage. πŸ’€

3) I want to clean up my mess, and install a new perl along with all modules I have. How do I go about it?

run the autobundle command for your old perl and optionally rename the resulting bundle file (e.g. Bundle/mybundle.pm), install the new perl with the Configure option prefix, e.g.

./Configure -Dprefix=/usr/local/perl-5.6.78.9

install the bundle file you produced in the first step with something like

cpan> install Bundle::mybundle

and you're done. πŸ’–

4) When I install bundles or multiple modules with one command there is too much output to keep track of.

you may want to configure something like

o conf make_arg "| tee -ai /root/.cpan/logs/make.out"
o conf make_install_arg "| tee -ai /root/.cpan/logs/make_install.out"

so that STDOUT is captured in a file for later inspection. πŸ“

5) I am not root, how can I install a module in a personal directory?

as of CPAN 1.9463, if you don't have permission to write the default perl library directories, CPAN's configuration process will ask you whether you want to bootstrap <local::lib>, which makes keeping a personal perl library directory easy. 🏑

another thing you should bear in mind: the UNINST parameter can be dangerous when you're installing into a private area, because you might accidentally remove modules that other people depend on that aren't using the private area.

6) How to get a package, unwrap it, and make a change before building it?

have a look at the look (!) command. πŸ‘€

7) I installed a Bundle and had a couple of fails. When I retried, everything resolved nicely. Can this be fixed to work on first try?

the reason for this is that CPAN doesn't know the dependencies of all modules when it starts out. to decide about the additional items to install, it just uses data found in the META.yml file or the generated Makefile. an undetected missing piece breaks the process. but it may well be that your Bundle installs some prerequisite later than some depending item, and thus your second try is able to resolve everything. please note, CPAN.pm does not know the dependency tree in advance and cannot sort the queue of things to install in a topologically correct order. it resolves perfectly well if all modules declare the prerequisites correctly with the PREREQ_PM attribute to MakeMaker or the requires stanza of Module::Build. for bundles which fail and you need to install often, it's recommended to sort the Bundle definition file manually. πŸ”§

8) In our intranet, we have many modules for internal use. How can I integrate these modules with CPAN.pm but without uploading the modules to CPAN?

have a look at the CPAN::Site module. 🏒

9) When I run CPAN's shell, I get an error message about things in my /etc/inputrc (or ~/.inputrc) file.

these are readline issues and can only be fixed by studying readline configuration on your architecture and adjusting the referenced file accordingly. please make a backup of the /etc/inputrc or ~/.inputrc and edit them. quite often harmless changes like uppercasing or lowercasing some arguments solves the problem. πŸ› 

10) Some authors have strange characters in their names.

internally CPAN.pm uses the UTF-8 charset. if your terminal is expecting ISO-8859-1 charset, a converter can be activated by setting term_is_latin to a true value in your config file. one way of doing so would be

cpan> o conf term_is_latin 1

if other charset support is needed, please file a bug report against CPAN.pm at rt.cpan.org and describe your needs. maybe we can extend the support, or maybe UTF-8 terminals become widely available. 🌈

Note: this config variable is deprecated and will be removed in a future version of CPAN.pm. it will be replaced with the conventions around the family of $LANG and $LC_* environment variables.

11) When an install fails for some reason and then I correct the error condition and retry, CPAN.pm refuses to install the module, saying "Already tried without success".

you could use the force pragma like so

force install Foo::Bar

πŸ’…

12) how do I install a DEVELOPER RELEASE of a module?

okay so by default CPAN will install the latest non-developer release of a module. that's just the deal. but if you want the dev release you have to specify the partial path starting with the author id, all the way to the tarball you wish to install, like so:

cpan> install KWILLIAMS/Module-Build-0.27_07.tar.gz

and psst β€” you can use the ls command to get this path listed for you πŸ’…


13) how do I install a module AND all its dependencies from the commandline, without being prompted for literally anything, despite my CPAN configuration (or the total lack thereof)?

CPAN uses ExtUtils::MakeMaker's prompt() function to ask its questions, so if you set the PERL_MM_USE_DEFAULT environment variable you shouldn't be asked any questions at all (assuming the modules you're installing are nice about obeying that variable as well):

% PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install My::Module'

14) how do I create a Module::Build based Build.PL derived from an ExtUtils::MakeMaker focused Makefile.PL?

http://search.cpan.org/dist/Module-Build-Convert/

15) I'm frequently irritated with the CPAN shell's inability to help me select a good mirror 🫠

bestie, CPAN can now help you select a "good" mirror, based on which ones have the lowest 'ping' round-trip times. from the shell, use the command o conf init urllist and let CPAN automatically select mirrors for you. slay.

beyond that help, the urllist config parameter is yours. you can add and remove sites at will. you should find out which sites have the best up-to-dateness, bandwidth, reliability, etc. and are topologically close to you. some people prefer fast downloads, others up-to-dateness, others reliability. you decide which to try in which order.

Henk P. Penning maintains a site that collects data about CPAN sites:

http://mirrors.cpan.org/

also, feel free to play with experimental features. run

o conf init randomize_urllist ftpstats_period ftpstats_size

and choose your favorite parameters. after a few downloads, running the hosts command will probably assist you in choosing the best mirror sites. πŸ’–

16) why do I get asked the same questions every time I start the shell?? 😭

you can make your configuration changes permanent by calling the command o conf commit. alternatively, set the auto_commit variable to true by running o conf init auto_commit and answering the following question with yes.

17) older versions of CPAN.pm had the original root directory of all tarballs in the build directory. now there are always random characters appended to these directory names. why was this done?

the random characters are provided by File::Temp and they ensure that each module's individual build directory is unique. this makes running CPAN.pm in concurrent processes simultaneously safe. iconic, honestly.

18) speaking of the build directory. do I have to clean it up myself?

you have the choice to set the config variable scan_cache to never. then yes β€” you must clean it up yourself. the other possible values, atstart and atexit, clean up the build directory when you start (or more precisely, after the first extraction into the build directory) or exit the CPAN shell, respectively. if you never start up the CPAN shell, you probably also have to clean up the build directory yourself.

19) how can I switch to sudo instead of local::lib?

the following 5 environment variables need to be reset to the previous values: PATH, PERL5LIB, PERL_LOCAL_LIB_ROOT, PERL_MB_OPT, PERL_MM_OPT; and these two CPAN.pm config variables must be reconfigured: make_install_make_command and mbuild_install_build_command. the five env variables have probably been overwritten in your $HOME/.bashrc or some equivalent. you either find them there and delete their traces and logout/login, or you override them temporarily β€” depending on your exact desire. the two cpanpm config variables can be set with:

o conf init /install_.*_command/

probably followed by

o conf commit

20) how do recommends_policy and suggests_policy work, exactly?

the terms "recommends" and "suggests" have been standardized in https://metacpan.org/pod/CPAN::Meta::Spec

in CPAN.pm, if you set recommands_policy to a true value, that means: if you then install a distribution Foo that recommends a module Bar, both Foo and Bar will be tested and potentially installed.

similarly, if you set suggests_policy to a true value, it means: if you install a distribution Foo that suggests a module Bar, both Foo and Bar will be tested and potentially installed.

in either case, when Foo passes its tests and Bar does not pass its tests, Foo will be installed nontheless. but if Foo does not pass its tests, neither will be installed. πŸ’€

this also works recursively for all recommends and suggests of the module Bar.

this has also been illustrated by a cpan tester, who wrote:

I just tested Starlink-AST-3.03 which recommends Tk::Zinc; Tk-Zinc-3.306 fails with http://www.cpantesters.org/cpan/report/a2de7c38-810d-11ee-9ad4-e2167316189a ; nonetheless Starlink-AST-3.03 succeeds with http://www.cpantesters.org/cpan/report/9352e754-810d-11ee-90e9-46117316189a

🧬 COMPATIBILITY

πŸ¦• OLD PERL VERSIONS

CPAN.pm is regularly tested to run under 5.005 and assorted newer versions. ngl it is getting more and more difficult to get the minimal prerequisites working on older perls. it is close to impossible to get the whole Bundle::CPAN working there. if you're in the position to have only these old versions, be advised that CPAN is designed to work fine without the Bundle::CPAN installed. 🫢

to get things going, note that GBARR/Scalar-List-Utils-1.18.tar.gz is compatible with ancient perls and that File::Temp is listed as a prerequisite β€” but CPAN has reasonable workarounds if it is missing.

🀝 CPANPLUS

this module and its competitor, the CPANPLUS module, are both much cooler than the other. (yes, that's genuinely what it says 😭) CPAN.pm is older. CPANPLUS was designed to be more modular, but it was never intended to be compatible with CPAN.pm.

πŸ‹ CPANMINUS

in the year 2010 App::cpanminus was launched as a new approach to a cpan shell with a considerably smaller footprint. very cool stuff. ✨


🚨 SECURITY ADVICE

this software enables you to upgrade software on your computer and so is inherently dangerous β€” because the newly installed software may contain bugs and may alter the way your computer works or even make it unusable. please consider backing up your data before every upgrade. like, every single one. fr fr.


πŸ› BUGS

please report bugs via http://rt.cpan.org/

before submitting a bug, please make sure that the traditional method of building a Perl module package from a shell β€” by following the installation instructions of that package β€” still works in your environment.


πŸ‘‘ AUTHOR

Andreas Koenig <andk@cpan.org>


πŸ“œ LICENSE

this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

see http://www.perl.com/perl/misc/Artistic.html


🌏 TRANSLATIONS

Kawai,Takanori provides a Japanese translation of a very old version of this manpage at http://homepage3.nifty.com/hippo2000/perltips/CPAN.htm


πŸ‘€ SEE ALSO

so many people enter the CPAN shell by running the cpan utility program, which is installed in the same directory as perl itself. so if you have this directory in your PATH variable (or some equivalent in your operating system) then typing cpan in a console window will work for you as well. above that, the utility provides several commandline shortcuts. πŸ‘‘

melezhik (Alexey) sent me a link where he published a chef recipe to work with CPAN.pm: http://community.opscode.com/cookbooks/cpan.


and that's a wrap on the whole page, bestie πŸŽ€ this was CPAN(3perl) β€” perl v5.44.0, dated 2026-10-17. go install something, you've earned it πŸ’œπŸ§š

πŸ“¦ where this page comes from
  • arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms