Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I update Perl on Windows without losing modules?

At work I'm using Perl 5.8.0 on Windows.

When I first put Perl on, I went to CPAN, downloaded all the sources, made a few changes (in the .MAK file(?) to support threads, or things like that), and did nmake / nmake test / nmake install. Then, bit by bit, I've downloaded individual modules from CPAN and done the nmake dance.

So, I'd like to upgrade to a more recent version, but the new one must not break any existing scripts. Notably, a bunch of "use" modules that I've installed must be installed in the new version.

What's the most reliable (and easiest) way to update my current version, ensuring that everything I've done with the nmake dance will still be there after updating?

like image 507
piCookie Avatar asked Sep 22 '08 20:09

piCookie


People also ask

Which Perl is best for Windows?

Strawberry Perl (a Perl packaged for Windows) is recommended as you get many useful modules (especially those that are tricky to install) along with it. To interact with the command line and run Perl commands, you need to run 'cmd'. There are better alternatives available as well.

Where does Perl look for modules?

Perl interpreter (which runs your perl program) will use a special array called @INC to search for a file containing the module. Each value in the @INC array is a directory name (but see note below); Perl will search within those directories in a loop using the rules specified below.

How do I know if a Perl module is installed in Windows?

Check installed perl modules via terminal Available commands are: l - List all installed modules m <module> - Select a module q - Quit the program cmd? Then type l to list all the installed modules, you can also use command m <module> to select the module and get its information. After finish, just type q to quit.


6 Answers

As others noted, start by installing the new perl in a separate place. I have several perls installed, each completely separate from all of the others.

To do that, you'll have to configure and compile the sources yourself. When you run configure, you'll get a chance to specify the installer. I gave detailed instructions for this in an "Compiling My Own Perl" in the Spring 2008 issue of The Perl Review. There's also an Item in Effective Perl Programming that shows you how to do it.

Now, go back to your original distribution and run cpan -a to create an autobundle file. This is a Pod document that lists all of the extra stuff you've installed, and CPAN.pm understands how to use that to reinstall everything.

To install things in the new perl, use that perl's path to start CPAN.pm and install the autobundle file you created. CPAN.pm will get the right installation paths from that perl's configuration.

Watch the output to make sure things go well. This process won't install the same versions of the modules, but the latest versions.

As for Strawberry Perl, there's a "portable" version you can install somewhere besides the default location. That way you could have the new perl on removable media. You can test it anywhere you like without disturbing the local installation. I don't think that's quite ready for general use though. The Berrybrew tool might help you manage that.

Good luck, :)

like image 150
brian d foy Avatar answered Oct 12 '22 22:10

brian d foy


I would seriously consider looking at using Strawberry Perl.

like image 32
Andy Lester Avatar answered Oct 12 '22 23:10

Andy Lester


You can install a second version of Perl in a different location. You'll have to re-install any non-core modules into the new version. In general, different versions of Perl are not binary compatible, which could be an issue if you have any program-specific libraries that utilize XS components. Pure Perl modules shouldn't be affected.

like image 36
Michael Carman Avatar answered Oct 13 '22 00:10

Michael Carman


If you stay within the 5.8 track, all installed modules that contain XS (binary) extensions will continue to work, as binary compatibility is guaranteed within the same 5.8 series. If you moved to 5.10 then you would have to recompile any modules that contain XS components.

All you need to do is ensure that the new build lists the previous include directories in its @INC array (which is used to look for modules).

By the sounds of it, I think you're on Windows, in which case the current @INC paths can be viewed with

perl -le "print for @INC"

Make sure you target your new Perl version in another directory. It will happily coexist with the previous version, and this will allow you to choose which Perl installation gets used; it's just a question of getting your PATH order sorted out. As soon as a Perl interpreter is started up, it knows where to look for the rest of its modules.

Strawberry Perl is probably the nicest distribution on Windows these days for rolling your own.

like image 23
dland Avatar answered Oct 12 '22 22:10

dland


I think the answer to this involves virtualisation of some kind:

  1. Set up an exact copy of your current live machine. Upgrade Perl, using the same directory locations and structures as you're using at the moment.
  2. Go through your scripts testing them on the new image.
  3. Once you're happy, flip the switch.

The thinking behind this is that there's probably all sorts of subtle dependencies and assumptions you haven't thought of. While unlikely, the latest version of a particular module (possibly even a core module, although that's even more unlikely) might have a subtle difference compared to the one you were using. Unless you've exhaustively gone through your entire codebase, there's quite possibly a particular module that's required only under certain circumstances.

You can try and spot this by building a list of all your scripts - a list that you should have anyway, by dint of all your code being under version control (you are using version control, e.g. Subversion, yes?) - and iterating through it, running perl -c on each script. e.g. this script. That sort of automated test is invaluable: you can set it running, go away for a coffee or whatever, and come back to check whether everything worked. The first few times you'll probably find an obscure module that you'd forgotten about, which is fine: the whole point of automating this is so that you don't have to do the drudge-work of checking every single script.

like image 30
Sam Kington Avatar answered Oct 12 '22 22:10

Sam Kington


When I did it I installed the newer one into a separate directory. There's a bit of added confusion running two versions, but it definitely helps make sure everything's working first, and provides a quick way of switching back to the old one in a pinch. I also set up Apache to run two separate services, so I could monkey around with the newer Perl in one service without touching the production one on the old Perl.

It's probably a lot wiser, in hindsight, to install on a separate computer, and do your testing there. Record every configuration change you need to make.

I am not sure about building it yourself—I always just used prepackaged binaries for Windows.

I'm not sure I understand exactly what you're asking. Do you have a list of changes you made to the 5.8 makefile? Or is the question how to obtain such a list? Are you also asking how to find out which packages above the base install you've obtained from CPAN? Are you also asking how to test that your custom changes won't break those packages if you get them from CPAN again?

like image 43
Kev Avatar answered Oct 12 '22 23:10

Kev