--- trunk/lib/WebPAC/Normalize/Set.pm 2006/05/14 11:06:52 486 +++ trunk/lib/WebPAC/Normalize/Set.pm 2006/05/14 12:35:20 490 @@ -21,11 +21,11 @@ =head1 VERSION -Version 0.03 +Version 0.04 =cut -our $VERSION = '0.03'; +our $VERSION = '0.04'; =head1 SYNOPSIS @@ -42,6 +42,35 @@ =head1 FUNCTIONS +=head2 data_structure + +Return data structure + + my $ds = WebPAC::Normalize::Set( + lookup => $lookup->lookup_hash, + row => $row, + rules => $normalize_pl_config, + ); + +This function will B if normalizastion can't be evaled. + +=cut + +sub data_structure { + my $arg = {@_}; + + die "need row argument" unless ($arg->{row}); + die "need normalisation argument" unless ($arg->{rules}); + + no strict 'subs'; + set_lookup( $arg->{lookup} ); + set_rec( $arg->{row} ); + clean_ds(); + eval "$arg->{rules}"; + die "error evaling $arg->{rules}: $@\n" if ($@); + return get_ds(); +} + =head2 set_rec Set current record hash @@ -158,13 +187,15 @@ sub rec1 { my $f = shift; - return unless (defined($rec && $rec->{$f})); + return unless (defined($rec) && defined($rec->{$f})); if (ref($rec->{$f}) eq 'ARRAY') { - if (ref($rec->{$f}->[0]) eq 'HASH') { - return map { values %{$_} } @{ $rec->{$f} }; - } else { - return @{ $rec->{$f} }; - } + return map { + if (ref($_) eq 'HASH') { + values %{$_}; + } else { + $_; + } + } @{ $rec->{$f} }; } elsif( defined($rec->{$f}) ) { return $rec->{$f}; } @@ -182,7 +213,7 @@ my $f = shift; return unless (defined($rec && $rec->{$f})); my $sf = shift; - return map { $_->{$sf} } grep { $_->{$sf} } @{ $rec->{$f} }; + return map { $_->{$sf} } grep { ref($_) eq 'HASH' && $_->{$sf} } @{ $rec->{$f} }; } =head2 rec