Εγκατάσταση, και πώς να βρείτε ό,τι εγκαταστήσατε#
Η εντολή#
Οτιδήποτε ακολουθεί το --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.