התקנה, ומציאת מה שהתקנתם#

הפקודה#

כל מה שבא אחרי --cpan עובר אל לקוח ה־CPAN, ולכן כל אפשרות של הפקודה cpan שאתם כבר מכירים ממשיכה לעבוד: -T כדי לדלג על הבדיקות, -f כדי לכפות התקנה.

pperl --cpan Text::CSV
pperl --cpan Plack Starman
pperl --cpan -T Try::Tiny

מלבד שמות מודולים, --cpan מקבל מאגר git: כתובת URL שמתחילה ב־git: או מסתיימת ב־.git. הוא משוכפל, וההתקנה נעשית מתוך השכפול. הוסיפו בסופו @ וענף, תג או commit כדי להתקין את הגרסה הזו.

pperl --cpan https://github.com/example/Some-Dist.git
pperl --cpan https://github.com/example/Some-Dist.git@v1.2

כשאין מה להתקין, הוא אומר זאת במקום לנחש:

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

לאן זה נוחת#

מודולים נוחתים בעץ שבבעלות pperl, לעולם לא בעץ של perl5. הבסיס הוא $PPERL_HOME, או ~/.pperl אם זה אינו מוגדר:

~/.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.

השארת העץ נפרד היא מכוונת. במכונה מצויים בדרך כלל גם pperl וגם perl5 אמיתי, ולמודול שנבנה עבור האחד אין מה להימצא על ידי האחר.

לגרום ל־pperl לראות אותו#

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
# ...

מדוע משתנה נפרד ולא שימוש חוזר ב־PERL5LIB: במכונה שמריצה את שני המפרשים, PERL5LIB בדרך כלל כבר מצביע על העצים של ה־perl המארח. העמסתו הייתה מאלצת אתכם לבחור בין השניים. שניהם נקראים, PPERL5LIB ראשון.

מדוע pperl קורא בכלל את עצי המערכת#

pperl מחפש בספריות של ה־perl המארח משום שמודול Perl טהור שנמצא שם רץ מצוין תחת pperl. זהו מצאי חינם ואין סיבה לסרב לו.

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.

התקנה ללא רשת#

ארכיון הפצה או ספרייה פרוסה על הדיסק מותקנים ללא הורדה משל עצמם. ציינו ספרייה עם ./ או / בתחילתה, כדי שלא תיחשב בטעות לשם מודול:

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.

הבדיקות רצות באופן לא־אינטראקטיבי: PERL_MM_USE_DEFAULT ו־NONINTERACTIVE_TESTING מוגדרים שניהם, ולכן הפצה שאחרת הייתה עוצרת כדי לשאול שאלה לוקחת את ברירת המחדל שלה במקום להיתקע.

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.