Bug 22544: Clarify documentation and change param 'type' to 'location'
[koha-ffzg.git] / Koha / SimpleMARC.pm
index cb92bff..995e392 100644 (file)
@@ -2,6 +2,20 @@ package Koha::SimpleMARC;
 
 # Copyright 2009 Kyle M. Hall <kyle.m.hall@gmail.com>
 
+# 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, see <http://www.gnu.org/licenses>.
+
+
 use Modern::Perl;
 
 #use MARC::Record;
@@ -28,8 +42,6 @@ our @EXPORT = qw(
 );
 
 
-our $debug = 0;
-
 =head1 NAME
 
 SimpleMARC - Perl module for making simple MARC record alterations.
@@ -127,8 +139,8 @@ sub copy_and_replace_field {
     if ( ! ( $record && $fromFieldName && $toFieldName ) ) { return; }
 
 
-    if ( not $fromSubfieldName or $fromSubfieldName eq ''
-      or not $toSubfieldName or $toSubfieldName eq ''
+    if ( !defined $fromSubfieldName or $fromSubfieldName eq ''
+      or !defined $toSubfieldName or $toSubfieldName eq ''
     ) {
         _copy_move_field(
             {   record        => $record,
@@ -466,9 +478,9 @@ sub move_field {
     my $regex = $params->{regex};
     my $field_numbers = $params->{field_numbers} // [];
 
-    if (   not $fromSubfieldName
+    if (   !defined $fromSubfieldName
         or $fromSubfieldName eq ''
-        or not $toSubfieldName
+        or !defined $toSubfieldName
         or $toSubfieldName eq '' ) {
         _copy_move_field(
             {   record        => $record,
@@ -512,7 +524,7 @@ sub delete_field {
     my $subfieldName = $params->{subfield};
     my $field_numbers = $params->{field_numbers} // [];
 
-    if ( not $subfieldName or $subfieldName eq '' ) {
+    if ( !defined $subfieldName or $subfieldName eq '' ) {
         _delete_field({ record => $record, field => $fieldName, field_numbers => $field_numbers });
     } else {
         _delete_subfield({ record => $record, field => $fieldName, subfield => $subfieldName, field_numbers => $field_numbers });
@@ -550,6 +562,7 @@ sub _delete_subfield {
 
     foreach my $field ( @fields ) {
         $field->delete_subfield( code => $subfieldName );
+        $record->delete_field( $field ) unless $field->subfields();
     }
 }