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

My CPAN module is v1.9800 and /usr/bin/cpan is v1.57 (2009).

As of CPAN v2.37, the "-n" option (dry run) remains unimplemented.

How do I perform a dry run of a module installation ? (ie. execute downloads, dependency checks, compile, tests, execute any "install" steps but not actually install anything).

Replies are listed 'Best First'.
Re: How to CPAN dry run ?
by marto (Cardinal) on Aug 30, 2024 at 08:22 UTC

    "How do I perform a dry run of a module installation ?

    Use cpanm, cpanm --test-only DBI.

      Note that cpanm --test-only will install any unsatisfied dependencies.
Re: How to CPAN dry run ?
by ikegami (Patriarch) on Aug 30, 2024 at 15:15 UTC

    You could install to a temporary directory by providing an install base via PERL_MM_OPT and PERL_MB_OPT.

Re: How to CPAN dry run ?
by afoken (Chancellor) on Aug 31, 2024 at 09:51 UTC
    How do I perform a dry run of a module installation ?

    Let me propose something unconventional:

    Create a virtual machine, and create a snapshot BEFORE the installation. Then do a cpan My::New::Module and watch it fail, crash and burn. Revert to the snapshot, fix the problems, and try again.

    I did something very similar to get a custom application installed in the last century. My installer required a fully patched Windows 2000 server and a database. Everything after that (webserver, perl, modules, application) was installed by my installer. To test the installer, I used a virtual machine set up with W2K, DB and patches, took a snapshot, and watched my installer fail over and over again, reverting the VM after each fail. See Re: How do you distribute your Perl application to your customers? and Re^3: How do you distribute your Perl application to your customers?.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: How to CPAN dry run ?
by Danny (Chaplain) on Aug 30, 2024 at 16:46 UTC
    On a related note, is there a good way to log all the unsatisfied dependencies without installing anything? On Cygwin I like to install modules from the Cygwin repository if available so they get updated etc. I often end up installing via cpan then look up all the newly installed dependencies and checking if any are available from Cygwin. Then I have to go back and remove from /usr/local/...

      I believe that this is what cpanm --scandeps does, although note that this is marked as a deprecated feature.


      🦛

        Great! Strangely, when I tried this before it did not work, but now seems to. I may have been missing a dependency before and just assumed that "deprecated" was really now fully gone.

        Update: I searched my history to find where I tried it previously. It turns out there was a unicode point 151 (which shows nothing in the terminal) immediately following --scandeps, which caused cpanm to tell me 'Unknown option: scandeps'

Re: How to CPAN dry run ?
by stevieb (Canon) on Aug 30, 2024 at 08:18 UTC
    How do I perform a dry run of a module installation ?

    What do you want to dry run against? Your current situated environment? A Windows, Linux or MacOS installation nearby? Do you want to ensure compilation of low-level code that isn't pure perl?

    Your question is very vague. It almost seems as though you have a complaint against an unimplemented flag, yet you haven't provided any tests or anything.

    You don't 'execute' downloads. If a distribution has direction, it is often make test. Done. All tests performed, including dependency checks, and nothing installed.

      > it is often make test. Done. All tests performed, including dependency checks, and nothing installed.

      It already installs all the dependencies.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

        I stand corrected.

      "Your question is very vague. It almost seems as though you have a complaint against an unimplemented flag, yet you haven't provided any tests or anything."

      It's not a complaint, it's an observation based on what the documentation tells people:

      "Do a dry run, but don't actually install anything. (unimplemented)"

      I'd argue the question isn't vague, since they ask how to do a specific thing.

      What do you want to dry run against? Your current situated environment? A Windows, Linux or MacOS installation nearby? Do you want to ensure compilation of low-level code that isn't pure perl?

      I want to review whatever cpan is doing (or going to do), and pre-determine the success of an operation before it actually modifies or installs anything, especially on a production server.

      I could tolerate it downloading and installing things into 1 single known temporary directory that I can rm -rf afterwards as long as I can isolate all of its changes (and [preferably] easily rollback).

      I'm also surprised the -n option still isn't implemented after +10 years.

        I want to review whatever cpan is doing (or going to do), and pre-determine the success of an operation before it actually modifies or installs anything, especially on a production server.

        That's why you should have a test/staging server configured in the same way as the production server.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)