| 1 | package Koha::Contrib::ARK::Clear; | ||
| 2 | # ABSTRACT: Clear Koha ARK field | ||
| 3 | $Koha::Contrib::ARK::Clear::VERSION = '1.0.5'; | ||
| 4 | use Moose; | ||
| 5 | use Modern::Perl; | ||
| 6 | |||
| 7 | with 'Koha::Contrib::ARK::Action'; | ||
| 8 | |||
| 9 | |||
| 10 | sub action { | ||
| 11 | my ($self, $biblionumber, $record) = @_; | ||
| 12 | |||
| 13 | return unless $record; | ||
| 14 | |||
| 15 | my $ark = $self->ark; | ||
| 16 | my $ka = $ark->c->{ark}->{koha}->{ark}; | ||
| 17 | my ($tag, $letter) = ($ka->{tag}, $ka->{letter}); | ||
| 18 | |||
| 19 | my $more = $ka->{tag}; | ||
| 20 | $more .= '$' . $ka->{letter} if $ka->{letter}; | ||
| 21 | $self->ark->what_append('clear', $more); | ||
| 22 | if ( $letter ) { | ||
| 23 | for my $field ( $record->field($tag) ) { | ||
| 24 | my @subf = grep { | ||
| 25 | my $keep = $_->[0] ne $letter; | ||
| 26 | $keep; | ||
| 27 | } @{$field->subf}; | ||
| 28 | $field->subf( \@subf ); | ||
| 29 | } | ||
| 30 | $record->fields( [ grep { | ||
| 31 | $_->tag eq $tag && @{$_->subf} == 0 ? 0 : 1; | ||
| 32 | } @{ $record->fields } ] ); | ||
| 33 | } | ||
| 34 | else { | ||
| 35 | $record->delete($tag); | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | |||
| 40 | __PACKAGE__->meta->make_immutable; | ||
| 41 | 1; | ||
| 42 | |||
| 43 | __END__ | ||
| 44 | |||
| 45 | =pod | ||
| 46 | |||
| 47 | =encoding UTF-8 | ||
| 48 | |||
| 49 | =head1 NAME | ||
| 50 | |||
| 51 | Koha::Contrib::ARK::Clear - Clear Koha ARK field | ||
| 52 | |||
| 53 | =head1 VERSION | ||
| 54 | |||
| 55 | version 1.0.5 | ||
| 56 | |||
| 57 | =head1 AUTHOR | ||
| 58 | |||
| 59 | Frédéric Demians <f.demians@tamil.fr> | ||
| 60 | |||
| 61 | =head1 COPYRIGHT AND LICENSE | ||
| 62 | |||
| 63 | This software is Copyright (c) 2020 by Fréderic Demians. | ||
| 64 | |||
| 65 | This is free software, licensed under: | ||
| 66 | |||
| 67 | The GNU General Public License, Version 3, June 2007 | ||
| 68 | |||
| 69 | =cut |