Tag: cpm

  • Fast Perl module installation with cpm

    Fast Perl module installation with cpm

    One of Perl’s car­di­nal strengths is the depth and vari­ety of add-​on mod­ules to extend its capa­bil­i­ties, col­lect­ed for the past 26 yearsand count­ing on CPAN, the Comprehensive Perl Archive Network. Starting with ver­sion 5.004in 1997, Perl has come pack­aged with a mod­ule (also called CPAN) and asso­ci­at­ed command-​line client for down­load­ing and installing from this ser­vice. Some devel­op­ers favor alter­na­tive tools such as CPANPLUSand its cpanpcom­mand or cpan­mi­nusand its cpanm, or tools built on the lat­ter such as Cartonand Carmel.

    My favorite of these over the past sev­er­al years has been Shoichi Kaji’s cpm, main­ly because it’s blaz­ing­ly fast. As an exam­ple, the doc­u­men­ta­tion citesan instal­la­tion of Plack, the Perl web appli­ca­tion toolk­it, as tak­ing three times as long using cpanmver­sus cpm. Both use the same Menlocore code but cpmachieves its speed by break­ing down depen­den­cies into indi­vid­ual streams, installing mod­ules in par­al­lel, and syn­chro­niz­ing the nec­es­sary work­er processes.

    Shoichi’s pre­sen­ta­tionfrom The Perl Conference2016 pro­vides a great summary:

    Shoichi Kaji: ​“Why a new CPAN client ​‘cpm’ is fast” (2016)

    It’s very impor­tant to note that cpmis not a drop-​in replace­mentfor the cpanor cpanmcommand-​line tools. Firstly, it uses the sub­com­mand install, e.g., cpm install Module::Name. Also, by default, it installs mod­ules into a sub­di­rec­to­ry named local/as if you spec­i­fied cpanm --local-lib-contained local. You might want this if you’re set­ting up a Perl project with its non-​core depen­den­cies in a sep­a­rate loca­tion addressed by the local::libmod­ule; oth­er­wise, you should use cpm install --globalto install into a direc­to­ry in Perl’s @INCarray. I tend to do the lat­ter when devel­op­ing, declar­ing my project’s depen­den­cies in a cpanfile.

    Speaking of cpanfiles, like cpanm --installdeps cpmwill use a cpanfileto dri­ve project depen­den­cy instal­la­tion. In fact, it defaults to look­ing for one if you don’t spec­i­fy indi­vid­ual mod­ules on the com­mand line and sup­ports the version-​controlled cpanfile.snapshotfile intro­duced by Cartonfor track­ing exact depen­den­cies used by your project. This is great for repeat­ed­ly build­ing Dockercon­tain­ers and cpmmakes that process even faster.

    Although speed is its most impor­tant fea­ture, cpmhas a cou­ple more tricks up its sleeve like installing from a Gitrepos­i­to­ry or self-​hosted ​“DarkPAN.” Check out its includ­ed tuto­r­i­al.