11 |
|
|
12 |
=head1 VERSION |
=head1 VERSION |
13 |
|
|
14 |
Version 0.01 |
Version 0.03 |
15 |
|
|
16 |
=cut |
=cut |
17 |
|
|
18 |
our $VERSION = '0.01'; |
our $VERSION = '0.03'; |
19 |
|
|
20 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
21 |
|
|
122 |
|
|
123 |
This structures are used to produce output. |
This structures are used to produce output. |
124 |
|
|
125 |
my @ds = $webpac->data_structure($rec); |
my $ds = $webpac->data_structure($rec); |
|
|
|
|
B<Note: historical oddity follows> |
|
|
|
|
|
This method will also set C<< $webpac->{'currnet_filename'} >> if there is |
|
|
C<< <filename> >> tag and C<< $webpac->{'headline'} >> if there is |
|
|
C<< <headline> >> tag. |
|
126 |
|
|
127 |
=cut |
=cut |
128 |
|
|
134 |
my $rec = shift; |
my $rec = shift; |
135 |
$log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o); |
$log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o); |
136 |
|
|
137 |
|
$log->debug("data_structure rec = ", sub { Dumper($rec) }); |
138 |
|
|
139 |
|
$log->logdie("need unique ID (mfn) in field 000 of record ", sub { Dumper($rec) } ) unless (defined($rec->{'000'})); |
140 |
|
|
141 |
|
my $mfn = $rec->{'000'}->[0] || $log->logdie("field 000 isn't array!"); |
142 |
|
|
143 |
my $cache_file; |
my $cache_file; |
144 |
|
|
145 |
if ($self->{'db'}) { |
if ($self->{'db'}) { |
146 |
my @ds = $self->{'db'}->load_ds($rec); |
my $ds = $self->{'db'}->load_ds( id => $mfn ); |
147 |
$log->debug("load_ds( rec = ", sub { Dumper($rec) }, ") = ", sub { Dumper(@ds) }); |
$log->debug("load_ds( rec = ", sub { Dumper($rec) }, ") = ", sub { Dumper($ds) }); |
148 |
return @ds if ($#ds > 0); |
return $ds if ($ds); |
149 |
$log->debug("cache miss, creating"); |
$log->debug("cache miss, creating"); |
150 |
} |
} |
151 |
|
|
160 |
$self->{tags_by_order} = \@sorted_tags; |
$self->{tags_by_order} = \@sorted_tags; |
161 |
} |
} |
162 |
|
|
163 |
my @ds; |
my $ds; |
164 |
|
|
165 |
$log->debug("tags: ",sub { join(", ",@sorted_tags) }); |
$log->debug("tags: ",sub { join(", ",@sorted_tags) }); |
166 |
|
|
195 |
@v = map { $self->apply_format($tag->{'format_name'},$tag->{'format_delimiter'},$_) } @v; |
@v = map { $self->apply_format($tag->{'format_name'},$tag->{'format_delimiter'},$_) } @v; |
196 |
} |
} |
197 |
|
|
|
if ($field eq 'filename') { |
|
|
$self->{'current_filename'} = join('',@v); |
|
|
$log->debug("filename: ",$self->{'current_filename'}); |
|
|
} elsif ($field eq 'headline') { |
|
|
$self->{'headline'} .= join('',@v); |
|
|
$log->debug("headline: ",$self->{'headline'}); |
|
|
next; # don't return headline in data_structure! |
|
|
} |
|
|
|
|
198 |
# delimiter will join repeatable fields |
# delimiter will join repeatable fields |
199 |
if ($tag->{'delimiter'}) { |
if ($tag->{'delimiter'}) { |
200 |
@v = ( join($tag->{'delimiter'}, @v) ); |
@v = ( join($tag->{'delimiter'}, @v) ); |
201 |
} |
} |
202 |
|
|
203 |
# default types |
# default types |
204 |
my @types = qw(display swish); |
my @types = qw(display search); |
205 |
# override by type attribute |
# override by type attribute |
206 |
@types = ( $tag->{'type'} ) if ($tag->{'type'}); |
@types = ( $tag->{'type'} ) if ($tag->{'type'}); |
207 |
|
|
234 |
|
|
235 |
# TODO: name_sigular, name_plural |
# TODO: name_sigular, name_plural |
236 |
my $name = $self->{'import_xml'}->{'indexer'}->{$field}->{'name'}; |
my $name = $self->{'import_xml'}->{'indexer'}->{$field}->{'name'}; |
237 |
$row->{'name'} = $name ? $self->_x($name) : $field; |
my $row_name = $name ? $self->_x($name) : $field; |
238 |
|
|
239 |
# post-sort all values in field |
# post-sort all values in field |
240 |
if ($self->{'import_xml'}->{'indexer'}->{$field}->{'sort'}) { |
if ($self->{'import_xml'}->{'indexer'}->{$field}->{'sort'}) { |
241 |
$log->warn("sort at field tag not implemented"); |
$log->warn("sort at field tag not implemented"); |
242 |
} |
} |
243 |
|
|
244 |
push @ds, $row; |
$ds->{$row_name} = $row; |
245 |
|
|
246 |
$log->debug("row $field: ",sub { Dumper($row) }); |
$log->debug("row $field: ",sub { Dumper($row) }); |
247 |
} |
} |
248 |
|
|
249 |
} |
} |
250 |
|
|
|
$log->logdie("there is no current_filename defined! Do you have filename tag in conf/normalize/?.xml") unless ($self->{'current_filename'}); |
|
|
|
|
251 |
$self->{'db'}->save_ds( |
$self->{'db'}->save_ds( |
252 |
ds => \@ds, |
id => $mfn, |
253 |
current_filename => $self->{'current_filename'}, |
ds => $ds, |
|
headline => $self->{'headline'}, |
|
254 |
) if ($self->{'db'}); |
) if ($self->{'db'}); |
255 |
|
|
256 |
$log->debug("ds: ", sub { Dumper(@ds) }); |
$log->debug("ds: ", sub { Dumper($ds) }); |
257 |
|
|
258 |
|
$log->logconfess("data structure returned is not array any more!") if wantarray; |
259 |
|
|
260 |
return @ds; |
return $ds; |
261 |
|
|
262 |
} |
} |
263 |
|
|
668 |
|
|
669 |
=cut |
=cut |
670 |
|
|
671 |
1; # End of WebPAC::DB |
1; # End of WebPAC::Normalize |