Bug 17461: Warn about plugins that can't be loaded
[koha.git] / Koha / RecordProcessor.pm
index 3d4e1bf..1f93571 100644 (file)
@@ -4,18 +4,18 @@ package Koha::RecordProcessor;
 #
 # 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 2 of the License, or (at your option) any later
-# version.
+# 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.
+# 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.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 =head1 NAME
 
@@ -57,8 +57,8 @@ clone it I<prior> to passing it off to the RecordProcessor.
 
 =cut
 
-use strict;
-use warnings;
+use Modern::Perl;
+
 use Module::Load::Conditional qw(can_load);
 use Module::Pluggable::Object;
 
@@ -90,21 +90,27 @@ Koha::Filter::${schema} namespace, as only the filter name, and
 
 =cut
 sub new {
+
     my $class = shift;
     my $param = shift;
 
 
-    my $schema = $param->{schema} || 'MARC';
+    my $schema  = $param->{schema}  || 'MARC';
     my $options = $param->{options} || '';
+
+    my $req_filters = ( ref($param->{filters}) ne 'ARRAY' )
+                        ? [ $param->{filters} ]
+                        :   $param->{filters};
     my @filters = ( );
 
-    foreach my $filter ($param->{filters}) {
-        next unless $filter;
-        my $filter_module = $filter =~ m/:/ ? $filter : "Koha::Filter::${schema}::${filter}";
+    foreach my $filter_name (@{ $req_filters }) {
+        next unless $filter_name;
+        # Fully qualify the module name.
+        my $filter_module = $filter_name =~ m/:/ ? $filter_name : "Koha::Filter::${schema}::${filter_name}";
         if (can_load( modules => { $filter_module => undef } )) {
-            my $object = $filter_module->new();
-            $filter_module->initialize($param);
-            push @filters, $object;
+            my $filter = $filter_module->new();
+            $filter->initialize($param);
+            push @filters, $filter;
         }
     }
 
@@ -146,14 +152,12 @@ sub process {
 
     return unless defined $record;
 
-    my $newrecord = $record;
-
     foreach my $filterobj (@{$self->filters}) {
         next unless $filterobj;
-        $newrecord = $filterobj->filter($newrecord);
+        $filterobj->filter($record);
     }
 
-    return $newrecord;
+    return $record;
 }
 
 sub DESTROY {