jimav has asked for the wisdom of the Perl Monks concerning the following question:

What exactly is "cpan -r" supposed to do? The man page says it runs CPAN::Shell->recompile and perldoc CPAN says recompile() should recompile XS code for all installed dynamically-linked extensions. But in fact, it seems to download and install many other modules I never installed!

To be sure I wasn't hallucinating, I created a brand-new user with an empty home directory, used local::lib to set up a local cpan build environment. Then ran "cpan -r" expecting it to do nothing because the new user had never installed any CPAN modules. However, it proceeded to download and install zillions of modules, until it finally failed with some unmet dependency. What causes this!?!

Can someone explain (or point me to documentation explaining) where "cpan -r" looks to decide what modules to update, and what is the correct procedure for just rebuilding the XS code for only the modules I previously installed? Really, I just want to recover from XS breakage due to perl being updated (during an OS upgrade).

BTW, I just did a clean Ubuntu 17.10 install (preserving only /home), so the system perl installation and library are pristine. And I never ran cpan as root, so there is no way it could have damaged the system setup (assuming there isn't a suid program lurking somewhere in cpan)

Here's what I did:

#Create a new user with pristine environment
$ sudo adduser test  
$ sudo rm -f /home/test/.*   # get rid of .profile or any other influence
$ sudo su - test
$ ls -a
.  ..  .bash_history 
# set up ~/perl5 and set environment vars for local cpan library
$ eval "$(perl -I/path/to/other/user/perl5 -Mlocal::lib)
$ env | grep -i PERL
PERL_MB_OPT=--install_base "/home/test/perl5"
PERL_MM_OPT=INSTALL_BASE=/home/test/perl5
PERL_LOCAL_LIB_ROOT=/home/test/perl5
PERL5LIB=/home/test/perl5/lib/perl5
PATH=/home/test/perl5/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin

# set up cpan for local builds
$ cpan
Sorry, we have to rerun the configuration dialog for CPAN.pm due to
some missing parameters. Configuration will be written to
 <</home/test/.cpan/CPAN/MyConfig.pm>>
CPAN.pm requires configuration, but most of it can be done automatically.
If you answer 'no' below, you will enter an interactive dialog for each
configuration option instead.
Would you like to configure as much as possible automatically? yes I hit Enter
Autoconfiguration complete.
commit: wrote '/home/test/.cpan/CPAN/MyConfig.pm'
...
quit

# Now the craziness begins...
# Since this test user has never installed any CPAN modules, I expected
# "cpan -r" to do nothing.  But...
$ cpan -r
Loading internal null logger. Install Log::Log4perl for logging messages
Fetching with LWP:
http://www.cpan.org/authors/01mailrc.txt.gz
Reading '/home/test/.cpan/sources/authors/01mailrc.txt.gz'
............................................................................DONE
Fetching with LWP:
http://www.cpan.org/modules/02packages.details.txt.gz
Reading '/home/test/.cpan/sources/modules/02packages.details.txt.gz'
  Database was generated on Thu, 14 Dec 2017 04:29:02 GMT
............................................................................DONE
Fetching with LWP:
http://www.cpan.org/modules/03modlist.data.gz
Reading '/home/test/.cpan/sources/modules/03modlist.data.gz'
DONE
Writing /home/test/.cpan/Metadata
.......................................................
  CPAN: Recompiling A/AM/AMS/Storable-2.51.tar.gz

Fetching with LWP:
http://www.cpan.org/authors/id/A/AM/AMS/Storable-2.51.tar.gz
Fetching with LWP:
http://www.cpan.org/authors/id/A/AM/AMS/CHECKSUMS
Checksum for /home/test/.cpan/sources/authors/id/A/AM/AMS/Storable-2.51.tar.gz ok
'YAML' not installed, will not store persistent state
Configuring A/AM/AMS/Storable-2.51.tar.gz with Makefile.PL
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for Storable
Writing MYMETA.yml and MYMETA.json
  AMS/Storable-2.51.tar.gz
  /usr/bin/perl Makefile.PL INSTALLDIRS=site -- OK
Running make for A/AM/AMS/Storable-2.51.tar.gz
cp Storable.pm blib/lib/Storable.pm
Running Mkbootstrap for Storable ()
chmod 644 "Storable.bs"
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- Storable.bs blib/arch/auto/Storable/Storable.bs 644
"/usr/bin/perl" "/usr/share/perl/5.26/ExtUtils/xsubpp"  -typemap '/usr/share/perl/5.26/ExtUtils/typemap'  Storable.xs > Storable.xsc
mv Storable.xsc Storable.c
x86_64-linux-gnu-gcc -c   -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g   -DVERSION=\"2.51\" -DXS_VERSION=\"2.51\" -fPIC "-I/usr/lib/x86_64-linux-gnu/perl/5.26/CORE"   Storable.c ...
<and much more>

...Eventually it died with some unsatisfied dependency...

Fetching with LWP:
http://www.cpan.org/authors/id/X/XA/XAOC/Pango-1.227.tar.gz
Checksum for /home/test/.cpan/sources/authors/id/X/XA/XAOC/Pango-1.227.tar.gz ok
---- Unsatisfied dependencies detected during ----
----          XAOC/Pango-1.227.tar.gz         ----
    ExtUtils::Depends build_requires
    ExtUtils::PkgConfig build_requires
  • Comment on Why does "cpan -r" download new modules?

Replies are listed 'Best First'.
Re: Why does "cpan -r" download new modules?
by ikegami (Patriarch) on Dec 14, 2017 at 07:18 UTC

    For each module on CPAN (as returned by the cpan shell command m /./), cpan -r searches the directories named in @INC for a DLL named after the module (e.g. auto/Foo/Bar.so or auto/Foo/Bar.dll for module Foo::Bar, depending on your system). If the DLL is found, it flags the module for reinstallation.

    You claim you never installed any modules, but some were installed along with Perl, and some of those are dual-lived. cpan is reinstalling those (e.g. Storable).

    There are no sources on your machine, so reinstalling requires downloading.

    It downloads the latest version of each module. This may introduce new dependencies.


    By the way, you appear to be saying that "Unsatisfied dependencies detected during" is an error, but it's not. It's just a list of modules the distribution is requesting to install.

Re: Why does "cpan -r" download new modules?
by Discipulus (Canon) on Dec 14, 2017 at 18:54 UTC