+=head2 RecordsFromMarcPlugin
+
+ Converts text of input_file into array of MARC records with to_marc plugin
+
+=cut
+
+sub RecordsFromMarcPlugin {
+ my ($input_file, $plugin_class, $encoding) = @_;
+ my ( $text, @return );
+ return \@return if !$input_file || !$plugin_class;
+
+ # Read input file
+ open my $fh, '<', $input_file or die "$0: cannot open input file $input_file: $!\n";
+ $/ = "\035";
+ while (<$fh>) {
+ s/^\s+//;
+ s/\s+$//;
+ next unless $_;
+ $text .= $_;
+ }
+ close $fh;
+
+ # Convert to large MARC blob with plugin
+ $text = Koha::Plugins::Handler->run({
+ class => $plugin_class,
+ method => 'to_marc',
+ params => { data => $text },
+ }) if $text;
+
+ # Convert to array of MARC records
+ if( $text ) {
+ my $marc_type = C4::Context->preference('marcflavour');
+ foreach my $blob ( split(/\x1D/, $text) ) {
+ next if $blob =~ /^\s*$/;
+ my ($marcrecord) = MarcToUTF8Record($blob, $marc_type, $encoding);
+ push @return, $marcrecord;
+ }
+ }
+ return \@return;
+}
+