1 package Koha
::Plugin
::MarcFieldValues
;
7 use base
qw(Koha::Plugins::Base);
11 name
=> 'MarcFieldValues',
12 author
=> 'M. de Rooy',
13 class => 'Koha::Plugin::MarcFieldValues',
14 description
=> 'Convert MARC fields from plain text',
15 date_authored
=> '2017-08-08',
16 date_updated
=> '2017-08-08',
17 minimum_version
=> '16.11',
18 maximum_version
=> undef,
20 input_format
=> 'MARC field/value pairs in plain text',
32 my ( $class, $args ) = @_;
33 $args->{'metadata'} = $metadata;
34 my $self = $class->SUPER::new
($args);
40 Create string of MARC blobs from plain text lines in the form:
41 field [,ind1|,ind2|,subcode] = value
51 my ( $self, $args ) = @_;
52 # $args->{data} contains text to convert to MARC
54 my @records = split /\r?\n\r?\n/, $args->{data
};
55 foreach my $rec ( @records ) {
56 my @lines = split /\r?\n/, $rec;
57 my $marc = MARC
::Record
->new;
60 foreach my $line ( @lines ) {
61 # each line is of the form field [,ind1|,ind2|,subcode] = value
62 my @temp = split /\s*=\s*/, $line, 2;
67 @temp = split /\s*,\s*/, $temp[0];
68 if( @temp > 1 && $temp[1] =~ /ind[12]/ ) {
69 $inds->{$temp[0]}->{$temp[1]} = substr($value, 0, 1);
73 $marc->append_fields( MARC
::Field
->new(
77 : ( ( $inds->{$temp[0]} ?
$inds->{$temp[0]}->{ind1
} // '' : '', $inds->{$temp[0]} ?
$inds->{$temp[0]}->{ind2
} // '' : ''), substr( $temp[1], 0, 1 ) ),
81 $retval .= $marc->as_usmarc if $fldcount;