Perl-Toolchain-Gang / CPAN-Meta-Requirements

a set of version requirements for a CPAN dist
5 stars 15 forks source link

Throws exception on lax version #31

Open andk opened 8 years ago

andk commented 8 years ago

This came to me a bit surprising. I cannot say whether it is a bug or feature. In my code I did not use eval and learned that I need it when I want to survive lax versions.

perl -E '
use CPAN::Meta::Requirements;
say "ok -- CMR version: $CPAN::Meta::Requirements::VERSION";
my $m = CPAN::Meta::Requirements->new;
$m->add_minimum(Foo => 1);
my $ok = eval { $m->accepts_module(Foo => "2.08a") };
say $ok ? "ok -- $ok" : "not ok -- $@";
'                                  
ok -- CMR version: 2.140
not ok -- Can't convert '2.08a': Invalid version format (non-numeric data)
karenetheridge commented 8 years ago

I think CPAN::Meta::Requirements should be able to (more gracefully) reject non-compliant version strings in all of the APIs that take them (using the validation regex in CPAN::Meta::Validator::version).

haarg commented 8 years ago

What would "more gracefully" mean?

Throwing an exception like it currently does seems like the appropriate behavior to me. CPAN::Meta::Requirements->new also accepts a bad_version_hook option to do custom conversions on non-compliant versions.