Installing Modules


 
Network Programming with Perl
By Lincoln  D.  Stein
Slots : 1
Table of Contents
Preface

    Content

Many of Perl's networking modules are preinstalled in the standard distribution. Others are third-party modules that you must download and install from the Web. Most third-party modules are written in pure Perl, but some, including several that are mentioned in this book, are written partly in C and must be compiled before they can be used.

CPAN is a large Web-based collection of contributed Perl modules. You can get access to it via a Web or FTP browser, or by using a command-line application built into Perl itself.

Installing from the Web

To find a CPAN site near you, point your Web browser at http://www.cpan.org/. This will present a page that allows you to search for specific modules, or to browse the entire list of contributed modules sorted in various ways. When you find the module you want, download it to disk.

Perl modules are distributed as gzipped tar archives. You can unpack them like this:

 % gunzip -c Digest-MD5-2.00.tar.gz   tar xvf - Digest-MD5-2.00/ Digest-MD5-2.00/typemap Digest-MD5-2.00/MD2/ Digest-MD5-2.00/MD2/MD2.pm ... 

Once the archives are unpacked, you'll enter the newly created directory and give the perl Makefile.PL, make, make test , and make install commands. These will build, test, and install the module.

 % cd Digest-MD5-2.00 % perl Makefile.PL Testing alignment requirements for U32... Checking if your kit is complete... Looks good Writing Makefile for Digest::MD2 Writing Makefile for Digest::MD5 % make mkdir ./blib mkdir ./blib/lib mkdir ./blib/lib/Digest ... % make test make[1]: Entering directory '/home/lstein/Digest-MD5-2.00/MD2' make[1]: Leaving directory '/home/lstein/Digest-MD5-2.00/MD2' PERL_DL_NONLAZY=1 /usr/local/bin/perl -I./blib/arch -I./blib/lib... t/digest............ok t/files.............ok t/md5-aaa...........ok t/md5...............ok t/rfc2202...........ok t/sha1..............skipping test on this platform All tests successful. Files=6,  Tests=291,  1 secs ( 1.37 cusr  0.08 csys =  1.45 cpu) % make install make[1]: Entering directory '/home/lstein/Digest-MD5-2.00/MD2' make[1]: Leaving directory '/home/lstein/Digest-MD5-2.00/MD2' Installing /usr/local/lib/perl5/site_perl/i586-linux/./auto/Digest/MD5/MD5.so Installing /usr/local/lib/perl5/site_perl/i586-linux/./auto/Digest/MD5/MD5.bs ... 

On UNIX systems, you may need superuser privileges to perform the final step. If you don't have such privileges, you can install the modules in your home directory. At the perl Makefile.PL step, provide a PREFIX = argument with the path of your home directory. For example, assuming your home directory can be found at /home/jdoe, you would type:

 % perl Makefile.PL PREFIX=/home/jdoe 

The rest of the install procedure is identical to what was shown earlier.

If you are using a custom install directory, you must tell Perl to look in this directory for installed modules. One way to do this is to add the name of the directory to the environment variable PERL5LIB. For example:

 setenv PERL5LIB /home/jdoe            # C shell PERL5LIB=/home/jdoe; export PERL5LIB  # bourne shell 

Another way is to place the following line at the top of each script that uses an installed module.

 use lib '/home/jdoe'; 

Installing from the Command Line

A simpler way to do the same thing is to use Andreas Koenig's wonderful CPAN shell. With it, you can search, download, build, and install Perl modules from a simple command-line shell. The install command does it all:

 %  perl -MCPAN -e shell  cpan shell -- CPAN exploration and modules installation (v1.40) ReadLine support enabled cpan>  install MD5  Running make for GAAS/Digest-MD5-2.00.tar.gz Fetching with LWP:   ftp://ftp.cis.ufl.edu/pub/perl/CPAN/authors/id/GAAS/Digest-MD5-2.00.tar.gz CPAN: MD5 loaded ok Fetching with LWP:   ftp://ftp.cis.ufl.edu/pub/perl/CPAN/authors/id/GAAS/CHECKSUMS ... Checksum for /home/lstein/.cpan/sources/authors/id/GAAS/Digest-MD5-2.00.tar.gz ok Digest-MD5-2.00/ Digest-MD5-2.00/typemap ... Installing /usr/local/lib/perl5/site_perl/i586-linux/./auto/Digest/MD5/MD5.so Installing /usr/local/lib/perl5/site_perl/i586-linux/./auto/Digest/MD5/MD5.bs Installing /usr/local/lib/perl5/site_perl/i586-linux/./auto/MD5/MD5.so ... Writing /usr/local/lib/perl5/site_perl/i586-linux/auto/MD5/.packlist Appending installation info to /usr/local/lib/perl5/i586-linux/ 5.00404/perllocal.pod cpan>  exit  

Installing Modules with the Perl Package Manager

These examples all assume that you have UNIX-compatible versions of the gzip, tar and make commands. Virgin Windows systems do not have these utilities. The Cygwin package, available from http://www.cygnus.com/cygwin/, provides these utilities as part of a complete set of UNIX-compatible tools.

It is easier, however, to use the ActiveState Perl Package Manager (PPM). This Perl script is installed by default in the ActiveState distribution of Perl, available at http://www. activestate .com/. Its interface is similar to the command-line CPAN interface shown in the previous section, except that it can install precompiled binaries as well as pure-Perl scripts. For example:

 C:\WINDOWS>  ppm  PPM interactive shell (1.1.3) - type 'help' for available commands. PPM>  install MD5  Install package 'MD5?' (y/N) :  Y  Retrieving package 'MD5' ... Installing C:\Perl\site\lib\auto\MD5\MD5.bs Installing C:\Perl\site\lib\auto\MD5\MD5.dll Installing C:\Perl\site\lib\auto\MD5\MD5.exp Installing C:\Perl\site\lib\auto\MD5\MD5.lib Installing C:\Perl\site\lib\MD5.pm Installing C:\Perl\site\lib\auto\MD5\autosplit.ix Writing C:\Perl\site]lib\auto\MD5\.packlist PPM>  exit  Quit! C:\WINDOWS> 

Installing Modules from MacPerl

The MacPerl Module Porters site, http://pudge.net/cgi-bin/mmp.plx, contains a series of modules that have been ported for use in MacPerl. A variety of helper programs have been developed to make module installation easier on the Macintosh. The packages are described at http://pudge.net/macperl/macperlmodinstall.html, which also gives instructions on downloading and installling them.


   
Top


Network Programming with Perl
Network Programming with Perl
ISBN: 0201615711
EAN: 2147483647
Year: 2000
Pages: 173

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