Dne Po 10.lis.2014 08:30:27, ppisar napsal(a):
Show quoted text> $ perl -Ilib -MParse::CPAN::Distributions -e 'my
> $d=Parse::CPAN::Distributions->new(file=>q{/tmp/find-ls.gz}); print
> $d->latest_version(q{MooseX-Workers})'
> Argument "0.15_0100" isn't numeric in numeric comparison (<=>) at
> lib/Parse/CPAN/Distributions.pm line 160.
> Argument "0.14_0100" isn't numeric in numeric comparison (<=>) at
> lib/Parse/CPAN/Distributions.pm line 160.
> 0.23
>
> Line 160 is is the first map() in this code:
>
> my @versions =
> map {$_->{external}}
> sort {$b->{internal} <=> $a->{internal}}
> map {my $v; eval {$v = version->new($_)}; {internal => $@ ? $_ :
> $v->numify, external => $_}} keys %{$distros{$distribution}};
>
The reason for calling numify() is that the sort() does not get in touch with a version object. If I remove the numify() call, then if the <=> operator gets a version object and non-parsable string, then it dies. (The overloaded operator attempts to parse the string by version module.)
If I "fix" the sort() by checking for both operands being a version object and fall back to non-version comparison for other cases, then the sort() will use two incompatible sorting functions which will lead to non-deterministic output.
However, because current implementation already drops the underscore suffixes or mixes strings and numbers when comparing, the output is non-deterministic too. Therefore I think the best approach is to skip version module incompatible strings completely.
The same problem is with Parse::CPAN::Distributions::versions(). It tries to sort the versions even if this is not documented. I'd rather simplify the versions() and stop sorting the output of this function.