Search code examples
perlcpan

Using local Perl module instead of one installed by CPAN


I have found it necessary to expand upon a CPAN module. (Unicode::CharName goes up to Unicode 4.1; I need some characters from Unicode 5.0 & 5.1).

I've made the changes needed and have my own CharName.pm module.

I now would like to use it with my various Perls. I currently use:

  • Strawberry Perl for Windows
  • git for Windows MINGW64; My .bashrc sets $PATH to Strawberry perl and $PERL5LIB=/c/Strawberry/perl/vendor/lib:/c/Strawberry/perl/site/lib
  • WSL Ubuntu

Where should I put my version of Unicode::CharName, so that it over-rides the ones installed by CPAN?

I don't want to have to change any scripts that currently

use Unicode::CharName;

Solution

  • Using cpanm you could download the module, patch it, and install it as normal:

    $ cpanm --look Unicode::CharName
    # new shell opens
    $ patch lib/Unicode/CharName.pm custom.patch # or whatever process
    $ perl Makefile.PL
    $ make install
    $ exit
    

    You can also install it to a local::lib to avoid overwriting it globally, by adding the -l local/ option to the cpanm command. Then you can add the absolute path of this local::lib to your PERL5LIB or via -I or use lib. If you specified /path/to/local for the -l option, it would be /path/to/local/lib/perl5.

    Manually copying files rather than going through the normal installation process is likely to lead to problems. Many distributions depend on the installation process to build the modules correctly. Also, you will need to install the module separately for each Perl you want to use it for; installed Perl modules are not generally cross-compatible between Perl versions or architectures. (A strictly simple pure-Perl module can be an exception to these rules, but the only module I feel comfortable abusing this way is App::cpanminus, because it was designed to do this.)