7 |
_debug |
_debug |
8 |
_pack_subfields_hash |
_pack_subfields_hash |
9 |
|
|
10 |
|
to |
11 |
search_display search display sorted |
search_display search display sorted |
12 |
|
|
13 |
rec1 rec2 rec |
rec1 rec2 rec |
21 |
get set |
get set |
22 |
count |
count |
23 |
|
|
24 |
|
row |
25 |
|
rec_array |
26 |
|
|
27 |
/; |
/; |
28 |
|
|
29 |
use warnings; |
use warnings; |
50 |
marc_template |
marc_template |
51 |
/); |
/); |
52 |
|
|
53 |
|
use Storable qw/dclone/; |
54 |
|
|
55 |
=head1 NAME |
=head1 NAME |
56 |
|
|
57 |
WebPAC::Normalize - describe normalisaton rules using sets |
WebPAC::Normalize - describe normalisaton rules using sets |
58 |
|
|
59 |
=cut |
=cut |
60 |
|
|
61 |
our $VERSION = '0.35'; |
our $VERSION = '0.36'; |
62 |
|
|
63 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
64 |
|
|
153 |
|
|
154 |
sub _get_rec { $rec }; |
sub _get_rec { $rec }; |
155 |
|
|
156 |
|
sub rec_array { |
157 |
|
my $d = $rec->{ $_[0] }; |
158 |
|
return @$d if ref($d) eq 'ARRAY'; |
159 |
|
die "field $_[0] not array: ",dump( $d ); |
160 |
|
} |
161 |
|
|
162 |
=head2 _set_config |
=head2 _set_config |
163 |
|
|
164 |
Set current config hash |
Set current config hash |
281 |
|
|
282 |
Those functions generally have to first in your normalization file. |
Those functions generally have to first in your normalization file. |
283 |
|
|
284 |
|
=head2 to |
285 |
|
|
286 |
|
Generic way to set values for some name |
287 |
|
|
288 |
|
to('field-name', 'name-value' => rec('200','a') ); |
289 |
|
|
290 |
|
There are many helpers defined below which might be easier to use. |
291 |
|
|
292 |
|
=cut |
293 |
|
|
294 |
|
sub to { |
295 |
|
my $type = shift or confess "need type -- BUG?"; |
296 |
|
my $name = shift or confess "needs name as first argument"; |
297 |
|
my @o = grep { defined($_) && $_ ne '' } @_; |
298 |
|
return unless (@o); |
299 |
|
$out->{$name}->{$type} = \@o; |
300 |
|
} |
301 |
|
|
302 |
=head2 search_display |
=head2 search_display |
303 |
|
|
304 |
Define output for L<search> and L<display> at the same time |
Define output for L<search> and L<display> at the same time |
305 |
|
|
306 |
search_display('Title', rec('200','a') ); |
search_display('Title', rec('200','a') ); |
307 |
|
|
|
|
|
308 |
=cut |
=cut |
309 |
|
|
310 |
sub search_display { |
sub search_display { |
317 |
|
|
318 |
=head2 tag |
=head2 tag |
319 |
|
|
320 |
Old name for L<search_display>, but supported |
Old name for L<search_display>, it will probably be removed at one point. |
321 |
|
|
322 |
=cut |
=cut |
323 |
|
|
333 |
|
|
334 |
=cut |
=cut |
335 |
|
|
336 |
sub _field { |
sub display { to( 'display', @_ ) } |
|
my $type = shift or confess "need type -- BUG?"; |
|
|
my $name = shift or confess "needs name as first argument"; |
|
|
my @o = grep { defined($_) && $_ ne '' } @_; |
|
|
return unless (@o); |
|
|
$out->{$name}->{$type} = \@o; |
|
|
} |
|
|
|
|
|
sub display { _field( 'display', @_ ) } |
|
337 |
|
|
338 |
=head2 search |
=head2 search |
339 |
|
|
343 |
|
|
344 |
=cut |
=cut |
345 |
|
|
346 |
sub search { _field( 'search', @_ ) } |
sub search { to( 'search', @_ ) } |
347 |
|
|
348 |
=head2 sorted |
=head2 sorted |
349 |
|
|
353 |
|
|
354 |
=cut |
=cut |
355 |
|
|
356 |
sub sorted { _field( 'sorted', @_ ) } |
sub sorted { to( 'sorted', @_ ) } |
357 |
|
|
358 |
|
=head2 row |
359 |
|
|
360 |
|
Insert new row of data into output module |
361 |
|
|
362 |
|
row( column => 'foo', column2 => 'bar' ); |
363 |
|
|
364 |
|
=cut |
365 |
|
|
366 |
|
use Data::Dump qw/dump/; |
367 |
|
|
368 |
|
sub row { |
369 |
|
die "array doesn't have odd number of elements but $#_: ",dump( @_ ) if $#_ % 2 == 1; |
370 |
|
my $table = shift @_; |
371 |
|
push @{ $out->{'_rows'}->{$table} }, {@_}; |
372 |
|
} |
373 |
|
|
374 |
|
|
375 |
=head1 Functions to extract data from input |
=head1 Functions to extract data from input |
391 |
|
|
392 |
warn "## _pack_subfields_hash( ",dump(@_), " )\n" if ($debug > 1); |
warn "## _pack_subfields_hash( ",dump(@_), " )\n" if ($debug > 1); |
393 |
|
|
394 |
my ($h,$include_subfields) = @_; |
my ($hash,$include_subfields) = @_; |
395 |
|
|
396 |
# sanity and ease of use |
# sanity and ease of use |
397 |
return $h if (ref($h) ne 'HASH'); |
return $hash if (ref($hash) ne 'HASH'); |
398 |
|
|
399 |
|
my $h = dclone( $hash ); |
400 |
|
|
401 |
if ( defined($h->{subfields}) ) { |
if ( defined($h->{subfields}) ) { |
402 |
my $sfs = delete $h->{subfields} || die "no subfields?"; |
my $sfs = delete $h->{subfields} || die "no subfields?"; |
487 |
} else { |
} else { |
488 |
$_->{$sf}; |
$_->{$sf}; |
489 |
} |
} |
490 |
} grep { ref($_) eq 'HASH' && $_->{$sf} } @{ $rec->{$f} }; |
} grep { ref($_) eq 'HASH' && defined $_->{$sf} } @{ $rec->{$f} }; |
491 |
} |
} |
492 |
|
|
493 |
=head2 rec |
=head2 rec |