What to Do When You re Not Allowed to Install Modules

 <  Day Day Up  >  

What to Do When You're Not Allowed to Install Modules

If you can install programs on a system, you can install modules. Your ability to do so depends on how complex the module is and what kind of trouble you're willing to go through. Sometimes the system administrator does not allow you to install a module because he or she doesn't want it used by others. In some cases, only you, or a group of people, want specific modules, and having them installed systemwide is too much hassle.

In either case, installing private copies of Perl modules in your own directories is not difficult.

First, you need to build the module using the instructions given previously ”with a small exception. You can specify to the installation program that you want the modules placed in a particular directory. With PPM under Microsoft Windows, before you install the module, you need to tell PPM that you want to install into a different directory. You do so by using the set command like this:

 PPM>  set root c:\myperl  PPM>  set build c:\myperl  

The module is then assembled and installed in the directory c:\myperl.

Under UNIX, when you're using the CPAN module, you can specify the installation directory by using the makepl_arg setting like this:

 cpan>  o conf makepl_arg PREFIX="/home/clintp/perl/lib"  

Or, if you're installing modules by hand using the make utility, you can specify the installation directory by using the PREFIX argument on the first line during the build:

 $  perl Makefile.PL PREFIX="/home/clintp/perl/lib"  

Using either method, the module you're trying to install is installed into /home/clintp/perl/lib. You can then move this module to another directory if you need to.

Watch Out!

You should be careful not to move modules between different kinds of machines. A compiled module will only work on one kind of system, like Perl itself. Also, try not to move modules between different versions of Perl; it sometimes does not work. In that case, you have to rebuild the module.


Using Modules Installed in Strange Places

To use modules that are installed in a directory other than the standard directory, you need to use a directive called use lib . For example, if you install the module Date::Manip in the directory /home/clintp/perl/lib using the instructions in the preceding section, you would have a file tree like the one shown in Figure A.2.

Figure A.2. File tree after installation for Date::Manip.


At the beginning of your program, you can simply put the following:

 use lib '/home/clintp/perl/lib';   # Look for module here else use Date::Manip; 

Perl then searches that directory for the module before it searches any of its own directories. You also can use this technique to install newer versions of modules onto the system ”for testing ”without overwriting older versions and creating incompatibilities.

 <  Day Day Up  >  


SAMS Teach Yourself Perl in 24 Hours
Sams Teach Yourself Perl in 24 Hours (3rd Edition)
ISBN: 0672327937
EAN: 2147483647
Year: 2005
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net