From 6a1191bb3f7b715006aa289d85692e569359fd74 Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Thu, 24 Jun 2010 15:57:21 +0100 Subject: [PATCH] Bug 4905 Runtime errors in about.pl Calls to VERSION were generating errors when called on a string. Use a bit of sleight of hand to avoid this Added a couple of tests on Installer/PerlModules Module needs better coverage testing (esp on newer perls) Sorted to list of modules to make koha_perl_deps.pl more human-friendly Signed-off-by: Galen Charlton --- C4/Installer/PerlModules.pm | 11 ++++++----- t/Installer_pm.t | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) create mode 100755 t/Installer_pm.t diff --git a/C4/Installer/PerlModules.pm b/C4/Installer/PerlModules.pm index 9419ce836d..35d7ce0668 100644 --- a/C4/Installer/PerlModules.pm +++ b/C4/Installer/PerlModules.pm @@ -80,16 +80,17 @@ sub version_info { } } else { - for (keys(%$PERL_DEPS)) { - eval "require $_"; + for (sort keys(%{$PERL_DEPS})) { + my $pkg = $_; # $_ holds the string + eval "require $pkg"; if ($@) { push (@{$self->{'missing_pm'}}, {$_ => {cur_ver => 0, min_ver => $PERL_DEPS->{$_}->{'min_ver'}, required => $PERL_DEPS->{$_}->{'required'}, usage => $PERL_DEPS->{$_}->{'usage'}}}); } - elsif ($_->VERSION lt $PERL_DEPS->{$_}->{'min_ver'}) { - push (@{$self->{'upgrade_pm'}}, {$_ => {cur_ver => $_->VERSION, min_ver => $PERL_DEPS->{$_}->{'min_ver'}, required => $PERL_DEPS->{$_}->{'required'}, usage => $PERL_DEPS->{$_}->{'usage'}}}); + elsif ($pkg->VERSION lt $PERL_DEPS->{$_}->{'min_ver'}) { + push (@{$self->{'upgrade_pm'}}, {$_ => {cur_ver => $pkg->VERSION, min_ver => $PERL_DEPS->{$_}->{'min_ver'}, required => $PERL_DEPS->{$_}->{'required'}, usage => $PERL_DEPS->{$_}->{'usage'}}}); } else { - push (@{$self->{'current_pm'}}, {$_ => {cur_ver => $_->VERSION, min_ver => $PERL_DEPS->{$_}->{'min_ver'}, required => $PERL_DEPS->{$_}->{'required'}, usage => $PERL_DEPS->{$_}->{'usage'}}}); + push (@{$self->{'current_pm'}}, {$_ => {cur_ver => $pkg->VERSION, min_ver => $PERL_DEPS->{$_}->{'min_ver'}, required => $PERL_DEPS->{$_}->{'required'}, usage => $PERL_DEPS->{$_}->{'usage'}}}); } } return; diff --git a/t/Installer_pm.t b/t/Installer_pm.t new file mode 100755 index 0000000000..4370174e3f --- /dev/null +++ b/t/Installer_pm.t @@ -0,0 +1,25 @@ +#!/usr/bin/perl +# +use strict; +use warnings; + +use Test::More tests => 4; +use Data::Dumper; + +BEGIN { + use_ok('C4::Installer::PerlModules'); +} + +my $obj = C4::Installer::PerlModules->new; + +isa_ok($obj,'C4::Installer::PerlModules'); + +my $hash_ref = $obj->version_info(module => 'Test::More'); + +my $control = $Test::More::VERSION; + +like($hash_ref->{'Test::More'}->{cur_ver}, qr/\d/, 'returns numeric version'); + +ok($hash_ref->{'Test::More'}->{cur_ver} == $control, 'returns correct version'); + + -- 2.39.5