Installing, and finding what you installed#
The command#
Everything after --cpan goes to the CPAN client, so any option of the cpan command you already know still works: -T to skip the tests, -f to force an install.
pperl --cpan Text::CSV
pperl --cpan Plack Starman
pperl --cpan -T Try::Tiny
Besides module names, --cpan takes a git repository: a URL that starts with git: or ends in .git. It is cloned and installed from the clone. Append @ and a branch, tag or commit to install that revision.
pperl --cpan https://github.com/example/Some-Dist.git
pperl --cpan https://github.com/example/Some-Dist.git@v1.2
With nothing to install, it says so rather than guessing:
pperl --cpan
# pperl: --cpan: nothing to install: pperl --cpan Module::Name [...]
When a run ends with modules it did not install, because CPAN does not know the name or because a distribution failed, the last line names them and pperl --cpan exits with status 1, so a script or a build step that runs it notices:
pperl --cpan No::Such::Module
# ...
# pperl: --cpan: not installed: No::Such::Module
echo $?
# 1
Where it goes#
Modules land in a pperl-owned tree, never in a perl5 one. The base is $PPERL_HOME, or ~/.pperl if that is unset:
~/.pperl/
├── lib/perl5/ <- the modules
└── cpan/ <- the installer's downloads and builds
--cpan --system installs for every account on the machine instead, under /usr/local/share/pperl:
/usr/local/share/pperl/
├── site_perl/ <- the modules
├── bin/ <- their scripts
├── man/ <- their manuals
└── cpan/ <- the installer's downloads and builds
Every pperl searches site_perl there without being told. Writing there takes root’s rights, or an account that may write /usr/local/share/pperl, so run it as sudo pperl --cpan --system Some::Module. Without those rights it stops before it downloads anything and says so.
Keeping the tree separate is deliberate. A machine commonly has both pperl and a real perl5, and a module built for one has no business being found by the other.
Making pperl see it#
pperl searches its own tree without being told: lib/perl5 under $PPERL_HOME, or under ~/.pperl if that is unset, comes ahead of every system tree. A module installed with pperl --cpan is found by the next pperl run, and it outranks a same-named copy belonging to the host perl:
pperl --cpan Text::CSV
# pperl: installed into /home/you/.pperl/lib/perl5
pperl -e 'print "$_\n" for @INC'
# ...
# /home/you/.pperl/lib/perl5
# /usr/share/perl5/site_perl
# ...
The same holds for the --system tree, which comes after the per-user one. Other trees you add yourself, with -I, PERL5LIB, or PPERL5LIB. PPERL5LIB is the pperl-private twin of PERL5LIB: same syntax, colon-separated, but read only by pperl, and honoured ahead of PERL5LIB:
PPERL5LIB=/opt/mytree PERL5LIB=/home/you/perl5/lib/perl5 \
pperl -e 'print "$_\n" for @INC'
# ...
# /opt/mytree <- PPERL5LIB
# /home/you/perl5/lib/perl5 <- PERL5LIB
# /home/you/.pperl/lib/perl5
# /usr/share/perl5/site_perl
# ...
Why a separate variable rather than reusing PERL5LIB: on a machine running both interpreters, PERL5LIB is usually already pointing at the host perl’s trees. Overloading it would force you to choose between the two. Both are read, PPERL5LIB first.
Why pperl reads the system trees at all#
pperl searches the host perl’s directories because a pure-Perl module found there runs perfectly well under pperl. That is free inventory and there is no reason to refuse it.
pperl also searches the architecture directory of each tree you add with PPERL5LIB, PERL5LIB or -I, and of ~/.pperl/lib/perl5, as perl does: <tree>/x86_64-linux and <tree>/<version>/x86_64-linux, ahead of the tree, when they exist. A distribution that declares XS installs its modules there, even its pure-Perl ones. Their compiled parts pperl cannot load, and the no-XS rule explains where that bites.
The tools it uses, and downloads over https#
Like perl’s own cpan on its first run, pperl --cpan looks on your PATH for the programs the CPAN client works with: make, tar, gzip, bzip2, unzip, gpg, patch and applypatch, and a downloader, the first it finds of wget, curl, lynx, ncftpget, ncftp and ftp.
pperl speaks https by itself only in a build with the native-max module set, which contains IO::Socket::SSL. Any other build downloads from CPAN over https through wget or curl, and fetches the XS substitutes the same way. To check which you have, run:
pperl -MIO::Socket::SSL -e 1
A build with TLS support prints nothing. One without it says Can't locate IO/Socket/SSL.pm in @INC, adding that it was built without the native-max capability.
A host with neither TLS support in pperl nor wget or curl falls back to plain http, and the CPAN client warns about it; see troubleshooting. Installing curl or wget is the remedy.
Installing without a network#
A distribution archive or an unpacked directory on disk installs without a download of its own. Name a directory with a leading ./ or /, so that it cannot be taken for a module name:
pperl --cpan ./Some-Dist-1.23.tar.gz
pperl --cpan ~/src/Some-Dist
The client still fetches the CPAN index on its first run, and any dependency that is not installed yet. It also tries to refresh the XS substitutes; without a network it says so and uses the ones it already has.
Tests run non-interactively: PERL_MM_USE_DEFAULT and NONINTERACTIVE_TESTING are both set, so a distribution that would otherwise stop to ask a question takes its own default instead of hanging.
Distribution preferences#
pperl --cpan applies CPAN.pm’s distribution preferences, the “distroprefs” described in CPAN under “Configuration for individual distributions”. A preference is a YAML file that matches distributions by name and changes how they are built: environment variables, build arguments, extra prerequisites, patches applied before the build.
Preferences go into prefs/ under the installer’s directory: ~/.pperl/cpan/prefs, or /usr/local/share/pperl/cpan/prefs for --system. A patch that a preference names is looked up in the same directory, so a preference and its patch sit side by side:
---
match:
distribution: '^AUTHOR/Some-Dist-1\.23'
patches:
- Some-Dist-1.23.patch
pperl reads .yml preferences with its built-in YAML::XS, so nothing else needs installing.
XS substitutes#
Before it installs anything, each pperl --cpan run fetches pperl’s pure-Perl substitutes for distributions that have a compiled part, from https://perl.petamem.com/downloads/cppan, into prefs/cppan beside your own preferences. Each substitute is a preference with a patch: it matches one XS distribution and replaces its compiled part with Perl. Because the set is fetched on every run, a substitute published after your pperl was released applies to it too.
Text::CSV_XS, for example, installs and runs on the Perl engine of Text::CSV; other substitutes rest on features and functions perl and pperl have built in. Where a distribution’s own tests show a difference from its compiled version, those tests are marked TODO, so you can see exactly what differs.
An unchanged set is not downloaded again. When the server cannot be reached, the run warns and uses the substitutes it fetched last. PPERL_CPPAN_URL names another address to fetch from; set to an empty string, it turns the fetch off, and the substitutes already on disk still apply.