[libcatmandu-marc-perl] 149/208: Fixing semicolons
Jonas Smedegaard
dr at jones.dk
Sat Oct 28 03:42:45 UTC 2017
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag upstream/1.19
in repository libcatmandu-marc-perl.
commit 94386253ffef84928f51cd9b827f9529e755fd6e
Author: Patrick Hochstenbach <patrick.hochstenbach at ugent.be>
Date: Thu Jun 15 09:00:12 2017 +0200
Fixing semicolons
---
Changes | 1 +
lib/Catmandu/MARC.pm | 124 ++++++++++++++++++++++++++-------------------------
2 files changed, 64 insertions(+), 61 deletions(-)
diff --git a/Changes b/Changes
index 2e172de..d14bada 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
Revision history for Catmandu-MARC
{{$NEXT}}
+ - Fixing join subfields per field correctly in marc_spec
1.12 2017-05-29 10:23:23 CEST
- Fixing missing space to caret translation in 008 fields for ALEPHSEQ exports
diff --git a/lib/Catmandu/MARC.pm b/lib/Catmandu/MARC.pm
index 75f63aa..e6ab9c7 100644
--- a/lib/Catmandu/MARC.pm
+++ b/lib/Catmandu/MARC.pm
@@ -381,11 +381,11 @@ sub marc_spec {
my ( $indicator1, $indicator2 );
if ( $field_spec->has_indicator1 ) {
$indicator1 = $field_spec->indicator1;
- $indicator1 = qr/$indicator1/
+ $indicator1 = qr/$indicator1/;
}
if ( $field_spec->has_indicator2 ) {
$indicator2 = $field_spec->indicator2;
- $indicator2 = qr/$indicator2/
+ $indicator2 = qr/$indicator2/;
}
# calculate char start
@@ -395,9 +395,9 @@ sub marc_spec {
if ( $sp->has_char_start ) {
$char_start = ( '#' eq $sp->char_start )
? $sp->char_length * -1
- : $sp->char_start
+ : $sp->char_start;
}
- return $char_start
+ return $char_start;
};
# vars we need only for subfields
@@ -406,7 +406,7 @@ sub marc_spec {
# set the order of subfields
@sf_spec = map { $_ } @{ $ms->subfields };
unless ( $pluck ) {
- @sf_spec = sort { $a->code cmp $b->code } @sf_spec
+ @sf_spec = sort { $a->code cmp $b->code } @sf_spec;
}
# set invert level default
@@ -414,20 +414,20 @@ sub marc_spec {
if ( $invert ) {
$codes = '[^';
$codes .= join $EMPTY, map { $_->code } @sf_spec;
- $codes .= ']'
+ $codes .= ']';
}
$invert_chars = sub {
my ( $str, $start, $length ) = @_;
for ( substr $str, $start, $length ) {
- $_ = $EMPTY
+ $_ = $EMPTY;
}
- return $str
+ return $str;
};
}
else {
# return $value_set ASAP
- return $value_set if defined $value_set
+ return $value_set if defined $value_set;
}
# vars we need for fields and subfields
@@ -440,9 +440,9 @@ sub marc_spec {
my $to_referred = sub {
my ( @values ) = @_;
if($nested_arrays) {
- push @{$referred}, \@values
+ push @{$referred}, \@values;
} elsif($split) {
- push @{$referred}, @values
+ push @{$referred}, @values;
} else {
push @{$referred}, join $join_char, @values;
}
@@ -450,7 +450,7 @@ sub marc_spec {
if( defined $field_spec->index_start ) {
$index_range =
- _get_index_range( $field_spec->index_start, $field_spec->index_end, $#fields )
+ _get_index_range( $field_spec->index_start, $field_spec->index_end, $#fields );
}
# iterate over fields
@@ -464,40 +464,40 @@ sub marc_spec {
# filter by indicator
if( defined $indicator1 ) {
- next unless ( defined $field->[1] && $field->[1] =~ $indicator1)
+ next unless ( defined $field->[1] && $field->[1] =~ $indicator1);
}
if( defined $indicator2 ) {
#next unless $field->[2] =~ $indicator2;
- next unless ( defined $field->[2] && $field->[2] =~ $indicator2)
+ next unless ( defined $field->[2] && $field->[2] =~ $indicator2);
}
# filter by index
if ( defined $index_range ) {
- next unless ( Catmandu::Util::array_includes( $index_range, $tag_index ) )
+ next unless ( Catmandu::Util::array_includes( $index_range, $tag_index ) );
}
# filter field by subspec
if( $field_spec->has_subspecs) {
my $valid = $self->_it_subspecs( $data, $field_spec->tag, $field_spec->subspecs, $tag_index );
- next unless $valid
+ next unless $valid;
}
-
+
my @subfields = ();
-
+
if ( $ms->has_subfields ) { # now we dealing with subfields
for my $sf (@sf_spec) {
# set invert level
if ( $invert && !$sf->has_subspecs) {
if ( -1 == $sf->index_length && !$sf->has_char_start ) {
next if ( $invert_level == 3 ); # skip subfield spec it's already covered
- $invert_level = 3
+ $invert_level = 3;
}
elsif ( $sf->has_char_start ) {
- $invert_level = 1
+ $invert_level = 1;
}
else {
- $invert_level = 2
+ $invert_level = 2;
}
}
@@ -506,7 +506,7 @@ sub marc_spec {
$code = qr/$code/;
for ( my $i = 3 ; $i < @{$field} ; $i += 2 ) {
if ( $field->[$i] =~ /$code/ ) {
- push @subfield, $field->[ $i + 1 ]
+ push @subfield, $field->[ $i + 1 ];
}
}
@@ -516,10 +516,12 @@ sub marc_spec {
}
if ( $referred && $value_set ) { # return $value_set ASAP
- return $value_set
+ return $value_set;
}
- next
+
+ next;
}
+
next unless (@subfield);
# filter by index
@@ -531,18 +533,18 @@ sub marc_spec {
@subfield = map {
Catmandu::Util::array_includes( $sf_range, $_ )
? ()
- : $subfield[$_]
- } 0 .. $#subfield
+ : $subfield[$_];
+ } 0 .. $#subfield;
}
else { # without invert
@subfield =
map {
defined $subfield[$_]
? $subfield[$_]
- : ()
- } @{$sf_range}
+ : ();
+ } @{$sf_range};
}
- next unless (@subfield)
+ next unless (@subfield);
}
# return $value_set ASAP
@@ -551,7 +553,7 @@ sub marc_spec {
# filter subfield by subspec
if( $sf->has_subspecs) {
my $valid = $self->_it_subspecs( $data, $field_spec->tag, $sf->subspecs, $tag_index);
- next unless $valid
+ next unless $valid;
}
# get substring
@@ -560,14 +562,14 @@ sub marc_spec {
if ( $invert_level == 1 ) { # inverted
@subfield =
map {
- $invert_chars->( $_, $char_start, $sf->char_length )
- } @subfield
+ $invert_chars->( $_, $char_start, $sf->char_length );
+ } @subfield;
}
else {
@subfield =
map {
- substr $_, $char_start, $sf->char_length
- } @subfield
+ substr $_, $char_start, $sf->char_length;
+ } @subfield;
}
}
next unless @subfield;
@@ -583,7 +585,7 @@ sub marc_spec {
my $content = ( defined $char_start )
? substr $field->[$i], $char_start, $field_spec->char_length
: $field->[$i];
- push @contents, $content
+ push @contents, $content;
}
next unless (@contents);
$to_referred->(@contents);
@@ -593,12 +595,12 @@ sub marc_spec {
if($append) {
return [$referred] if $split;
- return $referred
+ return $referred;
} elsif($split) {
- return [$referred]
+ return [$referred];
}
- return join $join_char, @{$referred}
+ return join $join_char, @{$referred};
}
sub _it_subspecs {
@@ -609,7 +611,7 @@ sub _it_subspecs {
next if ( ref $subspec->$side eq 'MARC::Spec::Comparisonstring' );
# only set new index if subspec field tag equals spec field tag!!
next unless ( $tag eq $subspec->$side->field->tag );
- $subspec->$side->field->set_index_start_end( $tag_index )
+ $subspec->$side->field->set_index_start_end( $tag_index );
}
};
@@ -620,17 +622,17 @@ sub _it_subspecs {
$set_index->( $or_subspec );
$valid = $self->_validate_subspec( $or_subspec, $data );
# at least one of them is true (OR)
- last if $valid
+ last if $valid;
}
}
else { # repeated SubSpecs (AND)
$set_index->( $subspec );
$valid = $self->_validate_subspec( $subspec, $data );
# all of them have to be true (AND)
- last unless $valid
+ last unless $valid;
}
}
- return $valid
+ return $valid;
}
sub _validate_subspec {
@@ -644,10 +646,10 @@ sub _validate_subspec {
$subspec->left,
{ '-split' => 1 }
); # split should result in an array ref
- return 0 unless defined $left_subterm
+ return 0 unless defined $left_subterm;
}
else {
- push @{$left_subterm}, $subspec->left->comparable
+ push @{$left_subterm}, $subspec->left->comparable;
}
}
@@ -658,77 +660,77 @@ sub _validate_subspec {
{ '-split' => 1 }
); # split should result in an array ref
unless( defined $right_subterm ) {
- $right_subterm = []
+ $right_subterm = [];
}
}
else {
- push @{$right_subterm}, $subspec->right->comparable
+ push @{$right_subterm}, $subspec->right->comparable;
}
if($subspec->operator eq '?') {
- return (@{$right_subterm}) ? 1 : 0
+ return (@{$right_subterm}) ? 1 : 0;
}
if($subspec->operator eq '!') {
- return (@{$right_subterm}) ? 0 : 1
+ return (@{$right_subterm}) ? 0 : 1;
}
if($subspec->operator eq '=') {
foreach my $v ( @{$left_subterm->[0]} ) {
- return 1 if List::Util::any {$v eq $_} @{$right_subterm}
+ return 1 if List::Util::any {$v eq $_} @{$right_subterm};
}
}
if($subspec->operator eq '!=') {
foreach my $v ( @{$left_subterm->[0]} ) {
- return 0 if List::Util::any {$v eq $_} @{$right_subterm}
+ return 0 if List::Util::any {$v eq $_} @{$right_subterm};
}
- return 1
+ return 1;
}
if($subspec->operator eq '~') {
foreach my $v ( @{$left_subterm->[0]} ) {
- return 1 if List::Util::any {$v =~ m?$_?} @{$right_subterm}
+ return 1 if List::Util::any {$v =~ m?$_?} @{$right_subterm};
}
}
if($subspec->operator eq '!~') {
foreach my $v ( @{$left_subterm->[0]} ) {
- return 0 if List::Util::any {$v =~ m?$_?} @{$right_subterm}
+ return 0 if List::Util::any {$v =~ m?$_?} @{$right_subterm};
}
- return 1
+ return 1;
}
- return 0
+ return 0;
}
sub parse_marc_spec {
my ( $self, $marc_spec ) = @_;
- return MARC::Spec::Parser->new( $marc_spec )->marcspec
+ return MARC::Spec::Parser->new( $marc_spec )->marcspec;
}
sub _get_index_range {
my ( $index_start, $index_end, $last_index ) = @_;
if ( '#' eq $index_start ) {
- if ( '#' eq $index_end or 0 == $index_end ) { return [$last_index] }
+ if ( '#' eq $index_end or 0 == $index_end ) { return [$last_index]; }
$index_start = $last_index;
$index_end = $last_index - $index_end;
- if ( 0 > $index_end ) { $index_end = 0 }
+ if ( 0 > $index_end ) { $index_end = 0; }
}
else {
if ( $last_index < $index_start ) {
- return [$index_start]
+ return [$index_start];
} # this will result to no hits
}
if ( '#' eq $index_end or $index_end > $last_index ) {
- $index_end = $last_index
+ $index_end = $last_index;
}
return ( $index_start <= $index_end )
? [ $index_start .. $index_end ]
- : [ $index_end .. $index_start ]
+ : [ $index_end .. $index_start ];
}
sub marc_xml {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatmandu-marc-perl.git
More information about the Pkg-perl-cvs-commits
mailing list