'Is it possible to require a git repo in a cpanfile for cpanm?

I am trying to use a cpanfile with cpanm to install a large list of modules. One of the modules, Unicode::String, has a bug on CPAN that the author has only fixed on Github. (https://github.com/msouth/Unicode-String)

Is it possible to list the Github repo as a requirement in the cpanfile and have cpanm install from there rather than from CPAN? If so, what is the proper syntax for doing so?

The closest I've found is a thread from 2013 where Miyagawa said it was coming in a future release, then that the future release was fragile and on-hold:

https://github.com/perl-carton/carton/issues/132 (This discusses carton, but since they both use cpanfile, the syntax should be the same.)



Solution 1:[1]

As you can not use git URL in your cpanfile, you can use Distroprefs to patch a package during installation. I do not know if this works with cpanm, cpm or any package manager other than cpan.

You can pass your own diff (git format-patch is your friend for that) and tell to patch a specific version (the next version should be fixed, no need to try to patch it).


I use it to patch Module::Manifest::Skip which have two bugs fixed in GitHub during a docker image creation to test some code on CI.

CPAN will need the YAML package.

I add a pref into cpandir (~/.cpan/prefs)

---
match:
  distribution: 'INGY/Module-Manifest-Skip-0.23.tar.gz'
depends:
  configure_requires:
    File::ShareDir: 1.114
patches:
  - 'FOOBAR/Module-Manifest-Skip-0.23.patch'

And the patch in CPAN sources (~/.cpan/sources/authors/id/F/FO/FOOBAR)

diff --git a/lib/Module/Manifest/Skip.pm b/lib/Module/Manifest/Skip.pm
index 434f7ce..27c1ac7 100644
--- a/lib/Module/Manifest/Skip.pm
+++ b/lib/Module/Manifest/Skip.pm
@@ -28,9 +28,6 @@ sub import {
         close MS;
         exit;
     }
-    else {
-        goto &Moo::import;
-    }
 }

 sub add {

With that CPAN will be able to patch the package on the fly. You can see it during install, it will tell us

# cpan Module::Manifest::Skip
Loading internal logger. Log::Log4perl recommended for better logging
Reading '/root/.cpan/Metadata'
  Database was generated on Wed, 30 Mar 2022 04:55:39 GMT
Running install for module 'Module::Manifest::Skip'

______________________ D i s t r o P r e f s ______________________
                    Module-Manifest-Skip.yml[0]
Checksum for /root/.cpan/sources/authors/id/I/IN/INGY/Module-Manifest-Skip-0.23.tar.gz ok
Applying 1 patch:
  /root/.cpan/sources/authors/id/F/FO/FOOBAR/Module-Manifest-Skip-0.23.patch
  /usr/bin/patch -N -p1
patching file lib/Module/Manifest/Skip.pm
Configuring I/IN/INGY/Module-Manifest-Skip-0.23.tar.gz with Makefile.PL
Checking if your kit is complete...
Looks good
# ...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Joel