package Koha::Plugin::ToMarcExample; use Modern::Perl; use Encode qw(encode); ## Required for all plugins use base qw(Koha::Plugins::Base); use MARC::Record; use MARC::Batch; use MARC::File::USMARC; ## Here we set our plugin version our $VERSION = 0.01; ## Here is our metadata, some keys are required, some are optional our $metadata = { name => 'to_marc example plugin', author => 'David Gustafsson', description => '', date_authored => '2021-11-30', date_updated => '2021-11-30', minimum_version => '16.05', maximum_version => undef, version => $VERSION, }; ## This is the minimum code required for a plugin's 'new' method ## More can be added, but none should be removed sub new { my ( $class, $args ) = @_; ## We need to add our metadata here so our base class can access it $args->{'metadata'} = $metadata; $args->{'metadata'}->{'class'} = $class; ## Here, we call the 'new' method for our base class ## This runs some additional magic and checking ## and returns our actual $self my $self = $class->SUPER::new($args); return $self; } ## The existiance of a 'to_marc' subroutine means the plugin is capable ## of converting some type of file to MARC for use from the stage records ## for import tool sub to_marc { my ($self, $args) = @_; my $marc_batch; my $fh; { open($fh, "<", \$args->{data}); binmode $fh, ':raw'; $marc_batch = MARC::Batch->new('USMARC', $fh); } my @records; while (my $record = $marc_batch->next()) { my $field = MARC::Field->new('590','','','a' => 'ToMarcExample added field'); $record->append_fields($field); push @records, $record; } close($fh); #? return encode('UTF-8', join('', map { $_->as_usmarc() } @records), 1) || undef; }