Skip to content

Commit

Permalink
Merge aad98f9 into a1cf140
Browse files Browse the repository at this point in the history
  • Loading branch information
cKlee committed Apr 6, 2017
2 parents a1cf140 + aad98f9 commit 1eb70e1
Show file tree
Hide file tree
Showing 8 changed files with 1,002 additions and 288 deletions.
3 changes: 1 addition & 2 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ requires 'MARC::File::MiJ' , '0.04';
requires 'MARC::Record', '2.0.6';
requires 'MARC::Lint', '0';
requires 'MARC::Parser::RAW', '0';
requires 'Const::Fast', '0.014';
requires 'MARC::Spec', '0.1.1';
requires 'MARC::Spec', '0.1.4';
requires 'Memoize', '0';
requires 'Moo', '1.0';
requires 'MooX::Singleton', '0';
66 changes: 52 additions & 14 deletions lib/Catmandu/Fix/marc_spec.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ with 'Catmandu::Fix::Base';

our $VERSION = '1.09';

has spec => ( fix_arg => 1 );
has path => ( fix_arg => 1 );
has split => ( fix_opt => 1 );
has join => ( fix_opt => 1 );
has value => ( fix_opt => 1 );
has pluck => ( fix_opt => 1 );
has invert => ( fix_opt => 1 );
has spec => ( fix_arg=> 1 );
has path => ( fix_arg=> 1 );
has split => ( fix_opt=> 1 );
has join => ( fix_opt=> 1 );
has value => ( fix_opt=> 1 );
has pluck => ( fix_opt=> 1 );
has invert => ( fix_opt=> 1 );
has nested_arrays => (fix_opt => 1);

sub emit {
my ( $self, $fixer ) = @_;
Expand All @@ -31,6 +32,7 @@ sub emit {
'-join' => $self->join // '' ,
'-split' => $self->split // 0 ,
'-pluck' => $self->pluck // 0 ,
'-nested_arrays' => $self->nested_arrays // 0 ,
'-invert' => $self->invert // 0 ,
'-value' => $self->value ,
'-force_array' => ($key =~ /^(\$.*|\d+)$/) ? 1 : 0
Expand Down Expand Up @@ -159,6 +161,10 @@ In a fix file e.g. 'my.fix':
# Assign values of of all other subfields than a of field 020
# to my.isbn.other.subfields
marc_spec('020$a' my.isbn.other.subfields, invert:1)
# Assign value of subfield a of field 245 only, if subfield a of field 246
# with value 1 for indicator1 exists
marc_spec('245$a{246_1$a}', my.var.title)
And then on command line:
Expand All @@ -182,7 +188,7 @@ for documentation on the path syntax.
=head1 METHODS
=head2 marc_spec(Str, Str, Str, ...)
=head2 marc_spec(MARCspec, JSON_PATH, OPT:VAL, OPT2:VAL,...)
First parameter must be a string, following the syntax of
L<MARCspec - A common MARC record path language|http://marcspec.github.io/MARCspec/>.
Expand All @@ -194,7 +200,8 @@ to assign referenced values to
You may use one of $first, $last, $prepend or $append to add
referenced data values to a specific position of an array
(see L<Catmandu Wildcards|http://librecat.org/Catmandu/#wildcards>).
(see L<Catmandu Wildcards|http://librecat.org/Catmandu/#wildcards> and
mapping rules at L<https://github.com/LibreCat/Catmandu-MARC/wiki/Mapping-rules>).
# INPUT
[245,1,0,"a","Cross-platform Perl /","c","Eric F. Johnson."]
Expand Down Expand Up @@ -240,6 +247,37 @@ an array element.
}
}
See split mapping rules at L<https://github.com/LibreCat/Catmandu-MARC/wiki/Mapping-rules>.
=head2 nested_arrays: 0|1
Using the nested_array
option the output will be an array of array of strings (one array item for
each matched field, one array of strings for each matched subfield).
# INPUT
[650," ",0,"a","Perl (Computer program language)"],
[650," ",0,"a","Web servers."]
# CALL
marc_spec('650', my.subjects, nested_arrays:1)
# OUTPUT
{
my {
subjects [
[0] [
[0] "Perl (Computer program language)"
]
[1] [
[0] "Web servers."
]
]
}
}
See nested_array mapping rules at L<https://github.com/LibreCat/Catmandu-MARC/wiki/Mapping-rules>.
=head2 join: Str
Expand Down Expand Up @@ -337,6 +375,8 @@ last pattern for every subfield. E.g.
# references all but not the last two characters of first subfield a
marc_spec('020$a[0]/#-1' my.other.subfields, invert:1)
Invert will not work with subspecs.
=head1 INLINE
This Fix can be used inline in a Perl script:
Expand All @@ -349,12 +389,10 @@ This Fix can be used inline in a Perl script:
print $data->{title} , "\n";
=head1 BUGS AND LIMITATIONS
This version of is agnostic of Subspecs as described in L<MARCspec - A common MARC record path language|http://marcspec.github.io/MARCspec/>.
Later versions will include this feature.
=head1 SEE ALSO
Please report any bugs to L<https://github.com/cKlee/Catmandu-Fix-marc_spec/issues>.
L<Catmandu::Fix>
L<Catmandu::Fix::marc_map>
=head1 AUTHOR
Expand Down
Loading

0 comments on commit 1eb70e1

Please sign in to comment.