Dealing With Duplicate CPAN Modules

Occasionally it may happen that you get multiple versions of a CPAN module or modules installed on your system, in which case you'll get error messages like "DBI object version 1.607 does not match $DBI::VERSION 1.604".

First thing you want to do is run this script:


(eval `perl -V:archname -V:version`; \
  perl -MCwd=abs_path -le '@u{map { abs_path($_) } grep { $_ ne "." } @INC} = (); print for keys %u' \
  | while read d; do \
    (chdir $d; find . -name '*.pm' | grep -v "$archname/" | grep -v "$version/"); done) \
  | sort | uniq -d

This will print out the .pm files for duplicate modules. If the script returns results, the next step is to reconfigure your CPAN and create an autobundle.

Launch cpan and run the following:

cpan[2]> o conf make_install_arg UNINST=1
cpan[3]> o conf mbuild_install_arg uninst=1
cpan[4]> o conf commit
commit: wrote '/home/rkitover/.cpan/CPAN/'
cpan[5]> autobundle
Wrote bundle file

Make a note of the name of the bundle file.

Now run the above script through:

./dup_script | xargs sudo rm -rf

Now you should be able to reinstall the modules with the proper settings, using the bundle you created earlier.

Enter cpan and do:

cpan[1]> notest install Bundle::Snapshot_2009_02_22_00

The name of the bundle is based on the bundle file you created earlier.

NOTE: if you have an old you don't get a "notest" command, if this is the case do an "install CPAN" first and restart cpan. Or just do a regular "install".

Now all of your broken modules should get properly reinstalled!

Last modified: 2009-5-4 (月) at 2:57 am