Skip to content
This repository

added metacpan support #109

Merged
merged 2 commits into from over 2 years ago

3 participants

Tokuhiro Matsuno Tatsuhiko Miyagawa Reini Urban
Tokuhiro Matsuno

use metacpan instead of cpanmetadb+search.cpan.org
(metacpan indexes modules very fast. you can use --metacpan option instead of cpanf)

Reini Urban

Shouldn't the require go into the if metacpan?

oops..

Tatsuhiko Miyagawa
Owner

Looks good.

Tatsuhiko Miyagawa miyagawa merged commit bad73ad into from October 13, 2011
Tatsuhiko Miyagawa miyagawa closed this October 13, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 23 additions and 0 deletions. Show diff stats Hide diff stats

  1. 23  lib/App/cpanminus/script.pm
23  lib/App/cpanminus/script.pm
@@ -118,6 +118,7 @@ sub parse_options {
118 118
             $self->{save_dists} = $self->maybe_abs($_[1]);
119 119
         },
120 120
         'skip-configure!' => \$self->{skip_configure},
  121
+        'metacpan'   => \$self->{metacpan},
121 122
     );
122 123
 
123 124
     if (!@ARGV && $0 ne '-' && !-t STDIN){ # e.g. # cpanm < author/requires.cpanm
@@ -303,6 +304,28 @@ sub search_module {
303 304
     my($self, $module, $version) = @_;
304 305
 
305 306
     unless ($self->{mirror_only}) {
  307
+        if ($self->{metacpan}) {
  308
+            require JSON::PP;
  309
+            $self->chat("Searching $module on metacpan ...\n");
  310
+            my $module_uri  = "http://api.metacpan.org/module/$module";
  311
+            my $module_yaml = $self->get($module_uri);
  312
+            my $module_meta = eval { JSON::PP::decode_json($module_yaml) };
  313
+            if ($module_meta && $module_meta->{distribution}) {
  314
+                my $dist_uri = "http://api.metacpan.org/release/$module_meta->{distribution}";
  315
+                my $dist_yaml = $self->get($dist_uri);
  316
+                my $dist_meta = eval { JSON::PP::decode_json($dist_yaml) };
  317
+                if ($dist_meta && $dist_meta->{download_url}) {
  318
+                    (my $distfile = $dist_meta->{download_url}) =~ s!.+/authors/id/!!;
  319
+                    local $self->{mirrors} = $self->{mirrors};
  320
+                    if ($dist_meta->{stat}->{mtime} > time()-24*60*60) {
  321
+                        $self->{mirrors} = ['http://cpan.cpantesters.org'];
  322
+                    }
  323
+                    return $self->cpan_module($module, $distfile, $dist_meta->{version});
  324
+                }
  325
+            }
  326
+            $self->diag_fail("Finding $module on metacpan failed.");
  327
+        }
  328
+
306 329
         $self->chat("Searching $module on cpanmetadb ...\n");
307 330
         my $uri  = "http://cpanmetadb.appspot.com/v1.0/package/$module";
308 331
         my $yaml = $self->get($uri);
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.