--- trunk/lib/WebPAC/Normalize/Set.pm 2006/05/12 14:07:08 460 +++ trunk/lib/WebPAC/Normalize/Set.pm 2006/05/12 14:54:25 461 @@ -2,7 +2,7 @@ use Exporter 'import'; @EXPORT = qw/ set_rec set_lookup - get_ds + get_ds clean_ds tag search display rec1 rec2 rec regex first lookup join_with /; @@ -19,11 +19,11 @@ =head1 VERSION -Version 0.01 +Version 0.02 =cut -our $VERSION = '0.01'; +our $VERSION = '0.02'; =head1 SYNOPSIS @@ -46,14 +46,6 @@ $rec = shift or die "no record hash"; } -=head2 set_lookup - -Set current lookup hash - - set_lookup( $lookup ); - -=cut - =head2 tag Define new tag for output @@ -65,7 +57,6 @@ =cut my $out; -my $type = 'default'; sub tag { my $name = shift or "tag needs name as first argument"; @@ -117,6 +108,26 @@ return $out; } +=head2 clean_ds + +Clean data structure hash for next record + + clean_ds(); + +=cut + +sub clean_ds { + $out = undef; +} + +=head2 set_lookup + +Set current lookup hash + + set_lookup( $lookup ); + +=cut + my $lookup; sub set_lookup { @@ -135,8 +146,13 @@ sub rec1 { my $f = shift; + return unless (defined($rec && $rec->{$f})); if (ref($rec->{$f}) eq 'ARRAY') { - return map { values %{$_} } @{ $rec->{$f} }; + if (ref($rec->{$f}->[0]) eq 'HASH') { + return map { values %{$_} } @{ $rec->{$f} }; + } else { + return @{ $rec->{$f} }; + } } elsif( defined($rec->{$f}) ) { return $rec->{$f}; } @@ -152,6 +168,7 @@ sub rec2 { my $f = shift; + return unless (defined($rec && $rec->{$f})); my $sf = shift; return map { $_->{$sf} } grep { $_->{$sf} } @{ $rec->{$f} }; } @@ -166,7 +183,6 @@ =cut sub rec { - warn "rec arguments: $#_\n"; if ($#_ == 0) { return rec1(@_); } elsif ($#_ == 1) { @@ -187,7 +203,6 @@ my @out; warn "r: $r\n",Dumper(\@_); foreach my $t (@_) { - warn "t: $t\n"; eval "\$t =~ $r"; push @out, $t; }