Refactor duplicate code for checking if cpanm is installed.