11 |
|
|
12 |
=head1 VERSION |
=head1 VERSION |
13 |
|
|
14 |
Version 0.06 |
Version 0.08 |
15 |
|
|
16 |
=cut |
=cut |
17 |
|
|
18 |
our $VERSION = '0.06'; |
our $VERSION = '0.08'; |
19 |
|
|
20 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
21 |
|
|
123 |
|
|
124 |
$log->debug("using lookup regex: ", $self->{lookup_regex}) if ($r && $l); |
$log->debug("using lookup regex: ", $self->{lookup_regex}) if ($r && $l); |
125 |
|
|
126 |
if ($self->{filter} && ! $self->{filter}->{regex}) { |
if (! $self->{filter} || ! $self->{filter}->{regex}) { |
127 |
$log->debug("adding built-in filter regex"); |
$log->debug("adding built-in filter regex"); |
128 |
$self->{filter}->{regex} = sub { |
$self->{filter}->{regex} = sub { |
129 |
my ($val, $regex) = @_; |
my ($val, $regex) = @_; |
157 |
|
|
158 |
$log->debug("data_structure rec = ", sub { Dumper($rec) }); |
$log->debug("data_structure rec = ", sub { Dumper($rec) }); |
159 |
|
|
160 |
$log->logdie("need unique ID (mfn) in field 000 of record ", sub { Dumper($rec) } ) unless (defined($rec->{'000'})); |
$log->logdie("need unique ID (mfn) in field 000 of record " . Dumper($rec) ) unless (defined($rec->{'000'})); |
161 |
|
|
162 |
my $id = $rec->{'000'}->[0] || $log->logdie("field 000 isn't array!"); |
my $id = $rec->{'000'}->[0] || $log->logdie("field 000 isn't array!"); |
163 |
|
|
327 |
# remove filter{...} from beginning |
# remove filter{...} from beginning |
328 |
$filter_name = $1 if ($format =~ s/^filter{([^}]+)}//s); |
$filter_name = $1 if ($format =~ s/^filter{([^}]+)}//s); |
329 |
|
|
330 |
|
# did we found any (att all) field from format in row? |
331 |
|
my $found_any = 0; |
332 |
|
# prefix before first field which we preserve it $found_any |
333 |
my $prefix; |
my $prefix; |
334 |
my $all_found=0; |
|
335 |
|
my $f_step = 1; |
336 |
|
|
337 |
while ($format =~ s/^(.*?)(v|s)(\d+)(?:\^(\w))?//s) { |
while ($format =~ s/^(.*?)(v|s)(\d+)(?:\^(\w))?//s) { |
338 |
|
|
339 |
my $del = $1 || ''; |
my $del = $1 || ''; |
340 |
$prefix ||= $del if ($all_found == 0); |
$prefix = $del if ($f_step == 1); |
341 |
|
|
342 |
# repeatable index |
# repeatable index |
343 |
my $r = $i; |
my $r = $i; |
347 |
my $tmp = $self->get_data(\$rec,$3,$4,$r,\$found); |
my $tmp = $self->get_data(\$rec,$3,$4,$r,\$found); |
348 |
|
|
349 |
if ($found) { |
if ($found) { |
350 |
push @out, $del; |
$found_any += $found; |
351 |
|
|
352 |
|
# we will skip delimiter before first occurence of field! |
353 |
|
push @out, $del unless($found_any == 1); |
354 |
push @out, $tmp; |
push @out, $tmp; |
|
$all_found += $found; |
|
355 |
} |
} |
356 |
|
$f_step++; |
357 |
} |
} |
358 |
|
|
359 |
return if (! $all_found); |
return if (! $found_any); |
360 |
|
|
361 |
my $out = join('',@out); |
my $out = join('',@out); |
362 |
|
|
470 |
} |
} |
471 |
|
|
472 |
my $found = 0; |
my $found = 0; |
473 |
|
my $just_single = 1; |
474 |
|
|
475 |
my $eval_code; |
my $eval_code; |
476 |
# remove eval{...} from beginning |
# remove eval{...} from beginning |
482 |
|
|
483 |
# do actual replacement of placeholders |
# do actual replacement of placeholders |
484 |
# repeatable fields |
# repeatable fields |
485 |
$format =~ s/v(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,$i,\$found)/ges; |
if ($format =~ s/v(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,$i,\$found)/ges) { |
486 |
|
$just_single = 0; |
487 |
|
} |
488 |
|
|
489 |
# non-repeatable fields |
# non-repeatable fields |
490 |
$format =~ s/s(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,0,\$found)/ges; |
if ($format =~ s/s(\d+)(?:\^(\w))?/$self->get_data(\$rec,$1,$2,0,\$found)/ges) { |
491 |
|
return if ($i > 0 && $just_single); |
492 |
|
} |
493 |
|
|
494 |
if ($found) { |
if ($found) { |
495 |
$log->debug("format: $format"); |
$log->debug("format: $format"); |