16 |
|
|
17 |
=head1 VERSION |
=head1 VERSION |
18 |
|
|
19 |
Version 0.17 |
Version 0.18 |
20 |
|
|
21 |
=cut |
=cut |
22 |
|
|
23 |
our $VERSION = '0.17'; |
our $VERSION = '0.18'; |
24 |
|
|
25 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
26 |
|
|
565 |
} |
} |
566 |
} |
} |
567 |
|
|
568 |
=head2 modify_record_regexps |
=head2 _get_regex |
569 |
|
|
570 |
Generate hash with regexpes to be applied using L<filter>. |
Helper function called which create regexps to be execute on code. |
571 |
|
|
572 |
my $regexpes = $input->modify_record_regexps( |
_get_regex( 900, 'regex:[0-9]+' ,'numbers' ); |
573 |
900 => { '^a' => { ' : ' => '^b' } }, |
_get_regex( 900, '^b', ' : ^b' ); |
574 |
901 => { '*' => { '^b' => ' ; ' } }, |
|
575 |
); |
It supports perl regexps with C<regex:> prefix to from value and has |
576 |
|
additional logic to skip empty subfields. |
577 |
|
|
578 |
=cut |
=cut |
579 |
|
|
590 |
$from = '\Q' . $from . '\E'; |
$from = '\Q' . $from . '\E'; |
591 |
} |
} |
592 |
if ($sf =~ /^\^/) { |
if ($sf =~ /^\^/) { |
593 |
|
my $need_subfield_data = '*'; # no |
594 |
|
# if from is also subfield, require some data in between |
595 |
|
# to correctly skip empty subfields |
596 |
|
$need_subfield_data = '+' if ($from =~ m/^\\Q\^/); |
597 |
return |
return |
598 |
's/\Q'. $sf .'\E([^\^]*?)'. $from .'([^\^]*?)/'. $sf .'$1'. $to .'$2/'; |
's/\Q'. $sf .'\E([^\^]' . $need_subfield_data . '?)'. $from .'([^\^]*?)/'. $sf .'$1'. $to .'$2/'; |
599 |
} else { |
} else { |
600 |
return |
return |
601 |
's/'. $from .'/'. $to .'/g'; |
's/'. $from .'/'. $to .'/g'; |
602 |
} |
} |
603 |
} |
} |
604 |
|
|
605 |
|
|
606 |
|
=head2 modify_record_regexps |
607 |
|
|
608 |
|
Generate hash with regexpes to be applied using L<filter>. |
609 |
|
|
610 |
|
my $regexpes = $input->modify_record_regexps( |
611 |
|
900 => { '^a' => { ' : ' => '^b' } }, |
612 |
|
901 => { '*' => { '^b' => ' ; ' } }, |
613 |
|
); |
614 |
|
|
615 |
|
=cut |
616 |
|
|
617 |
sub modify_record_regexps { |
sub modify_record_regexps { |
618 |
my $self = shift; |
my $self = shift; |
619 |
my $modify_record = {@_}; |
my $modify_record = {@_}; |