Skip to content

Commit

Permalink
Filter out duplicate entries in %Module::CoreList::version when listi…
Browse files Browse the repository at this point in the history
…ng perl versions

This may be a good candidate to be a CoreList method.
  • Loading branch information
schwern committed Apr 20, 2010
1 parent 7f08ec9 commit 367da98
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
18 changes: 16 additions & 2 deletions corelist
Expand Up @@ -92,7 +92,7 @@ pod2usage(-verbose=>2) if $Opts{man};
if(exists $Opts{v} ){
if( !$Opts{v} ) {
print "\nModule::CoreList has info on the following perl versions:\n";
print format_perl_version($_)."\n" for sort keys %Module::CoreList::version;
print format_perl_version($_)."\n" for all_perl_versions();
print "\n";
exit 0;
}
Expand Down Expand Up @@ -205,10 +205,24 @@ sub max {
return $that;
}


# Filter out duplicate entries like 5 and 5.000
sub all_perl_versions {
my %seen;
my @versions;
for my $v (sort keys %Module::CoreList::version) {
my $num = $v + 0;
next if $seen{$num}++;
push @versions, $v;
}

return @versions;
}

sub display_a {
my $mod = shift;

for my $v (sort keys %Module::CoreList::version ) {
for my $v (all_perl_versions()) {
next unless exists $Module::CoreList::version{$v}{$mod};

my $mod_v = $Module::CoreList::version{$v}{$mod} || 'undef';
Expand Down
13 changes: 3 additions & 10 deletions t/corelist-format.t
@@ -1,7 +1,8 @@
#!/usr/bin/perl

# This test will only work for this version of Module::CoreList.
# It exists to prove the refactoring correct.
# This test will break when the data in Module::CoreList changes.
# It could be made generic, but the data changes infrequently, and
# its much simpler to maintain manually.

use strict;
use warnings;
Expand All @@ -14,7 +15,6 @@ eq_or_diff scalar `$^X -Ilib ./corelist -a Test::Harness`, <<'END', "corelist -a
Test::Harness was first released with perl 5
5 undef
5.000 undef
5.001 undef
5.002 1.07
5.00307 1.13
Expand Down Expand Up @@ -44,17 +44,14 @@ Test::Harness was first released with perl 5
v5.9.4 2.62
v5.9.5 2.64
v5.10.0 2.64
v5.10.0 2.64
v5.10.1 3.17
v5.11.0 3.17
v5.11.0 3.17
v5.11.1 3.17
v5.11.2 3.17
v5.11.3 3.17
v5.11.4 3.17
v5.11.5 3.17
v5.12.0 3.17
v5.12.0 3.17
END

Expand All @@ -64,7 +61,6 @@ eq_or_diff scalar `$^X -Ilib ./corelist -v`, <<'END', "corelist -v";
Module::CoreList has info on the following perl versions:
5
5.000
5.001
5.002
5.00307
Expand Down Expand Up @@ -94,17 +90,14 @@ v5.9.3
v5.9.4
v5.9.5
v5.10.0
v5.10.0
v5.10.1
v5.11.0
v5.11.0
v5.11.1
v5.11.2
v5.11.3
v5.11.4
v5.11.5
v5.12.0
v5.12.0
END

Expand Down

0 comments on commit 367da98

Please sign in to comment.