r8980@llin: dpavlin | 2005-11-20 00:49:22 +0100
[webpac2] / lib / WebPAC / Normalize.pm
index afcf1c1..1e21425 100644 (file)
@@ -11,11 +11,11 @@ WebPAC::Normalize - data mungling for normalisation
 
 =head1 VERSION
 
-Version 0.01
+Version 0.02
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 
 =head1 SYNOPSIS
 
@@ -122,7 +122,7 @@ C<conf/normalize/*.xml>.
 
 This structures are used to produce output.
 
- my @ds = $webpac->data_structure($rec);
+ my $ds = $webpac->data_structure($rec);
 
 B<Note: historical oddity follows>
 
@@ -143,9 +143,9 @@ sub data_structure {
        my $cache_file;
 
        if ($self->{'db'}) {
-               my @ds = $self->{'db'}->load_ds($rec);
-               $log->debug("load_ds( rec = ", sub { Dumper($rec) }, ") = ", sub { Dumper(@ds) });
-               return @ds if ($#ds > 0);
+               my $ds = $self->{'db'}->load_ds($rec);
+               $log->debug("load_ds( rec = ", sub { Dumper($rec) }, ") = ", sub { Dumper($ds) });
+               return $ds if ($ds);
                $log->debug("cache miss, creating");
        }
 
@@ -160,7 +160,7 @@ sub data_structure {
                $self->{tags_by_order} = \@sorted_tags;
        }
 
-       my @ds;
+       my $ds;
 
        $log->debug("tags: ",sub { join(", ",@sorted_tags) });
 
@@ -243,14 +243,14 @@ sub data_structure {
 
                        # TODO: name_sigular, name_plural
                        my $name = $self->{'import_xml'}->{'indexer'}->{$field}->{'name'};
-                       $row->{'name'} = $name ? $self->_x($name) : $field;
+                       my $row_name = $name ? $self->_x($name) : $field;
 
                        # post-sort all values in field
                        if ($self->{'import_xml'}->{'indexer'}->{$field}->{'sort'}) {
                                $log->warn("sort at field tag not implemented");
                        }
 
-                       push @ds, $row;
+                       $ds->{$row_name} = $row;
 
                        $log->debug("row $field: ",sub { Dumper($row) });
                }
@@ -260,14 +260,16 @@ sub data_structure {
        $log->logdie("there is no current_filename defined! Do you have filename tag in conf/normalize/?.xml") unless ($self->{'current_filename'});
 
        $self->{'db'}->save_ds(
-               ds => \@ds,
+               ds => $ds,
                current_filename => $self->{'current_filename'},
                headline => $self->{'headline'},
        ) if ($self->{'db'});
 
-       $log->debug("ds: ", sub { Dumper(@ds) });
+       $log->debug("ds: ", sub { Dumper($ds) });
 
-       return @ds;
+       $log->logconfess("data structure returned is not array any more!") if wantarray;
+
+       return $ds;
 
 }