From f176402a5d2a6fc8c87fbc3431daacbb9e9e071c 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. --- 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 ed8a169..231baf3 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 b35a00e..37596c5 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( -- 1.7.2.5