On Sat, Jan 24, 2009 at 10:27:29AM -0800, Bill Moseley wrote:
> Currently, we have a rather simple approach:
>
> ( eval { require Test::More } and ( $Test::More::VERSION >= 0.62 ) )
> or push @fails, 'Test::More 0.62';
Hum, after looking at that I replaced it with:
# Let Perl use its version logic
eval "use $module_needed $need_version";
Question still stands about "test_requires" in Module::Install.
Here's my full code providing full opportunity to point out stupid
mistakes and how it can be all done in a just a few lines if I would
have read the documentation better....
my %test_module = (
'Foo::Bar' => 1.23,
);
sub MY::test {
my @missing_mods;
print "[test modules]\n";
for my $test_mod ( sort keys %test_modules ) {
my $need_version = $test_modules{$test_mod};
unless ( $test_mod->require ) {
printf(
"- %-40s *missing* (need %s)\n",
$test_mod,
$need_version,
);
push @missing_mods, $test_mod;
next;
}
# Let Perl use its version logic
eval "use $test_mod $need_version"; ## no critic
my $error = $@; ## no critic
if ( $error ) {
push @missing_mods, $test_mod;
my $error = $@;
$error =~ s/ at .*$//s;
warn "$error\n";
next;
}
printf(
"- %-40s loaded (%s >= %s)\n",
$test_mod,
$test_mod->VERSION,
$need_version,
);
} ## end for my $test_mod ( sort...
if ( @missing_mods ) {
my $fail_string = 'sorry, cannot run tests without ' . join( ' and ',
@missing_mods );
return <<"EOF";
test::
\...@echo $fail_string; exit 1
EOF
}
}
--
Bill Moseley
[email protected]
Sent from my iMutt