=head1 VERSION
-Version 0.17
+Version 0.18
=cut
-our $VERSION = '0.17';
+our $VERSION = '0.18';
=head1 SYNOPSIS
}
}
-=head2 modify_record_regexps
+=head2 _get_regex
-Generate hash with regexpes to be applied using L<filter>.
+Helper function called which create regexps to be execute on code.
- my $regexpes = $input->modify_record_regexps(
- 900 => { '^a' => { ' : ' => '^b' } },
- 901 => { '*' => { '^b' => ' ; ' } },
- );
+ _get_regex( 900, 'regex:[0-9]+' ,'numbers' );
+ _get_regex( 900, '^b', ' : ^b' );
+
+It supports perl regexps with C<regex:> prefix to from value and has
+additional logic to skip empty subfields.
=cut
$from = '\Q' . $from . '\E';
}
if ($sf =~ /^\^/) {
+ my $need_subfield_data = '*'; # no
+ # if from is also subfield, require some data in between
+ # to correctly skip empty subfields
+ $need_subfield_data = '+' if ($from =~ m/^\\Q\^/);
return
- 's/\Q'. $sf .'\E([^\^]*?)'. $from .'([^\^]*?)/'. $sf .'$1'. $to .'$2/';
+ 's/\Q'. $sf .'\E([^\^]' . $need_subfield_data . '?)'. $from .'([^\^]*?)/'. $sf .'$1'. $to .'$2/';
} else {
return
's/'. $from .'/'. $to .'/g';
}
}
+
+=head2 modify_record_regexps
+
+Generate hash with regexpes to be applied using L<filter>.
+
+ my $regexpes = $input->modify_record_regexps(
+ 900 => { '^a' => { ' : ' => '^b' } },
+ 901 => { '*' => { '^b' => ' ; ' } },
+ );
+
+=cut
+
sub modify_record_regexps {
my $self = shift;
my $modify_record = {@_};
#!/usr/bin/perl -w
-use Test::More tests => 116;
+use Test::More tests => 118;
use Test::Exception;
use Cwd qw/abs_path/;
use blib;
modify_records => {
900 => {
'^a' => { '^e' => ' : ^e' },
- }
+ },
+ 901 => {
+ '^a' => { 'foo' => 'baz' },
+ },
},
), "open (with modify_records for empty subfields)");
'^afoo^ebar',
'^afoo : ^ebar',
);
+
+test_filter(901,
+ '^afoo^ebar',
+ '^abaz^ebar',
+);