a car parked beside airplane

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 years and count­ing on CPAN, the Comprehensive Perl Archive Network. Starting with ver­sion 5.004 in 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 CPANPLUS and its cpanp com­mand or cpan­mi­nus and its cpanm, or tools built on the lat­ter such as Carton and 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 cites an instal­la­tion of Plack, the Perl web appli­ca­tion toolk­it, as tak­ing three times as long using cpanm ver­sus cpm. Both use the same Menlo core code but cpm achieves 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­tion from The Perl Conference 2016 pro­vides a great summary:

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

It’s very impor­tant to note that cpm is not a drop-​in replace­ment for the cpan or cpanm command-​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::lib mod­ule; oth­er­wise, you should use cpm install --global to install into a direc­to­ry in Perl’s @INC array. 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 cpm will use a cpanfile to 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.snapshot file intro­duced by Carton for track­ing exact depen­den­cies used by your project. This is great for repeat­ed­ly build­ing Docker con­tain­ers and cpm makes that process even faster.

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

“CONFLICT” Scrabble tiles

If you’re writ­ing Perl that’s nev­er going to the Comprehensive Perl Archive Network (CPAN), heed this little-​known note on the Perl Authors Upload Server (PAUSE):

By con­ven­tion, the top-​level Local name­space should nev­er con­flict with any­thing on CPAN. This allows you to be con­fi­dent that the name you choose under Local isn’t going to con­flict with any­thing from the out­side world.

PAUSE: On The Naming of Modules

So, Local::MyModule, Local::App::MyApp, what­ev­er. This is also good advice for bespoke appli­ca­tions and libraries (the so-​called DarkPAN) you’re devel­op­ing in-​house. The last thing you need is to acci­den­tal­ly bring in (per­haps via depen­den­cies) a mod­ule that gets loaded instead of yours.