Skip to content

Instantly share code, notes, and snippets.

@kits
Created November 12, 2010 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kits/674737 to your computer and use it in GitHub Desktop.
Save kits/674737 to your computer and use it in GitHub Desktop.
mycpanm (use 02packages.details.txt.gz, instead of cpanmetadb)
#!/usr/bin/env perl
use strict;
use File::Spec;
load_cpanm();
*App::cpanminus::script::search_module = sub {
my ($self, $module) = @_;
my $PKGS = '02packages.details.txt.gz';
my $mirror_site = $self->{mirrors}->[0];
my $local_pkgs = "$self->{home}/$PKGS";
my $status = $self->mirror("$mirror_site/modules/$PKGS", $local_pkgs);
$self->chat("Status $status at mirroring $PKGS\n");
$self->chat("Searching $module on $PKGS ...\n");
my $gzip = $self->which('gzip');
my $pkgs_fh;
if ($gzip) {
open $pkgs_fh, '-|' or exec $gzip, '-dc', $local_pkgs
or die "Cannot open $local_pkgs: $!";
}
elsif (eval {require IO::Zlib}) {
$pkgs_fh = IO::Zlib->new;
$pkgs_fh->open($local_pkgs, 'rb') or die "Cannot open $local_pkgs: $!";
}
else {
die "Failed to read $PKGS - You need to have gzip or IO::Zlib installed.\n";
}
while (<$pkgs_fh>) {
next if 1 .. /^$/;
my ($key, $version, $distfile) = split;
if ($key eq $module) {
close $pkgs_fh;
return $self->cpan_module($module, $distfile, $version);
}
}
$self->diag_fail("Finding $module on $PKGS failed.");
close $pkgs_fh;
return;
};
unless (caller) {
my $app = App::cpanminus::script->new;
$app->parse_options(@ARGV);
$app->doit or exit(1);
}
sub load_cpanm {
for my $dir (File::Spec->path) {
my $cpanm = File::Spec->catfile($dir, 'cpanm');
next if !-x $cpanm;
require "$cpanm";
return;
}
die "cpanm does not exist.";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment