next up previous contents index practicapracticaPP2moodleLHPmoodlepserratacpanmodulospauseperlgoogleetsiiullpcgull
Sig: Opciones de Configuración y Sup: Instalación de módulos Ant: Práctica: Instalar un Módulo Err: Si hallas una errata ...


Usando el módulo CPAN.pm como Administrador

Una forma de instalar un módulo desde CPAN es utilizar el módulo CPAN.pm. Supuesto que ese módulo está instalado en tu máquina, la orden para usarlo es:

%perl -MCPAN -e shell
Si conoces el nombre del módulo a instalar, por ejemplo Text::Balanced, todo lo que tienes que hacer es escribir:
cpan> install Text::Balanced
y el modulo CPAN hará el resto.

La primera vez que se ejecuta el módulo CPAN se dispara un proceso de configuración que establece los valores por defecto que posibilitan la descarga, desempaquetado construcción y verificación de los modulos cuya instalacion has requerido.

En el siguiente ejemplo arrancamos el módulo CPAN como administradores del sistema:

# perl -MCPAN -e shell

cpan shell -- CPAN exploration and modules installation (v1.70)
ReadLine support enabled
Pedimos ayuda ...
cpan> help

Display Information
 command  argument          description
 a,b,d,m  WORD or /REGEXP/  about authors, bundles, distributions, modules
 i        WORD or /REGEXP/  about anything of above
 r        NONE              reinstall recommendations
 ls       AUTHOR            about files in the author's directory

Download, Test, Make, Install...
 get                        download
 make                       make (implies get)
 test      MODULES,         make test (implies make)
 install   DISTS, BUNDLES   make install (implies test)
 clean                      make clean
 look                       open subshell in these dists' directories
 readme                     display these dists' README files

Other
 h,?           display this menu       ! perl-code   eval a perl command
 o conf [opt]  set and query options   q             quit the cpan shell
 reload cpan   load CPAN.pm again      reload index  load newer indices
 autobundle    Snapshot                force cmd     unconditionally do cmd
Y pasamos a instalar el módulo Switch desarrollado por Conway, el cual nos proporciona una sentencia switch similar a la de C:
cpan> install Switch
CPAN: Storable loaded ok
Going to read /root/.cpan/Metadata
  Database was generated on Tue, 02 Dec 2003 06:46:46 GMT
CPAN: LWP::UserAgent loaded ok
Fetching with LWP:
  ftp://ftp.rediris.es/mirror/CPAN/authors/01mailrc.txt.gz
Going to read /root/.cpan/sources/authors/01mailrc.txt.gz
Fetching with LWP:
  ftp://ftp.rediris.es/mirror/CPAN/modules/02packages.details.txt.gz
Going to read /root/.cpan/sources/modules/02packages.details.txt.gz
  Database was generated on Thu, 18 Mar 2004 06:50:42 GMT

  There's a new CPAN.pm version (v1.76) available!
  [Current version is v1.70]
  You might want to try
    install Bundle::CPAN
    reload cpan
  without quitting the current session. It should be a seamless upgrade
  while we are running...

Fetching with LWP:
  ftp://ftp.rediris.es/mirror/CPAN/modules/03modlist.data.gz
Going to read /root/.cpan/sources/modules/03modlist.data.gz
Going to write /root/.cpan/Metadata
Running install for module Switch
Running make for R/RG/RGARCIA/Switch-2.10.tar.gz
Fetching with LWP:
  ftp://ftp.rediris.es/mirror/CPAN/authors/id/R/RG/RGARCIA/Switch-2.10.tar.gz
CPAN: Digest::MD5 loaded ok
Fetching with LWP:
  ftp://ftp.rediris.es/mirror/CPAN/authors/id/R/RG/RGARCIA/CHECKSUMS
Checksum for /root/.cpan/sources/authors/id/R/RG/RGARCIA/Switch-2.10.tar.gz ok
Scanning cache /root/.cpan/build for sizes
Deleting from cache: /root/.cpan/build/HTML-Tagset-3.03 (11.0>10.0 MB)
Deleting from cache: /root/.cpan/build/HTML-Parser-3.34 (10.9>10.0 MB)
Deleting from cache: /root/.cpan/build/HTML-Tree-3.18 (10.3>10.0 MB)
Switch-2.10/
Switch-2.10/t/
Switch-2.10/t/given.t
Switch-2.10/t/switch.t
Switch-2.10/t/nested.t
Switch-2.10/MANIFEST
Switch-2.10/META.yml
Switch-2.10/Changes
Switch-2.10/Switch.pm
Switch-2.10/README
Switch-2.10/Makefile.PL

  CPAN.pm: Going to build R/RG/RGARCIA/Switch-2.10.tar.gz

Checking if your kit is complete...
Looks good
Writing Makefile for Switch
cp Switch.pm blib/lib/Switch.pm
Manifying blib/man3/Switch.3
  /usr/bin/make  -- OK
Running make test
PERL_DL_NONLAZY=1 /usr/local/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/given.....ok
t/nested....ok
t/switch....ok
All tests successful.
Files=3, Tests=590,  5 wallclock secs ( 4.57 cusr +  0.06 csys =  4.63 CPU)
  /usr/bin/make test -- OK
Running make install
cpan> install SwitchInstalling /usr/local/lib/perl5/site_perl/5.8.0/Switch.pm
Installing /usr/local/man/man3/Switch.3
Writing /usr/local/lib/perl5/site_perl/5.8.0/i686-linux/auto/Switch/.packlist
Appending installation info to /usr/local/lib/perl5/5.8.0/i686-linux/perllocal.pod
  /usr/bin/make install  -- OK

cpan> Use of uninitialized value in ord at /usr/local/lib/perl5/site_perl/5.8.0/Term/ReadLine/readline.pm line 1481.

Ahora podemos usar Switch:

> cat useswitch.pl
#!/usr/local/bin/perl5.8.0 -w

use Switch;

$val = shift;

switch ($val) {
  case 1 { print "number 1\n" }
  case "hello" { print "string hello\n" }
  else { print " none of these two\n" }
}
$ useswitch.pl "hello"
string hello
$ useswitch.pl "hola"
 none of these two


next up previous contents index practicapracticaPP2moodleLHPmoodlepserratacpanmodulospauseperlgoogleetsiiullpcgull
Sig: Opciones de Configuración y Sup: Instalación de módulos Ant: Práctica: Instalar un Módulo Err: Si hallas una errata ...
Casiano Rodríguez León
2006-02-21