add the --diff option to corelist
authorRicardo Signes <rjbs@cpan.org>
Tue, 1 May 2012 22:28:43 +0000 (18:28 -0400)
committerRicardo Signes <rjbs@cpan.org>
Thu, 10 May 2012 18:41:16 +0000 (14:41 -0400)
dist/Module-CoreList/Changes
dist/Module-CoreList/corelist

index c0c932b..a0ec032 100644 (file)
@@ -1,3 +1,6 @@
+2.66 ??
+  - Add the --diff option to compare two perl core modlibs
+
 2.65 Tue Mar 20 2012
   - Update of lib/charnames
 
index d5dac05..adf0fb0 100644 (file)
@@ -14,6 +14,7 @@ See L<Module::CoreList> for one.
     corelist [-a|-d] <ModuleName> | /<ModuleRegex>/ [<ModuleVersion>] ...
     corelist [-v <PerlVersion>] [ <ModuleName> | /<ModuleRegex>/ ] ...
     corelist [-r <PerlVersion>] ...
+    corelist --diff PerlVersion PerlVersion
 
 =head1 OPTIONS
 
@@ -78,6 +79,13 @@ used a module regexp) in the perls Module::CoreList knows about.
 finds the first perl version where a module has been released by
 date, and not by version number (as is the default).
 
+=item --diff
+
+Given two versions of perl, this prints a human-readable table of all module
+changes between the two.  The output format may change in the future, and is
+meant for I<humans>, not programs.  For programs, use the L<Module::CoreList>
+API.
+
 =item -? or -help
 
 help! help! help! to see more help, try --man.
@@ -119,7 +127,10 @@ use warnings;
 
 my %Opts;
 
-GetOptions(\%Opts, qw[ help|?! man! r|release:s v|version:s a! d ] );
+GetOptions(
+    \%Opts,
+    qw[ help|?! man! r|release:s v|version:s a! d diff|D ]
+);
 
 pod2usage(1) if $Opts{help};
 pod2usage(-verbose=>2) if $Opts{man};
@@ -175,6 +186,32 @@ if(exists $Opts{v} ){
     }
 }
 
+if ($Opts{diff}) {
+    if(@ARGV != 2) {
+        die "\nprovide exactly two perl core versions to diff with --diff\n";
+    }
+
+    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 %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)';
+
+        next if $old eq $new;
+
+        printf "%-35s %10s %10s\n", $lib, $old, $new;
+    }
+    exit(0);
+}
+
 if ( !@ARGV ) {
     pod2usage(0);
 }