EGTDC Perl Course 2004
Making use of CPAN modules Perl on other platforms
Tim Booth : [email protected]
CPAN Recap
• "Comprehensive Perl Archive Network".
• Holds virtually every Perl module, among other things.
• Access via the web (http) and by the CPAN shell.
– search.cpan.org is probably your first point of call.
• Most modules are standardised to make them easy to use right away:
– Documentation in ' perldoc' format.
– Standard installation procedure
– Selftesting
CPAN and modules
• CPAN contains around 2860 modules bits of code that can be plugged into your scripts. Some are small, some complex.
• Need to interface with a database? Use the DBI/DBD modules.
• Need to make webpages with Perl? Use the CGI module.
• Need to make a graphical interface? Use the Tk module.
• Need to do bioinformatics? Use the BioPerl modules!
• To use an installed module you " use module_name; " in the same way as you
" use strict; "
• Modules can be installed in 2 ways – Manually, from source
– From CPAN, using the CPAN shell.
Installing modules from source
• On BioLinux, log in as manager to install modules systemwide
• Modules are distributed as .tar.gz files.
• Download the module to the manager' s home directory.
• if you are missing components required for the module to work you will be told at the 2
ndstep below.
• Always check README or INSTALL files before installing.
tar -zxvf test_module.tar.gz
cd test_module #or whatever directory was created perl Makefile.PL #note the capitalisation
make
make test
sudo make install
Installing modules with CPAN
• sudo perl -MCPAN -e shell on the command line launches the CPAN interface.
• CPAN shell is very clever as it automtically downloads, builds, tests, installs and resolves dependencies (ie if one perl module requires another). If you specify a module you already have then it will be updated to the latest version.
• BioLinux has CPAN set up, for other systems you may need to configure it and install dependencies first.
• Full CPAN documentation is here:
http://theoryx5.uwinnipeg.ca/CPAN/data/CPAN/README.html
• Great for getting BioPerl up and running fast:
– install Bundle::BioPerl
Installing modules as a regular user
• You do not have to be the system administrator to install modules for your own use.
• You may also want to test new or updated modules in a temporary directory.
• CPAN can still help, but there is some fiddly setting up to do. You will probably find it easier to install the modules manually:
tar -xvzf downloaded_module.tar.gz ; cd downloaded_module_dir perl Makefile.PL PREFIX=~/myperl
make
make test && make install
• This puts the module in the ' myperl' subdirectory of your home dir. Don' t forget
to include this in your @INC path to use the module!
Setting the @INC path
●
The global array @INC lists all the places where Perl will look for modules, but you should not modify it directly. For example, to use modules in your ~/perl/lib/5.8.0 directory, do one of the following:
●
Set the PERL5LIB environment variable at the shell prompt:
export PERL5LIB=$HOME/perl/lib/5.8.0 perl myscript.perl
●
Run perl with the I option
perl -I$HOME/perl/lib/5.8.0 myscript.perl
●
Put a ' use lib' statement in your script.
#!/usr/bin/perl
use lib “/home/user1/perl/lib/5.8.0”;
use My::Module;
Checking installed modules
●
All good modules will self-test before they install, so you just need to verify that Perl can find the new module. Simply run:
●
perl -e 'use Config::Simple'
●
Specifying the name of the module to test.
●
If this succeeds you will get no output, otherwise you will get an error.
●