ARK/Update.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 8 Conditioncond n/a Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 45 CC 5 SCAR 30.9
CC
5
Cov
0%
action
30.0
BEGIN
2.0
BEGIN
2.0
CRAP 22.0
1 package Koha::Contrib::ARK::Update;
2 # ABSTRACT: Update Koha ARK fields
3 $Koha::Contrib::ARK::Update::VERSION = '1.0.3';
4  
5 use Moose;
6  
7 with 'Koha::Contrib::ARK::Action';
8  
9 use Modern::Perl;
10  
11  
12  
13 sub action {
14 my ($self, $biblionumber, $record) = @_;
15  
16 my $a = $self->ark->c->{ark};
17 my $ark = $self->ark->build_ark($biblionumber, $record);
18 my $kfield = $a->{koha}->{ark};
19 if ( $kfield->{letter} ) { # datafield
20 if ( my $field = $record->field($kfield->{tag}) ) {
21 my @subf = grep {
22 my $keep = $_->[0] ne $kfield->{letter};
23 $self->ark->what_append('remove_existing') unless $keep;
24 $keep;
25 } @{$field->subf};
26 push @subf, [ $kfield->{letter} => $ark ];
27 $field->subf( \@subf );
28 }
29 else {
30 $record->append( MARC::Moose::Field::Std->new(
31 tag => $kfield->{tag}, subf => [ [ $kfield->{letter} => $ark ] ] ) );
32 }
33 }
34 else {
35 if ( $record->field($kfield->{tag}) ) {
36 $record->delete($kfield->{tag});
37 $self->ark->what_append('remove_existing');
38 }
39 $record->append( MARC::Moose::Field::Control->new(
40 tag => $kfield->{tag},
41 value => $ark ) );
42 }
43 $self->ark->what_append('add');
44 }
45  
46  
47 __PACKAGE__->meta->make_immutable;
48 1;
49  
50 __END__
51  
52 =pod
53  
54 =encoding UTF-8
55  
56 =head1 NAME
57  
58 Koha::Contrib::ARK::Update - Update Koha ARK fields
59  
60 =head1 VERSION
61  
62 version 1.0.3
63  
64 =head1 AUTHOR
65  
66 Frédéric Demians <f.demians@tamil.fr>
67  
68 =head1 COPYRIGHT AND LICENSE
69  
70 This software is Copyright (c) 2018 by Fréderic Demians.
71  
72 This is free software, licensed under:
73  
74 The GNU General Public License, Version 3, June 2007
75  
76 =cut