# Copyright 2009 Kyle M. Hall <kyle.m.hall@gmail.com>
-use Modern::Perl;
-
-#use MARC::Record;
-
-require Exporter;
-
-our @ISA = qw(Exporter);
-our %EXPORT_TAGS = ( 'all' => [ qw(
-
-) ] );
+# 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>.
-our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
-
-our @EXPORT = qw(
- read_field
- add_field
- update_field
- copy_field
- copy_and_replace_field
- move_field
- delete_field
- field_exists
- field_equals
-);
+use Modern::Perl;
-our $debug = 0;
+our (@ISA, @EXPORT_OK);
+BEGIN {
+ require Exporter;
+ our @ISA = qw(Exporter);
+
+ @EXPORT_OK = qw(
+ read_field
+ add_field
+ update_field
+ copy_field
+ copy_and_replace_field
+ move_field
+ delete_field
+ field_exists
+ field_equals
+ );
+}
=head1 NAME
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,
if ( ! ( $record && $fieldName ) ) { return; }
- if ( not $subfieldName or $subfieldName eq '' ) {
+ if ( not defined $subfieldName or $subfieldName eq '' ) {
# FIXME I'm not sure the actual implementation is correct.
die "This action is not implemented yet";
#_update_field({ record => $record, field => $fieldName, values => \@values });
my $subfieldName = $params->{subfield};
my $field_numbers = $params->{field_numbers} // [];
- if ( not $subfieldName or $subfieldName eq '' ) {
+ if ( not defined $subfieldName or $subfieldName eq '' ) {
_read_field({ record => $record, field => $fieldName, field_numbers => $field_numbers });
} else {
_read_subfield({ record => $record, field => $fieldName, subfield => $subfieldName, field_numbers => $field_numbers });
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,
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 });
foreach my $field ( @fields ) {
$field->delete_subfield( code => $subfieldName );
+ $record->delete_field( $field ) unless $field->subfields();
}
}
my $regex = $params->{regex};
if ( $regex and $regex->{search} ) {
+ my $replace = $regex->{replace};
+ $replace =~ s/"/\\"/g; # Protection from embedded code
+ $replace = '"' . $replace . '"'; # Put in a string for /ee
$regex->{modifiers} //= q||;
my @available_modifiers = qw( i g );
my $modifiers = q||;
}
foreach my $value ( @$values ) {
if ( $modifiers =~ m/^(ig|gi)$/ ) {
- $value =~ s/$regex->{search}/$regex->{replace}/ig;
+ $value =~ s/$regex->{search}/$replace/igee;
}
elsif ( $modifiers eq 'i' ) {
- $value =~ s/$regex->{search}/$regex->{replace}/i;
+ $value =~ s/$regex->{search}/$replace/iee;
}
elsif ( $modifiers eq 'g' ) {
- $value =~ s/$regex->{search}/$regex->{replace}/g;
+ $value =~ s/$regex->{search}/$replace/gee;
}
else {
- $value =~ s/$regex->{search}/$regex->{replace}/;
+ $value =~ s/$regex->{search}/$replace/ee;
}
}
}