Each time an upgrade to OS X comes along, I end up have to go through a whole mess of updating Perl modules. Why? I made the mistake of writing a utility in Perl that relies on several CPAN modules, including Curses, Curses::UI, Mac::iTunes::Library, and File::HomeDir. At the time I wanted to learn to use Curses. I should remake this utility in something else, but when Perl is working the utility works like I need it to. The utility allows me to sync playlists from my iTunes library to SD cards, without the chore of manually moving them around.
After an upgrade, I usually end up with several errors like this:
Can't locate Curses.pm in @INC (you may need to install the Curses module) (@INC contains: /Users/xxxxx/Library/Perl /Library/Perl/5.18/darwin-thread-multi-2level /Library/Perl/5.18 /Network/Library/Perl/5.18/darwin-thread-multi-2level /Network/Library/Perl/5.18 /Library/Perl/Updates/5.18.2 /System/Library/Perl/5.18/darwin-thread-multi-2level /System/Library/Perl/5.18 /System/Library/Perl/Extras/5.18/darwin-thread-multi-2level /System/Library/Perl/Extras/5.18 .) at /Users/xxxxx/Library/Perl/Curses/UI/Common.pm line 20.
Tired of seeing this, I removed the dependency for “File::HomeDir” with a minor change to my MediaSync perl source code. That still leaves the problem of the other modules.
I described in an earlier post how to install CPAN modules in OS X. Since this method uses sudo, I’ll use it only to install the Curses module.
Now I am going to setup a module library that is independent of the Perl version, and not going to become broken when OS X is upgraded.
- Create a directory to hold the Perl modules. I chose “~/Library/Perl”, which is in my users Library. Open the Library folder, and create a new sub folder called Perl.
- Copy your other CPAN modules to the new “~/Library/Perl” folder. If the module has a directory structure to it, copy it intact. For example, the two modules I need are Curses::UI, and Mac::iTunes::Library. You can see I moved the entire directory structure over intact.
- Next, Perl needs to be able to find the custom location of my module library. The @INC path needs to get updated. To do this, you need to export the path you want to add from your bash shell’s profile (~/.bash_profile). Add the following line:
- With the above line added, each time the shell is invoked Perl will add the defined path to @INC when started.
Now the my module library is independent of the installed Perl version, and won’t get wiped out by an OS update. You might ask why I didn’t include the Curses module. My response is that the OS Curses library may be updated with an OS update, and I want the Perl module to be rebuilt so it reflects any new or removed functions in the base OS library.
And MediaSync is running again: