#  Reinstall packages that add their own perl modules
if [ -n "$(get_module_config UPGRADE_PERL_MODULES)" ]; then
  message "$MESSAGE_COLOR" &&
  message "Any perl module previously installed is now broken due to the way"  &&
  message "perl handles modules. They need to be recompiled in order to work." &&
  message "$DEFAULT_COLOR" &&
  OLD_PERL_VERSION=$(get_module_config OLD_PERL_VERSION) &&
  if query "Do you want lunar to attempt to upgrade your perl modules?" ${ASK_FOR_REBUILDS:-y}; then
    # preserve CPAN config?
    if [ ! -f /usr/lib/perl5/$VERSION/CPAN/Config.pm -a -f /usr/lib/perl5/$OLD_PERL_VERSION/CPAN/Config.pm ]; then
      cp /usr/lib/perl5/$OLD_PERL_VERSION/CPAN/Config.pm /usr/lib/perl5/$VERSION/CPAN/Config.pm
    fi &&
    PERLMODS="$( lvu from /usr/lib/perl5/ | cut -d: -f1 | uniq )" &&
    for PERLMOD in $(sort_by_dependency $PERLMODS); do
      if [[ $PERLMOD != "perl" ]]; then
        lin -c $PERLMOD || true
      fi
    done
  fi &&
  unset_module_config OLD_PERL_VERSION &&
  unset_module_config UPGRADE_PERL_MODULES
fi &&

message "$MESSAGE_COLOR" &&
message "Remember to re-install all CPAN modules by hand!" &&
message "$DEFAULT_COLOR" &&

# re-lin vim if perl support there has been enabled, otherwise it will stop working
# if module_installed vim ; then
#   if in_depends vim perl ; then
#     verbose_msg "Rebuilding vim ..."
#     lin -c vim
#   fi
# fi
# unfortunately the in_depends branch in the above never fires due to a bug
# see http://bugs.lunar-linux.org/view.php?id=474
# therefore just rebuild vim whether it uses perl or not
if module_installed vim; then
  verbose_msg "Rebuilding vim ..." &&
  lin -c vim
fi
