--- trunk/lib/WebPAC/Normalize.pm 2007/11/27 22:31:09 1066 +++ trunk/lib/WebPAC/Normalize.pm 2011/12/15 21:40:37 1367 @@ -21,6 +21,9 @@ get set count + row + rec_array + /; use warnings; @@ -47,6 +50,8 @@ marc_template /); +use Storable qw/dclone/; + =head1 NAME WebPAC::Normalize - describe normalisaton rules using sets @@ -118,7 +123,7 @@ $load_row_coderef = $arg->{load_row_coderef}; no strict 'subs'; - no warnings 'redefine'; + no warnings 'all'; eval "$arg->{rules};"; die "error evaling $arg->{rules}: $@\n" if ($@); @@ -140,7 +145,7 @@ $WebPAC::Normalize::MARC::rec = $rec; } -=head2 +=head2 _get_rec my $rec = _get_rec(); @@ -148,6 +153,14 @@ sub _get_rec { $rec }; +=head2 _set_rec + + _set_rec( $rec ); + +=cut + +sub _set_rec { $rec = $_[0] } + =head2 _set_config Set current config hash @@ -344,6 +357,22 @@ sub sorted { to( 'sorted', @_ ) } +=head2 row + +Insert new row of data into output module + + row( column => 'foo', column2 => 'bar' ); + +=cut + +use Data::Dump qw/dump/; + +sub row { + die "array doesn't have odd number of elements but $#_: ",dump( @_ ) if $#_ % 2 == 1; + my $table = shift @_; + push @{ $out->{'_rows'}->{$table} }, {@_}; +} + =head1 Functions to extract data from input @@ -364,10 +393,12 @@ warn "## _pack_subfields_hash( ",dump(@_), " )\n" if ($debug > 1); - my ($h,$include_subfields) = @_; + my ($hash,$include_subfields) = @_; # sanity and ease of use - return $h if (ref($h) ne 'HASH'); + return $hash if (ref($hash) ne 'HASH'); + + my $h = dclone( $hash ); if ( defined($h->{subfields}) ) { my $sfs = delete $h->{subfields} || die "no subfields?"; @@ -927,5 +958,21 @@ return @_ . ''; } +=head2 rec_array + +Always return field as array + + foreach my $d ( rec_array('field') ) { + warn $d; + } + +=cut + +sub rec_array { + my $d = $rec->{ $_[0] }; + return @$d if ref($d) eq 'ARRAY'; + return ($d); +} + # END 1;