If you are using cpanm
you can force it to rebuild modules in your local::lib
location by using the -L
and --reinstall
switches:
list_modules | cpanm -L ~/perl5 --reinstall
where list_modules
is a script that feeds the names of modules to cpanm
(there's also an -f
option to cpanm
). This script could be like @ikegami's above or something like cpan-outdated
(which only lists outdated modules however). Here is a
hackish attempt that mostly worked for me recently (note: ikegami's is probably better) - when it fails or the script gives cpanm
a module name it doesn't recognize, cpanm
keeps going and doesn't seem to break anything (but make backups):
cd $PERL_LOCAL_LIB_ROOT
perl -MFile::Find -MConfig -E'
find {
wanted => sub {
$mod = $_ if /\.pm\z/;
$mod =~ s/lib\/perl5\/auto\/.*//g;
$mod =~ s/lib\/perl5\/\Q$Config{archname}\E\/.*//g;
$mod =~ s/lib\/perl5\///g;
push @mods, $mod unless $mod =~ /^$/;
},no_chdir=>1
},"lib/perl5"; @modhash{@mods}=(); say for sort keys %modhash '
By changing where and what File::Find
finds with wanted()
you can feed a different list of modules to cpanm
. It would be nice if cpan
or cpanm
had an internal _method
or -switch
that allowed you to force the rebuilding of local::lib
installed modules that use XS. Is there such a thing?
It was cpanm
, carton
(and seeing the node.js
tool npm
in action) that inspired me to do a lot more local::lib
based installs. Now the CORE bundled "CPAN client" that ships with perl (cpan
) seems to be getting more automagical and easier to use as well. I really like local::lib
since it allows you to use the system perl
but manage your own module stack without system level privileges. However, it can be easier overall to manage changes and upgrades if you use perlbrew
to run a "non system" ("local") perl
. Of course you can do this and still have local::lib
, carton
etc. manage a directory or application specific stack of modules.
1). Another way to do an upgrade is to use perllocal
to generate a list of your currently installed modules (NB I'm not entirely sure if perllocal.pod
is kept in a reliable/useful state). [Edit: In fact perllocal
keeps a history of your installed modules rather than a list of those currently installed. You'll want to filter this or you will end up reinstalling the entire series of module versions one after the other!). This perlmonks node shows how to clean up your perllocal.pod
: http://www.perlmonks.org/?node_id=483020. I prefer to keep the history.]
To parse perllocal.pod
for input to cpanm
, search through the file saving the matches in an array, then split them by twos to create a hash from the array elements (key,value,key,value
). More recent installations and versions numbers are lower in the file, so you can create a hash with module names as keys and have the values updated by later entries:
perl -ne 'push @arr, grep {defined}
(/\A=head2.*:\s+C<Module>\s+L<(.*)\||.*C<VERSION:\s(.*)>\Z/msx); }{
%h = map{ split/,/,$_,2 } @arr; print "$_\@$h{$_}\n" for keys %h' perllocal.pod
(NB: this doesn't error check - entries in perllocal.pod
occasionally lack VERSION
data and other oddities so beware.)
2). But this method pales in comparison to the shell script mentioned by ilmari in #perl-help on IRC. It uses
jq
- a commandline utility you really need to have (you'll want it more after this). If you have used cpanm
to install your modules it will have created install.json
files. You can leverage that to make list to feed to cpanm
for reinstalling your current set of modules:
find ~/perl5/ -name install.json -exec jq '.name + "@" + .version' {} +
Very fast, very simple and you can combine it with the cpanm
method of using curl
to self-install in order to rebuild your modules.
3). If you use perlbrew
to manage your perl installations you can easily copy and reinstall all your modules from one perl
version to another.
HTH!
perl -MCPAN -Mlocal::lib -e "CPAN::install($module)"
(as per thelocal::lib
docs). I've put some wrapper code around it to reinstalllocal::lib
and handle errors gracefully and it seems to work fine, though it does take a long time and tries to install a lot of modules which don't exist. – Saskatoon