13 compare-snapshots.pl file file
21 my @opt = <<'=back' =~ /B<--(\S+)>/g;
31 Reads two snapshot files and outputs differing modules.
33 For the record, snapshot files are generated within the CPAN shell by
34 running C<autobundle>, frequently with
36 echo autobundle | cpan
46 use lib
"$FindBin::Bin/../lib";
52 use File
::Basename
qw(dirname);
53 use File
::Path
qw(mkpath);
57 use Hash
::Util
qw(lock_keys);
58 use List
::MoreUtils
qw(uniq);
61 lock_keys
%Opt, map { /([^=]+)/ } @opt;
66 my($lfile,$rfile) = @ARGV;
67 pod2usage
(1) unless $rfile;
70 for my $tuple ([$left,$lfile],
73 my($snap,$file) = @
$tuple;
74 open my $fh, $file or die "Could not open '$file': $!";
76 SNAPLINE
: while (<$fh>) {
77 if (/^=head1\sCONTENTS$/) {
80 } elsif (/^=head1\s/) {
83 next SNAPLINE
unless $in_list;
84 next SNAPLINE
if /^\s*$/;
85 my($mod,$v) = split " ", $_;
89 my(@miss_left,@miss_right,@diff_version);
91 for my $m (uniq
keys %$left, keys %$right) {
92 $c1 = length $m if length $m > $c1;
93 if (! exists $right->{$m}) {
94 push @miss_right, [$m, $left->{$m}];
96 } elsif (! exists $left->{$m}) {
97 push @miss_left, [$m, $right->{$m}];
100 next if $left->{$m} eq $right->{$m};
101 push @diff_version, [$m, $left->{$m}, $right->{$m}];
104 for my $tuple (sort {$a->[0] cmp $b->[0]} @miss_right) {
105 printf "%${c1}s %${c2}s =>\n", @
$tuple;
107 for my $tuple (sort {$a->[0] cmp $b->[0]} @miss_left) {
108 while (length $tuple->[0] > $c1) {
109 (my $trim,$tuple->[0]) = unpack("a" . $c1 . "a*", $tuple->[0]);
112 printf "%${c1}s %${c2}s => %${c2}s\n", $tuple->[0], "", $tuple->[1];
114 for my $tuple (sort {$a->[0] cmp $b->[0]} @diff_version) {
115 printf "%${c1}s %${c2}s => %${c2}s\n", @
$tuple;
120 # cperl-indent-level: 4