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 |
|
|
275 |
|
|
276 |
Those functions generally have to first in your normalization file. |
Those functions generally have to first in your normalization file. |
277 |
|
|
278 |
|
=head2 to |
279 |
|
|
280 |
|
Generic way to set values for some name |
281 |
|
|
282 |
|
to('field-name', 'name-value' => rec('200','a') ); |
283 |
|
|
284 |
|
There are many helpers defined below which might be easier to use. |
285 |
|
|
286 |
|
=cut |
287 |
|
|
288 |
|
sub to { |
289 |
|
my $type = shift or confess "need type -- BUG?"; |
290 |
|
my $name = shift or confess "needs name as first argument"; |
291 |
|
my @o = grep { defined($_) && $_ ne '' } @_; |
292 |
|
return unless (@o); |
293 |
|
$out->{$name}->{$type} = \@o; |
294 |
|
} |
295 |
|
|
296 |
=head2 search_display |
=head2 search_display |
297 |
|
|
298 |
Define output for L<search> and L<display> at the same time |
Define output for L<search> and L<display> at the same time |
299 |
|
|
300 |
search_display('Title', rec('200','a') ); |
search_display('Title', rec('200','a') ); |
301 |
|
|
|
|
|
302 |
=cut |
=cut |
303 |
|
|
304 |
sub search_display { |
sub search_display { |
311 |
|
|
312 |
=head2 tag |
=head2 tag |
313 |
|
|
314 |
Old name for L<search_display>, but supported |
Old name for L<search_display>, it will probably be removed at one point. |
315 |
|
|
316 |
=cut |
=cut |
317 |
|
|
327 |
|
|
328 |
=cut |
=cut |
329 |
|
|
330 |
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', @_ ) } |
|
331 |
|
|
332 |
=head2 search |
=head2 search |
333 |
|
|
337 |
|
|
338 |
=cut |
=cut |
339 |
|
|
340 |
sub search { _field( 'search', @_ ) } |
sub search { to( 'search', @_ ) } |
341 |
|
|
342 |
=head2 sorted |
=head2 sorted |
343 |
|
|
347 |
|
|
348 |
=cut |
=cut |
349 |
|
|
350 |
sub sorted { _field( 'sorted', @_ ) } |
sub sorted { to( 'sorted', @_ ) } |
351 |
|
|
352 |
|
=head2 row |
353 |
|
|
354 |
|
Insert new row of data into output module |
355 |
|
|
356 |
|
row( column => 'foo', column2 => 'bar' ); |
357 |
|
|
358 |
|
=cut |
359 |
|
|
360 |
|
use Data::Dump qw/dump/; |
361 |
|
|
362 |
|
sub row { |
363 |
|
die "array doesn't have odd number of elements but $#_: ",dump( @_ ) if $#_ % 2 == 1; |
364 |
|
my $table = shift @_; |
365 |
|
push @{ $out->{'_rows'}->{$table} }, {@_}; |
366 |
|
} |
367 |
|
|
368 |
|
|
369 |
=head1 Functions to extract data from input |
=head1 Functions to extract data from input |
385 |
|
|
386 |
warn "## _pack_subfields_hash( ",dump(@_), " )\n" if ($debug > 1); |
warn "## _pack_subfields_hash( ",dump(@_), " )\n" if ($debug > 1); |
387 |
|
|
388 |
my ($h,$include_subfields) = @_; |
my ($hash,$include_subfields) = @_; |
389 |
|
|
390 |
# sanity and ease of use |
# sanity and ease of use |
391 |
return $h if (ref($h) ne 'HASH'); |
return $hash if (ref($hash) ne 'HASH'); |
392 |
|
|
393 |
|
my $h = dclone( $hash ); |
394 |
|
|
395 |
if ( defined($h->{subfields}) ) { |
if ( defined($h->{subfields}) ) { |
396 |
my $sfs = delete $h->{subfields} || die "no subfields?"; |
my $sfs = delete $h->{subfields} || die "no subfields?"; |
481 |
} else { |
} else { |
482 |
$_->{$sf}; |
$_->{$sf}; |
483 |
} |
} |
484 |
} grep { ref($_) eq 'HASH' && $_->{$sf} } @{ $rec->{$f} }; |
} grep { ref($_) eq 'HASH' && defined $_->{$sf} } @{ $rec->{$f} }; |
485 |
} |
} |
486 |
|
|
487 |
=head2 rec |
=head2 rec |
950 |
return @_ . ''; |
return @_ . ''; |
951 |
} |
} |
952 |
|
|
953 |
|
=head2 rec_array |
954 |
|
|
955 |
|
Always return field as array |
956 |
|
|
957 |
|
foreach my $d ( rec_array('field') { |
958 |
|
warn $d; |
959 |
|
} |
960 |
|
|
961 |
|
=cut |
962 |
|
|
963 |
|
sub rec_array { |
964 |
|
my $d = $rec->{ $_[0] }; |
965 |
|
return @$d if ref($d) eq 'ARRAY'; |
966 |
|
return ($d); |
967 |
|
} |
968 |
|
|
969 |
# END |
# END |
970 |
1; |
1; |