Koha-Contrib-ARK

 view release on metacpan or  search on metacpan

lib/Koha/Contrib/ARK/Clear.pm  view on Meta::CPAN

package Koha::Contrib::ARK::Clear;
# ABSTRACT: Clear Koha ARK field
$Koha::Contrib::ARK::Clear::VERSION = '1.1.2';
use Moose;
use Modern::Perl;

with 'Koha::Contrib::ARK::Action';


sub action {
    my $self = shift;
    my $ark = $self->ark;
    my $current = $ark->current;
    my $biblio = $current->{biblio};
    my $record = $biblio->{record};

    return unless $record;

    my $ka = $ark->c->{ark}->{koha}->{ark};
    my ($tag, $letter) = ($ka->{tag}, $ka->{letter});

    my $more = $ka->{tag};
    $more .= '$' . $ka->{letter} if $ka->{letter};
    $self->ark->what_append('clear', $more);
    if ( $letter ) {
        for my $field ( $record->field($tag) ) {
            my @subf = grep {
                my $keep = $_->[0] ne $letter;
                $keep;
            } @{$field->subf};
            $field->subf( \@subf );
        }
        $record->fields( [ grep {
            $_->tag eq $tag && @{$_->subf} == 0 ? 0 : 1;
        } @{ $record->fields } ] );
    }
    else {
        $record->delete($tag);
    }

    $ark->current_modified();
}


__PACKAGE__->meta->make_immutable;
1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Koha::Contrib::ARK::Clear - Clear Koha ARK field

=head1 VERSION

version 1.1.2

=head1 AUTHOR

Frédéric Demians <f.demians@tamil.fr>



( run in 1.546 second using v1.01-cache-2.11-cpan-5a3173703d6 )