add a changes_between function in Module::CoreList
authorRicardo Signes <rjbs@cpan.org>
Thu, 10 May 2012 19:08:21 +0000 (15:08 -0400)
committerRicardo Signes <rjbs@cpan.org>
Thu, 10 May 2012 19:08:25 +0000 (15:08 -0400)
dist/Module-CoreList/corelist
dist/Module-CoreList/lib/Module/CoreList.pm
dist/Module-CoreList/lib/Module/CoreList.pod

index adf0fb0..9cd0e8f 100644 (file)
@@ -193,21 +193,23 @@ if ($Opts{diff}) {
 
     my ($old_ver, $new_ver) = @ARGV;
 
-    my $old = $Module::CoreList::version{ numify_version($old_ver) };
-    my $new = $Module::CoreList::version{ numify_version($new_ver) };
+    my $old = numify_version($old_ver);
+    my $new = numify_version($new_ver);
 
-    my %uniq = (%$old, %$new);
-    for my $lib (sort keys %uniq) {
-        my $old = exists $old->{ $lib }
-                ? (defined $old->{ $lib } ? $old->{ $lib } : '(undef)')
-                : '(absent)';
-        my $new = exists $new->{ $lib }
-                ? (defined $new->{ $lib } ? $new->{ $lib } : '(undef)')
-                : '(absent)';
+    my %diff = Module::CoreList::changes_between($old, $new);
 
-        next if $old eq $new;
+    for my $lib (sort keys %diff) {
+      my $diff = $diff{$lib};
 
-        printf "%-35s %10s %10s\n", $lib, $old, $new;
+      my $was = ! exists  $diff->{left} ? '(absent)'
+              : ! defined $diff->{left} ? '(undef)'
+              :                          $diff->{left};
+
+      my $now = ! exists  $diff->{right} ? '(absent)'
+              : ! defined $diff->{right} ? '(undef)'
+              :                          $diff->{right};
+
+        printf "%-35s %10s %10s\n", $lib, $was, $now;
     }
     exit(0);
 }
index 6a118be..6078dfd 100644 (file)
@@ -97,6 +97,36 @@ sub removed_raw {
   return @removed;
 }
 
+sub changes_between {
+  my ($left_ver, $right_ver) = @_;
+
+  my $left  = $version{ $left_ver };
+  my $right = $version{ $right_ver };
+
+  my %uniq = (%$left, %$right);
+
+  my %changes;
+  for my $lib (keys %uniq) {
+      my $lhs = exists $left->{ $lib }
+              ? (defined $left->{ $lib } ? $left->{ $lib } : '(undef)')
+              : '(absent)';
+      my $rhs = exists $right->{ $lib }
+              ? (defined $right->{ $lib } ? $right->{ $lib } : '(undef)')
+              : '(absent)';
+
+      next if $lhs eq $rhs;
+
+      my $change = {
+        (exists $left->{$lib}  ? (left  => $left->{$lib})  : ()),
+        (exists $right->{$lib} ? (right => $right->{$lib}) : ()),
+      };
+
+      $changes{$lib} = $change;
+  }
+
+  return %changes;
+}
+
 # When things escaped.
 # NB. If you put version numbers with trailing zeroes here, you
 # should also add an alias for the numerical ($]) version; see
index 77485dc..342e4b5 100644 (file)
@@ -94,6 +94,27 @@ Takes a module name as an argument, returns the first perl version by release da
 was removed from core. Returns undef if the given module was never in core or remains
 in core.
 
+=item C<changes_between( PERL_VERSION, PERL_VERSION )>
+
+Available in version 2.66 and above.
+
+Given two perl versions, this returns a list of pairs describing the changes in
+core module content betweent hem.  The list is suitable for storing in a hash.
+The keys are library names and the values are hashrefs.  Each hashref has an
+entry for one or both of C<left> and C<right>, giving the versions of the
+library in each of the left and right perl distributions.
+
+For example, it might return these data (among others) for the the difference
+between 5.008000 and 5.008001:
+
+  'Pod::ParseLink'  => { left => '1.05', right => '1.06' },
+  'Pod::ParseUtils' => { left => '0.22', right => '0.3'  },
+  'Pod::Perldoc'    => {                 right => '3.10' },
+  'Pod::Perldoc::BaseTo' => {            right => undef  },
+
+This shows us two libraries being updated and two being added, one of which has
+an undefined version in the right-hand side version.
+
 =back
 
 =head1 DATA STRUCTURES