# Perl (Homebrew)



On peut installer une version plus récente de Perl avec **Homebrew**:

```bash
$ brew install perl
```

```bash
$ brew info perl
zsh: correct 'perl' to 'perl5' [nyae]? n

perl: stable 5.30.0 (bottled), HEAD
Highly capable, feature-rich programming language
https://www.perl.org/
/usr/local/Cellar/perl/5.30.0 (2,440 files, 61.8MB) *
  Poured from bottle on 2019-08-04 at 13:32:46
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/perl.rb
==> Options
--HEAD
	Install HEAD version
==> Caveats
By default non-brewed cpan modules are installed to the Cellar. If you wish
for your modules to persist across updates we recommend using `local::lib`.

You can set that up like this:
  PERL_MM_OPT="INSTALL_BASE=$HOME/perl5" cpan local::lib
  echo 'eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib=$HOME/perl5)"' >> ~/.zshrc
```

```bash
$ which perl
/usr/local/bin/perl

$ perl -v

This is perl 5, version 30, subversion 0 (v5.30.0) built for darwin-thread-multi-2level

Copyright 1987-2019, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
```

#### cpan:

**cpan** gère les modules Perl.

```bash
$ cpan
Loading internal logger. Log::Log4perl recommended for better logging

CPAN.pm requires configuration, but most of it can be done automatically.
If you answer 'no' below, you will enter an interactive dialog for each
configuration option instead.

Would you like to configure as much as possible automatically? [yes] yes


Autoconfiguration complete.

commit: wrote '/Users/bruno/.cpan/CPAN/MyConfig.pm'

You can re-run configuration any time with 'o conf init' in the CPAN shell
Terminal does not support AddHistory.

To fix enter>  install Term::ReadLine::Perl


cpan shell -- CPAN exploration and modules installation (v2.22)
Enter 'h' for help.
```

Sans argument, la commande **cpan** ouvre un shell:

```bash
$ cpan
Loading internal logger. Log::Log4perl recommended for better logging

cpan shell -- CPAN exploration and modules installation (v2.27)
Enter 'h' for help.

cpan[1]> h
```

```bash
cpan[1]> h

Display Information                                                  (ver 2.27)
 command  argument          description
 a,b,d,m  WORD or /REGEXP/  about authors, bundles, distributions, modules
 i        WORD or /REGEXP/  about any of the above
 ls       AUTHOR or GLOB    about files in the author's directory
    (with WORD being a module, bundle or author name or a distribution
    name of the form AUTHOR/DISTRIBUTION)

Download, Test, Make, Install...
 get      download                     clean    make clean
 make     make (implies get)           look     open subshell in dist directory
 test     make test (implies make)     readme   display these README files
 install  make install (implies test)  perldoc  display POD documentation

Upgrade installed modules
 r        WORDs or /REGEXP/ or NONE    report updates for some/matching/all
 upgrade  WORDs or /REGEXP/ or NONE    upgrade some/matching/all modules

Pragmas
 force  CMD    try hard to do command  fforce CMD    try harder
 notest CMD    skip testing

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                recent        latest CPAN uploads
```

La commande **cpan** peut aussi s'utiliser avec arguments:



Avec <u>Perl installé via homebrew</u>, les modules sont installés dans Cellar (`Installing /usr/local/Cellar/perl/5.30.0/lib/perl5/site_perl/5.30.0/CPAN/DistnameInfo.pm`). Ils sont donc perdu à chaque mise-à-jour de Perl.

Il est donc conseillé d'utiliser `local::lib`

```bash
PERL_MM_OPT="INSTALL_BASE=$HOME/perl5" cpan local::lib
echo 'eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib=$HOME/perl5)"' >> ~/.zshrc

# les dossiers suivants sont crées:
#		$HOME/perl5/bin/
#		$HOME/perl5/lib/
#		
# à côté de $HOME/perl5/perlbrew/
```

Les modules sont alors installés ici `Installing /Users/bruno/perl5/lib/perl5/Log/Log4perl.pm`



##### Info sur un module:  `cpan -D <module>`

```bash
$ cpan -D CPAN::DistnameInfo
Reading '/Users/bruno/.cpan/Metadata'
  Database was generated on Tue, 17 Dec 2019 07:29:02 GMT
CPAN::DistnameInfo
-------------------------------------------------------------------------
	CPAN: Module::CoreList loaded ok (v5.20190522)
(no description)
	G/GB/GBARR/CPAN-DistnameInfo-0.12.tar.gz
	/usr/local/Cellar/perl/5.30.0/lib/perl5/site_perl/5.30.0/CPAN/DistnameInfo.pm
	Installed: 0.12
	CPAN:      0.12  up to date
	Graham Barr (GBARR)
	gbarr@pobox.com
```



##### Liste des modules installés: `cpan -l`

```bash
$ cpan -l
Spiffy	0.46
YAML	1.29
CPAN::DistnameInfo	0.12
App::pmuninstall	0.30
Test::YAML	1.07
```



##### Désintaller un module:

Il n'y a pas de commande prévue pour ça. 

On peut installer [pmuninstall](https://github.com/xaicron/pm-uninstall).

```bash
$ cpan -i App::pmuninstall
```

Puis pour désinstaller:

```bash
$ pm-uninstall -v App::cpnaminus
```



##### Modules mis-à-jour:

On peut installer [cpanoutdated](https://github.com/tokuhirom/cpan-outdated)

```bash
$ cpan -i App::cpanoutdated
```

et voir les modules 'outdated'

```bash
$ cpan-outdated -p
Compress::Raw::Bzip2
Compress::Raw::Zlib
Compress::Zlib
DB_File

$ cpan-outdated
P/PM/PMQS/Compress-Raw-Bzip2-2.093.tar.gz
P/PM/PMQS/Compress-Raw-Zlib-2.093.tar.gz
P/PM/PMQS/IO-Compress-2.093.tar.gz
P/PM/PMQS/DB_File-1.852.tar.gz
```



Il est recommandé d'installer les modules suivants:

- Term::ReadLine::Perl (réclamé par le shell cpan)

- CPAN::DistnameInfo (réclamé par l'installeur de module)
- Log::Log4perl (pas installé le 3/9/24)



#####Mettre à jour tous les modules: 

Lancer le shell cpan:

```bash
$ cpan
```

puis

```bash
cpan[1]> upgrade /(.*)/
```



#### Erreur après mise-à-jour de tous les modules:

```bash
$ exiftool -j /Users/bruno/Pictures/_Canon/Export/2024/Juillet/2024-07-13_Cerfs_9771.jpg

ListUtil.c: loadable library and perl binaries are mismatched (got handshake key 0x10200080, needed 0xfb80080)
```

```bash
brew uninstall perl
rm -rf $HOME/perl5
brew install perl
PERL_MM_OPT="INSTALL_BASE=$HOME/perl5" cpan local::lib

cpan -i App::pmuninstall
cpan -i App::cpanoutdated
```



##### perl-migrate-modules

```bash
$ cpan App::MigrateModules
```

```bash
$ perl-migrate-modules --from perl5_old /usr/bin/perl

# Don't be alarmed by passing /usr/bin/perl as the destination of perl-migrate-modules. As long as you have the local::lib environment variables configured, it'll make a new ~/perl5 directory (or whatever you have it set to) and migrate the modules into that folder.
```



```
perl -MCPAN -e 'recompile()'
```



https://stackoverflow.com/questions/11680500/how-to-upgrade-perl-modules-that-install-from-cpan/11680539
