5

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.)

Mik
  • 443
  • 4
  • 9
  • 4
    Ack, no, don't do that!!! Either copy the module to a new name, or simply monkey patch the fix – ikegami Jul 27 '16 at 05:00
  • Can you help me understand why this would be a bad idea? – Mik Jul 27 '16 at 16:20
  • What if the unpatched version is already installed, are you going to force the installation of yours? What if a newer version is installed? What if a newer version comes out and that gets installed? And I'm just getting started – ikegami Jul 27 '16 at 17:28
  • Yep, those seem like great reasons to avoid doing this. I've emailed the module's maintainer to see about getting the patch released as a new version; in the meantime I'll work around it. Thanks! – Mik Jul 27 '16 at 19:20
  • Info I didn't provide before: I'm bundling these to use when spinning up Docker containers. I need a central place where every module is the same, so if a module changes on CPAN, I still get the same copy as before. cpanfile allows me to specify a version number, and plan upgrades to modules. For now, I've bundled the modules with Carton and installed them from a cache, which allowed me to temporarily work around the one buggy module by replacing the tarball in the cache and modifying the cpanfile.snapshot. This is an ugly hack, and I'd rather just use the git repo for now. – Mik Jul 27 '16 at 23:00
  • [This](http://blogs.perl.org/users/lestrrat/2013/03/the-main-problem-with-cpan-modules-on-github.html) blog post gives syntax (also in one of its links) as **requires 'Unicode::String' => 'git:https://github.com/msouth/Unicode-String.git';** but that errors out with "Invalid version format", so either cpanm changed how it processes cpanfiles, or my syntax is still messed up. – Mik Jul 27 '16 at 23:03

1 Answers1

0

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
# ...
Joel
  • 1,187
  • 1
  • 6
  • 15