From 813c74400803a5ec26497d9a809cf874d2c200fd Mon Sep 17 00:00:00 2001 From: Jared Camins-Esakov Date: Tue, 25 Sep 2012 19:38:32 -0400 Subject: [PATCH] Bug 8818: make sure we load modules before using them An eval { eval "require $module;" }; was replaced with eval { eval { require $module; }; }; which is a no-op, meaning that the linker was not getting loaded, and the catalog module was throwing up a big nasty error every time someone tried to save a record with a heading. This patch replaces the require with can_load from Module::Load::Conditional, which is PBP-friendly, and offers equivalent functionality. Signed-off-by: Nicole C. Engard Signed-off-by: Paul Poulain --- C4/Biblio.pm | 11 +++++------ misc/link_bibs_to_authorities.pl | 11 +++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index ed8a169e71..231baf33e4 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -28,6 +28,7 @@ use MARC::Record; use MARC::File::USMARC; use MARC::File::XML; use POSIX qw(strftime); +use Module::Load::Conditional qw(can_load); use C4::Koha; use C4::Dates qw/format_date/; @@ -491,13 +492,11 @@ sub BiblioAutoLink { my $linker_module = "C4::Linker::" . ( C4::Context->preference("LinkerModule") || 'Default' ); - eval { eval {require $linker_module}; }; - if ($@) { + unless ( can_load( modules => { $linker_module => undef } ) ) { $linker_module = 'C4::Linker::Default'; - eval {require $linker_module}; - } - if ($@) { - return 0, 0; + unless ( can_load( modules => { $linker_module => undef } ) ) { + return 0, 0; + } } my $linker = $linker_module->new( diff --git a/misc/link_bibs_to_authorities.pl b/misc/link_bibs_to_authorities.pl index b35a00e837..37596c5024 100755 --- a/misc/link_bibs_to_authorities.pl +++ b/misc/link_bibs_to_authorities.pl @@ -18,6 +18,7 @@ use Pod::Usage; use Data::Dumper; use Time::HiRes qw/time/; use POSIX qw/strftime ceil/; +use Module::Load::Conditional qw(can_load); sub usage { pod2usage( -verbose => 2 ); @@ -53,13 +54,11 @@ if ( not $result or $want_help ) { my $linker_module = "C4::Linker::" . ( C4::Context->preference("LinkerModule") || 'Default' ); -eval { eval "require $linker_module"; }; -if ($@) { +unless ( can_load( modules => { $linker_module => undef } ) ) { $linker_module = 'C4::Linker::Default'; - eval "require $linker_module"; -} -if ($@) { - die "Unable to load linker module. Aborting."; + unless ( can_load( modules => { $linker_module => undef } ) ) { + die "Unable to load linker module. Aborting."; + } } my $linker = $linker_module->new( -- 2.39.5