Skip to content

Commit eafbef4

Browse files
committed
use metacpan API to retrieve a module's changes
1 parent 2d54687 commit eafbef4

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

lib/App/Cpan.pm

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,10 +1249,7 @@ sub _show_Changes
12491249
next unless eval { $module->inst_file };
12501250
#next if $module->uptodate;
12511251

1252-
( my $id = $module->id() ) =~ s/::/\-/;
1253-
1254-
my $url = "http://search.cpan.org/~" . lc( $module->userid ) . "/" .
1255-
$id . "-" . $module->cpan_version() . "/";
1252+
my $url = "https://fastapi.metacpan.org/v1/module/" . $module->id();
12561253

12571254
#print "URL: $url\n";
12581255
_get_changes_file($url);
@@ -1263,21 +1260,21 @@ sub _show_Changes
12631260

12641261
sub _get_changes_file
12651262
{
1266-
croak "Reading Changes files requires LWP::Simple and URI\n"
1267-
unless _safe_load_module("LWP::Simple") && _safe_load_module("URI");
1263+
croak "Reading Changes files requires LWP::Simple, LWP::Protocol::https, JSON::PP\n"
1264+
unless _safe_load_module("LWP::Simple") && _safe_load_module("LWP::Protocol::https")
1265+
&& _safe_load_module("JSON::PP");
12681266

12691267
my $url = shift;
12701268

12711269
my $content = LWP::Simple::get( $url );
12721270
$logger->info( "Got $url ..." ) if defined $content;
12731271
#print $content;
12741272

1275-
my( $change_link ) = $content =~ m|<a href="(.*?)">Changes</a>|gi;
1276-
1277-
my $changes_url = URI->new_abs( $change_link, $url );
1273+
my $distribution = JSON::PP::decode_json( $content )->{distribution};
1274+
my $changes_url = "https://fastapi.metacpan.org/v1/changes/$distribution";
12781275
$logger->debug( "Change link is: $changes_url" );
12791276

1280-
my $changes = LWP::Simple::get( $changes_url );
1277+
my $changes = JSON::PP::decode_json( LWP::Simple::get( $changes_url ) )->{content};
12811278

12821279
print $changes;
12831280

0 commit comments

Comments
 (0)