Fix/marc_add.pm

filter: Statementstmt 100% 22 / 22 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 96.4% 27 / 28 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Fix/marc_set.pm ↑ Summary Importer/MARC/Record.pm »
1 package Catmandu::Fix::marc_add;
2  
3 3 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Catmandu::MARC;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Catmandu::Fix::Has;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 with 'Catmandu::Fix::Inlineable';
9  
10 3 our $VERSION = '1.33';
11  
12 3 has marc_path => (fix_arg => 1);
13 3 has subfields => (fix_arg => 'collect');
14  
15 7 ▶sub fix {
Subroutine fix: called CC=1 SCAR=0.0
Pod undocumented
16 7 my ($self, $data) = @_;
17 7 my $marc_path = $self->marc_path;
18 7 my @subfields = @{$self->subfields};
19  
20 7 return Catmandu::MARC->instance->marc_add($data,$marc_path,@subfields);
21 }
22  
23 =head1 NAME
24  
25 Catmandu::Fix::marc_add - add new fields to marc
26  
27 =head1 SYNOPSIS
28  
29 # Set literal values
30 marc_add('900', a, 'test' , 'b', test)
31 marc_add('900', ind1 , ' ' , a, 'test' , 'b', test)
32 marc_add('900', ind1 , ' ' , a, 'test' , 'b', test)
33  
34 # Set control fields
35 marc_add('009','_','23123131')
36  
37 # Copy data from an other field (when the field value is an array, the
38 # subfield will be repeated)
39 marc_add('900', a, '$.my.data.field')
40  
41 =head1 DESCRIPTION
42  
43 Add a new subfield to MARC record.
44  
45 =head1 METHODS
46  
47 =head2 marc_add(MARC_FIELD, SUBFIELD, VALUE, [ SUBFIELD, VALUE , ... ])
48  
49 Add new subfields to a MARC record. The MARC_FIELD should contain a marc field
50 name, all other arguments contain the subfields to be added.
51  
52 By default literal values will be added. To point to an existing value in
53 a record use the JSON_PATH syntax with a dollar '$.' added in front.
54  
55 =head1 INLINE
56  
57 This Fix can be used inline in a Perl script:
58  
59 use Catmandu::Fix::marc_add as => 'marc_add';
60  
61 my $data = { record => [...] };
62  
63 $data = marc_add($data,'245','a','title');
64  
65 =head1 SEE ALSO
66  
67 L<Catmandu::Fix::marc_set>,
68 L<Catmandu::Fix::marc_copy>,
69 L<Catmandu::Fix::marc_cut>,
70 L<Catmandu::Fix::marc_paste>
71  
72 =cut
73  
74 3 1;
« Fix/marc_set.pm ↑ Summary Importer/MARC/Record.pm »