Skip to content
Browse files

Add all modules in the dist, not just the main one

Instead of adding only the "main" module, we add all the
modules that the distro provides.  This is basically what
the Pause indexer would do.

CPAN::Mini::Inject is flawed in this regard.  The add()
method is basically designed to inject distros that contain
only a single module.  But any non-trivial distro will
have several modules.  The mcpani[1] command works around
this limitation by calling the add() method for each
module that the distro provides.  Each call to add() also
copies the *.tar.gz into the repository.  So it ends up
copying the same file over and over.  I think the correct
solution is to change the interface on the add() method
to support multiple module names, which could all have
different version numbers.

I suspect the decision to design CPAN::Mini::Inject is the
result of an old anti-pattern.  Once upon a time, it was
typical for CPAN authors to only declare dependence
on the *main* module of a distro within their Makefile.PL
or Build.PL script.  For example, my code might say:

use PPI::Document;

but in my Makefile.PL it would say:

requires => { 'PPI' => 0 };

This implies that PPI and PPI::Document will always be in
the same distro.  But you cannot rely on that -- authors
are free to move modules into other distros at any time.
Technically, this would not constitute an interface
change, becaus the dependency is upon the module, not
the distribution it belongs to.

These days, the correct approach is to list every module
that you C<use> in your code as a dependency.  This
ensures you'll get the physical files that you require,
even if their logical location moves from one distro to
  • Loading branch information...
1 parent f3e5c72 commit 0bfc5f27f50beea51de8fca914e332017494c7e2 Jeffrey Thalhammer committed Jul 7, 2011
Showing with 9 additions and 8 deletions.
  1. +9 −8 lib/CPAN/
17 lib/CPAN/
@@ -82,14 +82,15 @@ sub inject_files
Carp::croak( "Cannot find '$file'" ) unless $file and -e $file;
my $meta = $self->load_metayaml( $file );
- (my $module = $meta->{name}) =~ s/-/::/g;
- $cpmi->add(
- file => $file,
- module => $module,
- version => $meta->{version},
- authorid => $cpmi->config->{author},
- );
+ for my $module ( keys %{$meta->{provides}} )
+ {
+ $cpmi->add(
+ file => $file,
+ module => $module,
+ authorid => $cpmi->config->{author},
+ version => $meta->{provides}->{$module}->{version},
+ );
+ }

0 comments on commit 0bfc5f2

Please sign in to comment.
Something went wrong with that request. Please try again.