Developers,
Below is a simple Perl script that I use to look up MD5 values for Perl module distributions on CPAN. I thought others might find it useful, particularly when upgrading existing .info files. I like to use this script because it fetches the CHECKSUMS file from the root CPAN server. It depends on libwww-pm and file-slurp-pm.
Chris
----------------------------------------------- Example:
% cat module-scandeps-pm.info Package: module-scandeps-pm Version: 0.51 Revision: 1 Source: mirror:cpan:authors/id/A/AU/AUTRIJUS/Module-ScanDeps-%v.tar.gz Source-MD5: 5fc35c473d7d33818bc061c098fb5f6a Type: perl [snip]
% perl getmd5.pl module-scandeps-pm.info Reading module-scandeps-pm.info Retrieving http://www.cpan.org/authors/id/A/AU/AUTRIJUS/CHECKSUMS Evaling http://www.cpan.org/authors/id/A/AU/AUTRIJUS/CHECKSUMS Fetching record for Module-ScanDeps-0.51.tar.gz Old MD5: 5fc35c473d7d33818bc061c098fb5f6a New MD5: 5fc35c473d7d33818bc061c098fb5f6a
------------------------------------------------- #!/usr/bin/perl -w
use strict; use LWP::Simple qw(get); use File::Slurp;
my $SERVER = "http://www.cpan.org/";
my $file = shift || die "Syntax: $0 <infofile>\n";
print "Reading $file\n"; $_ = read_file($file); # extract .info fields as a hash. Doesn't support multiline fields my %info = /^([\w\-]+): *(.*)$/gm;
my $src = $info{Source}; $src =~ s/mirror:cpan:/$SERVER/; $src =~ s/([^\/]*)$/CHECKSUMS/; my $dist = $1; $dist =~ s/%v/$info{Version}/g;
print "Retrieving $src\n"; my $cksum = get($src) || die "Failed\n";
print "Evaling $src\n"; eval $cksum; ($@ || !$cksum) && die "Failed\n";
print "Fetching record for $dist\n"; my $record = $cksum->{$dist} || die "Failed\n"; print "Old MD5: ".$info{"Source-MD5"}."\n"; print "New MD5: ".$record->{md5}."\n";
-- Chris Dolan, Software Developer, Clotho Advanced Media Inc. 608-294-7900, fax 294-7025, 1435 E Main St, Madison WI 53703
Clotho Advanced Media, Inc. - Creators of MediaLandscape Software (http://www.media-landscape.com/) and partners in the revolutionary Croquet project (http://www.opencroquet.org/)
PGP.sig
Description: This is a digitally signed message part