From c4a8e5fb3e8a40f44664a8103551c37534104053 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 7 Nov 2014 15:45:08 +0100 Subject: [PATCH] Bug 13223: Plugin housekeeping: do not redefine wrapper This report is connected to bug 10480 which will change the general mechanism of loading plugins, but can be tested independently and ahead of that proposed change. Several unimarc plugins use a wrapper sub. The code of this subroutine is not exactly the same for all plugins: in some cases the routine is extended for double character strings (dblspace and dblpipe). It would not hurt to use the extended code for all plugins. By moving the code to a module, we prevent redefinition when two or more plugins are loading wrapper in a do-statement. NOTE: You will not see wrapper redefine errors in your log, since the plugins do not use the warnings pragma (yet). Since this patch touches seventeen unimarc plugins, a unimarc signoff is preferred :) Test plan: Use some plugins changed in this patch (if not in use already). Load the MARC editor. Click on some tag editor-buttons to check unchanged behavior. Signed-off-by: Frederic Demians Unimarc plugins work as usual. No regression. Simple code factorization. Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- Koha/Util/FrameworkPlugin.pm | 55 +++++++++++++++++++ .../value_builder/unimarc_field_100.pl | 9 +-- .../unimarc_field_100_authorities.pl | 9 +-- .../value_builder/unimarc_field_105.pl | 8 +-- .../value_builder/unimarc_field_110.pl | 8 +-- .../value_builder/unimarc_field_115a.pl | 8 +-- .../value_builder/unimarc_field_115b.pl | 8 +-- .../value_builder/unimarc_field_116.pl | 10 +--- .../value_builder/unimarc_field_117.pl | 10 +--- .../value_builder/unimarc_field_120.pl | 9 +-- .../value_builder/unimarc_field_121a.pl | 8 +-- .../value_builder/unimarc_field_125b.pl | 8 +-- .../value_builder/unimarc_field_126a.pl | 8 +-- .../value_builder/unimarc_field_128b.pl | 7 +-- .../value_builder/unimarc_field_130.pl | 8 +-- .../value_builder/unimarc_field_135a.pl | 8 +-- .../value_builder/unimarc_field_140.pl | 9 +-- cataloguing/value_builder/unimarc_leader.pl | 8 +-- 18 files changed, 89 insertions(+), 109 deletions(-) create mode 100644 Koha/Util/FrameworkPlugin.pm diff --git a/Koha/Util/FrameworkPlugin.pm b/Koha/Util/FrameworkPlugin.pm new file mode 100644 index 0000000000..698b68acba --- /dev/null +++ b/Koha/Util/FrameworkPlugin.pm @@ -0,0 +1,55 @@ +package Koha::Util::FrameworkPlugin; + +# Module contains subroutines used in the framework plugins +# +# Copyright 2014 Koha Development Team +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +use Modern::Perl; + +our ( @ISA, @EXPORT, @EXPORT_OK ); +BEGIN { + require Exporter; + @ISA = qw( Exporter ); + @EXPORT = qw( ); + @EXPORT_OK = qw( wrapper ); +} + +=head1 NAME + +Koha::Util::Plugin - utility class with routines for framework plugins + +=head1 FUNCTIONS + +=head2 wrapper + + wrapper returns a text for strings containing spaces, pipe chars, ... + The wrapper subroutine is used in several UNIMARC plugins. + +=cut + +sub wrapper { + my ( $str ) = @_; + return "space" if $str eq " "; + return "dblspace" if $str eq " "; + return "pipe" if $str eq "|"; + return "dblpipe" if $str eq "||"; + return $str; +} + +1; diff --git a/cataloguing/value_builder/unimarc_field_100.pl b/cataloguing/value_builder/unimarc_field_100.pl index 6a660d3945..55bc77021f 100755 --- a/cataloguing/value_builder/unimarc_field_100.pl +++ b/cataloguing/value_builder/unimarc_field_100.pl @@ -20,6 +20,8 @@ use strict; #use warnings; FIXME - Bug 2505 + +use Koha::Util::FrameworkPlugin qw(wrapper); use C4::Auth; use CGI; use C4::Context; @@ -67,13 +69,6 @@ sub plugin_javascript { return ( $field_number, $res ); } -sub wrapper { - my ($char) = @_; - return "space" if $char eq " "; - return "dblspace" if $char eq " "; - return "pipe" if $char eq "|"; - return $char; -} sub plugin { my ($input) = @_; diff --git a/cataloguing/value_builder/unimarc_field_100_authorities.pl b/cataloguing/value_builder/unimarc_field_100_authorities.pl index d929e885a9..0a4012b176 100644 --- a/cataloguing/value_builder/unimarc_field_100_authorities.pl +++ b/cataloguing/value_builder/unimarc_field_100_authorities.pl @@ -18,6 +18,8 @@ # along with Koha; if not, see . use Modern::Perl; + +use Koha::Util::FrameworkPlugin qw(wrapper); use C4::Auth; use CGI; use C4::Context; @@ -65,13 +67,6 @@ sub plugin_javascript { return ( $field_number, $res ); } -sub wrapper { - my ($char) = @_; - return "space" if $char eq " "; - return "dblspace" if $char eq " "; - return "pipe" if $char eq "|"; - return $char; -} sub plugin { my ($input) = @_; diff --git a/cataloguing/value_builder/unimarc_field_105.pl b/cataloguing/value_builder/unimarc_field_105.pl index ec6d967db4..67f6cbc3da 100755 --- a/cataloguing/value_builder/unimarc_field_105.pl +++ b/cataloguing/value_builder/unimarc_field_105.pl @@ -20,6 +20,8 @@ use strict; #use warnings; FIXME - Bug 2505 + +use Koha::Util::FrameworkPlugin qw(wrapper); use C4::Auth; use CGI; use C4::Context; @@ -63,12 +65,6 @@ sub plugin_javascript { return ($field_number,$res); } -sub wrapper { - my ($char) = @_; - return "space" if $char eq " "; - return "pipe" if $char eq "|"; - return $char; -} sub plugin { my ($input) = @_; diff --git a/cataloguing/value_builder/unimarc_field_110.pl b/cataloguing/value_builder/unimarc_field_110.pl index a2a866bc6b..1c567c1be6 100755 --- a/cataloguing/value_builder/unimarc_field_110.pl +++ b/cataloguing/value_builder/unimarc_field_110.pl @@ -20,6 +20,8 @@ use strict; #use warnings; FIXME - Bug 2505 + +use Koha::Util::FrameworkPlugin qw(wrapper); use C4::Auth; use CGI; use C4::Context; @@ -63,12 +65,6 @@ sub plugin_javascript { return ($field_number,$res); } -sub wrapper { - my ($char) = @_; - return "space" if $char eq " "; - return "pipe" if $char eq "|"; - return $char; -} sub plugin { my ($input) = @_; diff --git a/cataloguing/value_builder/unimarc_field_115a.pl b/cataloguing/value_builder/unimarc_field_115a.pl index dda2e917e2..8075ae5ea9 100755 --- a/cataloguing/value_builder/unimarc_field_115a.pl +++ b/cataloguing/value_builder/unimarc_field_115a.pl @@ -20,6 +20,8 @@ use strict; #use warnings; FIXME - Bug 2505 + +use Koha::Util::FrameworkPlugin qw(wrapper); use C4::Auth; use CGI; use C4::Context; @@ -69,12 +71,6 @@ sub plugin_javascript { return ( $field_number, $res ); } -sub wrapper { - my ($char) = @_; - return "space" if $char eq " "; - return "pipe" if $char eq "|"; - return $char; -} sub plugin { my ($input) = @_; diff --git a/cataloguing/value_builder/unimarc_field_115b.pl b/cataloguing/value_builder/unimarc_field_115b.pl index 32cdfb18b1..fbdde35e4a 100755 --- a/cataloguing/value_builder/unimarc_field_115b.pl +++ b/cataloguing/value_builder/unimarc_field_115b.pl @@ -20,6 +20,8 @@ use strict; #use warnings; FIXME - Bug 2505 + +use Koha::Util::FrameworkPlugin qw(wrapper); use C4::Auth; use CGI; use C4::Context; @@ -63,12 +65,6 @@ function Clic$field_number() { return ( $field_number, $res ); } -sub wrapper { - my ($char) = @_; - return "space" if $char eq " "; - return "pipe" if $char eq "|"; - return $char; -} sub plugin { my ($input) = @_; diff --git a/cataloguing/value_builder/unimarc_field_116.pl b/cataloguing/value_builder/unimarc_field_116.pl index 389ee2108a..a1688747be 100755 --- a/cataloguing/value_builder/unimarc_field_116.pl +++ b/cataloguing/value_builder/unimarc_field_116.pl @@ -20,6 +20,8 @@ use strict; #use warnings; FIXME - Bug 2505 + +use Koha::Util::FrameworkPlugin qw(wrapper); use C4::Auth; use CGI; use C4::Context; @@ -63,14 +65,6 @@ function Clic$field_number(i) { return ( $field_number, $res ); } -sub wrapper { - my ($char) = @_; - return "space" if $char eq " "; - return "dblspace" if $char eq " "; - return "pipe" if $char eq "|"; - return "dblpipe" if $char eq "||"; - return $char; -} sub plugin { my ($input) = @_; diff --git a/cataloguing/value_builder/unimarc_field_117.pl b/cataloguing/value_builder/unimarc_field_117.pl index cc558cf724..6901765a52 100755 --- a/cataloguing/value_builder/unimarc_field_117.pl +++ b/cataloguing/value_builder/unimarc_field_117.pl @@ -20,6 +20,8 @@ use strict; #use warnings; FIXME - Bug 2505 + +use Koha::Util::FrameworkPlugin qw(wrapper); use C4::Auth; use CGI; use C4::Context; @@ -63,14 +65,6 @@ function Clic$field_number(i) { return ($field_number,$res); } -sub wrapper { - my ($char) = @_; - return "space" if $char eq " "; - return "dblspace" if $char eq " "; - return "pipe" if $char eq "|"; - return "dblpipe" if $char eq "||"; - return $char; -} sub plugin { my ($input) = @_; diff --git a/cataloguing/value_builder/unimarc_field_120.pl b/cataloguing/value_builder/unimarc_field_120.pl index 26d9521492..de9beeb0af 100755 --- a/cataloguing/value_builder/unimarc_field_120.pl +++ b/cataloguing/value_builder/unimarc_field_120.pl @@ -20,6 +20,8 @@ use strict; #use warnings; FIXME - Bug 2505 + +use Koha::Util::FrameworkPlugin qw(wrapper); use C4::Auth; use CGI; use C4::Context; @@ -64,13 +66,6 @@ function Clic$function_name(i) { return ($function_name,$res); } -sub wrapper { - my ($char) = @_; - return "space" if $char eq " "; - return "dblspace" if $char eq " "; - return "pipe" if $char eq "|"; - return $char; -} sub plugin { my ($input) = @_; diff --git a/cataloguing/value_builder/unimarc_field_121a.pl b/cataloguing/value_builder/unimarc_field_121a.pl index 9918697faa..359a61d0e4 100755 --- a/cataloguing/value_builder/unimarc_field_121a.pl +++ b/cataloguing/value_builder/unimarc_field_121a.pl @@ -20,6 +20,8 @@ use strict; #use warnings; FIXME - Bug 2505 + +use Koha::Util::FrameworkPlugin qw(wrapper); use C4::Auth; use CGI; use C4::Context; @@ -64,12 +66,6 @@ function Clic$function_name(i) { return ($function_name,$res); } -sub wrapper { - my ($char) = @_; - return "space" if $char eq " "; - return "pipe" if $char eq "|"; - return $char; -} sub plugin { my ($input) = @_; diff --git a/cataloguing/value_builder/unimarc_field_125b.pl b/cataloguing/value_builder/unimarc_field_125b.pl index ea3efcb359..4e73164a8b 100755 --- a/cataloguing/value_builder/unimarc_field_125b.pl +++ b/cataloguing/value_builder/unimarc_field_125b.pl @@ -20,6 +20,8 @@ use strict; #use warnings; FIXME - Bug 2505 + +use Koha::Util::FrameworkPlugin qw(wrapper); use C4::Auth; use CGI; use C4::Context; @@ -61,12 +63,6 @@ function Clic$function_name(i) { return ($function_name,$res); } -sub wrapper { - my ($char) = @_; - return "space" if $char eq " "; - return "pipe" if $char eq "|"; - return $char; -} sub plugin { my ($input) = @_; diff --git a/cataloguing/value_builder/unimarc_field_126a.pl b/cataloguing/value_builder/unimarc_field_126a.pl index 17da533180..1afbba84c6 100755 --- a/cataloguing/value_builder/unimarc_field_126a.pl +++ b/cataloguing/value_builder/unimarc_field_126a.pl @@ -20,6 +20,8 @@ use strict; #use warnings; FIXME - Bug 2505 + +use Koha::Util::FrameworkPlugin qw(wrapper); use C4::Auth; use CGI; use C4::Context; @@ -61,12 +63,6 @@ function Clic$function_name(i) { return ($function_name,$res); } -sub wrapper { - my ($char) = @_; - return "space" if $char eq " "; - return "pipe" if $char eq "|"; - return $char; -} sub plugin { my ($input) = @_; diff --git a/cataloguing/value_builder/unimarc_field_128b.pl b/cataloguing/value_builder/unimarc_field_128b.pl index 94eafa03f3..3f0835b1e8 100755 --- a/cataloguing/value_builder/unimarc_field_128b.pl +++ b/cataloguing/value_builder/unimarc_field_128b.pl @@ -20,6 +20,8 @@ use strict; #use warnings; FIXME - Bug 2505 + +use Koha::Util::FrameworkPlugin qw(wrapper); use C4::Auth; use CGI; use C4::Context; @@ -61,11 +63,6 @@ function Clic$function_name(i) { return ($function_name,$res); } -sub wrapper { - my ($char) = @_; - return "dblpipe" if $char eq "||"; - return $char; -} sub plugin { my ($input) = @_; diff --git a/cataloguing/value_builder/unimarc_field_130.pl b/cataloguing/value_builder/unimarc_field_130.pl index 6441ecdbb5..d6f99fa85c 100755 --- a/cataloguing/value_builder/unimarc_field_130.pl +++ b/cataloguing/value_builder/unimarc_field_130.pl @@ -20,6 +20,8 @@ use strict; #use warnings; FIXME - Bug 2505 + +use Koha::Util::FrameworkPlugin qw(wrapper); use C4::Auth; use CGI; use C4::Context; @@ -62,12 +64,6 @@ function Clic$function_name(i) { return ($function_name,$res); } -sub wrapper { - my ($char) = @_; - return "space" if $char eq " "; - return "pipe" if $char eq "|"; - return $char; -} sub plugin { my ($input) = @_; diff --git a/cataloguing/value_builder/unimarc_field_135a.pl b/cataloguing/value_builder/unimarc_field_135a.pl index fab677ddc7..15c21eeb6b 100755 --- a/cataloguing/value_builder/unimarc_field_135a.pl +++ b/cataloguing/value_builder/unimarc_field_135a.pl @@ -20,6 +20,8 @@ use strict; #use warnings; FIXME - Bug 2505 + +use Koha::Util::FrameworkPlugin qw(wrapper); use C4::Auth; use CGI; use C4::Context; @@ -64,12 +66,6 @@ function Clic$function_name(i) { return ($function_name,$res); } -sub wrapper { - my ($char) = @_; - return "space" if $char eq " "; - return "pipe" if $char eq "|"; - return $char; -} sub plugin { my ($input) = @_; diff --git a/cataloguing/value_builder/unimarc_field_140.pl b/cataloguing/value_builder/unimarc_field_140.pl index 524f0dc881..7d17caf1a7 100755 --- a/cataloguing/value_builder/unimarc_field_140.pl +++ b/cataloguing/value_builder/unimarc_field_140.pl @@ -20,6 +20,8 @@ use strict; #use warnings; FIXME - Bug 2505 + +use Koha::Util::FrameworkPlugin qw(wrapper); use C4::Auth; use CGI; use C4::Context; @@ -64,13 +66,6 @@ function Clic$function_name(i) { return ($function_name,$res); } -sub wrapper { - my ($char) = @_; - return "space" if $char eq " "; - return "dblspace" if $char eq " "; - return "pipe" if $char eq "|"; - return $char; -} sub plugin { my ($input) = @_; diff --git a/cataloguing/value_builder/unimarc_leader.pl b/cataloguing/value_builder/unimarc_leader.pl index 497d9a7959..04457e6b52 100755 --- a/cataloguing/value_builder/unimarc_leader.pl +++ b/cataloguing/value_builder/unimarc_leader.pl @@ -20,6 +20,8 @@ use strict; #use warnings; FIXME - Bug 2505 + +use Koha::Util::FrameworkPlugin qw(wrapper); use C4::Auth; use CGI; use C4::Context; @@ -68,12 +70,6 @@ function Clic$function_name(i) { return ( $function_name, $res ); } -sub wrapper { - my ($char) = @_; - return "space" if $char eq " "; - return "pipe" if $char eq "|"; - return $char; -} sub plugin { my ($input) = @_; -- 2.39.5